Map::Map(int seed, float scale)
	: SEED(seed) {
	srand(SEED);

	if (scale < 0.5)
		map_scale = 0.5;
	else if (scale > 2.5)
		map_scale = 2.5;
	else
		map_scale = scale;

	max_players_per_team = int(6 * map_scale);
	min_players_per_team = 1;
	number_of_planets = rand() % 7 + 1;

	map_bounds.x = (number_of_planets / 2) * map_scale * -1000.0 - 500.0 * map_scale;
	map_bounds.y = map_scale * -1000.0;
	map_bounds.w = number_of_planets * map_scale * 1000.0;
	map_bounds.h = map_bounds.w;

	int spawn_points = 3 * map_scale;
	for (int i = 0; i < spawn_points; ++i)
	{
		red_spawn_points.push_back(SpawnPoint(-map_bounds.w / 2 + 100 + rand() % 200, map_bounds.y + 100 + rand() % (map_bounds.h - 200)));
		blue_spawn_points.push_back(SpawnPoint(map_bounds.w / 2 - 100 - rand() % 200, map_bounds.y + 100 + rand() % (map_bounds.h - 200)));
	}

	srand(time(NULL));
}
std::vector<std::vector<std::shared_ptr<GameObject>>> MapGenerator::placeGameObjects(std::vector<std::vector<TileType>>& baseMap, std::vector<Team>& teams)
{
	auto objectGrid = std::vector<std::vector<std::shared_ptr<GameObject>>>();

	int width = baseMap.size();
	int height = baseMap[0].size();

	// Reserve memory
	objectGrid.resize(width);
	for (int x = 0; x < width; ++x) {
		// Reserve memory for each column
		objectGrid[x].resize(height);
		for (int y = 0; y < height; ++y) {
			objectGrid[x][y] = nullptr;
		}
	}

	// Place spawn point for every team
	for (int i = 0; i < teams.size(); ++i) {
		// Get random empty tile
		auto pos = findEmptyTile(baseMap);
		// Create and place spawn point
		auto newSpawnPoint = SpawnPoint(teams[i].getId(), teams[i].getColour(), pos, "ant", "antAgent");
		objectGrid[pos.x][pos.y] = std::make_shared<GameObject>(newSpawnPoint);
		// Add to the team's spawnPoint list
		teams[i].addSpawnPoint(newSpawnPoint);
		// Turn surrounding tiles into empty tiles
		for (int x = pos.x - 1; x <= pos.x + 1; ++x) {
			for (int y = pos.y - 1; y <= pos.y + 1; ++y) {
				baseMap[x][y] = TileType::empty;
			}
		}
	}
	return objectGrid;
}
SpawnPoints_t CtfSoldierSpawnPointMapElementSystem::GetActiveSpawnPoints( Team::Type team )
{
    SpawnPoints_t r;
    MapElementListFilter<MapSystem::All> mapElementListFilter( mMapSystem->GetMapElementList(), CtfSoldierSpawnPointMapElement::GetType_static() );
    for( MapElementListFilter<MapSystem::All>::const_iterator ctfSoldierSpawnPointMapElementIt = mapElementListFilter.begin(), ctfSoldierSpawnPointMapElementE = mapElementListFilter.end(); ctfSoldierSpawnPointMapElementIt != ctfSoldierSpawnPointMapElementE; ++ctfSoldierSpawnPointMapElementIt )
    {
        Opt<CtfSoldierSpawnPointMapElement> ctfSoldierSpawnPointMapElement( *ctfSoldierSpawnPointMapElementIt );
        if ( ctfSoldierSpawnPointMapElement->GetTeam() == team )
        {
            r.push_back( SpawnPoint( ctfSoldierSpawnPointMapElement->GetX(), ctfSoldierSpawnPointMapElement->GetY() ) );
        }
    }
    return r;
}
Exemple #4
0
void World::addEnemy(Aircraft::Type type, float x, float y)
{
    mEnemySpawnPoints.push_back(SpawnPoint(type, mSpawnPosition.x + x,
                                           mSpawnPosition.y - y));
}