int Noun::attachTrait( Trait * pTrait ) { if ( pTrait == NULL ) return -1; pTrait->setParent( this ); if ( m_bInitialized ) pTrait->initialize(); const ClassKey & nKey = pTrait->factory()->classKey(); for(size_t i=0;i<m_Traits.size();i++) { Trait * pOldTrait = m_Traits[i]; if ( pOldTrait->factory()->classKey() == nKey ) { m_Traits[i] = pTrait; return i; } } // new trait, insert the trait, keep sorted by name m_Traits.push_back( pTrait ); std::sort( m_Traits.begin(), m_Traits.end(), SortTraits ); updateVersion(); return m_Traits.size() - 1; }
void Object::_remove(const TypeIdentifier& i_trait_name) { if (m_deleting) { return ; } InternalMessage("Kernel","removed trait " + i_trait_name.toString() + " to objectid=" + toString(getIdentifier())) ; Trait* trait = traits[i_trait_name] ; trait->_close() ; TraitFormula::removeTrait(this,i_trait_name) ; this->traits.erase(i_trait_name) ; delete trait ; }
Trait *Trait::get( Reader *r, int end, Context *ctx ) { int type = r->getNBitInt( 4 ); int len = end - r->getPosition(); Trait* ret = getByType( type ); if( !ret ) { ret = handleError( type ); } if( ret ) { ret->setType( type ); ret->setLength( len ); ret->parse( r, end, ctx ); } return ret; }
void Noun::simulate( dword nTick ) { if (! m_bInitialized ) initialize(); if (! m_bPostInit ) m_bPostInit = postInitialize(); // simulate our traits, do this before we update our current tick... for(size_t i=0;i<m_Traits.size();) { Trait * pTrait = m_Traits[i]; if ( pTrait == NULL || pTrait->detach() ) { detachTrait( i ); continue; } pTrait->simulate( nTick ); ++i; } // simulate our children for(int i=0;i<childCount();) { Noun * pChild = (Noun *)child(i); if ( pChild->detach() ) { detachNodeSwap( i ); // remove child, swap with last child... continue; } pChild->simulate( nTick ); ++i; } // lastly, update the current tick m_Tick = nTick; // execute and detach attached verbs detachVerbs(); }
double Trait::compareWithTrait(const Trait& trait) const { double returnValue; this->getValue() == trait.getValue() ? returnValue = 1.0 : returnValue = 0.0; return returnValue; }
void psCreationManager::HandleTraitData( MsgEntry* me ) { psCharCreateTraitsMessage msg(me); iDocumentSystem* xml = psengine->GetXMLParser (); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse(msg.GetString().GetData()); if ( error ) { Error2("Error in XML: %s", error ); return; } csRef<iDocumentNode> root = doc->GetRoot(); if(!root) { Error1("No XML root in Trait Data"); return; } csRef<iDocumentNodeIterator> iter1 = root->GetNode("traits")->GetNodes("trait"); // Build the traits list while ( iter1->HasNext() ) { csRef<iDocumentNode> node = iter1->Next(); Trait *t = new Trait; t->Load( node ); traits.Push(t); } TraitIterator iter2 = GetTraitIterator(); while ( iter2.HasNext() ) { Trait * t = iter2.Next(); t->next_trait = GetTrait(t->next_trait_uid); if (t->next_trait != NULL) { t->next_trait->prev_trait = t; } } // Insert into the custom location structure all top trait TraitIterator iter3 = GetTraitIterator(); while ( iter3.HasNext() ) { Trait * t = iter3.Next(); // Check for top trait if (t->prev_trait == NULL) { RaceDefinition * race = GetRace(t->raceID); if (race != NULL) { if (t->gender == PSCHARACTER_GENDER_NONE) { race->location[t->location][PSCHARACTER_GENDER_MALE].Push(t); // still needed? race->location[t->location][PSCHARACTER_GENDER_FEMALE].Push(t); // still needed? race->location[t->location][PSCHARACTER_GENDER_NONE].Push(t); } else { race->location[t->location][t->gender].Push(t); } } else { Error3("Failed to insert trait '%s' into location table for race %d.\n",t->name.GetData(),t->raceID); } } } }
bool Trait::operator==(const Trait& t){ return ID() == t.ID(); }
void psCharAppearance::ApplyTraits(const csString& traitString) { if ( traitString.Length() == 0 ) { return; } csRef<iDocument> doc = xmlparser->CreateDocument(); const char* traitError = doc->Parse(traitString); if ( traitError ) { Error2("Error in XML: %s", traitError ); return; } csRef<iDocumentNodeIterator> traitIter = doc->GetRoot()->GetNode("traits")->GetNodes("trait"); csPDelArray<Trait> traits; // Build traits table while ( traitIter->HasNext() ) { csRef<iDocumentNode> traitNode = traitIter->Next(); Trait * trait = new Trait; trait->Load(traitNode); traits.Push(trait); } // Build next and prev pointers for trait sets csPDelArray<Trait>::Iterator iter = traits.GetIterator(); while (iter.HasNext()) { Trait * trait = iter.Next(); csPDelArray<Trait>::Iterator iter2 = traits.GetIterator(); while (iter2.HasNext()) { Trait * trait2 = iter2.Next(); if (trait->next_trait_uid == trait2->uid) { trait->next_trait = trait2; trait2->prev_trait = trait; } } } // Find top traits and set them on mesh csPDelArray<Trait>::Iterator iter3 = traits.GetIterator(); while (iter3.HasNext()) { Trait * trait = iter3.Next(); if (trait->prev_trait == NULL) { if (!SetTrait(trait)) { Error2("Failed to set trait %s for mesh.", traitString.GetData()); } } } return; }