本文整理汇总了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;
}
}
示例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;
}