예제 #1
0
void ForceHandler::ShowGroupStates ()
{
	for (int a=0;a<batches.size();a++)  {
		UnitGroup *gr = batches[a];
		ChatMsgPrintf (globals->cb, "Group %s is in state: %s on(%d,%d)", gr->GetName(), groupstatestr[(int)gr->state], gr->current.x,gr->current.y);
	}
}
void BaseManager::updateDepositCenterPosition()
{
	std::set<Base*> allBases = this->getAllBases();

	if (allBases.size() <=1)
	{
		return;
	}

	for(std::set<Base*>::iterator b = allBases.begin(); b != allBases.end(); b++)
	{
		BWAPI::TilePosition tile = (*b)->getBaseLocation()->getTilePosition();
		std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(tile.x(),tile.y());
		if (units.size() == 0)
		{
			UnitGroup commandCenters = SelectAll(BWAPI::UnitTypes::Terran_Command_Center).inRadius(400, (*b)->getBaseLocation()->getPosition());
			if (commandCenters.size() > 0)
			{
				(*(commandCenters.begin()))->lift();
				if ((*(commandCenters.begin()))->isLifted())
				{
					(*(commandCenters.begin()))->land(tile);
				}
			}
		}
	}
}
예제 #3
0
UnitGroup ObserverScoutTask::getFinishedUnits()
{
	UnitGroup returnUnits;

	returnUnits.insert(mUnit);

	return returnUnits;
}
예제 #4
0
UnitGroup RequirementGroup::getUnits() const
{
	UnitGroup units;
	for(std::vector<Requirement>::const_iterator requirement = mUnitRequirements.begin(); requirement != mUnitRequirements.end(); ++requirement)
		units.insert(requirement->getUnit());

	return units;
}
예제 #5
0
UnitGroup TechTask::getFinishedUnits()
{
	UnitGroup returnUnits;

	if(mUnit)
		returnUnits.insert(mUnit);

	return returnUnits;
}
예제 #6
0
UnitGroup TrainTask::getFinishedUnits()
{
	UnitGroup returnUnits;

	if(mProductionBuilding)
		returnUnits.insert(mProductionBuilding);
	if(mProducedUnit)
		returnUnits.insert(mProducedUnit);

	return returnUnits;
}
예제 #7
0
UnitGroup ConstructionTask::getFinishedUnits()
{
	UnitGroup returnUnits;

	if(mBuilder && finishedWithBuilder())
		returnUnits.insert(mBuilder);

	if(mProducedUnit && mProducedUnit->exists() && isCompleted())
		returnUnits.insert(mProducedUnit);

	return returnUnits;
}
예제 #8
0
UnitGroup GatherTask::getFinishedUnits()
{
	UnitGroup returnUnits;

	if(mWorkerOne)
		returnUnits.insert(mWorkerOne);
	if(mWorkerTwo)
		returnUnits.insert(mWorkerTwo);
	if(mWorkerThree)
		returnUnits.insert(mWorkerThree);

	return returnUnits;
}
예제 #9
0
void UnitGroupManager::onUnitEvade(BWAPI::Unit* unit)
{
	unitOwner[unit]=unit->getPlayer();
	unitType[unit]=unit->getType();
	data[unit->getPlayer()][unit->getType()].erase(unit);
	allOwnedUnits[unit->getPlayer()].erase(unit);
	allUnits.erase(unit);
}
예제 #10
0
void UnitGroupManager::onUnitDiscover(BWAPI::Unit* unit)
{
	unitOwner[unit]=unit->getPlayer();
	unitType[unit]=unit->getType();
	data[unit->getPlayer()][unit->getType()].insert(unit);
	allOwnedUnits[unit->getPlayer()].insert(unit);
	allUnits.insert(unit);
}
예제 #11
0
	void AIModule::camera()
	{
		if (game->getMouseState(BWAPI::M_LEFT))
		{
			return;
		}

		const int CENTER_SCREEN_X = 320;
		const int CENTER_SCREEN_Y = 140;

		if (!autocam)
		{
			return;
		}

		UnitGroup interestingUnits = AllUnits()(isAttacking);

		if (interestingUnits.size() == 0)
		{
			return;
		}

		BWAPI::Unit *unit = (*interestingUnits.begin());

		BWAPI::Position unitPosition = unit->getPosition();

		int x, y;
		x = unitPosition.x() - CENTER_SCREEN_X;
		y = unitPosition.y() - CENTER_SCREEN_Y;

		if (x < 0)
		{
			x = 0;
		}

		if (y < 0)
		{
			y = 0;
		}

		BWAPI::Broodwar->setScreenPosition(x, y);
	}
