bool CEntityPoolSignature::CompareNodeAttributes(const XmlNodeRef &a, const XmlNodeRef &b) { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(bool(a)); assert(bool(b)); const int attrCount_a = a->getNumAttributes(); const int attrCount_b = b->getNumAttributes(); bool bResult = (attrCount_a == attrCount_b); if (bResult) { const char *attrKey_a, *attrValue_a; const char *attrKey_b, *attrValue_b; for (int attr = 0; bResult && attr < attrCount_a; ++attr) { const bool bHasForA = a->getAttributeByIndex(attr, &attrKey_a, &attrValue_a); const bool bHasForB = b->getAttributeByIndex(attr, &attrKey_b, &attrValue_b); if ((bHasForA && !bHasForB) || (!bHasForA && bHasForB)) bResult = false; else if (bHasForA && (0 != strcmp(attrKey_a, attrKey_b) || 0 != strcmp(attrValue_a, attrValue_b))) bResult = false; } } return bResult; }
void CScriptProperties::Assign( XmlNodeRef &propsNode,IScriptTable* pPropsTable ) { const char* key = ""; const char* value = ""; int nAttrs = propsNode->getNumAttributes(); for (int attr = 0; attr < nAttrs; attr++) { if (!propsNode->getAttributeByIndex( attr,&key,&value )) continue; ScriptVarType varType = pPropsTable->GetValueType(key); switch (varType) { case svtNull: break; case svtString: pPropsTable->SetValue( key,value ); break; case svtNumber: { float fValue = (float)atof(value); pPropsTable->SetValue( key,fValue ); } break; case svtBool: { bool const bValue = (stricmp(value, "true") == 0) || (stricmp(value, "1") == 0); pPropsTable->SetValue(key, bValue); } break; case svtObject: { Vec3 vec; propsNode->getAttr(key,vec); CScriptVector vecTable; pPropsTable->GetValue( key,vecTable ); vecTable.Set( vec ); //pPropsTable->SetValue( key,vec ); } break; case svtPointer: case svtUserData: case svtFunction: // Ignore invalid property types. break; } } for (int i = 0; i < propsNode->getChildCount(); i++) { XmlNodeRef childNode = propsNode->getChild(i); SmartScriptTable pChildPropTable; if (pPropsTable->GetValue(childNode->getTag(),pChildPropTable)) { // Recurse. Assign( childNode,pChildPropTable ); } } }
bool CCheckpointSystem::ReadMetaData(XmlNodeRef parentNode, SCheckpointData &metaData, bool bRepairId /*=true*/) { XmlNodeRef data = parentNode->findChild(META_DATA_SECTION); if(!data) return false; metaData.m_versionNumber = 0; metaData.m_levelName.clear(); metaData.m_saveTime.clear(); metaData.m_checkPointId = 0; //read meta data int numAttribs = data->getNumAttributes(); const char *key, *value; const char *checkpointName = NULL; for(int i = 0; i < numAttribs; ++i) { data->getAttributeByIndex(i, &key, &value); if(!stricmp("Version", key)) { metaData.m_versionNumber = atoi(value); } else if(!stricmp("CheckpointId", key)) { metaData.m_checkPointId = EntityId(atoi(value)); } else if(!stricmp("CheckpointName", key)) { checkpointName = value; } else if(!stricmp("LevelName", key)) { metaData.m_levelName = value; } else if(!stricmp("Timestamp", key)) { metaData.m_saveTime = value; } } //EntityId's may change on level export -> fix id if(checkpointName && bRepairId) { if(!RepairEntityId(metaData.m_checkPointId, checkpointName)) CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed finding checkpoint entity during loading, flowgraph might be broken."); } //check all values have been read CRY_ASSERT(metaData.m_levelName.size() > 0); CRY_ASSERT(metaData.m_saveTime.size() > 0); //CRY_ASSERT(metaData.m_checkPointId); return true; }
//-------------------------------------------------------------------------------------------- void CUIObjectives::UpdateObjectiveInfo() { m_ObjectiveMap.clear(); string path = "Libs/UI/Objectives_new.xml"; XmlNodeRef missionObjectives = GetISystem()->LoadXmlFromFile( path.c_str() ); if (missionObjectives == 0) { gEnv->pLog->LogError("Error while loading MissionObjective file '%s'", path.c_str() ); return; } for(int tag = 0; tag < missionObjectives->getChildCount(); ++tag) { XmlNodeRef mission = missionObjectives->getChild(tag); const char* attrib; const char* objective; const char* text; for(int obj = 0; obj < mission->getChildCount(); ++obj) { XmlNodeRef objectiveNode = mission->getChild(obj); string id(mission->getTag()); id += "."; id += objectiveNode->getTag(); if(objectiveNode->getAttributeByIndex(0, &attrib, &objective) && objectiveNode->getAttributeByIndex(1, &attrib, &text)) { m_ObjectiveMap[ id ].Name = objective; m_ObjectiveMap[ id ].Desc = text; } else { gEnv->pLog->LogError("Error while loading MissionObjective file '%s'", path.c_str() ); return; } } } }
bool CItemParamsNode::ConvertFromXMLWithFiltering(const XmlNodeRef &root, const char * keepWithThisAttrValue) { bool filteringRequired = false; int nattributes = root->getNumAttributes(); m_attributes.reserve(nattributes); for (int a=0; a<nattributes; a++) { const char *name=0; const char *value=0; if (root->getAttributeByIndex(a, &name, &value)) { float f; int i; Vec3 v; if (!stricmp(value, "true")) SetAttribute(name, 1); else if (!stricmp(value, "false")) SetAttribute(name, 0); else if (IsInteger(value, &i)) SetAttribute(name, i); else if (IsFloat(value, &f)) SetAttribute(name, f); else if (IsVec3(value, &v)) SetAttribute(name, v); else SetAttribute(name, value); } } int nchildren = root->getChildCount(); m_children.reserve(nchildren); for (int c=0; c<nchildren; c++) { XmlNodeRef child = root->getChild(c); EXMLFilterType filterType = ShouldConvertNodeFromXML(child, keepWithThisAttrValue); filteringRequired = (filterType != eXMLFT_none) || filteringRequired ? true : false; if(filterType != eXMLFT_remove) { filteringRequired = (InsertChild(child->getTag())->ConvertFromXMLWithFiltering(child, keepWithThisAttrValue) || filteringRequired); } } return filteringRequired; }
void CUIHUD3D::SpawnHudEntities() { RemoveHudEntities(); if (gEnv->IsEditor() && gEnv->IsEditing()) return; const char* hudprefab = NULL; IGameRules* pGameRules = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRules(); if (pGameRules) { IScriptTable* pTable = pGameRules->GetEntity()->GetScriptTable(); if (pTable) { if (!pTable->GetValue("hud_prefab", hudprefab)) hudprefab = NULL; } } hudprefab = hudprefab ? hudprefab : HUD3D_PREFAB_LIB; XmlNodeRef node = gEnv->pSystem->LoadXmlFromFile(hudprefab); if (node) { // get the prefab with the name defined in HUD3D_PREFAB_NAME XmlNodeRef prefab = NULL; for (int i = 0; i < node->getChildCount(); ++i) { const char* name = node->getChild(i)->getAttr("Name"); if (name && strcmp(name, HUD3D_PREFAB_NAME) == 0) { prefab = node->getChild(i); prefab = prefab ? prefab->findChild("Objects") : XmlNodeRef(); break; } } if (prefab) { // get the PIVOT entity and collect childs XmlNodeRef pivotNode = NULL; std::vector<XmlNodeRef> childs; const int count = prefab->getChildCount(); childs.reserve(count-1); for (int i = 0; i < count; ++i) { const char* name = prefab->getChild(i)->getAttr("Name"); if (strcmp("PIVOT", name) == 0) { assert(pivotNode == NULL); pivotNode = prefab->getChild(i); } else { childs.push_back(prefab->getChild(i)); } } if (pivotNode) { // spawn pivot entity IEntityClass* pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( pivotNode->getAttr("EntityClass") ); if (pEntClass) { SEntitySpawnParams params; params.nFlags = ENTITY_FLAG_CLIENT_ONLY; params.pClass = pEntClass; m_pHUDRootEntity = gEnv->pEntitySystem->SpawnEntity(params); } if (!m_pHUDRootEntity) return; m_HUDRootEntityId = m_pHUDRootEntity->GetId(); // spawn the childs and link to the pivot enity for (std::vector<XmlNodeRef>::iterator it = childs.begin(); it != childs.end(); ++it) { XmlNodeRef child = *it; pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( child->getAttr("EntityClass") ); if (pEntClass) { const char* material = child->getAttr("Material"); Vec3 pos; Vec3 scale; Quat rot; child->getAttr("Pos", pos); child->getAttr("Rotate", rot); child->getAttr("Scale", scale); SEntitySpawnParams params; params.nFlags = ENTITY_FLAG_CLIENT_ONLY; params.pClass = pEntClass; params.vPosition = pos; params.qRotation = rot; params.vScale = scale; IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(params); if (pEntity) { IScriptTable* pScriptTable = pEntity->GetScriptTable(); if (pScriptTable) { SmartScriptTable probs; pScriptTable->GetValue("Properties", probs); XmlNodeRef properties = child->findChild("Properties"); if (probs && properties) { for (int k = 0; k < properties->getNumAttributes(); ++k) { const char* sKey; const char* sVal; properties->getAttributeByIndex(k, &sKey, &sVal); probs->SetValue(sKey, sVal); } } Script::CallMethod(pScriptTable,"OnPropertyChange"); } if (material) { IMaterial* pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material); if (pMat) pEntity->SetMaterial(pMat); } m_pHUDRootEntity->AttachChild(pEntity); m_HUDEnties.push_back( pEntity->GetId() ); } } } } } } OnVisCVarChange( NULL ); }
void CHUDMissionObjectiveSystem::LoadLevelObjectivesInternal(const char* levelpath) { CryFixedStringT<128> filename; if (levelpath==NULL) { // there is no Objectives_global.xml, but there is a file with the previous standard naming // load the file with old name for backwards compatibility if (!gEnv->pCryPak->IsFileExist("Libs/UI/Objectives_global.xml") && gEnv->pCryPak->IsFileExist("Libs/UI/Objectives_new.xml")) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "File 'Objectives_new.xml' is deprecated and should be renamed to 'Objectives_global.xml'"); filename = "Libs/UI/Objectives_new.xml"; } else { filename = "Libs/UI/Objectives_global.xml"; } } else { filename.Format("%s/leveldata/Objectives.xml", levelpath); } /*if(gEnv->bMultiplayer) { CGameRules *pGameRules = g_pGame->GetGameRules(); if(stricmp (pGameRules->GetEntity()->GetClass()->GetName(), "Coop")) filename = "Libs/UI/MP_Objectives.xml"; }*/ XmlNodeRef missionObjectives = GetISystem()->LoadXmlFromFile(filename.c_str()); if (missionObjectives == 0) return; for(int tag = 0; tag < missionObjectives->getChildCount(); ++tag) { XmlNodeRef mission = missionObjectives->getChild(tag); const char* attrib; const char* objective; const char* text; const char* optional; const char* levelName; if (!mission->getAttr("name", &levelName)) { levelName = mission->getTag(); } for(int obj = 0; obj < mission->getChildCount(); ++obj) { XmlNodeRef objectiveNode = mission->getChild(obj); string id(levelName); id.append("."); id.append(objectiveNode->getTag()); if(objectiveNode->getAttributeByIndex(0, &attrib, &objective) && objectiveNode->getAttributeByIndex(1, &attrib, &text)) { bool secondaryObjective = false; int attribs = objectiveNode->getNumAttributes(); for(int attribIndex = 2; attribIndex < attribs; ++attribIndex) { if(objectiveNode->getAttributeByIndex(attribIndex, &attrib, &optional)) { if(attrib) { if(!stricmp(attrib, "Secondary")) { if(!stricmp(optional, "true")) secondaryObjective = true; } } } } m_currentMissionObjectives.push_back(CHUDMissionObjective(this, id.c_str(), objective, text, secondaryObjective)); } else GameWarning("Error reading mission objectives."); } } }
////////////////////////////////////////////////////////////////////////// //this respawns the active AI at their spawn locations void CCheckpointSystem::RespawnAI(XmlNodeRef data) { if(!data) return; XmlNodeRef actorData = data->findChild(ACTOR_FLAGS_SECTION); if(!actorData) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed reading actor data from checkpoint, actors won't be respawned"); return; } IActorSystem *pActorSystem = CCryAction::GetCryAction()->GetIActorSystem(); //first run through all actors and hide/deactivate them IActorIteratorPtr it = pActorSystem->CreateActorIterator(); while (IActor *pActor = it->Next()) { IEntity *pEntity = pActor->GetEntity(); //deactivate all actors pEntity->Hide(true); pEntity->Activate(false); } //load actorflags for active actors XmlNodeRef activatedActors = actorData->findChild(ACTIVATED_ACTORS_SECTION); if(activatedActors) { int actorFlags = activatedActors->getNumAttributes(); const char *key; const char *value; for(int i = 0; i < actorFlags; ++i) { activatedActors->getAttributeByIndex(i, &key, &value); //format is "idXXX" CRY_ASSERT(strlen(key)>2); EntityId id = (EntityId)(atoi(&key[2])); bool foundEntity = RepairEntityId(id, value); if(foundEntity) { IActor* pActor = pActorSystem->GetActor(id); if(pActor) { pActor->GetEntity()->Hide(false); pActor->GetEntity()->Activate(true); } else CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed finding actor %i from checkpoint.", (int)id); } else CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed finding actor %s from checkpoint, actor is not setup correctly.", value); } } else CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Deactivated actors section was missing in checkpoint."); it = pActorSystem->CreateActorIterator(); //iterate all actors and respawn if active while (IActor *pActor = it->Next()) { IEntity *pEntity = pActor->GetEntity(); if(pEntity->GetId() == LOCAL_PLAYER_ENTITY_ID) //don't respawn player continue; //we don't respawn deactivated actors if(!pEntity->IsHidden() && pEntity->IsActive()) { pActor->SetHealth(0); pActor->Respawn(); } else //but we still reset their position { pActor->ResetToSpawnLocation(); } } }
// Load an equipment pack from an XML node bool CEquipmentManager::LoadEquipmentPack(const XmlNodeRef& rootNode, bool bOverrideExisting) { if (rootNode->isTag("EquipPack") == false) return false; const char* packName = rootNode->getAttr("name"); const char* primaryName = rootNode->getAttr("primary"); if (!packName || packName[0] == 0) return false; // re-use existing pack SEquipmentPack* pPack = GetPack(packName); if (pPack == 0) { pPack = new SEquipmentPack; m_equipmentPacks.push_back(pPack); } else if (bOverrideExisting == false) return false; pPack->Init(packName); for (int iChild=0; iChild<rootNode->getChildCount(); ++iChild) { const XmlNodeRef childNode = rootNode->getChild(iChild); if (childNode == 0) continue; if (childNode->isTag("Items")) { pPack->PrepareForItems(childNode->getChildCount()); for (int i=0; i<childNode->getChildCount(); ++i) { XmlNodeRef itemNode = childNode->getChild(i); const char* itemName = itemNode->getTag(); const char* itemType = itemNode->getAttr("type"); const char* itemSetup = itemNode->getAttr("setup"); pPack->AddItem(itemName, itemType, itemSetup); } } else if (childNode->isTag("Ammo")) // legacy { const char *ammoName = ""; const char *ammoCount = ""; int nAttr = childNode->getNumAttributes(); for (int j=0; j<nAttr; ++j) { if (childNode->getAttributeByIndex(j, &ammoName, &ammoCount)) { int nAmmoCount = atoi(ammoCount); pPack->m_ammoCount[ammoName] = nAmmoCount; } } } else if (childNode->isTag("Ammos")) { for (int i=0; i<childNode->getChildCount(); ++i) { XmlNodeRef ammoNode = childNode->getChild(i); if (ammoNode->isTag("Ammo") == false) continue; const char* ammoName = ammoNode->getAttr("name"); if (ammoName == 0 || ammoName[0] == '\0') continue; int nAmmoCount = 0; ammoNode->getAttr("amount", nAmmoCount); pPack->m_ammoCount[ammoName] = nAmmoCount; } } } // assign primary. if (pPack->HasItem(primaryName)) pPack->m_primaryItem = primaryName; else pPack->m_primaryItem = ""; return true; }