#include "../../script/helpers/entity.lua"

function init()
    local bodies = FindBodies("mission")
    for i = 1, #bodies do
        local body = bodies[i]
        local mission = GetTagValue(body, "mission")
        if not GetBool("savegame.mod.mission." .. mission) then
            Delete(body)
        end
    end
    local shapes = FindShapes("mission")
    local wb = GetWorldBody()
    for i = 1, #shapes do
        local shape = shapes[i]
        local mission = GetTagValue(shape, "mission")
        if not GetBool("savegame.mod.mission." .. mission) then
            local body = GetShapeBody(shape)
            local joints = GetShapeJoints(shape)
            for j = 1, #joints do
                Delete(joints[j])
            end
            if body ~= wb then Delete(body) end
            Delete(shape)
        end
    end
    cEntity:EnqueueDeletion()
end
