//------------------------------------------------------------------------ void CGameRulesHoldObjectiveBase::Init( XmlNodeRef xml ) { const int numChildren = xml->getChildCount(); for (int childIdx = 0; childIdx < numChildren; ++ childIdx) { XmlNodeRef xmlChild = xml->getChild(childIdx); if (!stricmp(xmlChild->getTag(), "SpawnParams")) { const char *pType = 0; if (xmlChild->getAttr("type", &pType)) { if (!stricmp(pType, "avoid")) { m_spawnPOIType = eSPT_Avoid; } else { CryLog("CGameRulesHoldObjectiveBase::Init: ERROR: Unknown spawn point of interest type ('%s')", pType); } xmlChild->getAttr("distance", m_spawnPOIDistance); } } else if (!stricmp(xmlChild->getTag(), "EffectData")) { InitEffectData(xmlChild); } } for (int i = 0; i < HOLD_OBJECTIVE_MAX_ENTITIES; ++ i) { m_entities[i].Reset(); } }
void CForceFeedBackSystem::LoadXmlData() { const char* xmlDataFile = "Libs/GameForceFeedback/ForceFeedbackEffects.xml"; XmlNodeRef rootNode = gEnv->pSystem->LoadXmlFromFile(xmlDataFile); if (!rootNode || strcmpi(rootNode->getTag(), "ForceFeedback")) { FORCEFEEDBACK_LOG("Could not load force feedback system data. Invalid XML file '%s'! ", xmlDataFile); return; } const int childCount = rootNode->getChildCount(); for (int i = 0; i < childCount; ++i) { XmlNodeRef childNode = rootNode->getChild(i); const char* childTag = childNode->getTag(); if (strcmp(childTag, "Patterns") == 0) { LoadPatters(childNode); } else if (strcmp(childTag, "Envelopes") == 0) { LoadEnvelopes(childNode); } else if (strcmp(childTag, "Effects") == 0) { LoadEffects(childNode); } } }
void CEditorGame::InitGlobalFileEnums(IGameToEditorInterface *pGTE) { // Read in enums stored offline XML. Format is // <GlobalEnums> // <EnumName> // <entry enum="someName=someValue" /> <!-- displayed name != value --> // <entry enum="someNameValue" /> <!-- displayed name == value --> // </EnumName> // </GlobalEnums> // XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile("Libs/GlobalEnums.xml"); if (!rootNode || !rootNode->getTag() || stricmp(rootNode->getTag(), "GlobalEnums") != 0) { // GameWarning("CEditorGame::InitUIEnums: File 'Libs/GlobalEnums.xml' is not a GlobalEnums file"); return; } for (int i = 0; i < rootNode->getChildCount(); ++i) { XmlNodeRef enumNameNode = rootNode->getChild(i); const char *enumId = enumNameNode->getTag(); if (enumId == 0 || *enumId == '\0') { continue; } int maxChilds = enumNameNode->getChildCount(); if (maxChilds > 0) { // allocate enough space to hold all strings const char **nameValueStrings = new const char*[maxChilds]; int curEntryIndex = 0; for (int j = 0; j < maxChilds; ++j) { XmlNodeRef enumNode = enumNameNode->getChild(j); const char *nameValue = enumNode->getAttr("enum"); if (nameValue != 0 && *nameValue != '\0') { // put in the nameValue pair nameValueStrings[curEntryIndex++] = nameValue; } } // if we found some entries inform CUIDataBase about it if (curEntryIndex > 0) { pGTE->SetUIEnums(enumId, nameValueStrings, curEntryIndex); } // be nice and free our array delete[] nameValueStrings; } } }
void CMovementTransitions::Load() { Reset(); if (!g_pGame->GetCVars()->g_movementTransitions_enable) return; string filename = GetXMLFilename(); XmlNodeRef rootNode = gEnv->pSystem->LoadXmlFromFile(filename.c_str()); if (!rootNode || strcmpi(rootNode->getTag(), "MovementTransitions")) { GameWarning("Could not load movement transition data. Invalid XML file '%s'! ", filename.c_str()); return; } IItemParamsNode *paramNode = g_pGame->GetIGameFramework()->GetIItemSystem()->CreateParams(); paramNode->ConvertFromXML(rootNode); ReadGeneralParams(paramNode->GetChild("General")); bool success = ReadTransitionsParams(paramNode->GetChild("Transitions")); paramNode->Release(); m_isDataValid = success; }
virtual bool Execute(SActivationInfo *pActInfo) { bool bResult = false; SXmlDocument *doc; if (GDM->GetXmlDocument(pActInfo->pGraph, &doc) && doc->active) { const char* childName = GetPortString(pActInfo, EIP_Name); const int childIndex = GetPortInt(pActInfo, EIP_Index); const int childCount = doc->active->getChildCount(); XmlNodeRef ref = NULL; for (int i = 0, realCount = 0; i < childCount; ++i) { ref = doc->active->getChild(i); if (ref && strcmp(ref->getTag(), childName) == 0) { if (++realCount >= childIndex) { doc->active->deleteChildAt(i); bResult = true; break; } } } } return bResult; }
virtual bool Execute(SActivationInfo *pActInfo) { bool bResult = false; SXmlDocument *doc; if (GDM->GetXmlDocument(pActInfo->pGraph, &doc) && doc->active) { char const* name = GetPortString(pActInfo, EIP_Name); if (!name || !name[0]) { doc->active->removeAllChilds(); } else { const int childCount = doc->active->getChildCount(); XmlNodeRef ref = NULL; for (int i = 0; i < childCount; ++i) { ref = doc->active->getChild(i); if (ref && strcmp(ref->getTag(), name) == 0) { doc->active->deleteChildAt(i); } } } bResult = true; } return bResult; }
void CMFXParticleEffect::LoadParamsFromXml(const XmlNodeRef& paramsNode) { // Xml data format /* <Particle> <Name userdata="..." scale="..." maxdist="..." minscale="..." maxscale="..." maxscaledist="..." attach="...">particle.name</Name> <Direction>DirectionType</Direction> </Particle> */ for (int i=0; i<paramsNode->getChildCount(); ++i) { XmlNodeRef child = paramsNode->getChild(i); if (!strcmp(child->getTag(), "Name")) { SMFXParticleEntry entry; entry.name = child->getContent(); if (child->haveAttr("userdata")) entry.userdata = child->getAttr("userdata"); if (child->haveAttr("scale")) child->getAttr("scale", entry.scale); if (child->haveAttr("maxdist")) child->getAttr("maxdist", entry.maxdist); if (child->haveAttr("minscale")) child->getAttr("minscale", entry.minscale); if (child->haveAttr("maxscale")) child->getAttr("maxscale", entry.maxscale); if (child->haveAttr("maxscaledist")) child->getAttr("maxscaledist", entry.maxscaledist); if (child->haveAttr("attach")) child->getAttr("attach", entry.attachToTarget); m_particleParams.m_entries.push_back(entry); } } SMFXParticleParams::EDirectionType directionType = SMFXParticleParams::eDT_Normal; XmlNodeRef dirType = paramsNode->findChild("Direction"); if (dirType) { const char *val = dirType->getContent(); if (!strcmp(val, "Normal")) { directionType = SMFXParticleParams::eDT_Normal; } else if (!strcmp(val, "Ricochet")) { directionType = SMFXParticleParams::eDT_Ricochet; } } m_particleParams.directionType = directionType; }
float CWorldState::GetFloat(const char * entityName, char * valueName) { // CryLog("CWorldState::GetFloat()"); float result = 0.f; if(worldStateXml) { XmlNodeRef entityNode = worldStateXml->findChild(entityName); if(entityNode) { const uint32 Count = entityNode->getChildCount(); for (uint32 Index = 0; Index < Count; ++Index) { const XmlNodeRef currentNode = entityNode->getChild(Index); if(strcmp(currentNode->getTag(),valueName)==0) { currentNode->getAttr("value",result); break; } } } else CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CWorldState::Failed to get world state value!"); } else CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CWorldState::Failed to get world state value!"); return result; }
void CWorldState::SetString(const char * entityName, char * valueName , string value) { // CryLog("CWorldState::SetString()"); if(worldStateXml) { XmlNodeRef entityNode = worldStateXml->findChild(entityName); if(!entityNode) { CreateChild(entityName); entityNode = worldStateXml->findChild(entityName); } const uint32 Count = entityNode->getChildCount(); for (uint32 Index = 0; Index < Count; ++Index) { XmlNodeRef child = entityNode->getChild(Index); if(strcmp(child->getTag(),valueName)==0) { child->setAttr("value",value); worldStateXml->saveToFile(szSaveFile); return; } } //CryLog("CWorldState::CreateString()"); XmlNodeRef child = entityNode->newChild(valueName); child->setAttr("value",value); worldStateXml->saveToFile(szSaveFile); } else return; }
void CMFXContainer::BuildChildEffects( const XmlNodeRef& paramsNode ) { const CGameXmlParamReader reader(paramsNode); const int totalChildCount = reader.GetUnfilteredChildCount(); const int filteredChildCount = reader.GetFilteredChildCount(); m_effects.reserve(filteredChildCount); for(int i = 0; i < totalChildCount; i++) { XmlNodeRef currentEffectNode = reader.GetFilteredChildAt(i); if (currentEffectNode == NULL) continue; const char* nodeName = currentEffectNode->getTag(); if (nodeName == 0 || *nodeName==0) continue; TMFXEffectBasePtr pEffect = MaterialEffectsUtils::CreateEffectByName(nodeName); if (pEffect != NULL) { pEffect->LoadParamsFromXml(currentEffectNode); m_effects.push_back(pEffect); } } }
//------------------------------------------------------------------------- void CGameRulesStandardState::Init( XmlNodeRef xml ) { m_pGameRules = g_pGame->GetGameRules(); m_state = EGRS_Intro; m_lastReceivedServerState = m_state; m_timeInPostGame = 0.f; m_introMessageShown = false; m_isStarting = false; m_isWaitingForOverrideTimer = false; m_startTimerOverrideWait = 0.0f; m_timeInCurrentPostGameState = 0.f; m_postGameState = ePGS_Unknown; m_bHaveNotifiedIntroListeners = false; m_bHasShownHighlightReel = false; ChangeState(EGRS_Intro); int numChildren = xml->getChildCount(); for (int i = 0; i < numChildren; ++ i) { XmlNodeRef xmlChild = xml->getChild(i); if (!stricmp(xmlChild->getTag(), "StartStrings")) { const char *pString = 0; if (xmlChild->getAttr("startMatch", &pString)) { m_startMatchString.Format("@%s", pString); } } } }
void CAntiCheatManager::LoadAntiCheatVars(XmlNodeRef child) { int numVars = child->getChildCount(); for (int i=0; i<numVars; ++i) { XmlNodeRef varsChild = child->getChild(i); if (varsChild->isTag("Var")) { const char* sVarName = varsChild->getAttr("name"); TAntiCheatVarIdx antiCheatVarIdx = FindAntiCheatVarIdx_Float(sVarName); if (antiCheatVarIdx != eAV_Invalid_Float) { varsChild->getAttr("value", m_cheatVarsFloat[antiCheatVarIdx]); } else { antiCheatVarIdx = FindAntiCheatVarIdx_Int(sVarName); if (antiCheatVarIdx != eAV_Invalid_Int) { varsChild->getAttr("value", m_cheatVarsInt[antiCheatVarIdx]); } else { CryLog("Unrecognised anti cheat var '%s'", sVarName); } } } else { CryLog("Unrecognised child node '%s'", varsChild->getTag()); } } }
void SAmmoParams::LoadExplosion(const XmlNodeRef& ammoParamsNode) { static const int maxExplosions = 4; CGameXmlParamReader reader(ammoParamsNode); const int childCount = ammoParamsNode->getChildCount(); //int explosionCount = 0; XmlNodeRef explosions[maxExplosions]; int finalExplosionCount = 0; for (int i= 0; (i < childCount) && (finalExplosionCount < maxExplosions); ++i) { XmlNodeRef child = reader.GetFilteredChildAt(i); if(child && stricmp(child->getTag(), "explosion") == 0) { explosions[finalExplosionCount] = child; ++finalExplosionCount; } } m_explosion_count = finalExplosionCount; if(m_explosion_count) { pExplosions = new SExplosionParams*[m_explosion_count]; for(int i = 0; i < m_explosion_count; ++i) { pExplosions[i] = new SExplosionParams(explosions[i]); } pExplosion = pExplosions[0]; } }
EAudioRequestStatus CAudioSystemImpl_sdlmixer::ParseAudioFileEntry(XmlNodeRef const pAudioFileEntryNode, SATLAudioFileEntryInfo* const pFileEntryInfo) { EAudioRequestStatus eResult = eARS_FAILURE; if ((_stricmp(pAudioFileEntryNode->getTag(), ms_sSDLFileTag) == 0) && (pFileEntryInfo != NPTR)) { char const* const sFileName = pAudioFileEntryNode->getAttr(ms_sSDLCommonAttribute); // Currently the SDLMixer Implementation does not support localized files. pFileEntryInfo->bLocalized = false; if (sFileName != NPTR && sFileName[0] != '\0') { pFileEntryInfo->sFileName = sFileName; pFileEntryInfo->nMemoryBlockAlignment = m_nMemoryAlignment; POOL_NEW(SSDLMixerAudioFileEntryData, pFileEntryInfo->pImplData); eResult = eARS_SUCCESS; } else { pFileEntryInfo->sFileName = NPTR; pFileEntryInfo->nMemoryBlockAlignment = 0; pFileEntryInfo->pImplData = NPTR; } } return eResult; }
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 CPlayerProfile::LoadAttributes(const XmlNodeRef& root, int requiredVersion) { int version = 0; const bool bHaveVersion = root->getAttr(VERSION_TAG, version); if (requiredVersion > 0) { if (bHaveVersion && version < requiredVersion) { GameWarning("CPlayerProfile::LoadAttributes: Attributes of profile '%s' have different version (%d != %d). Updated.", GetName(), version, requiredVersion); return false; } else if (!bHaveVersion) { GameWarning("CPlayerProfile::LoadAttributes: Attributes of legacy profile '%s' has no version (req=%d). Loading anyway.", GetName(), requiredVersion); } m_attributesVersion = requiredVersion; } else // for default profile we set the version we found in the rootNode m_attributesVersion = version; int nChilds = root->getChildCount(); for (int i=0; i<nChilds; ++i) { XmlNodeRef child = root->getChild(i); if (child && strcmp(child->getTag(), "Attr") == 0) { const char* name = child->getAttr("name"); const char* value = child->getAttr("value"); const char* platform = child->getAttr("platform"); bool platformValid = true; if(platform != NULL && platform[0]) { #if defined(DURANGO) platformValid = (strstr(platform, "xbox")!=0); #elif defined(ORBIS) platformValid = (strstr(platform, "ps4")!=0); #else platformValid = (strstr(platform, "pc")!=0); #endif } if (name && value && platformValid) { m_attributeMap[name] = TFlowInputData(string(value)); } } } if(m_pManager->HasEnabledOnlineAttributes() && m_pManager->CanProcessOnlineAttributes() && !IsDefault()) { m_pManager->LoadOnlineAttributes(this); } return true; }
//------------------------------------------------------------------------ void CGameRulesCommonDamageHandling::Init( XmlNodeRef xml ) { m_pGameRules = g_pGame->GetGameRules(); // Reserved hit types - in sync with RESERVED_HIT_TYPES /*00*/ //m_pGameRules->RegisterHitType("invalid", CGameRules::EHitTypeFlag::None); /*01*/ m_pGameRules->RegisterHitType("melee", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*02*/ m_pGameRules->RegisterHitType("collision", CGameRules::EHitTypeFlag::Server); /*03*/ m_pGameRules->RegisterHitType("frag", CGameRules::EHitTypeFlag::Server | CGameRules::EHitTypeFlag::AllowPostDeathDamage); /*04*/ m_pGameRules->RegisterHitType("explosion", CGameRules::EHitTypeFlag::Server | CGameRules::EHitTypeFlag::AllowPostDeathDamage); /*05*/ m_pGameRules->RegisterHitType("stealthKill", CGameRules::EHitTypeFlag::Server | CGameRules::EHitTypeFlag::AllowPostDeathDamage); /*06*/ m_pGameRules->RegisterHitType("silentMelee", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::SinglePlayerOnly | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*07*/ m_pGameRules->RegisterHitType("punish", CGameRules::EHitTypeFlag::ClientSelfHarm); /*08*/ m_pGameRules->RegisterHitType("punishFall", CGameRules::EHitTypeFlag::ClientSelfHarm); /*10*/ m_pGameRules->RegisterHitType("fall", CGameRules::EHitTypeFlag::ClientSelfHarm); /*11*/ m_pGameRules->RegisterHitType("normal", CGameRules::EHitTypeFlag::Server); //Used for killing players so they can switch teams /*12*/ m_pGameRules->RegisterHitType("fire", CGameRules::EHitTypeFlag::Server); // used by PressurizedObject.lua /*14*/ m_pGameRules->RegisterHitType("heavyBullet", CGameRules::EHitTypeFlag::ValidationRequired); /*18*/ m_pGameRules->RegisterHitType("environmentalThrow", CGameRules::EHitTypeFlag::CustomValidationRequired | CGameRules::EHitTypeFlag::AllowPostDeathDamage | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*19*/ m_pGameRules->RegisterHitType("meleeLeft", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::SinglePlayerOnly | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*20*/ m_pGameRules->RegisterHitType("meleeRight", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::SinglePlayerOnly | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*21*/ m_pGameRules->RegisterHitType("meleeKick", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::SinglePlayerOnly | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*22*/ m_pGameRules->RegisterHitType("meleeUppercut", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::SinglePlayerOnly | CGameRules::EHitTypeFlag::IgnoreHeadshots); /*23*/ m_pGameRules->RegisterHitType("vehicleDestruction", CGameRules::EHitTypeFlag::Server | CGameRules::EHitTypeFlag::AllowPostDeathDamage); /*27*/ m_pGameRules->RegisterHitType("eventDamage", CGameRules::EHitTypeFlag::ClientSelfHarm); /*29*/ m_pGameRules->RegisterHitType("environmentalMelee", CGameRules::EHitTypeFlag::IsMeleeAttack | CGameRules::EHitTypeFlag::CustomValidationRequired | CGameRules::EHitTypeFlag::AllowPostDeathDamage | CGameRules::EHitTypeFlag::IgnoreHeadshots); CRY_ASSERT(m_pGameRules->GetHitTypesCount() == CGameRules::EHitType::Unreserved); // Read any non-native hit_types from the HitTypes.xml file! XmlNodeRef xmlNode = gEnv->pSystem->LoadXmlFromFile( "Scripts/Entities/Items/HitTypes.xml" ); if( xmlNode ) { const int numEntries = xmlNode->getChildCount(); for (int i = 0; i < numEntries; ++i) { XmlNodeRef hitTypeXML = xmlNode->getChild(i); if (strcmp(hitTypeXML->getTag(), "hit_type") != 0) continue; if( const char* pHitType = hitTypeXML->getAttr("name") ) { TBitfield flags = CGameRules::EHitTypeFlag::None; if( const char * pHitTypeFlags = hitTypeXML->getAttr("flags")) { flags = AutoEnum_GetBitfieldFromString(pHitTypeFlags, CGameRules::s_hitTypeFlags, CGameRules::EHitTypeFlag::HIT_TYPES_FLAGS_numBits); } m_pGameRules->RegisterHitType( pHitType, flags ); } } } m_scriptHitInfo.Create(gEnv->pScriptSystem); }
bool CFlowGraphModule::PreLoadModule(const char* fileName) { m_fileName = fileName; XmlNodeRef moduleRef = gEnv->pSystem->LoadXmlFromFile(fileName); if (!moduleRef) { CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "Unable to preload Flowgraph Module: %s", PathUtil::GetFileName(fileName).c_str()); return false; } assert(!stricmp(moduleRef->getTag(), "Graph")); bool module = false; moduleRef->getAttr("isModule", module); assert(module); XmlString tempName; if (moduleRef->getAttr("moduleName", tempName)) m_name = tempName; bool bResult = (m_pRootGraph != NULL); assert(m_pRootGraph == NULL); // first handle module ports XmlNodeRef modulePorts = moduleRef->findChild("ModuleInputsOutputs"); RemoveModulePorts(); if (modulePorts) { int nPorts = modulePorts->getChildCount(); for (int i = 0; i < nPorts; ++i) { XmlString portName; int portType; bool isInput; XmlNodeRef port = modulePorts->getChild(i); port->getAttr("Name", portName); port->getAttr("Type", portType); port->getAttr("Input", isInput); IFlowGraphModule::SModulePortConfig portConfig; portConfig.name = portName.c_str(); portConfig.type = (EFlowDataTypes)portType; portConfig.input = isInput; AddModulePort(portConfig); } } // and create nodes for this module (needs to be done before actual graph load, so that the // nodes can be created there) RegisterNodes(); return bResult; }
void CHUD::LoadWeaponAccessories(XmlNodeRef weaponXmlNode) { if(weaponXmlNode) { TMapWeaponAccessoriesHelperOffsets mapWeaponAccessoriesHelpersOffsets; int iNumChildren = weaponXmlNode->getChildCount(); for(int iChild=0; iChild<iNumChildren; iChild++) { XmlNodeRef helperXmlNode = weaponXmlNode->getChild(iChild); SWeaponAccessoriesHelpersOffsets offsets; offsets.iX = atoi(helperXmlNode->getAttr("X")); offsets.iY = atoi(helperXmlNode->getAttr("Y")); mapWeaponAccessoriesHelpersOffsets.insert(std::make_pair(helperXmlNode->getTag(),offsets)); } m_mapWeaponAccessoriesHelpersOffsets.insert(std::make_pair(weaponXmlNode->getTag(),mapWeaponAccessoriesHelpersOffsets)); } }
void CD6ArmorManager::LoadFromXML(XmlNodeRef& rootNode) { int childCount = rootNode->getChildCount(); for (int i = 0; i < childCount; ++i) { XmlNodeRef node = rootNode->getChild(i); if (NULL == node) continue; if (0 == strcmp(node->getTag(), "Armor")) { XmlString armorName; SArmorDef armorDef; // Read the Armor tag's name attribute if (!node->getAttr("name", armorName)) continue; armorDef.szArmorName = armorName; // Read warheads int childCount = node->getChildCount(); for (int i = 0; i < childCount; ++i) { XmlNodeRef warhead = node->getChild(i); if (0 == strcmp(warhead->getTag(), "Warhead")) { SArmorWarheadDef warheadDef; XmlString name; if (!warhead->getAttr("name", name)) break; warheadDef.szWarheadName = name; if (!warhead->getAttr("multiplier", warheadDef.fMultiplier)) warheadDef.fMultiplier = 1.0f; armorDef.warheads.push_back(warheadDef); } } m_ArmorDefs.insert(std::make_pair(m_NextArmorId++, armorDef)); } } }
SUnlock::SUnlock(XmlNodeRef node, int rank) { m_name[0] = '\0'; m_rank = rank; m_reincarnation = 0; m_unlocked = false; m_type = eUT_Invalid; DesignerWarning(strcmpi(node->getTag(), "unlock") == 0 || strcmpi(node->getTag(), "allow") == 0, "expect tag of unlock or allow at %d", node->getLine()); const char * theName = node->getAttr("name"); const char * theType = node->getAttr("type"); const char * theReincarnationLevel = node->getAttr("reincarnation"); // These pointers should always be valid... if an attribute isn't found, getAttr returns a pointer to an empty string [TF] assert (theName && theType); if (theType && theType[0] != '\0') { m_type = SUnlock::GetUnlockTypeFromName(theType); cry_strcpy(m_name, theName); bool expectName = (m_type == eUT_Loadout || m_type == eUT_Weapon || m_type == eUT_Attachment || m_type == eUT_Playlist || m_type == eUT_CreateCustomClass); bool gotName = (theName[0] != '\0'); if (expectName != gotName && m_type != eUT_Invalid) // If it's invalid, we'll already have displayed a warning... { GameWarning("[PROGRESSION] An unlock of type '%s' %s have a name but XML says name='%s'", theType, expectName ? "should" : "shouldn't", theName); } } else { GameWarning("[PROGRESSION] XML node contains an 'unlock' tag with no type (name='%s')", theName); } if (theReincarnationLevel != NULL && theReincarnationLevel[0] != '\0') { m_reincarnation = atoi(theReincarnationLevel); CPlayerProgression *pPlayerProgression = CPlayerProgression::GetInstance(); DesignerWarning(m_reincarnation > 0 && m_reincarnation < pPlayerProgression->GetMaxReincarnations()+1, "Unlock %s reincarnation parameter is outside of the range 0 - %d", theName, pPlayerProgression->GetMaxReincarnations()+1); } }
//------------------------------------------------------------------------ bool CPlayerProfileImplFS::LoginUser(SUserEntry* pEntry) { // lookup stored profiles of the user (pEntry->userId) and fill in the pEntry->profileDesc // vector pEntry->profileDesc.clear(); // scan directory for profiles string path; InternalMakeFSPath(pEntry, "", path); // no profile name -> only path ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; path.TrimRight("/\\"); string search = path + "/*.xml"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { // fd.name contains the profile name string filename = path; filename += "/" ; filename += fd.name; XmlNodeRef rootNode = LoadXMLFile(filename.c_str()); // see if the root tag is o.k. if (rootNode && stricmp(rootNode->getTag(), PROFILE_ROOT_TAG) == 0) { string profileName = fd.name; PathUtil::RemoveExtension(profileName); if (rootNode->haveAttr(PROFILE_NAME_TAG)) { const char* profileHumanName = rootNode->getAttr(PROFILE_NAME_TAG); if (profileHumanName!=0 && stricmp(profileHumanName, profileName) == 0) { profileName = profileHumanName; } } pEntry->profileDesc.push_back(SLocalProfileInfo(profileName)); } else { GameWarning("CPlayerProfileImplFS::LoginUser: Profile '%s' of User '%s' seems to exist, but is invalid (File '%s). Skipped", fd.name, pEntry->userId.c_str(), filename.c_str()); } } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } 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; } } } }
//--------------------------------------- void CMiscAnnouncer::InitXML(XmlNodeRef root) { IEntityClassRegistry *pEntityClassRegistry = gEnv->pEntitySystem->GetClassRegistry(); XmlNodeRef onWeaponFiringRoot = root->findChild("OnWeaponFiring"); CryLog("CMiscAnnouncer::InitXML()"); if(onWeaponFiringRoot) { const int numChildren = onWeaponFiringRoot->getChildCount(); CryLog("CMiscAnnouncer::InitXML() found OnWeaponFiringRoot with %d children", numChildren); for(int i=0; i<numChildren; ++i) { XmlNodeRef child = onWeaponFiringRoot->getChild(i); if(child->isTag("OnWeaponFired")) { const char *pWeaponClassName = child->getAttr("weaponClass"); CRY_ASSERT(pWeaponClassName && pWeaponClassName[0] != 0); CryLog("CMiscAnnouncer::InitXML() OnWeaponFired tag - pWeaponClassName=%s", pWeaponClassName ? pWeaponClassName : "NULL"); if(IEntityClass* pWeaponEntityClass = pEntityClassRegistry->FindClass(pWeaponClassName)) { const char *pAnnouncement = child->getAttr("announcement"); CRY_ASSERT(pAnnouncement && pAnnouncement[0] != 0); EAnnouncementID announcementID = CAnnouncer::NameToID(pAnnouncement); CryLog("CMiscAnnouncer::InitXML() found weapon entity class for pWeaponClassName=%s; found pAnnouncement=%s announcementID=%x", pWeaponClassName, pAnnouncement ? pAnnouncement : "NULL", announcementID); SOnWeaponFired newWeaponFired(pWeaponEntityClass, pAnnouncement, announcementID); m_weaponFiredMap.insert(TWeaponFiredMap::value_type(pWeaponEntityClass, newWeaponFired)); } else { CryLog("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName); CRY_ASSERT_MESSAGE(0, string().Format("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName)); } } else { CryLog("CMiscAnnouncer::InitXML() unhandled childtag of %s found", child->getTag()); } } } }
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; }
bool CFlowGraphModule::LoadModuleGraph(const char* moduleName, const char* fileName) { assert(m_name == moduleName); assert(m_fileName == fileName); XmlNodeRef moduleRef = gEnv->pSystem->LoadXmlFromFile(fileName); if (!moduleRef) { CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "Unable to load Flowgraph Module Graph: %s", moduleName); return false; } assert(!stricmp(moduleRef->getTag(), "Graph")); bool module = false; moduleRef->getAttr("isModule", module); assert(module); bool bResult = (m_pRootGraph != NULL); assert(m_pRootGraph == NULL); if (!m_pRootGraph) { IFlowSystem* pSystem = gEnv->pFlowSystem; assert(pSystem); // Create graph m_pRootGraph = pSystem->CreateFlowGraph(); if (m_pRootGraph) { m_pRootGraph->SerializeXML(moduleRef, true); // Root graph is for cloning, so not active! m_pRootGraph->UnregisterFromFlowSystem(); m_pRootGraph->SetEnabled(false); m_pRootGraph->SetActive(false); bResult = true; } } return bResult; }
void GetArchetypesFromLevelLib(XmlNodeRef root, std::vector<string>* archetypeNames) { if (!root) return; string sRootName; sRootName = root->getTag(); XmlNodeRef pLevelNode = root->findChild("EntityPrototypesLibs"); if (!pLevelNode) return; XmlNodeRef pLevelLibrary = pLevelNode->findChild("LevelLibrary"); if (!pLevelLibrary) return; GetArchetypesFromLib(pLevelLibrary, sRootName, archetypeNames); }
void GetArchetypesFromLib(XmlNodeRef root, string& name, std::vector<string>* archetypeNames) { if (!root) return; const int iChildCount = root->getChildCount(); for (int iChild = 0; iChild < iChildCount; ++iChild) { XmlNodeRef pChild = root->getChild(iChild); if (!pChild || stricmp(pChild->getTag(), "EntityPrototype")) continue; XmlString sChildName; pChild->getAttr("Name", sChildName); string sFullName; sFullName.Format("%s.%s", name.c_str(), sChildName.c_str()); archetypeNames->push_back(sFullName); } }
bool CEntityPoolSignature::CompareNodes(const XmlNodeRef &a, const XmlNodeRef &b, bool bRecursive) { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(bool(a)); assert(bool(b)); bool bResult = (a && b && a->isTag(b->getTag())); // Check value bResult &= (bResult && 0 == strcmp(a->getContent(), b->getContent())); // Check attributes bResult &= (bResult && CompareNodeAttributes(a, b)); // Check children if recursive if (bResult && bRecursive) { const int childCount_a = a->getChildCount(); const int childCount_b = b->getChildCount(); bResult &= (childCount_a == childCount_b); if (bResult) { for (int child = 0; bResult && child < childCount_a; ++child) { XmlNodeRef child_a = a->getChild(child); XmlNodeRef child_b = b->getChild(child); if (child_a && child_b) { bResult &= CompareNodes(child_a, child_b, true); } } } } return bResult; }
void CWorldState::RemoveEntity(const char * entityName) { if(worldStateXml) { CryLog("CWorldState::RemoveEntity()"); const uint32 Count = worldStateXml->getChildCount(); for (uint32 Index = 0; Index < Count; ++Index) { XmlNodeRef child = worldStateXml->getChild(Index); if(strcmp(child->getTag(),entityName)==0) { worldStateXml->deleteChildAt(Index); } } worldStateXml->saveToFile(szSaveFile); } else return; }