当前位置: 首页>>代码示例>>C++>>正文


C++ BaseAgent::getUnit方法代码示例

本文整理汇总了C++中BaseAgent::getUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseAgent::getUnit方法的具体用法?C++ BaseAgent::getUnit怎么用?C++ BaseAgent::getUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseAgent的用法示例。


在下文中一共展示了BaseAgent::getUnit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: chargeShields

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;
}
开发者ID:BuffBuff,项目名称:BTHAI_3.0,代码行数:30,代码来源:UnitAgent.cpp

示例2: getCurrentLoad

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;
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:26,代码来源:TransportAgent.cpp

示例3: doEnsnare

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;
}
开发者ID:Senth,项目名称:bats,代码行数:27,代码来源:BaseAgent.cpp

示例4: getFreeWorker

BaseAgent* AgentManager::getFreeWorker()
{
	for (int i = 0; i < (int)agents.size(); i++) {
		BaseAgent* agent = agents.at(i);
		if (agent != NULL && agent->isAlive() && agent->isWorker()) {
			if (agent->getUnit()->isIdle() || (agent->getUnit()->isGatheringMinerals() && !agent->getUnit()->isCarryingMinerals())) {
				agent->LockAgent();
				return agent;
			}
		}
	}
	return NULL;
}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:13,代码来源:AgentManager.cpp

示例5: checkRemovableObstacles

void Commander::checkRemovableObstacles()
{
	for(set<Unit*>::iterator m = Broodwar->getMinerals().begin(); m != Broodwar->getMinerals().end(); m++)
	{
		if ((*m)->getResources() <= 20)
		{
			//Found a mineral that we can remove.
			BaseAgent* baseAgent = AgentManager::getInstance()->getClosestBase((*m)->getTilePosition());
			if (baseAgent != NULL)
			{
				double cDist = baseAgent->getUnit()->getDistance((*m));
				if (cDist < 1000)
				{
					//It is close to a base, remove it.

					//Step 1: Check if someone already is working on it
					bool assign = true;
					vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
					for (int i = 0; i < (int)agents.size(); i++)
				{
						BaseAgent* agent = agents.at(i);
						if (agent->isWorker())
				{
							Unit* u = agent->getUnit();
							if (u->isGatheringMinerals())
				{
								Unit* t = u->getTarget();
								if (t != NULL && t->getID() == u->getID())
				{
									//Someone already working on it. Dont bother.
									assign = false;
								}
							}
						}
					}

					if (assign)
				{
						BaseAgent* worker = AgentManager::getInstance()->findClosestFreeWorker((*m)->getTilePosition());
						if (worker != NULL)
				{
							worker->getUnit()->rightClick((*m));
						}
					}
				}
			}
		}
	}
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:49,代码来源:Commander.cpp

示例6: findImportantUnit

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;
}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:15,代码来源:ScienceVesselAgent.cpp

示例7: buildOverlordIfNeeded

/** Build an overlord if needed. Returns true if the case was so.
Should perhaps be the job of ZergCommander? */
bool ZergBuildPlanner::buildOverlordIfNeeded() {
	//Broodwar->printf("minerals : %i , supply: %i,%i", Broodwar->self()->minerals(), Broodwar->self()->supplyUsed(), Broodwar->self()->supplyTotal());

	//1. Make sure we've got minerals.
	if (Broodwar->self()->minerals() < 100)
		return false;

	//2. Check if we need supplies
	int supplyTotal = Broodwar->self()->supplyTotal() / 2;
	int supplyUsed = Broodwar->self()->supplyUsed() / 2;
	if (supplyTotal - supplyUsed > 6 || supplyTotal == 200) {
		//Broodwar->printf("No overlord needed.");
		return false;
	}

	//3. Check if there is a Overlord already being built
	std::vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (unsigned int i = 0; i < agents.size(); i++)
	{
		BaseAgent *agent = agents.at(i);
		if (agent->isOfType(UnitTypes::Zerg_Egg))
		{
			//Broodwar->printf("found egg, checking for overlord");
			// TODO : do we need to check for in case an overlord is being morphed?
			if (agent->getUnit()->getBuildType() == UnitTypes::Zerg_Overlord)
			{
				//Broodwar->printf("already training overlord");
				return false;
			}
		}
	}

	//Broodwar->printf("Supplies: %d/%d. Building Overlord. Frame count: %d", supplyUsed, supplyTotal, Broodwar->getFrameCount());

	//std::vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (unsigned int i = 0; i < agents.size(); i++)
	{
		BaseAgent *agent = agents.at(i);
		if (agent->isOfType(UnitTypes::Zerg_Larva))
		{
			//Broodwar->printf("unit is larva, training overlord");
			agent->getUnit()->train(UnitTypes::Zerg_Overlord);
			return true;
		}
	}
	//Broodwar->printf("No larva for available, not training.");
	return false;
}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:50,代码来源:ZergBuildPlanner.cpp

示例8: findClosestMineral

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;
}
开发者ID:Malow,项目名称:Project-MalRilTil,代码行数:31,代码来源:CoverMap.cpp

示例9: findUnitToLoad

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;
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:26,代码来源:TransportAgent.cpp

示例10: computeActions

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);
}
开发者ID:jieverson,项目名称:BTHAIMOD,代码行数:32,代码来源:TransportAgent.cpp

示例11: sendWorkers

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;
		}
	}
}
开发者ID:Malow,项目名称:Project-MalRilTil,代码行数:26,代码来源:StructureAgent.cpp

示例12: computeActions

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);
}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:35,代码来源:HighTemplarAgent.cpp

示例13: findClosestMineral

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;
}
开发者ID:jhagelback,项目名称:OpprimoBot,代码行数:34,代码来源:BuildingPlacer.cpp

示例14: findExpansionSite

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;
}
开发者ID:Malow,项目名称:Project-MalRilTil,代码行数:60,代码来源:CoverMap.cpp

示例15: buildHatcheryIfNeeded

/** 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);

}
开发者ID:zarac,项目名称:tgspu-bthai,代码行数:34,代码来源:ZergBuildPlanner.cpp


注:本文中的BaseAgent::getUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。