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;
			}
		}
	}
}
void ExampleAIModule::onUnitComplete(BWAPI::Unit unit)
{
	Broodwar->sendText("unit completed! id = %d positionX = %d, positionY = %d", unit->getID(), unit->getPosition().x, unit->getPosition().y);
	std::ofstream fileFerran;
	fileFerran.open("bwapi-data\\logs\\fileFerran.txt");
	fileFerran << "unit id " << unit->getID();
	fileFerran.close();
}
Example #3
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 #4
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 #5
0
void SwarmCAT::onUnitShow(BWAPI::Unit unit)
{
	if (!Broodwar->isReplay())
	{
		if (unit->getPlayer() == util::game::getEnemy())
			ArmyHelper::addScoutedUnit(unit->getID(), unit->getType());
	}
}
Example #6
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 #7
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());
	}
}
    Action DesolatorModule::moveUnitToPosition(BWAPI::Unit & unit, BWAPI::Position position) {
        auto & GS = unitStates_[unit->getID()];

        if (convertToTile(position) != unit->getTilePosition()) {
            unit->move(position);
            GS.setDraw(position);
            return Action::Move;
        }
        else {
            GS.setNoDraw();
            return Action::None;
        }
    }
Example #9
0
//NEW
void CombatSimulation::addToState(BWAPI::Unit unit)
{
	// if (!SparCraft::System::isSupportedUnitType(unit->getType()))

	try
	{
		state.addUnit(getSparCraftUnit(unit));
	}
	catch (int e)
	{
		e = 1;
		BWAPI::Broodwar->printf("Problem Adding Self Unit with ID: %d", unit->getID());
	}
}
Example #10
0
void ProductionManager::manageBuildOrderQueue() 
{
	// if there is nothing in the _queue, oh well
	if (_queue.isEmpty()) 
	{
		return;
	}

	// the current item to be used
	BuildOrderItem & currentItem = _queue.getHighestPriorityItem();


	// while there is still something left in the _queue
	while (!_queue.isEmpty()) 
	{

		/*
		if (currentItem.metaType.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Carapace && UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 1)
		{
			MetaType type(BWAPI::UnitTypes::Zerg_Evolution_Chamber);
			ProductionManager::Instance()._queue.queueAsHighestPriority(type, true);
		}
		*/
		/*
		else if (currentItem.metaType.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Carapace && UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 2)
		{
			BWAPI::Unit myEvo = getUnusedEvo();
			myEvo->upgrade(currentItem.metaType.getUpgradeType());

		}
		*/
			//BWAPI::Broodwar->printf("%d\n", UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber));
		
		BWAPI::Unit producer;
		if (currentItem.metaType.getUnitType() == 143 && BuildingManager::Instance().createdHatcheriesVector.size() >= 1)
		{
			producer = getProducer(currentItem.metaType,BWAPI::Position(BuildingManager::Instance().createdHatcheriesVector[0]));
		}
		/*
		else if (currentItem.metaType.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Carapace && UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 2)
		{
			// this is the unit which can produce the currentItem
			//producer = getProducer(currentItem.metaType);
			producer = getUnusedEvo();
			producer->upgrade(currentItem.metaType.getUpgradeType());
		}
		*/
		else
		{
			/*
			if (currentItem.metaType.whatBuilds().isBuilding() && !canProduce(currentItem.metaType.whatBuilds()))
			{
				_queue.queueAsHighestPriority(currentItem.metaType.whatBuilds(), false);

			}
			*/
			producer = getProducer(currentItem.metaType);
			if (currentItem.metaType.isUpgrade())
			{
				if (currentItem.metaType.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Carapace)
				{
					BWAPI::Broodwar->printf("First evo chamber is %d, chosen Evo chamber is %d\n", BuildingManager::Instance().firstEvoChamber, producer->getID());
				}
			}
		
		}

		// check to see if we can make it right now
		bool canMake = canMakeNow(producer, currentItem.metaType);

		// if we try to build too many refineries manually remove it
		if (currentItem.metaType.isRefinery() && (BWAPI::Broodwar->self()->allUnitCount(BWAPI::Broodwar->self()->getRace().getRefinery() >= 3)))
		{
			_queue.removeCurrentHighestPriorityItem();
			break;
		}

		// if the next item in the list is a building and we can't yet make it
        if (currentItem.metaType.isBuilding() && !(producer && canMake) && currentItem.metaType.whatBuilds().isWorker())
		{
			// construct a temporary building object
			Building b(currentItem.metaType.getUnitType(), BWAPI::Broodwar->self()->getStartLocation());
            b.isGasSteal = currentItem.isGasSteal;

			// set the producer as the closest worker, but do not set its job yet
			producer = WorkerManager::Instance().getBuilder(b, false);

			// predict the worker movement to that building location
			predictWorkerMovement(b);
		}

		// if we can make the current item
		if (producer && canMake) 
		{
			// create it
			create(producer, currentItem);
			_assignedWorkerForThisBuilding = false;
			_haveLocationForThisBuilding = false;

			// and remove it from the _queue
			_queue.removeCurrentHighestPriorityItem();

			// don't actually loop around in here
			break;
		}
		// otherwise, if we can skip the current item
		else if (_queue.canSkipItem())
		{
			// skip it
			_queue.skipItem();

			// and get the next one
			currentItem = _queue.getNextHighestPriorityItem();				
		}
		else 
		{
			// so break out
			break;
		}
	}
}