Ejemplo n.º 1
0
void LevelLoader::loadUnitDataFromXml(XmlNode* unitBaseNode) {
	// Start with player units
	XmlNode* unitNode = unitBaseNode->GetFirstChildByNodeName("");
	while (unitNode != nullptr) {
		int unitXmlId          = unitNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string unitPrefab = unitNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		GameObject* unitObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + unitPrefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[unitXmlId] = unitObj->GetId();

		// Units require a GridNavigator component
		GridNavigator* gNav = unitObj->GetComponent<GridNavigator>();
		ASSERT(gNav != nullptr, "Unit with id %d has GridNavigator component", unitObj->GetId());

		// Read the initial position of the unit
		int gX = unitNode->GetAttributeValueI(X_ATTRIBUTE);
		int gZ = unitNode->GetAttributeValueI(Z_ATTRIBUTE);
		float rotation = unitNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		// Add the unit to the grid
		SINGLETONS->GetGridManager()->placeUnitOnGrid(unitObj->GetId(), gX, gZ);

		// Orient the unit.
		unitObj->GetTransform()->SetOrientation(rotation, YAXIS);

		// Check unit type
		if (unitNode->GetName() == ENEMY_UNIT_TAG) {
			EnemyUnit* enemyUnit = unitObj->GetComponent<EnemyUnit>();
			ASSERT(enemyUnit != nullptr, "Enemy unit with id %d has EnemyUnit component", unitObj->GetId());
			enemyUnit->Activate();

			AiPerception* aiPerception = unitObj->GetComponent<AiPerception>();
			ASSERT(aiPerception != nullptr, "Enemy unit with id %d has AiPerception component", unitObj->GetId());
			aiPerception->Activate();

			AiRoutine* aiRoutine = unitObj->GetComponent<AiRoutine>();
			ASSERT(aiRoutine != nullptr, "Enemy unit with id %d has AiRoutine component", unitObj->GetId());

			// Load the AI routine.
			XmlNode* aiCommandNode = unitNode->GetFirstChildByNodeName(AI_COMMAND_TAG);
			std::vector<std::string> commands;
			while (aiCommandNode != nullptr) {
				std::string command = aiCommandNode->GetValue();
				commands.push_back(command);
				aiCommandNode = aiCommandNode->GetNextSiblingByNodeName(AI_COMMAND_TAG);
			}
			aiRoutine->SetBehavior(commands);
		}

		GridZone* zone = unitObj->GetComponent<GridZone>();
		if (zone != nullptr) {
			SINGLETONS->GetGridManager()->placeZoneOnGrid(unitObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId());
		}

		unitNode = unitNode->GetNextSiblingByNodeName("");
	}
}
Ejemplo n.º 2
0
std::wstring XmlAttributeList::GetAttributeValue(const std::wstring& name) const
{
	const XmlNode attribute = GetAttribute(name);
	std::wstring result;

	if (attribute)
		result = attribute.GetValue();

	return result;
}
Ejemplo n.º 3
0
std::wstring XmlAttributeList::GetAttributeValue(size_t index) const
{
	const XmlNode attribute = GetAttribute(index);
	std::wstring result;

	if (attribute)
		result = attribute.GetValue();

	return result;
}