Example #1
0
void GameTraceCollector::CollectGameTraceForTrainedUnit(const BWAPI::Unit trainee, const BWAPI::Unit trainer)
{
    if (!trainer)
    {
        LogInfo("Unable to find trainee %s trainer, will use normal trace collector", trainee->getPlayer()->getName().c_str());
        CollectGameTraceForUnitOrder(trainee);
        return;
    }

    ActionType action;

    UNREFERENCED_PARAMETER(trainee);

    LogInfo("(P%d,%s) %s[%d]: %s",
            trainer->getPlayer()->getID(), trainer->getPlayer()->getName().c_str(),
            trainer->getType().c_str(), trainer->getID(), "Train");

    _ASSERTE(g_Database.ActionMapping.ContainsFirst(Orders::Train.getID()));
    action = g_Database.ActionMapping.GetByFirst(Orders::Train.getID());

    GameTrace *pTrace = nullptr;
    PlanStepParameters actionParams = m_abstractor.GetAbstractedParameter(trainee, trainer);

    pTrace = new GameTrace(Broodwar->getFrameCount(), action, actionParams, g_Game->Snapshot(), m_playerToObserve);

    SendGameTrace(pTrace);
}
Example #2
0
//BWAPI calls this when an accessible unit is created. Note that this is NOT called when a unit changes type
void ExampleAIModule::onUnitCreate(BWAPI::Unit unit) {
	if ( Broodwar->isReplay() ) {
		// if we are in a replay, then we will print out the build order of the structures
		if ( unit->getType().isBuilding() && !unit->getPlayer()->isNeutral() ) {
			int seconds = Broodwar->getFrameCount()/24;
			int minutes = seconds/60;
			seconds %= 60;
			Broodwar->sendText("%.2d:%.2d: %s creates a %s", minutes, seconds, unit->getPlayer()->getName().c_str(), unit->getType().c_str());
		}
    }
	/*else{
		if(unit->getType() == UnitTypes::Terran_Command_Center){
			Unitset visibleMinerals = Broodwar->getMinerals();
			
			//when base is created, check if it covers all accessible minerals
			bool allVisible = true;
			for(Unitset::iterator min = visibleMinerals.begin(); min != visibleMinerals.end(); ++min){
				if(unit->getDistance(*min) < BASE_RADIUS){
					//allVisible = false;
					//break;
					mineralsOutOfBaseRange--;
				}
			}
		}
	}*/
}
Example #3
0
void InformationManager::updateUnit(BWAPI::Unit unit)
{
    if (!(unit->getPlayer() == _self || unit->getPlayer() == _enemy))
    {
        return;
    }

    _unitData[unit->getPlayer()].updateUnit(unit);
}
Example #4
0
void ExampleAIModule::onUnitMorph(BWAPI::Unit unit) {
  if ( Broodwar->isReplay() ) {
    // if we are in a replay, then we will print out the build order of the structures
    if ( unit->getType().isBuilding() && !unit->getPlayer()->isNeutral() ) {
      int seconds = Broodwar->getFrameCount()/24;
      int minutes = seconds/60;
      seconds %= 60;
      Broodwar->sendText("%.2d:%.2d: %s morphs a %s", minutes, seconds, unit->getPlayer()->getName().c_str(), unit->getType().c_str());
    }
  }
}
Example #5
0
void OpprimoBot::onUnitShow(BWAPI::Unit unit)
{
    if (Broodwar->isReplay() || Broodwar->getFrameCount() <= 1) return;

    if (unit->getPlayer()->getID() != Broodwar->self()->getID())
    {
        if (!unit->getPlayer()->isNeutral() && !unit->getPlayer()->isAlly(Broodwar->self()))
        {
            ExplorationManager::getInstance()->addSpottedUnit(unit);
        }
    }
}
Example #6
0
void OpprimoBot::onUnitCreate(BWAPI::Unit unit)
{
    if (unit->getPlayer()->getID() == Broodwar->self()->getID())
    {
        loop.addUnit(unit);
    }
}
void Commander::destroyUnit(BWAPI::Unit unit)
{
	// If its one of my units
	if(unit->getPlayer()->getID() == Broodwar->self()->getID())
	{
		for(auto i=pAllUnits.begin();i!=pAllUnits.end();i++)
		{
			if((*i)->getID() == unit->getID())
			{
				pAllUnits.erase(i);
				break;
			}
		}

		for(auto i=squads.begin();i!=squads.end();i++)
			(*i)->removeUnit(PUnit::get(unit));
	}
	else // If its one of my ennemy
	{
		for(auto i=oAllUnits.begin();i!=oAllUnits.end();i++)
		{
			if((*i)->getID() == unit->getID())
			{
				oAllUnits.erase(i);
				break;
			}
		}
	}
}
Example #8
0
void SwarmCAT::onUnitComplete(BWAPI::Unit unit)
{
	if (!Broodwar->isReplay())
	{
		if (unit->getPlayer() == util::game::getSelf())
		{			
			if (unit->getType().isResourceDepot())
			{
				DesireHelper::updateSupplyDesire(unit->getType());
				int unitCount = util::game::getSelf()->allUnitCount(unit->getType());
				if( unitCount > 1)
					util::eval::logExpansion(unitCount -1);
			}
			AgentHelper::createAgent(unit);

			auto unitZone = MapHelper::getZone(unit->getRegion()); 			

			if (unit->getType() == BWAPI::UnitTypes::Terran_Bunker)
			{
				for (auto &zone : unitZone->getNeighbourhood())
					zone->setBunkerDefense(true);
			}

			if (unit->getType() == BWAPI::UnitTypes::Terran_Missile_Turret)
			{
				for (auto &zone : unitZone->getNeighbourhood())
					zone->setTurretDefense(true);
			}

			DesireHelper::setDefendDesire(unitZone, unitZone->getEnemyScore());
		}
	}
}
Example #9
0
void SwarmCAT::onUnitDestroy(BWAPI::Unit unit)
{	
	if (!Broodwar->isReplay())
	{
		if (unit->getPlayer() == util::game::getSelf() && !unit->isBeingConstructed())
		{
			if (unit->getType() == BWAPI::UnitTypes::Terran_Bunker)
			{
				int bunkerCount = 0;
				const MapHelper::Field& neighbourhood = MapHelper::getZone(unit->getRegion())->getNeighbourhood();
				for (const auto &zone : neighbourhood)
					bunkerCount += zone->getRegion()->getUnits(BWAPI::Filter::IsOwned && BWAPI::Filter::GetType == BWAPI::UnitTypes::Terran_Bunker).size();

				if (bunkerCount == 0)
				{
					for (const auto &zone : neighbourhood)
						zone->setBunkerDefense(false);
				}
			}

			if (unit->getType() == BWAPI::UnitTypes::Terran_Missile_Turret)
			{
				int turretCount = 0;
				for (auto &zone : MapHelper::getZone(unit->getRegion())->getNeighbourhood())
					turretCount += zone->getRegion()->getUnits(BWAPI::Filter::IsOwned && BWAPI::Filter::GetType == BWAPI::UnitTypes::Terran_Missile_Turret).size();

				if (turretCount == 0)
				{
					for (auto &zone : MapHelper::getZone(unit->getRegion())->getNeighbourhood())
						zone->setTurretDefense(false);
				}
			}

			DesireHelper::updateSupplyDesire(unit->getType(), true);
			AgentHelper::removeAgent(unit->getID());
			
		}

		if (unit->getPlayer() == util::game::getEnemy())
		{
			if (unit->getType().isBuilding())
				ArmyHelper::removeTargetPriority(unit);
			else
				ArmyHelper::removeScoutedUnit(unit->getID());
		}
	}
}
Example #10
0
void SwarmCAT::onUnitShow(BWAPI::Unit unit)
{
	if (!Broodwar->isReplay())
	{
		if (unit->getPlayer() == util::game::getEnemy())
			ArmyHelper::addScoutedUnit(unit->getID(), unit->getType());
	}
}
Example #11
0
void SwarmCAT::onUnitDiscover(BWAPI::Unit unit)
{
	if (!Broodwar->isReplay())
	{
		if (unit->getType().isBuilding() && unit->getPlayer() == util::game::getEnemy())
			ArmyHelper::addTargetPriority(unit);
	}
}
void WorkerManager::onUnitMorph(BWAPI::Unit unit)
{
	UAB_ASSERT(unit != nullptr, "Unit was null");

	// if something morphs into a worker, add it
	if (unit->getType().isWorker() && unit->getPlayer() == BWAPI::Broodwar->self() && unit->getHitPoints() >= 0)
	{
		workerData.addWorker(unit);
	}

	// if something morphs into a building, it was a worker?
	if (unit->getType().isBuilding() && unit->getPlayer() == BWAPI::Broodwar->self() && unit->getPlayer()->getRace() == BWAPI::Races::Zerg)
	{
		//BWAPI::Broodwar->printf("A Drone started building");
		workerData.workerDestroyed(unit);
	}
}
void WorkerManager::onUnitShow(BWAPI::Unit unit)
{
	UAB_ASSERT(unit != nullptr, "Unit was null");

	// add the depot if it exists
	if (unit->getType().isResourceDepot() && unit->getPlayer() == BWAPI::Broodwar->self())
	{
		workerData.addDepot(unit);
	}

	// if something morphs into a worker, add it
	if (unit->getType().isWorker() && unit->getPlayer() == BWAPI::Broodwar->self() && unit->getHitPoints() >= 0)
	{
		//BWAPI::Broodwar->printf("A worker was shown %d", unit->getID());
		workerData.addWorker(unit);
	}
}
Example #14
0
void InformationManager::onUnitDestroy(BWAPI::Unit unit) 
{ 
    if (unit->getType().isNeutral())
    {
        return;
    }

    _unitData[unit->getPlayer()].removeUnit(unit);
}
void WorkerManager::onUnitDestroy(BWAPI::Unit unit) 
{
	UAB_ASSERT(unit != nullptr, "Unit was null");

	if (unit->getType().isResourceDepot() && unit->getPlayer() == BWAPI::Broodwar->self())
	{
		workerData.removeDepot(unit);
	}

	if (unit->getType().isWorker() && unit->getPlayer() == BWAPI::Broodwar->self()) 
	{
		workerData.workerDestroyed(unit);
	}

	if (unit->getType() == BWAPI::UnitTypes::Resource_Mineral_Field)
	{
		rebalanceWorkers();
	}
}
Example #16
0
void TurkAnalyzer::onUnitComplete(BWAPI::Unit unit)
{
	if (unit->getType().isBuilding() && !unit->getPlayer()->isNeutral())
	{
		Position pos = unit->getPosition();
		//int seconds = Broodwar->getFrameCount() / 24;
		//int minutes = seconds / 60;
		//seconds %= 60;
		Broodwar->sendText("%.2d:%.2d: %s completed a %s", pos, unit->getPlayer()->getName().c_str(), unit->getType().c_str());

		if (unit->getType() == BWAPI::UnitTypes::Protoss_Gateway)
		{
			FirstGateExist = true;
		}
		else if (unit->getType() == BWAPI::UnitTypes::Protoss_Pylon)
		{
			FirstPylonExist = true;
		}
		else if (unit->getType() == BWAPI::UnitTypes::Protoss_Assimilator)
		{
			FirstGasExist = true;
		}
		else if (unit->getType() == BWAPI::UnitTypes::Protoss_Cybernetics_Core)
		{
			FirstCybernetics = true;
			PylonLimiter = 1;
		}
		else if (unit->getType() == BWAPI::UpgradeTypes::Singularity_Charge)
		{
			Singularity = true;
		}
		else if (unit->getType() == BWAPI::UnitTypes::Protoss_Citadel_of_Adun)
		{
			FirstAdun = true;
		}
		else if (unit->getType() == BWAPI::UpgradeTypes::Leg_Enhancements)
		{
			Leg_Enhancements = true;
		}

	}
}
Example #17
0
// Gets a SparCraft unit from a BWAPI::Unit, used for our own units since we have all their info
const SparCraft::Unit CombatSimulation::getSparCraftUnit(BWAPI::Unit unit) const
{
    return SparCraft::Unit( unit->getType(),
                            SparCraft::Position(unit->getPosition()), 
                            unit->getID(), 
                            getSparCraftPlayerID(unit->getPlayer()), 
                            unit->getHitPoints() + unit->getShields(), 
                            0,
		                    BWAPI::Broodwar->getFrameCount(), 
                            BWAPI::Broodwar->getFrameCount());	
}
Example #18
0
void SwarmCAT::onUnitCreate(BWAPI::Unit unit)
{
	if (!Broodwar->isReplay())
	{
		if (unit->getPlayer() == util::game::getSelf() && !(unit->getType().supplyProvided() == 16 || unit->getType().isBuilding()))
			DesireHelper::updateSupplyDesire(unit->getType());

		if (Broodwar->isReplay())
		{
			// if we are in a replay, then we will print out the build order of the structures
			if (unit->getType().isBuilding() && !unit->getPlayer()->isNeutral())
			{
				int seconds = Broodwar->getFrameCount() / 24;
				int minutes = seconds / 60;
				seconds %= 60;
				Broodwar->sendText("%.2d:%.2d: %s creates a %s", minutes, seconds, unit->getPlayer()->getName().c_str(), unit->getType().c_str());
			}
		}
	}
}
Example #19
0
void StrategOS::onUnitMorph(BWAPI::Unit unit) {
  if (unit->getPlayer()->getID() != Broodwar->self()->getID()) {
    return;
  }

  if (unit->getType().getID() == UnitTypes::Zerg_Larva.getID()) {
    return;
  }

  agents.push_back(AgentFactory::makeAgent(unit));
}
Example #20
0
// is the unit valid?
bool InformationManager::isValidUnit(BWAPI::Unit unit) 
{
	// we only care about our units and enemy units
	if (unit->getPlayer() != BWAPI::Broodwar->self() && unit->getPlayer() != BWAPI::Broodwar->enemy()) 
	{
		return false;
	}

	// if it's a weird unit, don't bother
	if (unit->getType() == BWAPI::UnitTypes::None || unit->getType() == BWAPI::UnitTypes::Unknown ||
		unit->getType() == BWAPI::UnitTypes::Zerg_Larva || unit->getType() == BWAPI::UnitTypes::Zerg_Egg) 
	{
		return false;
	}

	// if the position isn't valid throw it out
	if (!unit->getPosition().isValid()) 
	{
		return false;	
	}

	// s'all good baby baby
	return true;
}
Example #21
0
void LizurdModule::onUnitDestroy(BWAPI::Unit unit)
{
	if(_initialised == Result::Success)
	{
		if (!Broodwar->isReplay())
		{
			if(unit->getPlayer() == Broodwar->self())
			{
				Notification notification(UnitDiscoveryCoord);
				notification.SetAction(Action::DeRegisterUnit);
				notification.AddUnit(unit);
				_gateway.RegisterNotification(notification);
			}
		}
	}
}
Example #22
0
void OpprimoBot::onUnitMorph(BWAPI::Unit unit)
{
    if (Broodwar->isReplay() || Broodwar->getFrameCount() <= 1) return;

    if (unit->getPlayer()->getID() == Broodwar->self()->getID())
    {
        if (Constructor::isZerg())
        {
            loop.morphUnit(unit);
        }
        else
        {
            loop.addUnit(unit);
        }
    }
}
Example #23
0
void StrategOS::onUnitCreate(BWAPI::Unit unit) {
  if (Broodwar->getFrameCount() == 0) {
    return;
  }

  if (unit->getPlayer()->getID() != Broodwar->self()->getID()) {
    return;
  }

  if (unit->getType().getID() == UnitTypes::Zerg_Larva.getID()) {
    return;
  }

  Blackboard::Instance().unlock(unit->getType());

  agents.push_back(AgentFactory::makeAgent(unit));
}
Example #24
0
//BWAPI calls this when a unit dies or otherwise removed from the game (i.e. a mined out mineral patch)
void ExampleAIModule::onUnitDestroy(BWAPI::Unit unit){
	if (unit->getPlayer() == Broodwar->self()){
		Broodwar->sendText("%s lost.", unit->getType().getName().c_str());
		if(unit->getType() == UnitTypes::Terran_SCV){
			// Delete this SCV from the map
			scvMap.erase(unit->getID()); 
		}
		else if(unit->getType() == UnitTypes::Terran_Marine){
			marines.erase(unit->getID());
		}
		else if (unit->getType() == UnitTypes::Terran_Command_Center){
			//Broodwar->sendText("cmdSize before: %d",commandCenters.size());
			commandCenters.erase(unit);
			//Broodwar->sendText("cmdSize AFTER: %d",commandCenters.size());
		}
	}
	else {
		Broodwar->sendText("%s shot down.", unit->getType().getName().c_str());
	}
}
Example #25
0
// on unit destroy
void ProductionManager::onUnitDestroy(BWAPI::Unit unit)
{
	// we don't care if it's not our unit
	if (!unit || unit->getPlayer() != BWAPI::Broodwar->self())
	{
		return;
	}
		
	if (Config::Modules::UsingBuildOrderSearch)
	{
		// if it's a worker or a building, we need to re-search for the current goal
		if ((unit->getType().isWorker() && !WorkerManager::Instance().isWorkerScout(unit)) || unit->getType().isBuilding())
		{
			if (unit->getType() != BWAPI::UnitTypes::Zerg_Drone)
			{
				performBuildOrderSearch();
			}
		}
	}
}
Example #26
0
int UnitUtil::GetAttackRange(BWAPI::Unit attacker, BWAPI::Unit target)
{
    BWAPI::WeaponType weapon = GetWeapon(attacker, target);

    if (weapon == BWAPI::WeaponTypes::None)
    {
        return 0;
    }

    int range = weapon.maxRange();

    if ((attacker->getType() == BWAPI::UnitTypes::Protoss_Dragoon) 
        && (attacker->getPlayer() == BWAPI::Broodwar->self())
        && BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Singularity_Charge))
	{
		range = 6 * 32;
	}

    return range;
}
Example #27
0
void MutaliskHarassTactic::onUnitShow(BWAPI::Unit unit)
{
	if (unit->getPlayer() == BWAPI::Broodwar->enemy())
	{
		if (unit->getType() == BWAPI::UnitTypes::Protoss_Photon_Cannon
			|| unit->getType() == BWAPI::UnitTypes::Zerg_Spore_Colony
			|| unit->getType() == BWAPI::UnitTypes::Terran_Missile_Turret)
		{
			newCannonCount++;
		}
		else if (unit->getType().airWeapon() != BWAPI::WeaponTypes::None && !unit->getType().isBuilding())
		{
			newAntiAirAnmyCount++;
		}

		if (BWAPI::Broodwar->getFrameCount() > triggerChangeTime && (newCannonCount >= 3 || newAntiAirAnmyCount >= 5) && tacticArmy[BWAPI::UnitTypes::Zerg_Mutalisk]->getUnits().size() > 0)
		{
			triggerChangeTime = BWAPI::Broodwar->getFrameCount() + 25 * 4;

			if (state == MOVE || state == BACKMOVE)
			{
				state = LOCATIONASSIGN;
			}

			for (std::map<BWAPI::Unit, std::vector<BWAPI::Position>>::iterator it = newAddArmy.begin(); it != newAddArmy.end(); it++)
			{
				it->second.clear();
				std::list<BWAPI::TilePosition> pathFind = aStarPathFinding(it->first->getTilePosition(), tacticArmy[BWAPI::UnitTypes::Zerg_Mutalisk]->getUnits().front().unit->getTilePosition(), true, true);
				std::vector<BWAPI::Position> movePath;
				movePath.reserve(pathFind.size());
				BOOST_FOREACH(BWAPI::TilePosition p, pathFind)
				{
					movePath.push_back(BWAPI::Position(p));
				}
				it->second = movePath;
			}

			newCannonCount = 0;
			newAntiAirAnmyCount = 0;
		}
Example #28
0
void BaseManager::update()
{
	for(std::set<Base*>::iterator b = this->allBases.begin(); b != this->allBases.end(); b++)
	{
		Base *base = (*b);

		// periodicky check, ci baza pouziva najblizsi resource depot
		if (BWAPI::Broodwar->getFrameCount() % 300 == 231)
		{
			BWAPI::TilePosition tilePosition = base->getBaseLocation()->getTilePosition();
			BWAPI::Position position = BWAPI::Position(tilePosition);

			UnitGroup centers = UnitGroup::getUnitGroup(BWAPI::Broodwar->getUnitsInRadius(position, 600))
			(BWAPI::Broodwar->self())
			(isResourceDepot);
			UnitGroup::iterator it;

			BWAPI::Unit *nearestCenter = NULL;
			double distance = 10000;

			for (it = centers.begin(); it != centers.end(); it++)
			{
				BWAPI::Unit *centerCandidate = (*it);
				dementor::Vector vector = dementor::Vector::fromPositions(position, centerCandidate->getPosition());

				if (vector.getLength() < distance)
				{
					nearestCenter = centerCandidate;
					distance = vector.getLength();
				}
			}

			if (nearestCenter != NULL)
			{
				base->setResourceDepot(nearestCenter);
			}

			if (base->getResourceDepot() != NULL)
			{
				if (!base->getResourceDepot()->exists())
				{
					base->setResourceDepot(NULL);
				}
				else if (base->getResourceDepot()->isCompleted() || base->getResourceDepot()->getRemainingBuildTime() < 250)
				{
					base->setActive(true);
				}
			}
		}

		//Set Refinerys
		if (!base->isActiveGas() && base->hasGas())
		{
			if (base->getRefinery() == NULL)
			{
				std::set<BWAPI::Unit*> baseGeysers = (*b)->getBaseLocation()->getGeysers();

				BWAPI::TilePosition geyserLocation;

				//cycle through geysers & get tile location
				for(std::set<BWAPI::Unit*>::iterator bg = baseGeysers.begin(); bg != baseGeysers.end(); bg++)
				{
					geyserLocation = (*bg)->getTilePosition();
				}

				//check for refinery already on geyser
				std::set<BWAPI::Unit*> unitsOnGeyser = BWAPI::Broodwar->getUnitsOnTile(geyserLocation.x(),geyserLocation.y());

				for(std::set<BWAPI::Unit*>::iterator u = unitsOnGeyser.begin(); u != unitsOnGeyser.end(); u++)
				{
					BWAPI::Unit *unit = (*u);
					if (unit->getPlayer() == BWAPI::Broodwar->self() && unit->getType().isRefinery())
					{
						base->setRefinery(*u);
						break;
					}
				}
			}

			if (base->getRefinery() != NULL)
			{
				if (!base->getRefinery()->exists())
				{
					base->setResourceDepot(NULL);
				}
				else
				{
					if (base->getRefinery()->isCompleted() || base->getRefinery()->getRemainingBuildTime() < 250)
					{
						base->setActiveGas(true);
					}
				}
			}
		}
	}

	//check to see if any new base locations need to be added
	for(std::set<BWTA::BaseLocation*>::const_iterator bl = BWTA::getBaseLocations().begin(); bl != BWTA::getBaseLocations().end(); bl++)
	{
		if (location2base.find(*bl) == location2base.end())
		{
			BWAPI::TilePosition tile = (*bl)->getTilePosition();
			std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(tile.x(), tile.y());

			for(std::set<BWAPI::Unit*>::iterator u = units.begin(); u != units.end(); u++)
			{
				if ((*u)->getPlayer() == BWAPI::Broodwar->self() && (*u)->getType().isResourceDepot())
				{
					addBase(*bl);
				}
			}
		}
	}

	if(BWAPI::Broodwar->getFrameCount() % 500 == 0 && BWAPI::Broodwar->getFrameCount() >= 3000 && refineryBuildPriority > 0)
	{
		updateRefineries();
	}
}