//------------------------------------------------------------------------
bool CPlayerProfileImplConsole::LoadProfile(SUserEntry* pEntry, CPlayerProfile* pProfile, const char* name)
{
	// load the profile from a specific location

	// XML for now
	string path;
	InternalMakeFSPath(pEntry, name, path);

	XmlNodeRef rootNode = GetISystem()->CreateXmlNode(PROFILE_ROOT_TAG);
	CSerializerXML serializer(rootNode, true);

	XmlNodeRef profile = LoadXMLFile(path+"profile.xml");

	bool ok = false;
	if(profile)
	{
		XmlNodeRef attrNode = profile->findChild("Attributes");
		XmlNodeRef actionNode = profile->findChild("ActionMaps");
		if(!(attrNode && actionNode)) //default (PC) profile?
		{
			attrNode = LoadXMLFile(path+"attributes.xml");
			actionNode = LoadXMLFile(path+"actionmaps.xml");
		}

		if(attrNode && actionNode)
		{
			serializer.SetSection(CPlayerProfileManager::ePPS_Attribute, attrNode);
			serializer.SetSection(CPlayerProfileManager::ePPS_Actionmap, actionNode);

			ok = pProfile->SerializeXML(&serializer);
		}
	}

	return ok;
}
//------------------------------------------------------------------------
bool CPlayerProfileImplConsole::SaveProfile(SUserEntry* pEntry, CPlayerProfile* pProfile, const char* name, bool initialSave, int /*reason = ePR_All*/)
{
	IPlatformOS *os = gEnv->pSystem->GetPlatformOS();

	// save the profile into a specific location

	// check if it's a valid filename
	if (IsValidFilename(name) == false)
		return false;

	string path;
	InternalMakeFSPath(pEntry, name, path);

	XmlNodeRef rootNode = GetISystem()->CreateXmlNode(PROFILE_ROOT_TAG);
	rootNode->setAttr(PROFILE_NAME_TAG, name);
	CSerializerXML serializer(rootNode, false);
	pProfile->SerializeXML(&serializer);

	XmlNodeRef attributes = serializer.GetSection(CPlayerProfileManager::ePPS_Attribute);
	XmlNodeRef actionMap = serializer.GetSection(CPlayerProfileManager::ePPS_Actionmap);

	if(!rootNode->findChild("Attributes"))
		rootNode->addChild(attributes);
	if(!rootNode->findChild("ActionMaps"))
		rootNode->addChild(actionMap);

	return SaveXMLFile(path+"profile.xml", rootNode);
}
void CMercyTimeFilter::Init( const XmlNodeRef& xml )
{
	CRY_ASSERT(xml != NULL);

	const XmlNodeRef difficultyFilterNode = xml->findChild("DifficultyFilters");
	if(difficultyFilterNode != NULL)
	{
		const int childCount = difficultyFilterNode->getChildCount();
		for(int i = 0; i < childCount; ++i)
		{
			const XmlNodeRef& childNode = difficultyFilterNode->getChild(i);

			int difficultyLevel = 0;
			if(childNode->getAttr("level", difficultyLevel) && 
				((difficultyLevel > 0) && (difficultyLevel <= MaxDifficultyLevels)))
			{
				uint32 allowedHits = 0;
				childNode->getAttr("killAfterHits", allowedHits);
				m_difficultyTolerance[difficultyLevel-1] = allowedHits;
			}
		}
	}

	const XmlNodeRef projectileFilterNode = xml->findChild("ProjectileFilters");
	if(projectileFilterNode != NULL)
	{
		const int childCount = projectileFilterNode->getChildCount();

		m_filteredProjectiles.reserve( childCount );

		for (int i = 0; i < childCount; ++i)
		{
			const XmlNodeRef& childNode = projectileFilterNode->getChild( i );

			ClassFilter classFilter;
			classFilter.classId = ~uint16(0); 
			classFilter.type = ClassFilter::eType_None;

			if(g_pGame->GetIGameFramework()->GetNetworkSafeClassId( classFilter.classId, childNode->getAttr("class") ))
			{
				const char* filterType = childNode->haveAttr("filter") ? childNode->getAttr("filter") : "none";

				if(strcmp(filterType, "self") == 0)
				{
					classFilter.type = ClassFilter::eType_Self;
				}

				m_filteredProjectiles.push_back( classFilter );
			}
		}

		std::sort( m_filteredProjectiles.begin(), m_filteredProjectiles.end(), CompareClassFilter() );
	}
}
Exemple #4
0
void CDLCManager::PopulateDLCContents(const XmlNodeRef &rootNode, int dlcId, const char* name )
{
	mbstowcs( m_dlcContents[dlcId].name, name, MAX_DLC_NAME );

	XmlNodeRef levelsNode = rootNode->findChild("levels");
	if (levelsNode)
	{
		XmlString levelName;
		int numLevels = levelsNode->getChildCount();

		CryLog( "Found %d levels in the DLC", numLevels );
		
		m_dlcContents[dlcId].levels.reserve(numLevels);
		for (int i=0; i<numLevels; ++i)
		{
			XmlNodeRef levelNode = levelsNode->getChild(i);
			if (levelNode->getAttr("name", levelName))
			{
				CryLog( "Found level %s and added to the DLC manager", levelName.c_str() );
				m_dlcContents[dlcId].levels.push_back(levelName);
			}
		}
	}

	XmlNodeRef bonusNode = rootNode->findChild("bonus");
	if( bonusNode )
	{
		CryLog( "DLC pak includes a pre-sale bonus" );
		uint32 bonusID = 0;
		bonusNode->getAttr("id", bonusID );
		m_dlcContents[dlcId].bonusID = bonusID;
	}

	XmlNodeRef uniqueIdNode = rootNode->findChild("uniqueId");
	if( uniqueIdNode )
	{
		uint32 uniqueID = 0;
		uniqueIdNode->getAttr("id", uniqueID );
		m_dlcContents[dlcId].uniqueID = uniqueID;
	}

	XmlNodeRef uniqueTagNode = rootNode->findChild("uniqueTag");
	if( uniqueTagNode )
	{
		const char* str =	uniqueTagNode->getAttr( "tag" );
		m_dlcContents[dlcId].uniqueTag.Format( str );
	}
}
void CEntityPropertyHandler::LoadEntityXMLProperties(IEntity *pEntity, const XmlNodeRef& xml)
{
	if(auto properties = xml->findChild("Properties"))
	{
		for(int i = 0; i < properties->getNumAttributes(); i++)
		{
			const char *name;
			const char *value;

			properties->getAttributeByIndex(i, &name, &value);

			int index = 0;
			bool exists = false;

			for(; index < GetPropertyCount(); index++)
			{
				SPropertyInfo info;
				GetPropertyInfo(index, info);

				if(!strcmp(info.name, name))
				{
					exists = true;
					break;
				}
			}

			if(exists)
				SetProperty(pEntity, index, value);
			else
				MonoWarning("Could not set property %s because it did not exist", name);
		}
	}
}
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;
	
}
void CVehicleModificationParams::InitModification( XmlNodeRef xmlModificationData )
{
	assert( xmlModificationData );

	bool hasParentModification = xmlModificationData->haveAttr( "parent" );
	if ( hasParentModification )
	{
		XmlNodeRef xmlModificationsGroup = xmlModificationData->getParent();

		const char* parentModificationName = xmlModificationData->getAttr( "parent" );
		XmlNodeRef xmlParentModificationData = FindModificationNodeByName( parentModificationName, xmlModificationsGroup );
		if ( xmlParentModificationData && ( xmlParentModificationData != xmlModificationData ) )
		{
			InitModification( xmlParentModificationData );
		}
	}

	XmlNodeRef xmlElemsGroup = xmlModificationData->findChild( "Elems" );
	if ( ! xmlElemsGroup )
	{
		return;
	}

	for ( int i = 0; i < xmlElemsGroup->getChildCount(); ++i )
	{
		XmlNodeRef xmlElem = xmlElemsGroup->getChild( i );

		InitModificationElem( xmlElem );
	}
}
Exemple #8
0
void CClipVolumeProxy::SerializeXML(XmlNodeRef &entityNodeXML, bool loading)
{
	if(loading)
	{
		LOADING_TIME_PROFILE_SECTION;

		if(XmlNodeRef pVolumeNode = entityNodeXML->findChild( "ClipVolume" ))
		{
			const char* szFileName = NULL;
			if(pVolumeNode->getAttr("GeometryFileName",&szFileName))
			{
				// replace %level% by level path
				char szFilePath[_MAX_PATH];
				const int nAliasNameLen = sizeof("%level%")-1;

				cry_strcpy(szFilePath, gEnv->p3DEngine->GetLevelFilePath(szFileName+nAliasNameLen));

				if(m_pEntity && LoadFromFile(szFilePath))
					gEnv->p3DEngine->UpdateClipVolume(m_pClipVolume, m_pRenderMesh, m_pBspTree, m_pEntity->GetWorldTM(), !m_pEntity->IsHidden(), m_pEntity->GetName());
			}
		}
	}
	else
	{
		XmlNodeRef volumeNode = entityNodeXML->newChild( "ClipVolume" );
		volumeNode->setAttr( "GeometryFileName", m_GeometryFileName );
	}
}
//------------------------------------------------------------------------
bool CVehicleDamagesTemplateRegistry::RegisterTemplates(const string& filename, const string& defFilename)
{
	XmlNodeRef table = gEnv->pSystem->LoadXmlFromFile(filename);
	if (!table)
		return false;

	m_templateFiles.resize(m_templateFiles.size() + 1);
	STemplateFile& templateFile = m_templateFiles.back();

	templateFile.defFilename = defFilename;
	templateFile.filename = filename;
	templateFile.templateTable = table;

	if (XmlNodeRef damagesGroupsTable = table->findChild("DamagesGroups"))
	{
		int i = 0;
		int c = damagesGroupsTable->getChildCount();

		for (; i < c; i++)
		{
			if (XmlNodeRef damagesGroupTable = damagesGroupsTable->getChild(i))
			{
				string name = damagesGroupTable->getAttr("name");
				if (!name.empty())
					m_templates.insert(TTemplateMap::value_type(name, damagesGroupTable));
			}
		}
	}

	return true;
}
void CItemComponent::GetSharedParameters(XmlNodeRef rootParams)
{
	// Parameters get stored under a combination of the class name and the section name for the parameters.
	CryFixedStringT<256> sharedName;
	sharedName.Format("item::%s::%s", GetEntity()->GetClass()->GetName(), "itemBase");

	ISharedParamsManager* pSharedParamsManager = gEnv->pGameFramework->GetISharedParamsManager();
	CRY_ASSERT(pSharedParamsManager);
	m_itemBaseParameter = CastSharedParamsPtr<SItemBaseParameter>(pSharedParamsManager->Get(sharedName));

	// If no parameter set exists we should attempt to create and register one.
	if (!m_itemBaseParameter)
	{
		SItemBaseParameter sharedParams;

		// Load in the base item shared parameters.
		XmlNodeRef itemBaseParams = rootParams->findChild("itemBase");
		if (itemBaseParams)
			sharedParams.Read(itemBaseParams);

		// Register a new set of parameters and retrieve a shared pointer to them.
		m_itemBaseParameter = CastSharedParamsPtr<SItemBaseParameter>(pSharedParamsManager->Register(sharedName, sharedParams));
	}

	// Double check the shared parameter.
	CRY_ASSERT(m_itemBaseParameter.get());
}
void CCheckpointSystem::LoadExternalEntities(XmlNodeRef parentNode)
{
	XmlNodeRef data = parentNode->findChild(EXTERNAL_ENTITIES_SECTION);
	if(!data)
		return;

	int numEntities = data->getChildCount();
	for(int i = 0; i < numEntities; ++i)
	{
		XmlNodeRef nextEntity = data->getChild(i);
		if(nextEntity)
		{
			EntityId id = 0;
			nextEntity->getAttr("id", id);
			const char *name = nextEntity->getAttr("name");
			
			//fix entityId if broken
			if(RepairEntityId(id, name))
			{
				IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id);
				//setup entity
				bool bActive = false;
				bool bHidden = false;
				nextEntity->getAttr("active", bActive);
				nextEntity->getAttr("hidden", bHidden);
				pEntity->Activate(bActive);
				pEntity->Hide(bHidden);
				//load matrix
				SerializeWorldTM(pEntity, nextEntity, false);
			}
		}
	}
}
Exemple #12
0
//////////////////////////////////////////////////////////////////////////
//
// Allows the game code to write game-specific data into the minimap xml
// file on level export. Currently used to export data to StatsTool
//
//////////////////////////////////////////////////////////////////////////
bool CEditorGame::GetAdditionalMinimapData(XmlNodeRef output)
{
	string classes = g_pGameCVars->g_telemetryEntityClassesToExport;
	if(!classes.empty())
	{
		// additional data relating to StatsTool
		XmlNodeRef statsNode = output->findChild("StatsTool");
		if(!statsNode)
		{
			statsNode = GetISystem()->CreateXmlNode("StatsTool");
			output->addChild(statsNode);
		}
		else
		{
			statsNode->removeAllChilds();
		}

		// first build a list of entity classes from the cvar
		std::vector<IEntityClass*> interestingClasses;
		int curPos = 0;
		string currentClass = classes.Tokenize(",",curPos);
		IEntitySystem* pES = GetISystem()->GetIEntitySystem();
		if(IEntityClassRegistry* pClassReg = pES->GetClassRegistry())
		{
			while (!currentClass.empty())
			{
				if(IEntityClass* pClass = pClassReg->FindClass(currentClass.c_str()))
				{
					interestingClasses.push_back(pClass);
				}

				currentClass = classes.Tokenize(",",curPos);
			}
		}

		// now iterate through all entities and save the ones which match the classes
		if(interestingClasses.size() > 0)
		{
			IEntityItPtr it = pES->GetEntityIterator();
			while(IEntity* pEntity = it->Next())
			{
				if(stl::find(interestingClasses, pEntity->GetClass()))
				{
					XmlNodeRef entityNode = GetISystem()->CreateXmlNode("Entity");
					statsNode->addChild(entityNode);

					entityNode->setAttr("class", pEntity->GetClass()->GetName());
					Vec3 pos = pEntity->GetWorldPos();
					entityNode->setAttr("x", pos.x);
					entityNode->setAttr("y", pos.y);
					entityNode->setAttr("z", pos.z);
				}
			}
		}
	}

	return true;
}
Exemple #13
0
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;
}
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;
}
Exemple #15
0
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);
}
bool CCheckpointSystem::SaveExternalEntity(EntityId id)
{
	//this function allows external logic (flowgraph) to save specific entities
	if(!CHECKPOINT_SAVE_XML_NODE)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tried writing external entity %i while savegame was not open.", (int)id);
		return false;
	}

	//find entity and access external section
	IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id);
	if(pEntity)
	{
		XmlNodeRef externalEntities = CHECKPOINT_SAVE_XML_NODE->findChild(EXTERNAL_ENTITIES_SECTION);
		if(!externalEntities)
		{
			externalEntities = GetISystem()->CreateXmlNode(EXTERNAL_ENTITIES_SECTION);
			CHECKPOINT_SAVE_XML_NODE->addChild(externalEntities);
		}

		IActor *pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEntity->GetId());
		if(pActor)
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "The actor %s is additionally saved as external entity.", pEntity->GetName());
		}

		//create entity data
		char entityId[16];
		_snprintf(entityId, sizeof(entityId), "%s%i", "id", id);
		XmlNodeRef nextEntity = GetISystem()->CreateXmlNode(entityId);
		if(nextEntity)
		{
			nextEntity->setAttr("id", pEntity->GetId());
			nextEntity->setAttr("name", pEntity->GetName());
			//save active / hidden
			nextEntity->setAttr("active", pEntity->IsActive());
			nextEntity->setAttr("hidden", pEntity->IsHidden());
			//save translation and rotation (complete tm matrix for simplicity)
			SerializeWorldTM(pEntity, nextEntity, true);
			//add new entity to checkpoint
			externalEntities->addChild(nextEntity);

			return true;
		}

		return false;
	}

	return false;
}
Exemple #17
0
void CScriptProxy::SerializeXML( XmlNodeRef &entityNode,bool bLoading )
{
	// Initialize script properties.
	if (bLoading)
	{
		CScriptProperties scriptProps;
		// Initialize properties.
		scriptProps.SetProperties( entityNode,m_pThis );

		XmlNodeRef eventTargets = entityNode->findChild("EventTargets");
		if (eventTargets)
			SetEventTargets( eventTargets );
	}
}
Exemple #18
0
	EContextEstablishTaskResult OnStep(SContextEstablishState& state)
	{
		ILevel*			pLevel = CCryAction::GetCryAction()->GetILevelSystem()->GetCurrentLevel();
		if (!pLevel)
		{
			GameWarning("level is null");
			return eCETR_Failed;
		}
		const char * levelName = CCryAction::GetCryAction()->GetLevelName();
		if (!levelName)
		{
			GameWarning("levelName is null");
			return eCETR_Failed;
		}
		ILevelInfo* pLevelInfo = CCryAction::GetCryAction()->GetILevelSystem()->GetLevelInfo(levelName);
		if (!pLevelInfo)
		{
			GameWarning("levelInfo is null");
			return eCETR_Failed;
		}


		// delete any pending entities before reserving EntityIds in LoadEntities()
		gEnv->pEntitySystem->DeletePendingEntities();

		string missionXml = pLevelInfo->GetDefaultGameType()->xmlFile;
		string xmlFile = string(pLevelInfo->GetPath()) + "/" + missionXml;

		XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(xmlFile.c_str());

		if (rootNode)
		{
			const char *script = rootNode->getAttr("Script");

			if (script && script[0])
				gEnv->pScriptSystem->ExecuteFile(script, true, true);

			XmlNodeRef objectsNode = rootNode->findChild("Objects");

			if (objectsNode)
				gEnv->pEntitySystem->LoadEntities(objectsNode, false);
		}
		else
			return eCETR_Failed;

		SEntityEvent loadingCompleteEvent(ENTITY_EVENT_LEVEL_LOADED);
		gEnv->pEntitySystem->SendEventToAll( loadingCompleteEvent );

		return eCETR_Ok;
	}
