Exemplo n.º 1
0
bool BuildPlanner::supplyBeingBuilt()
{
	//Zerg
	if (isZerg())
	{
		if (noInProduction(UnitTypes::Zerg_Overlord) > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//Terran and Protoss
	UnitType supply = Broodwar->self()->getRace().getSupplyProvider();

	//1. Check if we are already building a supply
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive())
		{
			if (agent->getUnitType().getID() == supply.getID())
			{
				if (agent->getUnit()->isBeingConstructed())
				{
					//Found one that is being constructed
					return true;
				}
			}
		}
	}

	//2. Check if we have a supply in build queue
	for (int i = 0; i < (int)buildQueue.size(); i++)
	{
		if (buildQueue.at(i).toBuild.getID() == supply.getID())
		{
			return true;
		}
	}

	return false;
}
Exemplo n.º 2
0
int BuildPlanner::noInProduction(UnitType type)
{
	int no = 0;
	
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isAlive())
		{
			if (agent->getUnitType().canProduce() && !agent->getUnit()->isBeingConstructed())
			{
				list<UnitType> queue = agent->getUnit()->getTrainingQueue();
				for (list<UnitType>::const_iterator i=queue.begin(); i != queue.end(); i++)
				{
					if ((*i).getID() == type.getID())
				{
						no++;
					}
				}
			}
		}
	}

	if (isZerg())
	{
		for(std::set<Unit*>::const_iterator i=Broodwar->self()->getUnits().begin();i!=Broodwar->self()->getUnits().end();i++)
		{
			if ((*i)->exists())
			{
				if ((*i)->getType().getID() == UnitTypes::Zerg_Egg.getID())
				{
					if ((*i)->getBuildType().getID() == type.getID())
					{
						no++;
						if (type.isTwoUnitsInOneEgg()) no++;
					}
				}
			}
		}
	}

	return no;
}
Exemplo n.º 3
0
int Constructor::noInProduction(UnitType type)
{
    int no = 0;

    Agentset agents = AgentManager::getInstance()->getAgents();
    for (auto &a : agents)
    {
        if (a->isAlive())
        {
            if (a->getUnitType().canProduce() && !a->getUnit()->isBeingConstructed())
            {
                for (auto &u : a->getUnit()->getTrainingQueue())
                {
                    if (u.getID() == type.getID())
                    {
                        no++;
                    }
                }
            }
        }
    }

    if (isZerg())
    {
        for (auto &u : Broodwar->self()->getUnits())
        {
            if (u->exists())
            {
                if (u->getType().getID() == UnitTypes::Zerg_Egg.getID())
                {
                    if (u->getBuildType().getID() == type.getID())
                    {
                        no++;
                        if (type.isTwoUnitsInOneEgg()) no++;
                    }
                }
            }
        }
    }

    return no;
}
Exemplo n.º 4
0
bool Constructor::executeOrder(UnitType type)
{
    //Max 5 concurrent buildings allowed at the same time
    if ((int)buildQueue.size() >= 5)
    {
        return false;
    }

    //Check if we meet requirements for the building
    map<UnitType,int> reqs = type.requiredUnits();
    for(map<UnitType,int>::iterator j=reqs.begin(); j!=reqs.end(); j++)
    {
        if (!AgentManager::getInstance()->hasBuilding((*j).first))
        {
            return false;
        }
    }

    if (type.isResourceDepot())
    {
        TilePosition pos = BuildingPlacer::getInstance()->findExpansionSite();
        if (pos.x == -1)
        {
            //No expansion site found.
            if ((int)buildPlan.size() > 0) buildPlan.erase(buildPlan.begin());
            return true;
        }
    }
    if (type.isRefinery())
    {
        TilePosition rSpot = BuildingPlacer::getInstance()->searchRefinerySpot();
        if (rSpot.x < 0)
        {
            //No buildspot found
            if ((int)buildPlan.size() > 0) buildPlan.erase(buildPlan.begin());
            return true;
        }
    }
    if (isZerg())
    {
        pair<UnitType, int> builder = type.whatBuilds();
        if (builder.first.getID() != UnitTypes::Zerg_Drone.getID())
        {
            //Needs to be morphed
            if (executeMorph(builder.first, type))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    //Check if we have resources
    if (!ResourceManager::getInstance()->hasResources(type))
    {
        return false;
    }

    bool found = false;
    Agentset agents = AgentManager::getInstance()->getAgents();
    for (auto &a : agents)
    {
        if (a->isFreeWorker())
        {
            if (a->canBuild(type))
            {
                found = true;
                if (a->assignToBuild(type))
                {
                    lock(0, a->getUnitID());
                    return true;
                }
                else
                {
                    //Unable to find a buildspot. Dont bother checking for all
                    //other workers
                    handleNoBuildspotFound(type);
                    return false;
                }
            }
        }
    }

    return false;
}
Exemplo n.º 5
0
bool BuildPlanner::executeOrder(UnitType type)
{
	//Max 3 concurrent buildings allowed at the same time
	if ((int)buildQueue.size() >= 3)
	{
		return false;
	}

	////Hold if we are to build a new base
	//if ((int)buildQueue.size() > 0)
	//{
	//	if (buildQueue.at(0).toBuild.isResourceDepot())
	//	{
	//		return false;
	//	}
	//	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	//	for (int i = 0; i < (int)agents.size(); i++)
	//	{
	//		if (agents.at(i)->getUnitType().isResourceDepot() && agents.at(i)->getUnit()->isBeingConstructed())
	//		{
	//			return false; // TODO: Check if necessary
	//		}
	//	}
	//}

	if (type.isResourceDepot())
	{
		TilePosition pos = CoverMap::getInstance()->findExpansionSite();
		if (pos.x() == -1)
		{
			Broodwar->printf("Removing expand as no expansion site could be found");
			//No expansion site found.
			if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin());
			return true;
		}
	}

	if (type.isRefinery())
	{
		TilePosition rSpot = CoverMap::getInstance()->searchRefinerySpot();
		if (rSpot.x() < 0)
		{
			//No buildspot found
			if ((int)buildOrder.size() > 0) buildOrder.erase(buildOrder.begin());
			return true;
		}
	}

	if (isZerg())
	{
		pair<UnitType, int> builder = type.whatBuilds();
		if (builder.first.getID() != UnitTypes::Zerg_Drone)
		{
			//Needs to be morphed
			return executeMorph(builder.first, type);
		}
	}

	//Check if we have resources
	if (!ResourceManager::getInstance()->hasResources(type))
	{
		return false;
	}


	// TODO: Check if we can improve finding the best worker
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent != NULL && agent->isAlive())
		{
			if (agent->canBuild(type))
			{
				if (agent->assignToBuild(type))
				{
					lock(0, agent->getUnitID());
					return true;
				}
				else
				{
					//Unable to find a buildspot. Dont bother checking for all
					//other workers
					handleNoBuildspotFound(type);

					Broodwar->printf("No build spot found for %s", type.getName().c_str());

					return false;
				}
			}
		}
	}
	return false;
}