示例#1
0
/* for a given BWTA region, draws bounding box for max width and height */
void EnhancedUI::drawRegionBoundingBox(const BWTA::Region * region)
{
	BWTA::Polygon poly;
	BWAPI::Position pLeft, pRight, pTop, pBottom;

	poly = region->getPolygon();

	pLeft = pRight = pTop = pBottom = (Position) poly[0];

	/* get bounds for BWTA region, map top left is (0,0) */
	for(int j = 1; j < (int)poly.size(); j++)
	{
		if(poly[j].x() < pLeft.x()){
			pLeft = poly[j];
		}
		if(poly[j].x() > pRight.x()){
			pRight = poly[j];
		}
		if(poly[j].y() < pTop.y()){
			pTop = poly[j];
		}
		if(poly[j].y() > pBottom.y()){
			pBottom = poly[j];
		}
	}

	Broodwar->drawBoxMap(pLeft.x(), pTop.y(), pRight.x(), pBottom.y(), Colors::Purple, false);

}
示例#2
0
void InformationManager::drawMapInformation()
{
    if (!Config::Debug::DrawBWTAInfo)
    {
        return;
    }

	//we will iterate through all the base locations, and draw their outlines.
	for (std::set<BWTA::BaseLocation*>::const_iterator i = BWTA::getBaseLocations().begin(); i != BWTA::getBaseLocations().end(); i++)
	{
		BWAPI::TilePosition p = (*i)->getTilePosition();
		BWAPI::Position c = (*i)->getPosition();

		//draw outline of center location
		BWAPI::Broodwar->drawBoxMap(p.x * 32, p.y * 32, p.x * 32 + 4 * 32, p.y * 32 + 3 * 32, BWAPI::Colors::Blue);

		//draw a circle at each mineral patch
		for (BWAPI::Unitset::iterator j = (*i)->getStaticMinerals().begin(); j != (*i)->getStaticMinerals().end(); j++)
		{
			BWAPI::Position q = (*j)->getInitialPosition();
			BWAPI::Broodwar->drawCircleMap(q.x, q.y, 30, BWAPI::Colors::Cyan);
		}

		//draw the outlines of vespene geysers
		for (BWAPI::Unitset::iterator j = (*i)->getGeysers().begin(); j != (*i)->getGeysers().end(); j++)
		{
			BWAPI::TilePosition q = (*j)->getInitialTilePosition();
			BWAPI::Broodwar->drawBoxMap(q.x * 32, q.y * 32, q.x * 32 + 4 * 32, q.y * 32 + 2 * 32, BWAPI::Colors::Orange);
		}

		//if this is an island expansion, draw a yellow circle around the base location
		if ((*i)->isIsland())
			BWAPI::Broodwar->drawCircleMap(c, 80, BWAPI::Colors::Yellow);
	}

	//we will iterate through all the regions and draw the polygon outline of it in green.
	for (std::set<BWTA::Region*>::const_iterator r = BWTA::getRegions().begin(); r != BWTA::getRegions().end(); r++)
	{
		BWTA::Polygon p = (*r)->getPolygon();
		for (int j = 0; j<(int)p.size(); j++)
		{
			BWAPI::Position point1 = p[j];
			BWAPI::Position point2 = p[(j + 1) % p.size()];
			BWAPI::Broodwar->drawLineMap(point1, point2, BWAPI::Colors::Green);
		}
	}

	//we will visualize the chokepoints with red lines
	for (std::set<BWTA::Region*>::const_iterator r = BWTA::getRegions().begin(); r != BWTA::getRegions().end(); r++)
	{
		for (std::set<BWTA::Chokepoint*>::const_iterator c = (*r)->getChokepoints().begin(); c != (*r)->getChokepoints().end(); c++)
		{
			BWAPI::Position point1 = (*c)->getSides().first;
			BWAPI::Position point2 = (*c)->getSides().second;
			BWAPI::Broodwar->drawLineMap(point1, point2, BWAPI::Colors::Red);
		}
	}
}
示例#3
0
/* draw region's polygon */
void EnhancedUI::drawPolygonFromRegion(BWTA::Region * region, BWAPI::Color color)
{
		BWTA::Polygon p = region->getPolygon();
		for (int j = 0; j < (int)p.size(); j++) {
			Position point1=p[j];
			Position point2=p[(j+1) % p.size()];
			Broodwar->drawLine(CoordinateType::Map,point1.x(),point1.y(),point2.x(),point2.y(),color);
		}
}
示例#4
0
/* for a given BWTA region, finds corner tile positions for max width and height */
void EnhancedUI::getRegionBoundingTilePositions(const BWTA::Region * region, BWAPI::TilePosition & topLeftTP, 
												BWAPI::TilePosition & topRightTP, BWAPI::TilePosition & bottomRightTP, 
												BWAPI::TilePosition & bottomLeftTP)
{

	BWTA::Polygon poly;
	BWAPI::Position pLeft, pRight, pTop, pBottom;
	/* tile sizes */
	int tsLeft, tsTop, tsRight, tsBottom;
	poly = region->getPolygon();

	pLeft = pRight = pTop = pBottom = (Position) poly[0];

	/* get bounds for BWTA region, map top left is (0,0) */
	for(int j = 1; j < (int)poly.size(); j++)
	{
		if(poly[j].x() < pLeft.x()){
			pLeft = poly[j];
		}
		if(poly[j].x() > pRight.x()){
			pRight = poly[j];
		}
		if(poly[j].y() < pTop.y()){
			pTop = poly[j];
		}
		if(poly[j].y() > pBottom.y()){
			pBottom = poly[j];
		}
	}
	/* align to tile sizes */
	tsLeft = this->getMaxTileSize(pLeft.x());
	tsTop = this->getMaxTileSize(pTop.y());

	tsRight = this->getMinTileSize(pRight.x());
	tsBottom = this->getMinTileSize(pBottom.y());

	/* set tile positions */
	topLeftTP.x() = tsLeft;
	topLeftTP.y() = tsTop;

	topRightTP.x() = tsRight;
	topRightTP.y() = tsTop;

	bottomRightTP.x() = tsRight;
	bottomRightTP.y() = tsBottom;

	bottomLeftTP.x() = tsLeft;
	bottomLeftTP.y() = tsBottom;

}
示例#5
0
void SwarmCAT::drawTerrainData()
{
	//we will iterate through all the base locations, and draw their outlines.
	for (const auto &baseLocation : BWTA::getBaseLocations()) {
		TilePosition p = baseLocation->getTilePosition();

		//draw outline of center location
		Position leftTop(p.x * TILE_SIZE, p.y * TILE_SIZE);
		Position rightBottom(leftTop.x + 4 * TILE_SIZE, leftTop.y + 3 * TILE_SIZE);
		Broodwar->drawBoxMap(leftTop, rightBottom, Colors::Blue);

		//draw a circle at each mineral patch
		for (const auto &mineral : baseLocation->getStaticMinerals()) {
			Broodwar->drawCircleMap(mineral->getInitialPosition(), 30, Colors::Cyan);
		}

		//draw the outlines of Vespene geysers
		for (const auto &geyser : baseLocation->getGeysers()) {
			TilePosition p1 = geyser->getInitialTilePosition();
			Position leftTop1(p1.x * TILE_SIZE, p1.y * TILE_SIZE);
			Position rightBottom1(leftTop1.x + 4 * TILE_SIZE, leftTop1.y + 2 * TILE_SIZE);
			Broodwar->drawBoxMap(leftTop1, rightBottom1, Colors::Orange);
		}

		//if this is an island expansion, draw a yellow circle around the base location
		if (baseLocation->isIsland()) {
			Broodwar->drawCircleMap(baseLocation->getPosition(), 80, Colors::Yellow);
		}
	}

	//we will iterate through all the regions and ...
	for (const auto & region : BWTA::getRegions()) {
		// draw the polygon outline of it in green
		BWTA::Polygon p = region->getPolygon();
		for (size_t j = 0; j < p.size(); ++j) {
			Position point1 = p[j];
			Position point2 = p[(j + 1) % p.size()];
			Broodwar->drawLineMap(point1, point2, Colors::Green);
		}
		// visualize the chokepoints with red lines
		for (auto const& chokepoint : region->getChokepoints()) {
			Position point1 = chokepoint->getSides().first;
			Position point2 = chokepoint->getSides().second;
			Broodwar->drawLineMap(point1, point2, Colors::Red);
		}
	}
}
示例#6
0
void Mentat::onFrame()
{

	if (analyzed)
	{
		//we will iterate through all the base locations, and draw their outlines.
		for( set<BWTA::BaseLocation*>::const_iterator i = BWTA::getBaseLocations().begin(); i != BWTA::getBaseLocations().end(); i++)
		{
			TilePosition p = (*i)->getTilePosition();
			Position base = (*i)->getPosition();

			//draw outline of center location
			Broodwar->drawBox(CoordinateType::Map,p.x() * 32, p.y() * 32, p.x() * 32 + 4 * 32, p.y() * 32 + 3 * 32, Colors::Blue, false);

			//draw a circle at each mineral patch
			for( set<BWAPI::Unit*>::const_iterator j = (*i)->getStaticMinerals().begin(); j != (*i)->getStaticMinerals().end(); j++)
			{
				Position mineral = (*j)->getInitialPosition();
				Broodwar->drawCircle(CoordinateType::Map, mineral.x(), mineral.y(), 30, Colors::Cyan, false);
			}

			//draw the outlines of vespene geysers
			for( set<BWAPI::Unit*>::const_iterator j = (*i)->getGeysers().begin(); j != (*i)->getGeysers().end(); j++)
			{
				TilePosition vespene = (*j)->getInitialTilePosition();
				Broodwar->drawBox(CoordinateType::Map,vespene.x() * 32, vespene.y() * 32, vespene.x() * 32 + 4 * 32, vespene.y() * 32 + 2 * 32, Colors::Orange, false);
			}

			//if this is an island expansion, draw a yellow circle around the base location
			if ( (*i)->isIsland() )
			{
				Broodwar->drawCircle(CoordinateType::Map, base.x(), base.y(), 80, Colors::Yellow, false);
			}
		}

		//we will iterate through all the regions and draw the polygon outline of it in green.
		for( set<BWTA::Region*>::const_iterator i = BWTA::getRegions().begin(); i != BWTA::getRegions().end(); i++)
		{
			BWTA::Polygon region = (*i)->getPolygon();
			for( int j = 0; j<(int)region.size(); j++ )
			{
				Position point1 = region[j];
				Position point2 = region[(j + 1) % region.size()];
				Broodwar->drawLine(CoordinateType::Map, point1.x(), point1.y(), point2.x(), point2.y(), Colors::Green);
			}
		}

		//we will visualize the chokepoints with red lines
		for( set<BWTA::Region*>::const_iterator i = BWTA::getRegions().begin(); i != BWTA::getRegions().end(); i++)
		{
			for( set<BWTA::Chokepoint*>::const_iterator j = (*i)->getChokepoints().begin(); j != (*i)->getChokepoints().end(); j++)
			{
				Position point1 = (*j)->getSides().first;
				Position point2 = (*j)->getSides().second;
				Broodwar->drawLine(CoordinateType::Map, point1.x(), point1.y(), point2.x(), point2.y(), Colors::Red);
			}
		}
	}
	if (analysis_just_finished)
	{
		Broodwar->printf("Finished analyzing map.");
		analysis_just_finished = false;
	}
}
//ctx add
BWAPI::TilePosition BuildingPlacer::getBuildLocationFarFromChokePoint(const Building & b, int buildDist, bool horizontalOnly, bool flag) const
{
	SparCraft::Timer t;
	t.start();

	BWAPI::TilePosition startTitlePos = BWAPI::Broodwar->self()->getStartLocation();
	BWTA::Chokepoint *chokePoint = BWTA::getNearestChokepoint(startTitlePos);
	BWAPI::Position chokeCenterPosition = chokePoint->getCenter();
	BWTA::Region *baseRegion = BWTA::getRegion(BWAPI::Broodwar->self()->getStartLocation());
	BWTA::Polygon basePolygon = baseRegion->getPolygon();
	BWAPI::Position farPosition =  BWAPI::Position(0, 0);
	BWAPI::TilePosition resultPosition = BWAPI::TilePosition(0, 0);
	double dis = 0.0;

	

	for (int i = 0; i < (int)basePolygon.size(); i++) {
		BWAPI::Position point = basePolygon[i];
		double ms1 = t.getElapsedTimeInMilliSec();
		if (point.getDistance(chokeCenterPosition) > dis) {
			dis = point.getDistance(chokeCenterPosition);
			farPosition = point;
		}
	}

	const std::vector<BWAPI::TilePosition> & closestToBuilding = MapTools::Instance().getClosestTilesTo(BWAPI::Position(b.desiredPosition));

	//get best solution
	dis = farPosition.getDistance(BWAPI::Position(startTitlePos));
	
	if (flag == true) {
		for (size_t i = 0; i < closestToBuilding.size(); ++i)
		{
			double ms1 = t.getElapsedTimeInMilliSec();
			if (canBuildHereWithSpace(closestToBuilding[i], b, buildDist, horizontalOnly) && dis > farPosition.getDistance(BWAPI::Position(closestToBuilding[i])))
			{
				resultPosition = closestToBuilding[i];
				break;
				//return closestToBuilding[i];
			}
		}
	}
	else {
		for (size_t i = 0; i < closestToBuilding.size(); ++i)
		{
			double ms1 = t.getElapsedTimeInMilliSec();
			if (canBuildHereWithSpace(closestToBuilding[i], b, buildDist, horizontalOnly) && dis < farPosition.getDistance(BWAPI::Position(closestToBuilding[i])))
			{
				resultPosition = closestToBuilding[i];
				break;
				//return closestToBuilding[i];
			}
		}
	}
	
	if (!basePolygon.isInside(BWAPI::Position(resultPosition))) {
		resultPosition = getBuildLocationNear(b, buildDist, horizontalOnly);
	}

	return resultPosition;
}