Beispiel #1
0
bool ResourceManager::hasResources(TechType type)
{
	int nMinerals = type.mineralPrice();
	int nGas = type.gasPrice();

	return hasResources(nMinerals, nGas);
}
bool BattlecruiserAgent::useAbilities()
{
	//To prevent order spamming
	lastOrderFrame = Broodwar->getFrameCount();

	if (Broodwar->getFrameCount() - lastUseFrame >= 80 && (unit->isIdle() || unit->isMoving()))
	{
		TechType gun = TechTypes::Yamato_Gun;
		if (Broodwar->self()->hasResearched(gun))
		{
			if (unit->getEnergy() >= gun.energyCost())
			{
				int range = gun.getWeapon().maxRange();
				
				Unit target = TargetingAgent::findHighprioTarget(this, range, true, true);
				if (target != NULL)
				{
					Broodwar << "Yamato Gun used on " << target->getType().getName() << endl;
					unit->useTech(gun, target);
					lastUseFrame = Broodwar->getFrameCount();
					return true;
				}
			}
		}
	}

	return false;
}
//reserves resources for this tech type
pair<int, BuildOrderManager::Resources> BuildOrderManager::reserveResources(MetaUnit* techUnit, TechType techType)
{
  int t=Broodwar->getFrameCount();
  if (techUnit)
    t=nextFreeTime(techUnit);
  pair<int, Resources> ret;
  ret.first=t;
  ret.second.minerals=techType.mineralPrice();
  ret.second.gas=techType.gasPrice();
  reserveResources(ret);
  return ret;
}
Beispiel #4
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;
}
//----------------------------------------------------------------------------------------------
EntityClassType StarCraftTechTree::SourceEntity(int p_typeOrResearchId) const
{
    TName ident;
    TID id;
    UpgradeType upgrade;
    TechType tech;
    BWAPI::UnitType unitType;
    BWAPI::UnitType sourceType;

    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);
            tech = TechType::getType(ident);
            sourceType = tech.whatResearches();

            return g_Database.EntityMapping.GetByFirst(sourceType.getID());
        }
        // Is Upgrade
        else
        {
            id = g_Database.UpgradeMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.UpgradeIdentMapping.GetByFirst(id);
            upgrade = UpgradeType::getType(ident);
            sourceType = upgrade.whatUpgrades();

            return g_Database.EntityMapping.GetByFirst(sourceType.getID());
        }
    }
    else if(BELONG(EntityClassType, p_typeOrResearchId))
    {
        id = g_Database.EntityMapping.GetBySecond((EntityClassType)p_typeOrResearchId);
        ident = g_Database.EntityIdentMapping.GetByFirst(id);
        unitType = UnitType::getType(ident);
        sourceType = unitType.whatBuilds().first;

        return g_Database.EntityMapping.GetByFirst(sourceType.getID());
    }

    return ECLASS_END;
}
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;
}
Beispiel #7
0
bool UnitWrap::CanUseTech(TechType tech) const
{
  return pUnit->getPlayer()->hasResearched(TechTypes::Lockdown) && pUnit->getEnergy() >= tech.energyCost();
}
//----------------------------------------------------------------------------------------------
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;;
        }
    }
}
Beispiel #9
0
/*** 
 * Check if we can research the given TechType w.r.t. tech structures
 * !!! Ask TheBuilder to build them otherwise. !!!
 */
bool Producer::checkCanTech(TechType t)
{
    return checkHaveTech(t.whatResearches());
}
Beispiel #10
0
 bool PlayerImpl::isResearchAvailable(TechType tech) const
 {
   return tech.isValid() ? self->isResearchAvailable[tech] : false;
 }
Beispiel #11
0
 //--------------------------------------------- IS RESEARCHING ---------------------------------------------
 bool PlayerImpl::isResearching(TechType tech) const
 {
   return tech.isValid() ? self->isResearching[tech] : false;
 }
Beispiel #12
0
 //--------------------------------------------- HAS RESEARCHED ---------------------------------------------
 bool PlayerImpl::hasResearched(TechType tech) const
 {
   return tech.isValid() ? self->hasResearched[tech] : false;
 }