예제 #1
0
int Commander::addBunkerSquad()
{
	Squad* bSquad = new Squad(100 + AgentManager::getInstance()->countNoUnits(UnitTypes::Terran_Bunker), Squad::BUNKER, "BunkerSquad", 5);
	bSquad->addSetup(UnitTypes::Terran_Marine, 4);
	squads.push_back(bSquad);

	//Try to fill from other squads.
	int added = 0;
	for (int i = 0; i < (int)squads.size(); i++)
	{
		Squad* sq = squads.at(i);
		if (sq->isOffensive() || sq->isDefensive())
		{
			for (int i = 0; i < 4 - added; i++)
			{
				if (sq->hasUnits(UnitTypes::Terran_Marine, 1))
				{
					if (added < 4)
					{
						BaseAgent* ma = sq->removeMember(UnitTypes::Terran_Marine);
						if (ma != NULL)
					{
							added++;
							bSquad->addMember(ma);
							ma->clearGoal();
						}
					}
				}
			}
		}
	}

	return bSquad->getID();
}
예제 #2
0
파일: BaseAgent.cpp 프로젝트: Senth/bats
bool BaseAgent::doEnsnare(const TilePosition& pos)
{
	if (!bats::BuildPlanner::isZerg())
	{
		return false;
	}
	if (!Broodwar->self()->hasResearched(TechTypes::Ensnare))
	{
		return false;
	}

	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive() && agent->isOfType(UnitTypes::Zerg_Queen))
		{
			if (agent->getUnit()->getEnergy() >= 75)
			{
				agent->getUnit()->useTech(TechTypes::Ensnare, Position(pos));
				return true;
			}
		}
	}

	return false;
}
예제 #3
0
bool Commander::checkWorkersAttack(BaseAgent *base)
{
	int noAttack = 0;

	for(set<Unit*>::const_iterator i=Broodwar->enemy()->getUnits().begin();i!=Broodwar->enemy()->getUnits().end();i++)
	{
		if ((*i)->exists() && (*i)->getType().isWorker())
		{
			double dist = (*i)->getTilePosition().getDistance(base->getUnit()->getTilePosition());
			if (dist <= 12)
			{
				//Enemy unit discovered. Attack with some workers.
				vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
				for (int j = 0; j < (int)agents.size(); j++)
				{
					BaseAgent* agent = agents.at(j);
					if (agent->isAlive() && agent->isWorker() && noAttack < 1)
				{
						WorkerAgent* wAgent = (WorkerAgent*) agent;
						wAgent->setState(WorkerAgent::ATTACKING);
						agent->getUnit()->attack((*i));
						noAttack++;
					}
				}
			}
		}
	}

	if (noAttack > 0)
	{
		return true;
	}
	return false;
}
예제 #4
0
int TransportAgent::getCurrentLoad()
{
	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		int load = 0;
		vector<BaseAgent*> agents = sq->getMembers();
		for (int i = 0; i < (int)agents.size(); i++)
		{
			BaseAgent* a = agents.at(i);
			if (a->isAlive())
			{
				if (a->getUnit()->isLoaded())
				{
					if (a->getUnit()->getTransport()->getID() == unit->getID())
					{
						load += a->getUnitType().spaceRequired();
					}
				}
			}
		}
		currentLoad = load;
	}

	return currentLoad;
}
예제 #5
0
bool Commander::isOccupied(BWTA::Region* region)
{
	BWTA::Polygon p = region->getPolygon();
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive() && agent->getUnitType().isResourceDepot())
		{
			BWTA::Region* aRegion = getRegion(agents.at(i)->getUnit()->getTilePosition());
			Position c1 = region->getCenter();
			Position c2 = aRegion->getCenter();
			if (c2.x() == c1.x() && c2.y() == c1.y())
			{
				return true;
			}
		}
	}
	
	//Check expansion site
	TilePosition expansionSite = ExplorationManager::getInstance()->getExpansionSite();
	TilePosition center = TilePosition(region->getCenter());
	if (expansionSite.x() >= 0)
	{
		double dist = expansionSite.getDistance(center);
		if (dist <= 15)
		{
			return true;
		}
	}

	return false;
}
예제 #6
0
BaseAgent* TransportAgent::findUnitToLoad(int spaceLimit)
{
	BaseAgent* agent = NULL;
	double bestDist = 100000;

	Squad* sq = Commander::getInstance()->getSquad(squadID);
	if (sq != NULL)
	{
		vector<BaseAgent*> agents = sq->getMembers();
		for (int i = 0; i < (int)agents.size(); i++)
		{
			BaseAgent* a = agents.at(i);
			if (isValidLoadUnit(a))
			{
				double cDist = unit->getPosition().getDistance(a->getUnit()->getPosition());
				if (cDist < bestDist)
				{
					bestDist = cDist;
					agent = a;
				}
			}
		}
	}

	return agent;
}
예제 #7
0
int main ( int argc, char* argv[] )
{	
	PrintGreeting();
	initStaticModules(argc,argv);

    char s[]="0:1\n"; 

	//mkfifo("/tmp/trainer_pipe",0666);
    //int fd = open( "/home/wenbin/test-dir/mkfifo/pp", O_WRONLY );
    //write(fd, s, sizeof(s) );

    // registering the handler, catching SIGINT signals
	signal ( SIGINT, handler );
	BaseAgent *Agent;
	Agent = new BaseAgent();
	if ( ! NET.Init() )
	{
	    cout<<"int main-->Main network not initialized successfully."<<endl;
	    return 1;
	}
	while (gLoop)	
	    Agent->run();
	NET.Done();
	return 0;
}
예제 #8
0
TilePosition CoverMap::findExpansionSite()
{
	UnitType baseType = Broodwar->self()->getRace().getCenter();
	double bestDist = 100000;
	TilePosition bestPos = TilePosition(-1, -1);
	
	//Iterate through all base locations
	for(set<BWTA::BaseLocation*>::const_iterator i=BWTA::getBaseLocations().begin(); i!= BWTA::getBaseLocations().end(); i++)
	{
		TilePosition pos = (*i)->getTilePosition();
		bool taken = false;
		
		//Check if own buildings are close
		vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
		int noBases = 0;
		for (int i = 0; i < (int)agents.size(); i++)
		{
			BaseAgent* agent = agents.at(i);
			if (agent->isAlive() && agent->getUnitType().isResourceDepot())
			{
				double dist = pos.getDistance(agent->getUnit()->getTilePosition());
				if (dist <= 12)
				{
					noBases++;
				}
			}
		}
		if (BuildPlanner::isZerg())
		{
			if (noBases >= 2) taken = true;
		}
		else
		{
			if (noBases >= 1) taken = true;
		}

		//Check if enemy buildings are close
		int eCnt = ExplorationManager::getInstance()->spottedBuildingsWithinRange(pos, 20);
		if (eCnt > 0)
		{
			taken = true;
		}

		//Not taken, calculate ground distance
		if (!taken)
		{
			if (ExplorationManager::canReach(Broodwar->self()->getStartLocation(), pos))
			{
				double dist = mapData.getDistance(Broodwar->self()->getStartLocation(), pos);
				if (dist <= bestDist)
				{
					bestDist = dist;
					bestPos = pos;
				}
			}
		}
	}

	return bestPos;
}
예제 #9
0
Unit* CoverMap::findClosestMineral(TilePosition workerPos)
{
	Unit* mineral = NULL;
	double bestDist = 10000;

	for(set<BWTA::BaseLocation*>::const_iterator i=BWTA::getBaseLocations().begin(); i!= BWTA::getBaseLocations().end(); i++)
	{
		TilePosition pos = (*i)->getTilePosition();
		double cDist = pos.getDistance(workerPos);
		if (cDist < bestDist)
		{
			//Find closest base
			BaseAgent* base = AgentManager::getInstance()->getClosestBase(pos);
			double dist = pos.getDistance(base->getUnit()->getTilePosition());
			if (dist <= 12)
			{
				//We have a base near this base location
				//Check if we have minerals available
				Unit* cMineral = hasMineralNear(pos);
				if (cMineral != NULL)
				{
					mineral = cMineral;
					bestDist = cDist;
				}
			}
		}
	}

	//We have no base with minerals, do nothing
	return mineral;
}
예제 #10
0
void HighTemplarAgent::computeActions() {
	int cFrame = Broodwar->getFrameCount();
	if (cFrame - lastFrame < 20) {
		return;
	}
	lastFrame = cFrame;

	bool defensive = false;

	if (isOfType(unit->getType(), UnitTypes::Protoss_Archon)) {
		//High Templar has been transformed to an Archon.
		defensive = false;
	}
	else {
		//High Templar unit, use spells
		defensive = true;
		
		//Out of Energy, see if we can transform to an Archon
		if (unit->getEnergy() <= 50 && enemyUnitsWithinRange(320) > 0) {
			if (!hasCastTransform) {
				BaseAgent* target = findArchonTarget();
				if (target != NULL) {
					unit->useTech(TechTypes::Archon_Warp, target->getUnit());
					hasCastTransform = true;
					Broodwar->printf("[%d] %s uses Summon Archon on %s", unitID, unit->getType().getName().c_str(), target->getUnit()->getType().getName().c_str());
					return;
				}
			}
		}
		
		//TODO: Add unitspecific code here
	}

	PFManager::getInstance()->computeAttackingUnitActions(this, goal, defensive);
}
예제 #11
0
void TransportAgent::computeActions()
{
	if (unit->isBeingConstructed()) return;

	int currentLoad = getCurrentLoad();
	int eCnt = enemyUnitsWithinRange(unit->getType().sightRange());

	if (eCnt == 0)
	{
		if (currentLoad < maxLoad)
		{
			BaseAgent* toLoad = findUnitToLoad(maxLoad - currentLoad);
			if (toLoad != NULL)
			{
				unit->load(toLoad->getUnit());
				return;
			}
		}
	}
	else
	{
		if (currentLoad > 0)
		{
			TilePosition t = unit->getTilePosition();
			unit->unloadAll();
			return;
		}
	}

	defensive = true;
	NavigationAgent::getInstance()->computeMove(this, goal, defensive);
}
예제 #12
0
void StructureAgent::sendWorkers()
{
	//We have constructed a new base. Make some workers move here.
	int noWorkers = AgentManager::getInstance()->getNoWorkers();
	int toSend = noWorkers / AgentManager::getInstance()->countNoBases();
	int hasSent = 0;

	//Broodwar->printf("Sending %d/%d workers to new base", toSend, noWorkers);
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive() && agent->isFreeWorker())
		{
			Unit* worker = agent->getUnit();
			WorkerAgent* wa = (WorkerAgent*)agent;
			worker->rightClick(unit->getPosition());
			hasSent++;
		}

		if (hasSent >= toSend)
		{
			return;
		}
	}
}
예제 #13
0
Unit BuildingPlacer::findClosestMineral(TilePosition workerPos)
{
	Unit mineral = NULL;
	double bestDist = 10000;

	for(BaseLocation* base : getBaseLocations())
	{
		TilePosition pos = base->getTilePosition();
		double cDist = pos.getDistance(workerPos);
		if (cDist < bestDist)
		{
			//Find closest base
			BaseAgent* base = AgentManager::getInstance()->getClosestBase(pos);
			if (base != NULL)
			{
				double dist = pos.getDistance(base->getUnit()->getTilePosition());
				if (dist <= 12)
				{
					//We have a base near this base location
					//Check if we have minerals available
					Unit cMineral = hasMineralNear(pos);
					if (cMineral != NULL)
					{
						mineral = cMineral;
						bestDist = cDist;
					}
				}
			}
		}
	}

	//We have no base with minerals, do nothing
	return mineral;
}
예제 #14
0
bool UnitAgent::chargeShields()
{
	int cShields = unit->getShields();
	int maxShields = unit->getType().maxShields();

	if (cShields < maxShields)
	{
		//Shields are damaged
		BaseAgent* charger = AgentManager::getInstance()->getClosestAgent(unit->getTilePosition(), UnitTypes::Protoss_Shield_Battery);
		if (charger != NULL)
		{
			//Charger has energy
			if (charger->getUnit()->getEnergy() > 0)
			{
				double dist = charger->getUnit()->getTilePosition().getDistance(unit->getTilePosition());
				if (dist <= 15)
				{
					//We have charger nearby. Check if we have enemies around
					int eCnt = enemyAttackingUnitsWithinRange(12 * 32, unit->getTilePosition());
					if (eCnt == 0)
				{
						unit->rightClick(charger->getUnit());
						return true;
					}
				}
			}
		}
	}
	return false;
}
예제 #15
0
/** Build another hatchery, if it seems like a good time */
bool ZergBuildPlanner::buildHatcheryIfNeeded()
{
	// count hatcheries
	std::vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	int hatcheries = 0;
	for (unsigned int i = 0; i < agents.size(); i++)
	{
		BaseAgent *agent = agents.at(i);
		if (agent->isOfType(UnitTypes::Zerg_Hatchery))
		{
			hatcheries++;
		}
	}

	//1. Make sure we have plenty of cache but not so many hatcheries.
	if (Broodwar->self()->minerals() < 300 || hatcheries < 12)
		return false;

	//2. Make sure we're not already building one.
	for (unsigned int i = 0; i < agents.size(); i++)
	{
		BaseAgent *agent = agents.at(i);
		if (agent->isOfType(UnitTypes::Zerg_Hatchery)
			&& !agent->getUnit()->isCompleted())
		{
			return false;
		}
	}

	//Add one to beginning of build-order.
	buildOrder.insert(buildOrder.begin(), UnitTypes::Zerg_Hatchery);

}
예제 #16
0
Unit* CoverMap::findWorker()
{
	BaseAgent* worker = AgentManager::getInstance()->getAgent(Broodwar->self()->getRace().getWorker());
	if (worker != NULL)
	{
		return worker->getUnit();
	}
	return NULL;
}
예제 #17
0
void OverlordAgent::updateGoal()
{
    BaseAgent* agent = AgentManager::Instance().getClosestBase(unit->getTilePosition());
    if (agent != NULL)
    {
        goal = agent->getUnit()->getTilePosition();
        lastUpdateFrame = Broodwar->getFrameCount();
    }
}
예제 #18
0
Unit BuildingPlacer::findWorker(TilePosition spot)
{
	BaseAgent* worker = AgentManager::getInstance()->findClosestFreeWorker(spot);
	if (worker != NULL)
	{
		return worker->getUnit();
	}
	return NULL;
}
예제 #19
0
int AgentManager::getNoWorkers() {
	int wCnt = 0;
	for (int i = 0; i < (int)agents.size(); i++) {
		BaseAgent* agent = agents.at(i);
		if (agent != NULL && agent->isWorker() && agent->isAlive()) {
			wCnt++;
		}
	}
	return wCnt;
}
예제 #20
0
파일: Commander.cpp 프로젝트: JongKul/bthai
void Commander::finishBuild(BaseAgent* baseAgent)
{
	//First we must check if someone is repairing this building
	if(AgentManager::getInstance()->isAnyAgentRepairingThisAgent(baseAgent)) return;

	BaseAgent* repUnit = AgentManager::getInstance()->findClosestFreeWorker(baseAgent->getUnit()->getTilePosition());
	if (repUnit != NULL)
	{
		repUnit->assignToRepair(baseAgent->getUnit());
	}
}
예제 #21
0
TilePosition BuildingPlacer::findExpansionSite()
{
	UnitType baseType = Broodwar->self()->getRace().getCenter();
	double bestDist = 100000;
	TilePosition bestPos = TilePosition(-1, -1);
	
	//Iterate through all base locations
	for(BaseLocation* base : getBaseLocations())
	{
		TilePosition pos = base->getTilePosition();
		if (pos.x != Broodwar->self()->getStartLocation().x || pos.y != Broodwar->self()->getStartLocation().y)
		{
			bool taken = false;
			
			//Check if own buildings are close
			if (MapManager::getInstance()->hasOwnInfluenceIn(pos)) taken = true;
			//Check if enemy buildings are close
			if (MapManager::getInstance()->hasEnemyInfluenceIn(pos)) taken = true;

			//Not taken, calculate ground distance
			if (!taken)
			{
				if (ExplorationManager::canReach(Broodwar->self()->getStartLocation(), pos))
				{
					double dist = Pathfinder::getInstance()->getDistance(Broodwar->self()->getStartLocation(), pos);
					if (dist <= bestDist && dist > 0)
					{
						bestDist = dist;
						bestPos = pos;
					}
				}
			}
		}
	}

	//Don't build expansions too far away!
	BaseAgent* base = AgentManager::getInstance()->getClosestBase(bestPos);
	if (base != NULL)
	{
		double d = base->getUnit()->getTilePosition().getDistance(bestPos);
		if (d >= 140)
		{
			Broodwar << "Expansion site too far away: " << d << endl;
			return TilePosition(-1, -1);
		}
	}
	else
	{
		return TilePosition(-1, -1);
	}

	return bestPos;
}
예제 #22
0
파일: Squad.cpp 프로젝트: rarosu/FnulAI
bool Squad::contains(UnitType type)
{
	for (int i = 0; i < (int)agents.size();i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive() && agent->isOfType(type))
		{
			return true;
		}
	}
	return false;
}
예제 #23
0
void AgentManager::addAgent(Unit* unit)
{
	if (unit->getType().getID() == UnitTypes::Zerg_Larva.getID())
	{
		//Special case: Dont add Zerg larva as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Egg.getID())
	{
		//Special case: Dont add Zerg eggs as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Cocoon.getID())
	{
		//Special case: Dont add Zerg cocoons as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Lurker_Egg.getID())
	{
		//Special case: Dont add Zerg eggs as agents.
		return;
	}

	bool found = false;
	for (int i = 0; i < (int)agents.size(); i++)
	{
		if (agents.at(i)->matches(unit))
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		BaseAgent* newAgent = AgentFactory::getInstance()->createAgent(unit);
		agents.push_back(newAgent);

		if (newAgent->isBuilding())
		{
			CoverMap::getInstance()->addConstructedBuilding(unit);
			BuildPlanner::getInstance()->unlock(unit->getType());
			ResourceManager::getInstance()->unlockResources(unit->getType());
		}
		else
		{
			Commander::getInstance()->unitCreated(newAgent);
		}
	}
}
예제 #24
0
void AgentManager::addAgent(Unit unit)
{
	if (unit->getType().getID() == UnitTypes::Zerg_Larva.getID())
	{
		//Special case: Dont add Zerg larva as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Egg.getID())
	{
		//Special case: Dont add Zerg eggs as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Cocoon.getID())
	{
		//Special case: Dont add Zerg cocoons as agents.
		return;
	}
	if (unit->getType().getID() == UnitTypes::Zerg_Lurker_Egg.getID())
	{
		//Special case: Dont add Zerg eggs as agents.
		return;
	}
	
	bool found = false;
	for (auto &a : agents)
	{
		if (a->matches(unit))
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		BaseAgent* newAgent = AgentFactory::getInstance()->createAgent(unit);
		agents.insert(newAgent);
		
		if (newAgent->isBuilding())
		{
			BuildingPlacer::getInstance()->addConstructedBuilding(unit);
			Constructor::getInstance()->unlock(unit->getType());
			ResourceManager::getInstance()->unlockResources(unit->getType());
		}
		else
		{
			Commander::getInstance()->unitCreated(newAgent);
		}
	}
}
예제 #25
0
void ZergBuildPlanner::computeActions() {
	
	buildOverlordIfNeeded();
	buildHatcheryIfNeeded();

	//NOTE: No need to change this unless some special logic
	//shall be added.

	if (AgentManager::getInstance()->getNoWorkers() == 0) {
		//No workers so cant do anything
		return;
	}

	if (locked) {
		if (Broodwar->getFrameCount() - lockedFrame > getLockedTimer(buildOrder.at(0))) {
			//Locked timeout. Reset it.
			locked = false;
			Broodwar->printf("[BuildPlanner] Locked timeout. Resetting.");
			//Reset the worker to do it
			AgentManager* agentManager = AgentManager::getInstance();
			for (int i = 0; i < (int)agentManager->size(); i++) {
				BaseAgent* agent = agentManager->at(i);
				if (agent->isAlive() && agent->isWorker()) {
					WorkerAgent* worker = (WorkerAgent*)agent;
					if (worker->isConstructing(buildOrder.at(0))) {
						//Reset the worker
						worker->reset();
					}
				}
				AgentManager::release(agent);
			}
		}
		else {
			return;
		}
	}

	//Try to execute first in the list
	if ((int)buildOrder.size() > 0) {
		if (executeOrder(buildOrder.at(0))) {
			locked = true;
			lockedFrame = Broodwar->getFrameCount();
		}
	}

	//if (mineralsRunningLow()) {
		//buildOrder.insert(buildOrder.begin(), UnitTypes::Zerg_Hatchery);
	//}
}
예제 #26
0
TilePosition CoverMap::searchRefinerySpot()
{
	for(int i = 0 ; i < w ; i++)
	{
		for (int j = 0; j < h; j++)
		{
			if (cover_map[i][j] == GAS)
			{
				TilePosition cPos = TilePosition(i,j);

				bool found = false;
				vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
				for (int i = 0; i < (int)agents.size(); i++)
				{
					if (agents.at(i)->getUnitType().isRefinery())
				{
						double dist = agents.at(i)->getUnit()->getTilePosition().getDistance(cPos);
						TilePosition uPos = agents.at(i)->getUnit()->getTilePosition();
						if (dist <= 2)
				{
							found = true;
							break;
						}
					}
				}

				if (!found)
				{
					BaseAgent* agent = AgentManager::getInstance()->getClosestBase(cPos);
					if (agent != NULL)
					{
						TilePosition bPos = agent->getUnit()->getTilePosition();
						double dist = bPos.getDistance(cPos);

						if (dist < 15)
						{
							if (ExplorationManager::canReach(bPos, cPos))
							{
								return cPos;
							}			
						}
					}
				}
			}
		}
	}

	return TilePosition(-1, -1);
}
예제 #27
0
BaseAgent* HighTemplarAgent::findArchonTarget() {
	int maxRange = 12 * 32;

	AgentManager* agentManager = AgentManager::getInstance();
	for (int i = 0; i < (int)agentManager->size(); i++) {
		BaseAgent* agent = agentManager->at(i);
		if (!agent->matches(unit) && agent->isAlive() && agent->isOfType(UnitTypes::Protoss_High_Templar) && agent->getUnit()->getEnergy() <= 50) {
			AgentManager::release(agent);
			return agent;
		}
		AgentManager::release(agent);
	}

	return NULL;
}
예제 #28
0
BaseAgent* ScienceVesselAgent::findImportantUnit() {
	AgentManager* agentManager = AgentManager::getInstance();
	for (int i = 0; i < (int)agentManager->size(); i++) {
		BaseAgent* agent = agentManager->at(i);
		if (agent->isAlive() && isImportantUnit(agent) && !agent->getUnit()->isDefenseMatrixed()) {
			double dist = unit->getDistance(agent->getUnit());
			if (dist <= 320) {
				AgentManager::release(agent);
				return agent;
			}
		}
		AgentManager::release(agent);
	}
	return NULL;
}
예제 #29
0
TilePosition CoverMap::findClosestGasWithoutRefinery(UnitType toBuild, TilePosition start)
{
	TilePosition bestSpot = TilePosition(-1,-1);
	double bestDist = -1;
	TilePosition home = Broodwar->self()->getStartLocation();
	Unit* worker = findWorker();

	for(int i = 0 ; i < w ; i++)
	{
		for (int j = 0; j < h; j++)
		{
			if (cover_map[i][j] == GAS)
			{
				TilePosition cPos = TilePosition(i,j);

				bool ok = true;
				vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
				for (int i = 0; i < (int)agents.size(); i++)
				{
					Unit* unit = agents.at(i)->getUnit();
					if (unit->getType().isRefinery())
					{
						double dist = unit->getTilePosition().getDistance(cPos);
						if (dist <= 2)
						{
							ok = false;
						}
					}
				}
				if (ok)
				{
					if (ExplorationManager::canReach(home, cPos))
					{
						BaseAgent* agent = AgentManager::getInstance()->getClosestBase(cPos);
						double dist = agent->getUnit()->getTilePosition().getDistance(cPos);
						if (bestDist == -1 || dist < bestDist)
						{
							bestDist = dist;
							bestSpot = cPos;
						}
					}
				}
			}
		}
	}

	return bestSpot;
}
예제 #30
0
bool AgentManager::isAnyAgentRepairingThisAgent(BaseAgent* repairedAgent)
{
	for (int i = 0; i < (int)agents.size(); i++) {
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive() && agent->isWorker()) {
			Unit* unit = agent->getUnit();
			if (unit->isRepairing() || unit->isConstructing()) {
				if (unit->getTarget() != NULL && unit->getTarget()->getID() == repairedAgent->getUnitID()) {
					//Already have an assigned builder
					return true;
				}
			}
		}
	}
	return false;
}