void cTerritory::processNode( const cElement* Tag ) { QString TagName( Tag->name() ); QString Value( Tag->value() ); //<guards> // <npc mult="2">npcsection</npc> (mult inserts 2 same sections into the list so the probability rises! // <npc><random list="npcsectionlist" /></npc> // <list id="npcsectionlist" /> //</guards> if ( TagName == "guards" ) { for ( unsigned int i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); if ( childNode->name() == "npc" ) { UI32 mult = childNode->getAttribute( "mult" ).toInt(); if ( mult < 1 ) mult = 1; for ( UI32 i = 0; i < mult; i++ ) this->guardSections_.push_back( childNode->value() ); } else if ( childNode->name() == "list" && childNode->hasAttribute( "id" ) ) { QStringList NpcList = Definitions::instance()->getList( childNode->getAttribute( "id" ) ); QStringList::const_iterator it( NpcList.begin() ); for ( ; it != NpcList.end(); ++it ) this->guardSections_.push_back( *it ); } } } // <guardowner>text</guardowner> else if ( TagName == "guardowner" ) if ( Value == "the town" ) this->guardowner_ = ""; else this->guardowner_ = Value; // <midilist>MIDI_COMBAT</midilist> else if ( TagName == "midilist" ) this->midilist_ = Value; else if ( TagName == "flags" ) { flags_ = 0; for ( unsigned int i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); if ( childNode->name() == "guarded" ) setGuarded( true ); else if ( childNode->name() == "nomark" ) setNoMark( true ); else if ( childNode->name() == "nogate" ) setNoGate( true ); else if ( childNode->name() == "norecallout" ) setNoRecallOut( true ); else if ( childNode->name() == "norecallin" ) setNoRecallIn( true ); else if ( childNode->name() == "recallshield" ) setRecallShield( true ); else if ( childNode->name() == "noagressivemagic" ) setNoAgressiveMagic( true ); else if ( childNode->name() == "antimagic" ) setAntiMagic( true ); else if ( childNode->name() == "escortregion" ) setValidEscortRegion( true ); else if ( childNode->name() == "cave" ) setCave( true ); else if ( childNode->name() == "nomusic" ) setNoMusic( true ); else if ( childNode->name() == "noguardmessage" ) setNoGuardMessage( true ); else if ( childNode->name() == "noentermessage" ) setNoEnterMessage( true ); } } // <snowchance>50</snowchance> else if ( TagName == "snowchance" ) this->snowchance_ = Value.toUShort(); // <rainchance>50</rainchance> else if ( TagName == "rainchance" ) this->rainchance_ = Value.toUShort(); // <tradesystem> // <good num="1"> // <buyable>10</buyable> // <sellable>20</sellable> // <randomvalue min="10" max="20" /> // </good> // <good ...> // ... // </good> // </tradesystem> else if ( TagName == "tradesystem" ) { for ( unsigned int i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); good_st goods; goods.buyable = 0; goods.sellable = 0; goods.rndmin = 0; goods.rndmax = 0; UI32 num = 0xFFFFFFFF; if ( childNode->name() == "good" ) { if ( childNode->hasAttribute( "num" ) ) num = childNode->getAttribute( "num" ).toInt(); for ( unsigned int j = 0; j < childNode->childCount(); ++j ) { const cElement* chchildNode = childNode->getChild( j ); QString childValue = chchildNode->value(); if ( chchildNode->name() == "buyable" ) goods.buyable = childValue.toInt(); else if ( chchildNode->name() == "sellable" ) goods.sellable = childValue.toInt(); else if ( chchildNode->name() == "randomvalue" ) { goods.rndmin = chchildNode->getAttribute( "min" ).toInt(); goods.rndmax = chchildNode->getAttribute( "max" ).toInt(); } } } if ( num != 0xFFFFFFFF ) this->tradesystem_[num] = goods; } } // <region id="Cove Market Place"> // ...region nodes... // </region> else if ( TagName == "region" ) { cTerritory* toinsert_ = new cTerritory( Tag, this ); this->subregions_.push_back( toinsert_ ); } else if ( TagName == "teleport" ) { if ( !Tag->hasAttribute( "source" ) ) { qWarning( "ERROR: processing teleport tag, missing source attribute" ); return; } if ( !Tag->hasAttribute( "destination" ) ) { qWarning( "ERROR: processing teleport tag, missing destination attribute" ); return; } Coord_cl source, destination; if ( !parseCoordinates( Tag->getAttribute( "source" ), source ) ) { qWarning( "ERROR: parsing source attribute, not a valid coordinate vector" ); return; } if ( !parseCoordinates( Tag->getAttribute( "destination" ), destination ) ) { qWarning( "ERROR: parsing destination attribute, not a valid coordinate vector" ); return; } bool bothways = Tag->hasAttribute( "bothways" ); teleporters_st teleporter; teleporter.source = source; teleporter.destination = destination; teleporters.append( teleporter ); if ( bothways ) { teleporter.source = destination; teleporter.destination = source; teleporters.append( teleporter ); } } else cBaseRegion::processNode( Tag ); }
void cTerritory::processNode( const cElement* Tag, uint hash ) { QString TagName( Tag->name() ); QString Value( Tag->value() ); //<guards> // <npc mult="2">npcsection</npc> (mult inserts 2 same sections into the list so the probability rises! // <npc><random list="npcsectionlist" /></npc> // <list id="npcsectionlist" /> //</guards> if ( TagName == "guards" ) { for ( uint i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); if ( childNode->name() == "npc" ) { uint mult = childNode->getAttribute( "mult" ).toInt(); if ( mult < 1 ) mult = 1; for ( uint j = 0; j < mult; j++ ) this->guardSections_.push_back( childNode->value() ); } else if ( childNode->name() == "list" && childNode->hasAttribute( "id" ) ) { QStringList NpcList = Definitions::instance()->getList( childNode->getAttribute( "id" ) ); QStringList::const_iterator it( NpcList.begin() ); for ( ; it != NpcList.end(); ++it ) this->guardSections_.push_back( *it ); } } } // <fixedlight>number</fixedlight> else if ( TagName == "fixedlight" ) this->fixedlight_ = Value.toShort(); // <guardowner>text</guardowner> else if ( TagName == "guardowner" ) if ( Value == "the town" ) this->guardowner_ = ""; else this->guardowner_ = Value; // <resores>ORES</resores> else if ( TagName == "resores" ) this->resores_ = Value; // <firstcoin>IDofCOIN</firstcoin> else if ( TagName == "firstcoin" ) this->firstcoin_ = Value; // <secondcoin>IDofCOIN</secondcoin> else if ( TagName == "secondcoin" ) this->secondcoin_ = Value; // <thirdcoin>IDofCOIN</thirdcoin> else if ( TagName == "thirdcoin" ) this->thirdcoin_ = Value; // <midilist>MIDI_COMBAT</midilist> else if ( TagName == "midilist" ) this->midilist_ = Value; // <extraflags>ExtraFlags</extraflags> else if ( TagName == "extraflags" ) this->extraflags_ = Value.toUShort(); else if ( TagName == "flags" ) { flags_ = 0; for ( unsigned int i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); if ( childNode->name() == "guarded" ) setGuarded( true ); else if ( childNode->name() == "nomark" ) setNoMark( true ); else if ( childNode->name() == "nogate" ) setNoGate( true ); else if ( childNode->name() == "norecallout" ) setNoRecallOut( true ); else if ( childNode->name() == "norecallin" ) setNoRecallIn( true ); else if ( childNode->name() == "recallshield" ) setRecallShield( true ); else if ( childNode->name() == "noagressivemagic" ) setNoAgressiveMagic( true ); else if ( childNode->name() == "antimagic" ) setAntiMagic( true ); else if ( childNode->name() == "escortregion" ) setValidEscortRegion( true ); else if ( childNode->name() == "cave" ) setCave( true ); else if ( childNode->name() == "nomusic" ) setNoMusic( true ); else if ( childNode->name() == "noguardmessage" ) setNoGuardMessage( true ); else if ( childNode->name() == "noentermessage" ) setNoEnterMessage( true ); else if ( childNode->name() == "nohousing" ) setNoHousing( true ); else if ( childNode->name() == "nodecay" ) setNoDecay( true ); else if ( childNode->name() == "instalogout" ) setInstaLogout( true ); else if ( childNode->name() == "noteleport" ) setNoTeleport( true ); else if ( childNode->name() == "safe" ) setSafe( true ); else if ( childNode->name() == "nocriminalcombat" ) setNoCriminalCombat( true ); else if ( childNode->name() == "nokillcount" ) setNoKillCount( true ); } } // <snowchance>50</snowchance> else if ( TagName == "snowchance" ) { this->snowchance_ = Value.toUShort(); } // <rainchance>50</rainchance> else if ( TagName == "rainchance" ) { this->rainchance_ = Value.toUShort(); } // <rainduration>2</rainduration> else if ( TagName == "rainduration" ) { this->rainduration_ = Value.toUShort(); } // <snowduration>2</snowduration> else if ( TagName == "snowduration" ) { this->snowduration_ = Value.toUShort(); } // <dryduration>4</dryduration> else if ( TagName == "dryduration" ) { this->dryduration_ = Value.toUShort(); } // <rainrangeduration>1</rainrangeduration> else if ( TagName == "rainrangeduration" ) { this->rainrangeduration_ = Value.toUShort(); } // <snowrangeduration>1</snowrangeduration> else if ( TagName == "snowrangeduration" ) { this->snowrangeduration_ = Value.toUShort(); } // <dryrangeduration>1</dryrangeduration> else if ( TagName == "dryrangeduration" ) { this->dryrangeduration_ = Value.toUShort(); } // <minintensity>1</minintensity> else if ( TagName == "minintensity" ) { this->minintensity_ = Value.toUShort(); } // <maxintensity>1</maxintensity> else if ( TagName == "maxintensity" ) { this->maxintensity_ = Value.toUShort(); } // <tradesystem> // <good num="1"> // <buyable>10</buyable> // <sellable>20</sellable> // <randomvalue min="10" max="20" /> // </good> // <good ...> // ... // </good> // </tradesystem> else if ( TagName == "tradesystem" ) { for ( unsigned int i = 0; i < Tag->childCount(); ++i ) { const cElement* childNode = Tag->getChild( i ); good_st goods; goods.buyable = 0; goods.sellable = 0; goods.rndmin = 0; goods.rndmax = 0; uint num = 0xFFFFFFFF; if ( childNode->name() == "good" ) { if ( childNode->hasAttribute( "num" ) ) num = childNode->getAttribute( "num" ).toInt(); for ( unsigned int j = 0; j < childNode->childCount(); ++j ) { const cElement* chchildNode = childNode->getChild( j ); QString childValue = chchildNode->value(); if ( chchildNode->name() == "buyable" ) goods.buyable = childValue.toInt(); else if ( chchildNode->name() == "sellable" ) goods.sellable = childValue.toInt(); else if ( chchildNode->name() == "randomvalue" ) { goods.rndmin = chchildNode->getAttribute( "min" ).toInt(); goods.rndmax = chchildNode->getAttribute( "max" ).toInt(); } } } if ( num != 0xFFFFFFFF ) this->tradesystem_[num] = goods; } } // <region id="Cove Market Place"> // ...region nodes... // </region> else if ( TagName == "region" ) { cTerritory* toinsert_ = new cTerritory( Tag, this ); this->subregions_.push_back( toinsert_ ); } else if ( TagName == "teleport" ) { if ( !Tag->hasAttribute( "source" ) ) { Console::instance()->log( LOG_ERROR, tr("processing teleport tag, missing source attribute") ); return; } if ( !Tag->hasAttribute( "destination" ) ) { Console::instance()->log( LOG_ERROR, tr("processing teleport tag, missing destination attribute") ); return; } Coord source, destination; if ( !parseCoordinates( Tag->getAttribute( "source" ), source ) ) { Console::instance()->log( LOG_ERROR, tr("parsing source attribute, not a valid coordinate vector") ); return; } if ( !parseCoordinates( Tag->getAttribute( "destination" ), destination ) ) { Console::instance()->log( LOG_ERROR, tr("parsing destination attribute, not a valid coordinate vector") ); return; } bool bothways = Tag->hasAttribute( "bothways" ); teleporters_st teleporter; teleporter.source = source; teleporter.destination = destination; teleporters.append( teleporter ); if ( bothways ) { teleporter.source = destination; teleporter.destination = source; teleporters.append( teleporter ); } } else cBaseRegion::processNode( Tag, hash ); }
void cUObject::processNode( const cElement* Tag, uint /*hash*/ ) { QString TagName( Tag->name() ); QString Value( Tag->value() ); if ( TagName == "name" ) { name_ = Value; } // <tag type="string"> also type="value" // <key>multisection</key> // <value>smallboat</value> // </tag> else if ( TagName == "tag" ) { QString name = Tag->getAttribute( "name" ); QString value = Tag->getAttribute( "value" ); if ( !name.isNull() ) { // If there is no value attribute, use the // tag content instead. if ( value.isNull() ) { value = Tag->text(); if ( value.isNull() ) { value = ""; } } QString type = Tag->getAttribute( "type", "string" ); if ( type == "int" ) { // If the value is separated by a , // we assume it's a random gradient. // If it's separated by ; we assume it's a list of values // we should choose from randomly. int sep = value.indexOf( ',' ); if ( sep != -1 ) { int min = hex2dec( value.left( sep ) ).toInt(); int max = hex2dec( value.mid( sep + 1 ) ).toInt(); int value = RandomNum( min, max ); tags_.set( name, cVariant( ( int ) value ) ); } else { // Choose a random value from the list. if ( value.contains( ';' ) ) { QStringList values = value.split( ';' ); if ( values.size() > 0 ) { value = values[RandomNum( 0, values.size() - 1 )]; } } tags_.set( name, cVariant( hex2dec( value ).toInt() ) ); } } else if ( type == "float" ) { tags_.set( name, cVariant( value.toFloat() ) ); } else { tags_.set( name, cVariant( value ) ); } } } // <scripts>a,b,c</scripts> else if ( TagName == "scripts" ) { setScriptList( Value.toLatin1() ); } else { if ( Value.isEmpty() ) { Value = "1"; } cVariant variant( Value ); setProperty( TagName, variant ); } }