예제 #12
0
std::vector<UnitGroup> UnitHelper::getClusters(const UnitGroup &units, int distance, int minSize)
{
    std::vector<UnitGroup> clusters;

    for each(Unit unit in units)
    {
        std::vector<size_t> clustersInRange;
        for(size_t i = 0; i < clusters.size(); ++i)
        {
            for each(Unit clusterUnit in clusters[i])
            {
                if(unit->getPosition().getApproxDistance(clusterUnit->getPosition()) <= distance)
                {
                    clustersInRange.push_back(i);
                    break;
                }
            }
        }

        if(clustersInRange.empty())
        {
            UnitGroup newCluster;
            newCluster.insert(unit);
            clusters.push_back(newCluster);
        }
        else
        {
            clusters[clustersInRange[0]].insert(unit);

            for(size_t i = 1; i < clustersInRange.size(); ++i)
            {
                for each(Unit clusterUnit in clusters[clustersInRange[i]])
                {
                    clusters[clustersInRange[0]].insert(clusterUnit);
                }
                clusters[clustersInRange[i]].clear();
            }
        }
예제 #13
0
 bool operator()(const UnitGroup &set)
 {
     return set.empty() || set.size() < mMinSize;
 }
예제 #14
0
int ReplicatorGob::ProcessStateMachineMessage(State st, Message *pmsg)
{
BeginStateMachine
	OnMsg(kmidPlaySfx)
		gsndm.PlaySfx((Sfx)pmsg->PlaySfx.sfx);

	State(kstIdle)
		OnUpdate
			// If a mobile unit is at either output, ask it to move on

			TPoint tpt;
			GetTilePosition(&tpt);
			Gid gid;

			// Clear left and right output bays
			Player *pplrNeedCredits = NULL;
			bool fJammed = ClearOutputBay(tpt.tx + kdtxReplicatorOutput1, tpt.ty + kdtyReplicatorOutput1, tpt.tx + kdtxReplicatorOutput1 - 1, tpt.ty + kdtyReplicatorOutput1 + 1);
			fJammed = ClearOutputBay(tpt.tx + kdtxReplicatorOutput2, tpt.ty + kdtyReplicatorOutput2, tpt.tx + kdtxReplicatorOutput2 + 1, tpt.ty + kdtyReplicatorOutput2 + 1) || fJammed;

			// If there's nothing clogging the outputs we can consider the input
			if (m_fEnabled && !fJammed) {
				// loop through all the gobs on this tile to find the mobile unit and ignore ourself, or
				// shots flying by
				for (gid = ggobm.GetFirstGid(tpt.tx + kdtxReplicatorInput, tpt.ty + kdtyReplicatorInput); gid != kgidNull; gid = ggobm.GetNextGid(gid)) {
					MobileUnitGob *pmunt = (MobileUnitGob *)ggobm.GetGob(gid);
					if (pmunt == NULL)
						continue;
					if (!(pmunt->GetFlags() & kfGobMobileUnit))
						continue;

					// Something there! If it's ready, clone it.

					if (!(pmunt->GetMobileUnitFlags() & kfMuntAtReplicatorInput))
						continue;

					// At the limit?
// TUNE:
#define kctIntervalLimitNotify 600

					if (!ggobm.IsBelowLimit(knLimitMobileUnit, pmunt->GetOwner())) {
						if (pmunt->GetOwner() == gpplrLocal) {
							static long s_tLastNotify;
							long tCurrent = gtimm.GetTickCount();
							if (abs((int)(s_tLastNotify - tCurrent)) >= kctIntervalLimitNotify) {
								s_tLastNotify = tCurrent;
								ShowAlert(kidsUnitLimitReached);
							}
						}
						continue;
					}

					// Does the player have enough credits to perform the replication?

					MobileUnitConsts *pmuntc = (MobileUnitConsts *)pmunt->GetConsts();
					Player *pplr = pmunt->GetOwner();
					int cCredits = pplr->GetCredits();

					int nCost = pmuntc->GetCost();
					int cReplicationCost = GetReplicationCost(nCost);
					if (cCredits < cReplicationCost) {
						pplrNeedCredits = pplr;
						break; 
					}

					// Take the money!

					pplr->SetCredits(cCredits - cReplicationCost, true);

                    // Remove highlight

                    pmunt->Hilight(false);

					// Start the replicating animation

					m_fReplicating = true;
					m_ifrmLights = -1;

					MobileUnitGob *pmuntClone = (MobileUnitGob *)CreateGob(pmunt->GetType());
					if (pmuntClone != NULL) {
						pmuntClone->Init(WcFromTc(tpt.tx + kdtxReplicatorOutput2), WcFromTc(tpt.ty + kdtyReplicatorOutput2), pmunt->GetOwner(), pmunt->GetHealth(), 0, NULL);

						// Clone acquires the selection state of the original

						if (pmunt->GetFlags() & kfGobSelected)
							pmuntClone->Select(true);

						// Replicated GalaxMiners lose their load of Galaxite
						// UNDONE: if there is more of this special casing go with virtual UnitGob::Replicate()

						if (pmunt->GetType() == kgtGalaxMiner)
							((MinerGob *)pmunt)->SetGalaxiteAmount(0);

						// If this unit is a member of a group add its clone to the group too

						UnitGroup *pug = gsim.GetLevel()->GetUnitGroupMgr()->GetUnitGroup(pmunt->GetId());
						if (pug != NULL)
							pug->AddUnit(pmuntClone, true);
					}

					// Warp the original Unit to the left output port

					TerrainMap *ptrmap = gsim.GetLevel()->GetTerrainMap();
					ptrmap->ClearFlags(tpt.tx + kdtxReplicatorInput, tpt.ty + kdtyReplicatorInput, 1, 1, kbfMobileUnit);
					ptrmap->SetFlags(tpt.tx + kdtxReplicatorOutput1, tpt.ty + kdtyReplicatorOutput1, 1, 1, kbfMobileUnit);
					pmunt->SetPosition(WcFromTc(tpt.tx + kdtxReplicatorOutput1) + kwcTileHalf, WcFromTc(tpt.ty + kdtyReplicatorOutput1) + kwcTileHalf);

					// Clear the bit

					pmunt->SetMobileUnitFlags(pmunt->GetMobileUnitFlags() & ~kfMuntAtReplicatorInput);

					// Let player know the replication process has happened
					// play cool replication sound effect

					gsndm.PlaySfx(ksfxReplicatorBuild);

					// wait a quarter second and let the new unit announce itself

					Sfx sfx = SfxFromCategory(pmuntc->sfxcSelect);
					Message msgT;
					memset(&msgT, 0, sizeof(msgT));
					msgT.mid = kmidPlaySfx;
					msgT.smidSender = m_gid;
					msgT.smidReceiver = m_gid;
					msgT.PlaySfx.sfx = sfx;
					gsmm.SendDelayedMsg(&msgT, 24);

					// Play it again in another quarter of a second to sound cool

					memset(&msgT, 0, sizeof(msgT));
					msgT.mid = kmidPlaySfx;
					msgT.smidSender = m_gid;
					msgT.smidReceiver = m_gid;
					msgT.PlaySfx.sfx = sfx;
					gsmm.SendDelayedMsg(&msgT, 48);
					break;
				}
			}

			if (m_fReplicating) {
				m_ifrmLights++;
				int nStrip = m_pmuntc->panid->GetStripIndex("l 0");
				if (m_ifrmLights / 2 >= m_pmuntc->panid->GetFrameCount(nStrip)) {
					m_ifrmLights = -1;
					m_fReplicating = false;
				}
				MarkRedraw();
			}
			WaitingForCredits(pplrNeedCredits != NULL, false, pplrNeedCredits);
			m_unvl.MinSkip();
			DefUpdate();

#if 0
EndStateMachineInherit(StructGob)
#else
            return knHandled;
        }
예제 #15
0
void ZerglingMicro::micro(BWAPI::Unit* unit)
{
	Task task = this->hc->ta->getTaskOfUnit(unit);
	
	UnitGroup allies = allEigenUnits().inRadius(dist(12), unit->getPosition());
	UnitGroup enemiesground = allEnemyUnits().inRadius(dist(10), unit->getPosition()).not(isFlyer);
	UnitGroup enemiesair = allEnemyUnits().inRadius(dist(7), unit->getPosition())(isFlyer);
	if(amountCanAttackGround(enemiesair) > 0 && amountCanAttackAir(allies) == 0)
	{
		unit->move(moveAway(unit));
	}
	else
	{
		if(task.getType() == ScoutTask)
		{
			if(allEnemyUnits().not(isBuilding).inRadius(dist(4), unit->getPosition()).size() > 0)
			{
				unit->move(moveAway(unit));
			}
			else
			{
				if(unit->getDistance(task.getPosition()) < dist(4) && BWAPI::Broodwar->isVisible(BWAPI::TilePosition(task.getPosition())))
				{
					if(!unit->isMoving())
					{
						int x = unit->getPosition().x();
						int y = unit->getPosition().y();
						int factor = dist(10);
						int newx = x + (((rand() % 30)-15)*factor);
						int newy = y + (((rand() % 30)-15)*factor);
						unit->move(BWAPI::Position(newx, newy).makeValid());
					}
				}
				else
				{
					unit->move(task.getPosition());
				}
			}
		}
		else
		{
			UnitGroup swarms = allUnits()(Dark_Swarm);
			BWAPI::Unit* swarm = getNearestUnit(unit->getPosition(), swarms);
			if(swarm != NULL && swarm->getPosition().getDistance(unit->getPosition()) < dist(9))
			{
				if(!isUnderDarkSwarm(unit) && !unit->isAttacking())
				{
					unit->attack(swarm->getPosition());
				}
				else
				{
					UnitGroup enemiesunderswarm = allEnemyUnits().inRadius(dist(6), unit->getPosition()).not(isFlyer);
					if(!unit->isAttacking() && enemiesunderswarm.size() > 0)
					{
						unit->attack(getNearestUnit(unit->getPosition(), enemiesunderswarm));
					}
				}
			}
			else
			{
				if(allies.size() < amountCanAttackGround(enemiesground))
				{
					unit->move(moveAway(unit));
				}
				else
				{
					if(enemiesground.inRadius(dist(3), unit->getPosition()).size() > 0)
					{
						// game AI
					}
					else
					{
						if(enemiesground.size() > 0)
						{
							BWAPI::Unit* nearest = getNearestUnit(unit->getPosition(), enemiesground);
							unit->attack(nearest);
						}
						else
						{
							UnitGroup* ug = this->hc->eiugm->getGroupOfUnit(unit);
							if(ug != NULL && tooSplitUp(dist(7), *ug))
							{
								BWAPI::Unit* nearest = getNearestUnit(ug->getCenter(), *ug);
								unit->attack(nearest);
							}
							else
							{
								unit->move(task.getPosition());
							}
						}
					}
				}
			}
		}
	}
}
예제 #16
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();
	}
}