-- $LastChangedDate: 2010-04-16 22:43:07 -0500 (Fri, 16 Apr 2010) $
-- 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