Exemple #19
0
void CEditorGame::InitActionEnums(IGameToEditorInterface* pGTE)
{
	// init ActionFilter enums
	IActionMapManager* pActionMapMgr = m_pGame->GetIGameFramework()->GetIActionMapManager();
	if (pActionMapMgr)
	{
		std::vector<string> filterNames;
		filterNames.push_back(""); // empty
		IActionFilterIteratorPtr pFilterIter = pActionMapMgr->CreateActionFilterIterator();
		while (IActionFilter* pFilter = pFilterIter->Next())
		{
			filterNames.push_back(pFilter->GetName());
		}
		size_t numFilters = 0;
		const char** allFilters = new const char*[filterNames.size()];
		std::vector<string>::const_iterator iter = filterNames.begin();
		std::vector<string>::const_iterator iterEnd = filterNames.end();
		while (iter != iterEnd)
		{
			allFilters[numFilters++] = iter->c_str();
			++iter;
		}
		pGTE->SetUIEnums("action_filter", allFilters, numFilters);
		delete[] allFilters;
	}

	// init vehicle light type enum
	XmlNodeRef defaultDataRef = gEnv->pSystem->LoadXmlFromFile("Scripts/Entities/Vehicles/Lights/DefaultVehicleLights.xml");
	if (defaultDataRef)
	{
		if (XmlNodeRef lightDefaultsRef = defaultDataRef->findChild("Lights"))
		{
			const char** typeNames = NULL;
			int count = lightDefaultsRef->getChildCount() + 1;

			typeNames = new const char*[count];
			typeNames[0] = "All";

			for (int i=1; i < count; i++)
			{
				if (XmlNodeRef tableRef = lightDefaultsRef->getChild(i-1))
				{
					typeNames[i] = tableRef->getAttr("type");     
				}
			}
			pGTE->SetUIEnums("vehicleLightTypes", typeNames, count);
			delete[] typeNames;
		}
	}	
}
Exemple #20
0
bool CScriptProperties::SetProperties( XmlNodeRef &entityNode,IScriptTable* pEntityTable )
{
	XmlNodeRef propsNode = entityNode->findChild("Properties");
	if (propsNode)
	{
		SmartScriptTable pPropsTable;
		if (pEntityTable->GetValue( "Properties",pPropsTable ))
		{
			Assign( propsNode,pPropsTable );
		}
	}

	propsNode = entityNode->findChild("Properties2");
	if (propsNode)
	{
		SmartScriptTable pPropsTable;
		if (pEntityTable->GetValue( "PropertiesInstance",pPropsTable ))
		{
			Assign( propsNode,pPropsTable );
		}
	}

	return true;
}
Exemple #21
0
//---------------------------------------
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 CCommonSaveGameHelper::FetchMetaData(XmlNodeRef& root, CPlayerProfileManager::SSaveGameMetaData& metaData)
{
	// TODO: use CXmlLoadGame for this
	XmlNodeRef metaDataNode = root;
	if (metaDataNode->isTag("Metadata") == false)
		metaDataNode = root->findChild("Metadata");
	if (metaDataNode == 0)
		return false;
	bool ok = true;
	ok &= GetAttr(metaDataNode, "level", metaData.levelName);
	ok &= GetAttr(metaDataNode, "gameRules", metaData.gameRules);
	ok &= GetAttr(metaDataNode, "version", metaData.fileVersion);
	ok &= GetAttr(metaDataNode, "build", metaData.buildVersion);
	ok &= GetTimeAttr(metaDataNode, "saveTime", metaData.saveTime);
	metaData.loadTime = metaData.saveTime;
	metaData.xmlMetaDataNode = metaDataNode;
	return ok;
}
Exemple #23
0
bool CDialogLoader::LoadScript(const string& filename, TDialogScriptMap& outScriptMap)
{
	// parse MS Excel spreadsheet
	XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(filename);
	if (!rootNode)
	{
		GameWarning("[DIALOG] CDialogLoader::LoadScripts: Cannot find file '%s'", filename.c_str());
		return false;
	}

	// iterate over all children and load all worksheets
	int nChilds = rootNode->getChildCount();
	if (nChilds == 0)
	{
		GameWarning("[DIALOG] CDialogLoader::LoadScripts: Cannot find any 'Worksheet's in file '%s'", filename.c_str());
		return false;
	}

	int numScripts = 0;

	string baseName = PathUtil::GetFileName(filename);

	for (int i=0; i<nChilds; ++i)
	{
		XmlNodeRef childNode = rootNode->getChild(i);
		if (childNode && childNode->isTag("Worksheet"))
		{
			const char* wsName = childNode->getAttr("ss:Name");
			XmlNodeRef tableNode = childNode->findChild("Table");
			if (!tableNode)
			{
				GameWarning("[DIALOG] CDialogLoader::LoadScripts: Worksheet '%s' in file '%s' has no Table", wsName ? wsName : "<noname>", filename.c_str());
			}
			else
			{
				const string& groupName = baseName; // maybe we add the Worksheets name later on!
				numScripts = LoadFromTable(tableNode, groupName, outScriptMap);
				break; // only load first worksheet
			}
		}
	}

	return numScripts > 0;
}
bool ModInfo_FetchAttribute(int* value, const XmlNodeRef& pRoot, const char* pNodeName, const char* pAttrName)
{
	if (!value)
		return false;

	XmlNodeRef pNode = pRoot->findChild(pNodeName);
	if (!pNode)
		return false;

	const char* pAttr = 0;
	if (!pNode->getAttr(pAttrName, &pAttr))
		return false;

	if (!pAttr)
		return false;

	*value = atoi(pAttr);
	return true;
}
void CCheckpointSystem::ReadGameTokens(XmlNodeRef parentNode)
{
	//get source node
	XmlNodeRef node = parentNode->findChild(GAMETOKEN_SECTION);
	if(!node)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Couldn't find Gametoken section while reading checkpoint.");
		return;
	}

	//create serialization reader
	IXmlSerializer *pSerializer = GetISystem()->GetXmlUtils()->CreateXmlSerializer();
	ISerialize *pReader = pSerializer->GetReader(node);

	//read serialization data
	TSerialize ser = TSerialize(pReader);
	IGameTokenSystem *pTokenSystem = CCryAction::GetCryAction()->GetIGameTokenSystem();
	pTokenSystem->Serialize(ser);

	pSerializer->Release();
}
	bool WriteAdditionalData( const char* filename, XmlNodeRef data )
	{
		bool bOK = true;
		// we save the meta information also in a separate file
		XmlNodeRef meta = data->findChild("Metadata");
		const string fname (filename);
		if (meta)
		{
#if defined(PS3) || defined(XENON) //don't use meta files on PS3 or 360
#else
			const string metaPath = PathUtil::ReplaceExtension(fname, ".meta");
			bOK = ::SaveXMLFile(metaPath, meta);
#endif
		}
		if (m_thumbnail.data.size() > 0)
		{
			const string bmpPath = PathUtil::ReplaceExtension(fname, ".bmp");
			BMPHelper::SaveBMP(bmpPath, m_thumbnail.data.begin(), m_thumbnail.width, m_thumbnail.height, m_thumbnail.depth, false);
		}
		return bOK;
	}
