Exemplo n.º 1
0
//---------------------------------------------------------------------------------------------------------------------------
bool Map::AreNeighborsAllSolid(const IntVector2& loc) {
	UNREFERENCED_PARAMETER(loc);

	int numTilesSolid = 0;

	std::vector<Tile*> surroundingTiles;

	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2(-1,  1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2( 0,  1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2( 1,  1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2( 1,  0)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2( 1, -1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2( 0, -1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2(-1, -1)));
	surroundingTiles.push_back(GetTileAtLocation(loc + IntVector2(-1,  0)));

	for (unsigned int i = 0; i < surroundingTiles.size(); i++) {
		if (nullptr != surroundingTiles[i] && surroundingTiles[i]->IsBlockingPathing()) {
			numTilesSolid++;
		}
	}

	if (numTilesSolid == 8) {
		return true;
	}
	else {
		return false;
	}
}
Exemplo n.º 2
0
String Map::GetVisibilityAsText() {

	String visDataAsText = "";

	visDataAsText.push_back('\n');

	for (int y = m_size.y - 1; y >= 0; y--) {
		for (int x = 0; x < m_size.x; x++) {
			Tile* tile = GetTileAtLocation(IntVector2(x, y));


			if (tile->IsVisible()) {
				visDataAsText.push_back('*');
			}
			else if (tile->IsExplored()) {
				visDataAsText.push_back('.');
			}
			else {
				visDataAsText.push_back('#');
			}
		}

		visDataAsText.push_back('\n');
	}

	return visDataAsText;
}
Exemplo n.º 3
0
String Map::GetMapDataAsText() {

	String mapDataAsText = "";
	mapDataAsText.push_back('\n');

	for (int y = m_size.y - 1; y >= 0; y--) {
		for (int x = 0; x < m_size.x; x++) {
			Tile* tile = GetTileAtLocation(IntVector2(x, y));

			switch (tile->GetCurrentTileType()) {
			case TILE_AIR:
				mapDataAsText.push_back('0');
				break;
			case TILE_STONE:
				mapDataAsText.push_back('#');
				break;
			case TILE_GRASS:
				mapDataAsText.push_back('.');
				break;
			case TILE_WATER:
				mapDataAsText.push_back('$');
				break;
			case TILE_LAVA:
				mapDataAsText.push_back('x');
				break;
			}
		}

		mapDataAsText.push_back('\n');
	}

	//String mapData = StringUtils::ReverseString(mapDataAsText);

	return mapDataAsText;
}
Exemplo n.º 4
0
IntVector2 Map::GetLocationWithOpeningOnEitherSide() {

	std::vector<Tile*> allStoneTilesOnMap;

	for (int x = 0; x < m_size.x; x++) {
		for (int y = 0; y < m_size.y; y++) {
			IntVector2 loc = IntVector2(x, y);
			Tile* currTile = GetTileAtLocation(loc);

			if (currTile->GetCurrentTileType() == TILE_STONE) {
				allStoneTilesOnMap.push_back(currTile);
			}
		}
	}

	int numTimesRan = 0;
	bool b = true;
	while (b) {
		int which = RandIntZeroToSize(allStoneTilesOnMap.size());

		Tile*& currTile = allStoneTilesOnMap[which];
		IntVector2 loc = currTile->GetLocation();

		Tile* tileToLeft = GetTileAtLocation(loc + WEST);
		Tile* tileToRight = GetTileAtLocation(loc + EAST);
		Tile* tileToUp = GetTileAtLocation(loc + NORTH);
		Tile* tileToDown = GetTileAtLocation(loc + SOUTH);

		if (tileToLeft && tileToRight && tileToLeft->IsValid() && tileToRight->IsValid()) {
			return loc;
		}
		else if (tileToUp && tileToDown && tileToUp->IsValid() && tileToDown->IsValid()) {
			return loc;
		}


		if (numTimesRan > 10000) {
			DebuggerPrintf("ERROR: Find Random Valid Location running too long.");
			return IntVector2(0, 0);
		}
		numTimesRan++;
	}

	return IntVector2(0, 0);
}
Exemplo n.º 5
0
TArray<ATile*> ATileManager::GetAdjacentTiles(ATile* Tile)
{
	if (Tile->Neighbours.Num() > 0)
		return Tile->Neighbours;

	TArray<ATile*> Tiles;

	FVector Location = Tile->GetActorLocation();
	FVector AdjustedLocation;

	if (Location.X > -MaxX)
	{
		AdjustedLocation = Location;
		AdjustedLocation.X -= TileWidth;
		Tiles.Add(GetTileAtLocation(AdjustedLocation));
	}

	if (Location.X < MaxX)
	{
		AdjustedLocation = Location;
		AdjustedLocation.X += TileWidth;
		Tiles.Add(GetTileAtLocation(AdjustedLocation));
	}

	if (Location.Y > -MaxY)
	{
		AdjustedLocation = Location;
		AdjustedLocation.Y -= TileHeight;
		Tiles.Add(GetTileAtLocation(AdjustedLocation));
	}

	if (Location.Y < MaxY)
	{
		AdjustedLocation = Location;
		AdjustedLocation.Y += TileHeight;
		Tiles.Add(GetTileAtLocation(AdjustedLocation));
	}

	Tile->Neighbours = Tiles;

	return Tiles;
}
Exemplo n.º 6
0
//---------------------------------------------------------------------------------------------------------------------------
std::vector<IntVector2> Map::GetValidLocsToMoveToAroundLoc(const IntVector2& loc, int movementProperties) {

	std::vector<IntVector2> possibleLocs;

	possibleLocs.push_back(loc + NORTH);
	possibleLocs.push_back(loc + NORTHEAST);
	possibleLocs.push_back(loc + EAST);
	possibleLocs.push_back(loc + SOUTHEAST);
	possibleLocs.push_back(loc + SOUTH);
	possibleLocs.push_back(loc + SOUTHWEST);
	possibleLocs.push_back(loc + WEST);
	possibleLocs.push_back(loc + NORTHWEST);

	std::vector<IntVector2> locs;
	for (unsigned int i = 0; i < possibleLocs.size(); i++) {
		IntVector2 currLoc = possibleLocs[i];

		if (GetTileAtLocation(currLoc) && GetTileAtLocation(currLoc)->IsValidForAgent(movementProperties)) {
			locs.push_back(currLoc);
		}
	}

	return locs;
}
Exemplo n.º 7
0
ATile* ATileManager::GetTileInDirection(ATile* Source, ATile* Target)
{
	FVector SourceLoc = Source->GetActorLocation();
	FVector TargetLoc = Target->GetActorLocation();

	float xdiff = TargetLoc.X - SourceLoc.X;
	float ydiff = TargetLoc.Y - SourceLoc.Y;

	FVector ReturnTileLocation = SourceLoc;

	if (FMath::Abs(xdiff) > FMath::Abs(ydiff))
	{
		if (xdiff > 0)
		{
			ReturnTileLocation.X += TileWidth;
		}
		else
		{
			ReturnTileLocation.X -= TileWidth;
		}
	}
	else
	{
		if (ydiff > 0)
		{
			ReturnTileLocation.Y += TileHeight;
		}
		else
		{
			ReturnTileLocation.Y -= TileHeight;
		}
	}

	auto ReturnTile = GetTileAtLocation(ReturnTileLocation);

	return ReturnTile;
}