AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
local StartPos
local StartAng
function ENT:Initialize()
	self:SetMoveType(MOVETYPE_NONE)
	StartPos = self:GetPos()
	StartAng = self:GetAngles()
	self:SetNWInt('MaxHp',self.hp)
end

function ENT:Think()
	self:SetNWInt('Hp',self.hp)
	if self:GetNWInt("Hp") > self:GetNWInt("MaxHp") then
		self:SetNWInt('Hp',self:GetNWInt("MaxHp"))
	end
	if SERVER then
	if self.poscoef == 0 and self.building then 
		self.Owner:Freeze(false)
		self.Owner.building = false
		self:PhysicsInitStatic(6)
		self:SetCollisionGroup(0)
		self.building = false 
	end
	if self.building then
		self.Owner.building = true
		self.poscoef = self.poscoef + 1
		self.Owner:Freeze(true)
		self:SetAngles(StartAng)
		self:SetPos(StartPos - self:GetAngles():Up() * -self.poscoef)
	end
end
end

function ENT:OnRemove()
	if self.HasIdle then
		self:StopSound("TFA_INS2_RPG7.Loop")
		self.HasIdle = false
	end
end

function ENT:Use(activator, caller)

end

function ENT:OnTakeDamage( dmg )
	if dmg:GetInflictor() == self or dmg:GetAttacker() == self then return end
	if self.Exploded then return end
	if self.hp > 0 and self.hp - dmg:GetDamage() <= 0 then
		self.Exploded = true
		self:Remove()
	end
	self.hp = self.hp - dmg:GetDamage()
	dmg:SetAttacker(self)
	dmg:SetInflictor(self)
	self:TakePhysicsDamage( dmg )
end
