-- $LastChangedDate: 2010-05-25 21:26:05 -0400 (Tue, 25 May 2010) $
-- LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
-- Mission class.
-- See module.txt for documentation and pitfalls.

Mission = { }

-- Save program state.
function Mission:Save()
    PlayerActor:Save()
end

-- Reset program state.
function Mission:Reset()
    -- CRITICAL: Collect garbage to induce freeing memory of 3D models
    -- (which consume large amounts of memory).
    collectgarbage()

    -- Reset the C++ side.
    sim.Program:Reset()

    -- Play theme song (after Program:Reset() which stops sound).
    Sound:PlayThemeSong()

    -- Call the reset callbacks.
    Events:BroadcastReset()

    -- Again.
    collectgarbage()
end

-- Make a target.
-- NOP if target still exists (by its name).
function Mission:MakeTarget( actorName, ActorClass, sceneTable, teamNum )
    -- Is target already in Game?
    local actor = Game:GetActor( actorName )
    if ( not actor ) then
        -- No, it was destroyed or not-yet-made, spawn it.

        -- Scene defines the target Actor.
        Scene:LoadObject( sceneTable )

        -- Produce Actor from Scene table.
        actor = ActorClass:New( actorName, teamNum, sceneTable.object )

        -- Put Actor into the Game.
        Game:AttachActor( actor )
    end
    return actor
end
