include("class.lua")

SubsystemContainer = class()

function SubsystemContainer:init(parent, subsys)
    self.parent = parent
    self.subsys = subsys
end

function SubsystemContainer:get()
    if (self:isValid()) then
        return self.subsys
    else
        return nil
    end
end

function SubsystemContainer:isDead()
    if (not self:isValid()) then
        return true
    end

    return self.subsys.HitpointsLeft <= 0
end

function SubsystemContainer:getWorldPosition()
    if (not self:isValid()) then
        return ba.createVector()
    end

    return self.parent.Position + self.parent.Orientation:unrotateVector(self.subsys.Position)
end

function SubsystemContainer:isValid()
    if (self.parent == nil or self.subsys == nil) then
        return false
    end

    if (not self.parent:isValid() or not self.subsys:isValid()) then
        return false
    end

    return true
end

