Exemplo n.º 1
0
// Detect contiguous terrain tiles and store them in the regions list
void HexMap::findRegions()
{
	// new tiles to query
	multimap<int, sf::Vector2i> frontier;
	int i = (int)(mapSize_.x*mapSize_.y);
	HexTile* h = nullptr;
	sf::Vector2i p;
	std::unique_ptr<bool> seen(new bool[i]);
	for (int a = 0; a < i; a++) {
		seen.get()[a] = false;
	}
	std::deque<sf::Vector2i> peaks;
	std::deque<Region> regions;

	Region* currentRegion;
	for (int r = 0; r < mapSize_.y; r++) {
		for (int q = 0, qoff = (int)-floor(r / 2.0); q < mapSize_.x; q++, qoff++) {
			i = q + mapSize_.x * r;
			if (seen.get()[i]) {
				continue;
			}
			regions.emplace_back(1, sf::Vector2i(qoff, r));
			currentRegion = &regions.back();
			h = &getAxial(qoff, r);
			frontier.insert(make_pair(0, sf::Vector2i(qoff, r)));
			VectorSet adj;
			while (!frontier.empty()) {
				for (auto f : frontier) {
					clipToBounds(neighbors(f.second, adj));
				}
				frontier.clear();
				for (auto n : adj) {
					p = axialToOffset(n);
					i = p.x + p.y * mapSize_.x;
					if (seen.get()[i]) {
						continue;
					}
					HexTile& t = getAxial(n.x, n.y);
					if (t.height >= 200) {
						peaks.push_back(n);
					}
					if (t.hts == h->hts) {
						frontier.insert(make_pair(0, n));
						seen.get()[i] = true;
						(*currentRegion).size++;
					}
				}
				adj.clear();
			}
		}
	}
}
Exemplo n.º 2
0
void solve()
{
	borderSquares[xFace]->clear();
	borderSquares[yFace]->clear();
	borderSquares[zFace]->clear();

	for (vector<Face*>::iterator iter = faces.begin(); iter != faces.end(); iter++)
	{
		// derive all Squares of this face
		Face* f = *iter;
//		unsigned int startTime = getMicroSecs();
//		cout << "deriveSquares: ";
		f->deriveSquares();
//		cout << (getMicroSecs() - startTime) << endl;

		// put all squares of faces with the same orientation together
		VectorSet* squares = borderSquares[f->orientation];
		for(VectorSet::iterator iter = f->squares.begin(); iter != f->squares.end(); iter++)
		{
			Vertex v = *iter;
			squares->insert(v);
		}
	}

	VectorSet::iterator iter = borderSquares[zFace]->begin();
	Vertex min = *iter;
	while(iter != borderSquares[zFace]->end())
	{
		if(*iter < min)
			min = *iter;
		iter++;
	}

	blocks.clear();
	blocks.insert(min);
//	unsigned int startTime = getMicroSecs();
//		cout << "collectBlocks: ";
		collectBlocks(min);
//		cout << (getMicroSecs() - startTime) << endl;

	
	cout << "The bulk is composed of " << blocks.size() << " units.\n";
}
Exemplo n.º 3
0
void Face::deriveSquares()
{
	squares.clear();

	determineOrientation();

	vector<Vertex>::iterator iter = cornerVertices.begin();
	Vertex min = *iter;
	while(iter != cornerVertices.end())
	{
		if(*iter < min)
			min = *iter;
		iter++;
	}

	// min = starting point
	squares.insert(min);
	collectSquares(min);
}