Пример #1
0
IntVector2 Map::FindRandomValidLocationToSpawn() {
	IntVector2 position;
	bool foundALocation = false;
	int indicesToConsider = m_tiles.size();

	int numTimesRan = 0;

	while (!foundALocation) {
		int ind = RandInt(0, indicesToConsider - 1);

		Tile* currTile = GetTileAtIndex(ind);

		if (nullptr != currTile && currTile->IsValid() && currTile->GetCurrentTileType() != TILE_WATER && currTile->GetCurrentTileType() != TILE_LAVA) {
			position = currTile->GetLocation();
			foundALocation = true;
		}


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

	return position;
}
Пример #2
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);
}