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;
    }
}
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;
}