Example #1
0
void LevelLoader::loadLinkDataFromXml  (XmlNode* linkBaseNode) {
	XmlNode* triggerLinkNode = linkBaseNode->GetFirstChildByNodeName(TRIGGER_LINK_TAG);
	while (triggerLinkNode != nullptr) {
		int triggerXmlId = triggerLinkNode->GetAttributeValueI(ID_ATTRIBUTE);
		ObjectIdType triggerId = idsFromXml[triggerXmlId];
		GameObject* triggerObj = ENGINE->GetSceneGraph3D()->GetGameObjectById(triggerId);
		ASSERT(triggerObj != nullptr, "Trigger object with id %d exists in level", triggerId);
		if (triggerObj != nullptr) {
			Triggerable* triggerComp = triggerObj->GetComponent<Triggerable>();
			ASSERT((triggerComp != nullptr), "Object with id %d has Triggerable component", triggerId);
			if (triggerComp != nullptr) {
				XmlNode* switchNode = triggerLinkNode->GetFirstChildByNodeName(SWITCH_TAG);
				while (switchNode != nullptr) {
					int switchXmlId = switchNode->GetAttributeValueI(ID_ATTRIBUTE);
					ObjectIdType switchId = idsFromXml[switchXmlId];
					triggerComp->SubscribeToSwitchObject(switchId);

					switchNode = switchNode->GetNextSiblingByNodeName(SWITCH_TAG);
				}
			}
		}

		triggerLinkNode = triggerLinkNode->GetNextSiblingByNodeName(TRIGGER_LINK_TAG);
	}
}
Example #2
0
void LevelLoader::loadOtherDataFromXml(XmlNode* otherDataNode) {
	XmlNode* dynamicObjNode = otherDataNode->GetFirstChildByNodeName(DYNAMIC_OBJECT_TAG);
	while (dynamicObjNode != nullptr) {
		int objXmlId       = dynamicObjNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string prefab = dynamicObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		int xGridPosition  = dynamicObjNode->GetAttributeValueI(X_ATTRIBUTE);
		float yPosition    = dynamicObjNode->GetAttributeValueF(Y_ATTRIBUTE);
		int zGridPosition  = dynamicObjNode->GetAttributeValueI(Z_ATTRIBUTE);
		float rotation     = dynamicObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		GameObject* dynamicObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[objXmlId] = dynamicObj->GetId();

		// Position and orient the object
		dynamicObj->GetTransform()->SetPosition(xGridPosition, yPosition, -zGridPosition);
		dynamicObj->GetTransform()->SetOrientation(rotation, YAXIS);

		// Check for overloaded components
		XmlNode* compNode = dynamicObjNode->GetFirstChildByNodeName(COMPONENT_TAG);
		while (compNode != nullptr) {
			PrefabLoader::LoadComponentFromComponentNodeInPrefab(dynamicObj, compNode);
			compNode = compNode->GetNextSiblingByNodeName(COMPONENT_TAG);
		}

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

		dynamicObjNode = dynamicObjNode->GetNextSiblingByNodeName(DYNAMIC_OBJECT_TAG);
	}

	// TODO [Implement] Other things such as triggerables
}
Example #3
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("");
	}
}
Example #4
0
void Bundle::loadFromDisk() {
	std::ifstream file;
	GetBundleFileHandleForReading(this->bundleName, file);

	if (file.good()) {
		XmlParser* parser = new XmlParser();
		parser->ParseXmlFile(file);

		XmlTree* tree = parser->GetXmlTree();
		VERIFY(tree != nullptr, "Got xml tree for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* rootNode = tree->GetRootNode();
		VERIFY(rootNode != nullptr, "Got root node for bundle data in bundle %s", this->bundleName.c_str());
		VERIFY(rootNode->GetName() == BUNDLE_TAG, "Got bundle node for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* dataNode = rootNode->GetFirstChildByNodeName(DATA_TAG);
		while(dataNode != nullptr) {
			std::string key   = dataNode->GetAttributeValueS(KEY_ATTRIBUTE);
			std::string value = dataNode->GetAttributeValueS(VALUE_ATTRIBUTE);
			this->PutString(key, value);
			//
			dataNode = dataNode->GetNextSiblingByNodeName(DATA_TAG);
		}

		delete parser;
	}
}
Example #5
0
void LevelLoader::loadParentConnectionsFromXml(XmlNode* linkBaseNode) {
	XmlNode* parentNode = linkBaseNode->GetFirstChildByNodeName(PARENT_LINK_TAG);
	while (parentNode != nullptr) {
		int parentXmlId = parentNode->GetAttributeValueI(ID_ATTRIBUTE);
		GameObject* parentObj = ENGINE->GetSceneGraph3D()->GetGameObjectById(idsFromXml[parentXmlId]);
		if (parentObj != nullptr) {
			XmlNode* childNode = parentNode->GetFirstChildByNodeName(CHILD_TAG);
			while (childNode != nullptr) {
				int childXmlId = childNode->GetAttributeValueI(ID_ATTRIBUTE);

				parentObj->AddChild_maintainTransform(idsFromXml[childXmlId]);

				childNode = childNode->GetNextSiblingByNodeName(CHILD_TAG);
			}
		}

		parentNode = parentNode->GetNextSiblingByNodeName(PARENT_LINK_TAG);
	}
}
Example #6
0
void LevelLoader::loadEndConditionsFromXml(XmlNode* linkBaseNode) {
	XmlNode* winConditionNode = linkBaseNode->GetFirstChildByNodeName(WIN_CONDITION_TAG);
	//ASSERT(winConditionNode != nullptr, "Level has a win condition");
	while (winConditionNode != nullptr) {
		int switchXmlId = winConditionNode->GetAttributeValueI(ID_ATTRIBUTE);
		ObjectIdType switchId = idsFromXml[switchXmlId];
		SINGLETONS->GetLevelManager()->AddWinCondition(switchId);

		winConditionNode = winConditionNode->GetNextSiblingByNodeName(WIN_CONDITION_TAG);
	}

	XmlNode* loseConditionNode = linkBaseNode->GetFirstChildByNodeName(LOSE_CONDITION_TAG);
	while (loseConditionNode != nullptr) {
		int switchXmlId = loseConditionNode->GetAttributeValueI(ID_ATTRIBUTE);
		ObjectIdType switchId = idsFromXml[switchXmlId];
		SINGLETONS->GetLevelManager()->AddLoseCondition(switchId);

		loseConditionNode = loseConditionNode->GetNextSiblingByNodeName(LOSE_CONDITION_TAG);
	}

	// Generate the default lose condition
	GameObject* defaultLose = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + DEFAULT_LOSE_CONDITION + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
	SINGLETONS->GetLevelManager()->AddLoseCondition(defaultLose->GetId());
}
Example #7
0
void LevelLoader::loadStaticDataFromXml(XmlNode* staticNode) {
	XmlNode* staticObjNode = staticNode->GetFirstChildByNodeName(STATIC_OBJECT_TAG);
	while (staticObjNode != nullptr) {
		int objXmlId       = staticObjNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string prefab = staticObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		int westBound      = staticObjNode->GetAttributeValueI(X_ATTRIBUTE);
		float yPosition    = staticObjNode->GetAttributeValueF(Y_ATTRIBUTE);
		int southBound     = staticObjNode->GetAttributeValueI(Z_ATTRIBUTE);
		int objWidth       = staticObjNode->GetAttributeValueI(WIDTH_ATTRIBUTE);
		int objHeight      = staticObjNode->GetAttributeValueI(HEIGHT_ATTRIBUTE);
		float rotation     = staticObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		GameObject* staticObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[objXmlId] = staticObj->GetId();

		// Add the object to the grid
		SINGLETONS->GetGridManager()->placeStaticObjectOnGrid(staticObj->GetId(), westBound, southBound, objWidth, objHeight);

		staticObj->GetTransform()->Translate(yPosition, YAXIS);
		staticObj->GetTransform()->SetOrientation(rotation, YAXIS);

		staticObjNode = staticObjNode->GetNextSiblingByNodeName(STATIC_OBJECT_TAG);
	}
}