CVehicleModificationParams::CVehicleModificationParams( XmlNodeRef xmlVehicleData, const char* modificationName )
: m_pImpl( NULL )
{
	assert( modificationName != NULL );
	if ( modificationName[ 0 ] == 0 )
	{
		return;
	}

	string mods(modificationName);

	int start = 0;
	string modification = mods.Tokenize(",", start);

	while (!modification.empty())
	{
		XmlNodeRef xmlModificationsGroup = xmlVehicleData->findChild( "Modifications" );
		if ( ! xmlModificationsGroup )
		{
			GameWarning("Failed to set Modification '%s' because the vehicle doesn't have any modifications", modification.c_str());
			return;
		}

		XmlNodeRef xmlModification = FindModificationNodeByName( modification.c_str(), xmlModificationsGroup );
		if ( ! xmlModification )
		{
			GameWarning("Failed to set Modification '%s' because the vehicle doesn't have that modification", modification.c_str());
			return;
		}

		if(m_pImpl == NULL)
		{
			m_pImpl = new Implementation();
		}

		InitModification( xmlModification );

		modification = mods.Tokenize(",", start);
	}
}
Exemple #28
0
void FillMapping(XmlNodeRef row, unsigned char* pIndexToAttrMap)
{
	int nCellIndex = 0;
	int nNewIndex = 0;
	for (int cell=0; cell<row->getChildCount(); ++cell)
	{
		if (cell >= MAX_CELL_COUNT)
			continue;

		XmlNodeRef nodeCell = row->getChild(cell);
		if (!nodeCell->isTag("Cell"))
			continue;

		if (nodeCell->getAttr("ss:Index",nNewIndex))
		{
			// Check if some cells are skipped.
			nCellIndex = nNewIndex-1;
		}

		XmlNodeRef nodeCellData = nodeCell->findChild("Data");
		if (!nodeCellData)
		{
			++nCellIndex;
			continue;
		}

		const char *sCellContent = nodeCellData->getContent();

		for (int i = 0; i < sizeof(sColumnNames)/sizeof(*sColumnNames); ++i)
		{
			// this is a begins-with-check!
			if (CryStringUtils::stristr(sCellContent, sColumnNames[i]) == sCellContent)
			{
				pIndexToAttrMap[nCellIndex] = i;
				break;
			}
		}
		++nCellIndex;
	}
}
void CEntityAttributesProxy::SerializeXML(XmlNodeRef &entityNodeXML, bool loading)
{
	if(loading == true)
	{
		if(XmlNodeRef attributesNodeXML = entityNodeXML->findChild("Attributes"))
		{
			SEntityAttributesSerializer	serializer(m_attributes);
			Serialization::LoadXmlNode(serializer, attributesNodeXML);
		}
	}
	else
	{
		if(!m_attributes.empty())
		{
			SEntityAttributesSerializer	serializer(m_attributes);
			if(XmlNodeRef attributesNodeXML = Serialization::SaveXmlNode(serializer, "Attributes"))
			{
				entityNodeXML->addChild(attributesNodeXML);
			}
		}
	}
}
//------------------------------------------------------------------------
void CGameRulesMPDamageHandling::Init( XmlNodeRef xml )
{
	CGameRulesCommonDamageHandling::Init(xml);

	m_numKickableCarRecords = 0;

	m_vehicleDamageSettings.killSpeed = 10.f;

	if (XmlNodeRef table = xml->findChild("Table"))
	{
		if (const char* path = table->getAttr("path"))
		{
			if (XmlNodeRef damageTable = GetISystem()->LoadXmlFromFile(path))
			{
				if (XmlNodeRef vehicleDamage = damageTable->findChild("VehicleDamage"))
				{
					InitVehicleDamage(vehicleDamage);
				}
			}
		}
	}
}