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


C++ World::CalcRange方法代码示例

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


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

示例1: MoveUnitAwayFromEnemyUntilOutsideMinRange

bool AISystem::MoveUnitAwayFromEnemyUntilOutsideMinRange(Entity* selectedUnit, Entity* enemy)
{
    World* world = engine->GetContext()->GetWorld();
    UnitComponent* auc = dynamic_cast<UnitComponent*>(selectedUnit->GetComponent(Component::UNIT));
    PositionComponent* apc = dynamic_cast<PositionComponent*>(selectedUnit->GetComponent(Component::POSITION));
    PositionComponent* dpc = dynamic_cast<PositionComponent*>(enemy->GetComponent(Component::POSITION));

    set<Entity*> moveOptions;
    unsigned int distanceToEnemy = world->CalcRange(apc, dpc);
    unsigned int minMoveDistance = auc->range_min - distanceToEnemy + 1;

    // make list of tiles around the enemy that the unit could move to
    for (unsigned int i = 0; i <= auc->range_max - distanceToEnemy; i++)
    {
        moveOptions = FindEntitiesAtDistanceAroundUnit(enemy, minMoveDistance + i);

        if (moveOptions.size() > 0)
        {
            break;
        }
    }

    // if walkable tiles were found
    if (moveOptions.size() > 0)
    {
        // find the one that's closest by
        Entity* moveOption = FilterNearestEntity(selectedUnit, moveOptions);

        if (moveOption != nullptr)
        {
            // and move the unit towards it
            return MoveUnitTowardsEntity(selectedUnit, moveOption);
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
开发者ID:GrigoriLomonosov,项目名称:Strategic-War,代码行数:43,代码来源:AISystem.cpp

示例2: FindUnitsByPlayer

set<Entity*> AISystem::FindEnemiesInsideRange(Entity* selectedUnit, unsigned int range)
{
    World* world = engine->GetContext()->GetWorld();
    PositionComponent* apc = dynamic_cast<PositionComponent*>(selectedUnit->GetComponent(Component::POSITION));
    PositionComponent* dpc;
    set<Entity*> enemies = FindUnitsByPlayer(Entity::HUMAN);
    set<Entity*> enemiesInsideRange;

    for (Entity* enemy : enemies)
    {
        dpc = dynamic_cast<PositionComponent*>(enemy->GetComponent(Component::POSITION));

        if (world->CalcRange(apc, dpc) <= range)
        {
            enemiesInsideRange.insert(enemy);
        }
    }

    return enemiesInsideRange;
}
开发者ID:GrigoriLomonosov,项目名称:Strategic-War,代码行数:20,代码来源:AISystem.cpp


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