当前位置: 首页>>代码示例>>C++>>正文


C++ UnitType::requiredTech方法代码示例

本文整理汇总了C++中bwapi::UnitType::requiredTech方法的典型用法代码示例。如果您正苦于以下问题:C++ UnitType::requiredTech方法的具体用法?C++ UnitType::requiredTech怎么用?C++ UnitType::requiredTech使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bwapi::UnitType的用法示例。


在下文中一共展示了UnitType::requiredTech方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetRequirements

//----------------------------------------------------------------------------------------------
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;;
        }
    }
}
开发者ID:amrElroumy,项目名称:IStrategizer,代码行数:77,代码来源:StarCraftTechTree.cpp

示例2: canMake

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;
}
开发者ID:albertouri,项目名称:dementor-bot,代码行数:66,代码来源:MorphManager.cpp


注:本文中的bwapi::UnitType::requiredTech方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。