ObjectiveSecured

Check if objective is secured

Usage: Used in 9 task(s)

Lua Implementation

-- Objective Secured
function evaluate(params)
    local objective = params.objective or this:getStateProperty("Objective")

    if not objective then
        return false
    end

    -- Check if at objective
    local atObjective = IsAtLocation{location = objective, tolerance = 50}

    -- Check for threats nearby
    local threats = 0
    local contacts = this:getContactList()
    for _, contact in ipairs(contacts) do
        if contact:isValid() and IsHostile{target = contact} then
            local distance = spatialUtil.distance(objective, contact:getLocation3D())
            if distance < 200 then
                threats = threats + 1
            end
        end
    end

    return atObjective and threats == 0
end