CommonChecks

Common operational checks and validations

validation

Library Implementation

-- CommonChecks.lua
-- Reusable validation and operational checks

local CommonChecks = {}

-- Standard initialization checks
function CommonChecks.initChecks(params)
    -- Check if entity is operational
    if not IsOperational{} then
        return false, "Entity not operational"
    end

    -- Check fuel
    if not HasFuel{} then
        return false, "Insufficient fuel"
    end

    -- Check if entity has orders
    if not HasOrdersToEngage{} then
        return false, "No engagement orders"
    end

    return true, "Initialization checks passed"
end

-- Pre-execution checks
function CommonChecks.preExecutionChecks()
    -- Check operational status
    if not IsOperational{} then
        return false, "Entity not operational"
    end

    -- Check fuel
    if not HasFuel{} then
        return false, "Low fuel"
    end

    return true, "Ready to execute"
end

-- Mission completion checks
function CommonChecks.missionCompleteChecks()
    -- Check if mission objectives met
    if IsMissionComplete{} then
        return true, "Mission complete"
    end

    -- Check if unable to continue
    if not IsOperational{} then
        return false, "Cannot continue - not operational"
    end

    if not HasFuel{} then
        return false, "Cannot continue - no fuel"
    end

    return nil, "Mission still in progress"
end

-- Engagement authorization checks
function CommonChecks.canEngage(target)
    -- Check ROE
    if not ROEAllowsEngagement{} then
        return false, "ROE does not allow engagement"
    end

    -- Check orders
    if not HasOrdersToEngage{} then
        return false, "No engagement orders"
    end

    -- Check target validity
    if target and not IsHostile{} then
        return false, "Target is not hostile"
    end

    return true, "Engagement authorized"
end

return CommonChecks
1833 characters

Usage Example

-- Usage example:
local CommonChecks = require("CommonChecks")

function init(params)
    -- Run standard init checks
    local success, msg = CommonChecks.initChecks(params)
    if not success then
        return false, msg
    end

    -- Additional custom initialization
    taskState = TaskStateMachine.new(subtaskNames)
    taskState.startTime = vrf.getSimulationTime()

    return true, "Task initialized"
end

function tick()
    if taskState.current == "EXECUTING" then
        -- Check if can continue
        local canContinue, msg = CommonChecks.preExecutionChecks()
        if not canContinue then
            return "FAILURE", msg
        end

        -- Execute mission logic...

        -- Check if complete
        local complete, completeMsg = CommonChecks.missionCompleteChecks()
        if complete == true then
            return "COMPLETE", completeMsg
        elseif complete == false then
            return "FAILURE", completeMsg
        end
    end
    return "CONTINUE", "Executing"
end

Quick Reference

Import Statement

local CommonChecks = require("CommonChecks")

Category

validation

Key Features

  • Standard operational checks
  • Fuel and ammunition validation
  • ROE and engagement authorization
  • Mission completion verification