本文整理汇总了C++中BaseAgent类的典型用法代码示例。如果您正苦于以下问题:C++ BaseAgent类的具体用法?C++ BaseAgent怎么用?C++ BaseAgent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseAgent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Squad
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: 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;
}
示例3: checkWorkersAttack
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: isOccupied
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;
}
示例5: 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;
}
示例6: 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;
}
示例7: main
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: TilePosition
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: 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;
}
示例10: findArchonTarget
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: 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;
}
}
}
示例12: 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;
}
示例13: 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;
}
示例14: 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);
}
示例15: findWorker
Unit* CoverMap::findWorker()
{
BaseAgent* worker = AgentManager::getInstance()->getAgent(Broodwar->self()->getRace().getWorker());
if (worker != NULL)
{
return worker->getUnit();
}
return NULL;
}