Beispiel #1
0
bool Upgrader::canResearch(TechType type, Unit* unit)
{
	//Seems Broodwar->canResearch bugs when Lurker Aspect is requested without
	//having an upgraded Lair.
	if (type.getID() == TechTypes::Lurker_Aspect.getID())
	{
		if (AgentManager::getInstance()->countNoFinishedUnits(UnitTypes::Zerg_Lair) == 0) return false;
	}

	//1. Check if unit can do this upgrade
	if (!Broodwar->canResearch(unit, type))
	{
		return false;
	}
	
	//2. Check if we have enough resources
	if (!ResourceManager::getInstance()->hasResources(type))
	{
		return false;
	}
	
	//3. Check if unit is idle
	if (!unit->isIdle())
	{
		return false;
	}

	//4. Check if unit is being constructed
	if (unit->isBeingConstructed())
	{
		return false;
	}

	//5. Check if some other building is already doing this upgrade
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		if (agents.at(i)->getUnit()->getTech().getID() == type.getID())
		{
			return false;
		}
	}

	//6. Check if we are currently researching it
	if (Broodwar->self()->isResearching(type))
	{
		return false;
	}

	//All clear. Can do the research.
	return true;
}
bool UpgradesPlanner::canResearch(TechType type, Unit* unit)
{
	//1. Check if unit can do this upgrade
	if (!Broodwar->canResearch(unit, type))
	{
		return false;
	}
	
	//2. Check if we have enough resources
	if (!ResourceManager::getInstance()->hasResources(type))
	{
		return false;
	}
	
	//3. Check if unit is idle
	if (!unit->isIdle())
	{
		return false;
	}

	//4. Check if unit is being constructed
	if (unit->isBeingConstructed())
	{
		return false;
	}

	//5. Check if some other building is already doing this upgrade
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		if (agents.at(i)->getUnit()->getTech().getID() == type.getID())
		{
			return false;
		}
	}

	//6. Check if we are currently researching it
	if (Broodwar->self()->isResearching(type))
	{
		return false;
	}

	//All clear. Can do the research.
	return true;
}
//----------------------------------------------------------------------------------------------
void StarCraftTechTree::GetRequirements(int p_typeOrResearchId, vector<ResearchType>& p_researches, map<EntityClassType, unsigned>& p_buildings)
{
    TName ident;
    TID id;
    UpgradeType bwapiUpgrade;
    TechType bwapiTech;
    BWAPI::UnitType bwapiUnitType;
    BWAPI::UnitType bwapiSourceType;
    BWAPI::UnitType bwapiRequiredType;
    BWAPI::UnitType bwapiRequiredUnit;
    TechType bwapiRequiredTech;
    EntityClassType requiredEntity;
    ResearchType requiredResearch;
    
    if (BELONG(ResearchType, p_typeOrResearchId))
    {
        // Is Tech
        if ((int)p_typeOrResearchId >= ((int)(RESEARCH_START +  TechIdOffset)))
        {
            /*id = g_Database.TechMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.TechIdentMapping.GetByFirst(id);
            bwapiTech = TechType::getType(ident);

            bwapiSourceType = bwapiTech.whatResearches();
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
            p_buildings.push_back(requiredEntity);*/
        }
        // Is Upgrade
        else
        {
            id = g_Database.UpgradeMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.UpgradeIdentMapping.GetByFirst(id);
            bwapiUpgrade = UpgradeType::getType(ident);

            /*bwapiSourceType = bwapiUpgrade.whatUpgrades();
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
            p_buildings.push_back(requiredEntity);*/

            bwapiRequiredType = bwapiUpgrade.whatsRequired();

            if (bwapiRequiredType.getID() != UnitTypes::None.getID())
            {
                requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiRequiredType.getID());
                p_buildings[requiredEntity] = 1;
            }
        }
    }
    else if(BELONG(EntityClassType, p_typeOrResearchId))
    {
        id = g_Database.EntityMapping.GetBySecond((EntityClassType)p_typeOrResearchId);
        ident = g_Database.EntityIdentMapping.GetByFirst(id);
        bwapiUnitType = UnitType::getType(ident);

        /*bwapiSourceType = bwapiUnitType.whatBuilds().first;
        requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
        p_buildings.push_back(requiredEntity);*/

        bwapiRequiredTech = bwapiUnitType.requiredTech();

        if (bwapiRequiredTech.getID() != TechTypes::None.getID())
        {
            requiredResearch = g_Database.TechMapping.GetByFirst(bwapiRequiredTech.getID());
            p_researches.push_back(requiredResearch);
        }

        const map<BWAPI::UnitType, int> &bwapiUnits = bwapiUnitType.requiredUnits();

        for (map<BWAPI::UnitType, int>::const_iterator itr =  bwapiUnits.begin();
            itr != bwapiUnits.end(); ++itr)
        {
            bwapiRequiredUnit = itr->first;
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiRequiredUnit.getID());
            p_buildings[requiredEntity] = itr->second;;
        }
    }
}