WorldObject *World::getNearestTarget(const Vec2 &pos, int range)
{
    double minRange = 100000000;
    WorldObject *target = nullptr;

    for (std::list<WorldObject *>::iterator it = items.begin();
         it != items.end();
         ++it)
    {
        WorldObject *unit = *it;

        if (!unit->isTargetable())
            continue;

        if (unit->isDead())
            continue;

        double distance = pos.distance(unit->getPos());
        if (distance < range)
        {
            if (distance < minRange)
            {
                minRange = distance;
                target = unit;
            }
        }
    }

    return target;
}