예제 #1
0
void IRoom::PlaceSoldierSpawnPoint( RoomDesc &roomDesc, glm::vec2 pos )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()(AutoId( "soldier_spawn_point" )) );
    Opt<SoldierSpawnPointMapElement> ctfSoldierSpawn( static_cast<SoldierSpawnPointMapElement*>(mapElement.get()) );
    ctfSoldierSpawn->SetX( pos.x );
    ctfSoldierSpawn->SetY( pos.y );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
예제 #2
0
void SoldierSpawnTarget::PutTarget( glm::vec2 position )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()( AutoId( "soldier_spawn_point" ) ) );
    Opt<SoldierSpawnPointMapElement> soldierSpawn( static_cast<SoldierSpawnPointMapElement*>( mapElement.get() ) );
    soldierSpawn->SetX( position.x );
    soldierSpawn->SetY( position.y );
    int32_t nextIndex = MapSystem::GetNextUniqueSpawnIndex( "s" );
    soldierSpawn->SetIdentifier( AutoId( "s" + std::to_string( nextIndex ) ) );
    EditorSoldierSpawnSystem::Spawn( soldierSpawn );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
예제 #3
0
void WallTarget::PutTarget( glm::vec2 position )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()( AutoId( "spawn_actor" ) ) );
    Opt<SpawnActorMapElement> spawnActor( static_cast<SpawnActorMapElement*>( mapElement.get() ) );
    spawnActor->GetInputNodeId( SpawnActorMapElement::SpawnNodeId() )( 1 );

    AddPositionLoader( position, spawnActor );

    spawnActor->SetActorID( EditorTargetSystem::Get()->GetTarget().GetActorId() );
    mapElement->SetUID( AutoId( "spawn_at_start" ) );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
예제 #4
0
bool MapSystem::AddMapElementFromOneTextureDesc( Json::Value& mapElementDesc )
{
    std::string name;
    if ( !Json::GetStr( mapElementDesc["name"], name ) )
    {
        return false;
    }
    std::auto_ptr<MapElement> mapElement( mMapElementFactory( AutoId( name ) ) );
    mapElement->Load( mapElementDesc );
    mMapElementHolder.mAllMapElements.insert( Opt<MapElement>( mapElement.release() ) );
    return true;
}
예제 #5
0
void Player::generatePath(const Position& target)
{
	// todo und finalized liste leeren
	todo.clear();
	finalized.clear();

	// Ziel-Knoten in finalized Liste einfügen
	finalized.insert(mapElement(target, Node(target, 0)));

	// aktuellen Knoten auf Ziel-Knoten setzen
	current = &finalized.at(target);

	// rekursive Funktion aufrufen
	calculateStep(target);
}
	void TiledMapLoader::loadInternalMap(Map &map, char *xml) {
		rapidxml::xml_document<> document;
		rapidxml::xml_node<> *rootNode = nullptr;
		document.parse<rapidxml::parse_no_data_nodes>(xml);
		rootNode = document.first_node("map");
		if (!rootNode) {
			throw std::logic_error("Invalid tiled map: no map tag");
		}
		auto &rootNodeRef = *rootNode;
		XMLElement mapElement(*rootNode);
		map.setVersion(mapElement.getString("version"));
		map.setWidth(mapElement.getInt("width"));
		map.setHeight(mapElement.getInt("height"));
		map.setTileWidth(mapElement.getInt("tilewidth"));
		map.setTileHeight(mapElement.getInt("tileheight"));
		map.parseProperties(*rootNode);

		loadTilesets(map, rootNodeRef);
		loadLayers(map, rootNodeRef);
		loadObjectGroups(map, rootNodeRef);
	}
예제 #7
0
void Player::calculateStep(const Position& target)
{
	// Abbruchbedienung (Spieler-Position erreicht)
	if (current != 0 && current->position == position)
		return;

	// Nachbarn des aktuellen Knoten beziehen
	std::list<Node> neighbors = map.getNeighbors(current->position);

	for (std::list<Node>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
	{
		Node& neighbor = *it;

		// wenn Kosten größer 0 und noch nicht finalized
		if (neighbor.costs > 0 && finalized.find(neighbor.position) == finalized.end())
		{
			// in todo Liste nach Nachbarn suchen
			nodeMap::iterator todoIt = todo.find(neighbor.position);

			// wenn noch nicht in todo Liste oder aktuelle Kosten kleiner als Kosten in todo Liste
			if (todoIt == todo.end() || todoIt->second.costs > neighbor.costs + current->costs)
			{
				// wenn in todo Liste, Nachbarn aus todo Liste löschen
				if (todoIt != todo.end())
					todo.erase(todoIt);

				// Nachfolger auf aktuellen Knoten setzen
				neighbor.next = current;

				// Kosten um bisherige Kosten erhöhen
				neighbor.costs += current->costs;

				// in todo Liste einfügen
				todo.insert(mapElement(neighbor.position, neighbor));
			}
		}
	}

	current = &(todo.begin()->second);
	int currentHeuristic = getHeuristic(current->position, position);

	// in todo Liste nach billigstem Knoten suchen
	for (nodeMap::iterator it = todo.begin(); it != todo.end(); ++it)
	{
		Node& node = it->second;

		// Heuristik berechnen
		int heuristic = getHeuristic(node.position, position);

		// Gesamtkosten vergleichen
		if (node.costs + heuristic < current->costs + currentHeuristic)
		{
			currentHeuristic = heuristic;
			current = &node;
		}
	}

	// Knoten in die finalized List einfügen
	finalized.insert(mapElement(current->position, *current));
	current = &finalized.at(current->position);

	// Knoten aus der todo Liste löschen
	todo.erase(current->position);

	calculateStep(target);
}