示例#1
0
void InformationManager::updateBuildTime(BWAPI::UnitType type, int time)
{
  std::map<BWAPI::UnitType, int>::iterator i=buildTime.find(type);
  if (i!=buildTime.end() && (i->second<=time || i->second==0)) return;
  buildTime[type]=time;
  if (time<0) return;
  for(std::map<const BWAPI::UnitType*,int>::const_iterator i=type.requiredUnits().begin();i!=type.requiredUnits().end();i++)
  {
    updateBuildTime(*i->first,time-i->first->buildTime());
  }
}
示例#2
0
void InformationManager::updateBuildTime( BWAPI::UnitType type, int time )
{
    std::map< BWAPI::UnitType, int >::iterator i = m_buildTime.find( type );
    if ( i != m_buildTime.end() && ( i->second <= time || i->second == 0 ) )
    {
        // We have already determined an earlier build time
        return;
    }

    m_buildTime[type] = time;

    // Sanity check
    if ( time < 0 )
    {
        return;
    }

    // Update earliest known build times of required units
    for ( std::map< BWAPI::UnitType, int >::const_iterator r = type.requiredUnits().begin(); r != type.requiredUnits().end(); r++ )
    {
        updateBuildTime( r->first, time - r->first.buildTime() );
    }
}
//----------------------------------------------------------------------------------------------
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;;
        }
    }
}
示例#4
0
bool MorphManager::canMake(BWAPI::Unit* builder, BWAPI::UnitType type)
{
  if (builder != NULL)
  {
    /* Check if the owner of the unit is you */
    if (builder->getPlayer() != BWAPI::Broodwar->self())
      return false;

    /* Check if this unit can actually build the unit type */
    if (builder->getType() != (type.whatBuilds().first))
      return false;

    /* Carrier space */
    if (builder->getType() == BWAPI::UnitTypes::Protoss_Carrier)
    {
      int max_amt = 4;
      if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Carrier_Capacity)>0)
        max_amt += 4;
      if (builder->getInterceptorCount() + (int)builder->getTrainingQueue().size() >= max_amt)
        return false;
    }
    /* Reaver Space */
    if (builder->getType() == BWAPI::UnitTypes::Protoss_Reaver)
    {
      int max_amt = 5;
      if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Reaver_Capacity) > 0)
        max_amt += 5;
      if (builder->getScarabCount() + (int)builder->getTrainingQueue().size() >= max_amt)
        return false;
    }
  }

  BWAPI::UnitType addon = BWAPI::UnitTypes::None;
  for(std::map<BWAPI::UnitType, int>::const_iterator i = type.requiredUnits().begin(); i != type.requiredUnits().end(); i++)
    if (i->first.isAddon())
      addon=i->first;

  for(std::map<BWAPI::UnitType, int>::const_iterator i = type.requiredUnits().begin(); i != type.requiredUnits().end(); i++)
  {
    bool pass = false;
    if (BWAPI::Broodwar->self()->completedUnitCount(i->first) >= i->second)
      pass = true;
    if (i->first == BWAPI::UnitTypes::Zerg_Hatchery)
    {
      if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= i->second)
        pass = true;
      if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= i->second)
        pass = true;
    }
    if (i->first == BWAPI::UnitTypes::Zerg_Lair)
      if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= i->second)
        pass = true;
    if (pass == false)
      return false;
  }

  if (type.requiredTech() != BWAPI::TechTypes::None)
    if (!BWAPI::Broodwar->self()->hasResearched((type.requiredTech())))
      return false;

  if (builder != NULL)
    if (addon != BWAPI::UnitTypes::None && addon.whatBuilds().first==type.whatBuilds().first)
      if (builder->getAddon() == NULL || builder->getAddon()->getType() != addon)
        return false;
  return true;
}