AddCSLuaFile()

ENT.Base = "base_gmodentity"
ENT.Type = "anim"
ENT.PrintName = "Generator"

if SERVER then
    function ENT:Initialize()
        self:SetModel("models/surrounded/obj/w_QuestGenerator.mdl")
        self:PhysicsInit(SOLID_VPHYSICS)
        self:SetMoveType(MOVETYPE_VPHYSICS)
        self:SetUseType(SIMPLE_USE)
        self.FuelAmount = 0
        self:SetNWBool('HaveFuel', false)
    end

    function ENT:Fuel()
        if self:GetNWBool('HaveFuel') then return end

        self.FuelAmount = self.FuelAmount + 1
        SuR.ObjectiveFuel = SuR.ObjectiveFuel + 1

        if SuR.ObjectiveFuel >= SuR.ObjectiveFuelNeed then
            SuR:MessageOnClient(20)
            timer.Simple(15, function()
                SuR:StartObjectiveExfil()
            end)
        end

        if self.FuelAmount >= self.ToFuel then
            self:SetNWBool('HaveFuel', true)
            self.loop = self:StartLoopingSound("ambient/machines/diesel_engine_idle1.wav")
        end
    end

    function ENT:OnRemove()
        if isnumber(self.loop) then
            self:StopLoopingSound(self.loop)
        end
    end

    function ENT:Think()
        local phys = self:GetPhysicsObject()
        if IsValid(phys) then
            phys:EnableMotion(false)
        end
    end
end