Exemplo n.º 1
0
	void CGridMap::FillTileData( CMap * _map, Map::CMapParser::TTileMatrix tileMatrix )
	{
		for (int row = 0; row < _nMapRows; ++row)
			for (int col = 0; col < _nMapCols; ++col)
			{
				CTerrainTile* t_tile = new CTerrainTile(tileMatrix[row][col]->getType());
				t_tile->FillData(tileMatrix[row][col]);
				getTileFromCoord(row, col)->SetTerrain(t_tile);

				if (t_tile->isObstacle())
				{
					//@TODO: spawn Obstacle entity on this position.
					Vector2 pos = getRelativeMapPos(row, col);
					std::stringstream vecPos, name;

					// Creamos una nueva entidad con su entidad trigger sacada de los arquetipos
					Map::CEntity * obstacleInfo = Map::CMapParser::getSingletonPtr()->getEntityInfo("Obstacle");

					name << "Obstacle_" << row << "_" << col;
					vecPos << pos.x << " 0 " << pos.y;

					// Le ponemos un nuevo nombre para poder hacer spawn y la posición del edificio fantasma
					obstacleInfo->setName(name.str());
					obstacleInfo->setAttribute("position", vecPos.str());

					Logic::CEntityFactory::getSingletonPtr()->createEntity(obstacleInfo, _map);
				}
			}
	}
	CEntity* CEntityFactory::createEntityByType(const std::string &type, Vector3 position, CMap *map)
	{
		//solo hacemos creamos algo a partir de un arquetipo así que nos aseguramos de que exista
		ArchetypeMap::iterator find = _archetypes.find(type);
		if( find == _archetypes.end())
		{
			return NULL;
		}

		//nos aseguramos de construir un nombre unico
		//int id = EntityID::_nextId;
		
		std::string uniqueName = type;

		//Hacer un new para que no se desreferencie en el futuro
		Map::CEntity *entityInfo = new Map::CEntity(uniqueName);


		entityInfo->setType(type);
		std::string pos = std::to_string(position.x)+','+std::to_string(position.y)+','+std::to_string(position.z);
		entityInfo->setAttribute("position", pos );
		entityInfo->setName(entityInfo->getName()+std::to_string(EntityID::_nextId));
		//meterlo en la cola de entidades del parser para que se borren al recargar mapas
		Map::CMapParser::getSingletonPtr()->addEntityInfo(entityInfo);

		return createEntity(entityInfo, map);

	}
	CEntity* CEntityFactory::createEntityByTypeTransform(const std::string &type, Matrix4 transform, CMap *map)
	{
		//solo hacemos creamos algo a partir de un arquetipo así que nos aseguramos de que exista
		ArchetypeMap::iterator find = _archetypes.find(type);
		if( find == _archetypes.end())
		{
			return NULL;
		}

		//nos aseguramos de construir un nombre unico
		//int id = EntityID::_nextId;
		
		std::string uniqueName = type;

		//Hacer un new para que no se desreferencie en el futuro
		Map::CEntity *entityInfo = new Map::CEntity(uniqueName);

		//El tipo
		entityInfo->setType(type);

		//La posicion
		Vector3 pos;
		Vector3 scale;
		Quaternion quat;

		transform.decomposition(pos, scale, quat);

		std::string string = std::to_string(pos.x)+','+std::to_string(pos.y)+','+std::to_string(pos.z);
		entityInfo->setAttribute("position", string );
		
		//El nombre unico
		entityInfo->setName(entityInfo->getName()+std::to_string(EntityID::_nextId));

		//La orientacion
		Vector3 axis;
		Ogre::Degree angle;
		quat.ToAngleAxis(angle, axis);

		string = std::to_string(axis.x) +","+std::to_string(axis.y)+","+std::to_string(axis.z);
		entityInfo->setAttribute("orientation",string);
		//std::cout<<string<<std::endl;
		string = std::to_string(angle.valueDegrees());
		//std::cout<<string<<std::endl;
		entityInfo->setAttribute("orientation_angle", string);

		//meterlo en la cola de entidades del parser para que se borren al recargar mapas
		Map::CMapParser::getSingletonPtr()->addEntityInfo(entityInfo);

		return createEntity(entityInfo, map);

	}
Exemplo n.º 4
0
	void CGridMap::ShowDebugTiles( CMap * _map )
	{
		for (int i = 0; i < _nMapRows; ++i)
		{
			for (int j = 0; j < _nMapCols; ++j)
			{
				//Vector2 tilePos = getRelativeMapPos(i, j);
				std::stringstream vecPos, name;

				// Creamos una nueva entidad con su entidad trigger sacada de los arquetipos
				Map::CEntity * waypointInfo = Map::CMapParser::getSingletonPtr()->getEntityInfo("Waypoint");

				name << "Tile_" << i << "_" << j;
				vecPos << i << " " << j;

				// Le ponemos un nuevo nombre para poder hacer spawn y la posición del edificio fantasma
				waypointInfo->setName(name.str());
				waypointInfo->setAttribute("grid_position", vecPos.str());

				Logic::CEntityFactory::getSingletonPtr()->createEntity(waypointInfo, _map);
			}
		}
	}