2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "Distance"
|
|
|
|
|
|
|
|
local MODEL = Model( "models/props_lab/huladoll.mdl" )
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:SetModel( MODEL )
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
2007-03-20 05:51:58 +00:00
|
|
|
|
|
|
|
self.Inputs = Wire_CreateInputs(self.Entity, { "Target" })
|
2007-02-04 01:16:06 +00:00
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Out" })
|
|
|
|
end
|
|
|
|
|
2007-03-29 04:57:31 +00:00
|
|
|
function ENT:Setup( xyz_mode, outdist, outbrng, gpscord, swapyz )
|
2007-02-04 01:16:06 +00:00
|
|
|
self.XYZMode = xyz_mode
|
|
|
|
self.PrevOutput = nil
|
|
|
|
self.Value = 0
|
|
|
|
self.OutDist = outdist
|
|
|
|
self.OutBrng = outbrng
|
2007-03-20 05:51:58 +00:00
|
|
|
self.GPSCord = gpscord
|
2007-03-29 04:57:31 +00:00
|
|
|
self.SwapYZ = swapyz
|
2007-03-20 05:51:58 +00:00
|
|
|
|
|
|
|
if !xyz_mode and !outdist and !outbrng and !gpscord then self.OutDist = true end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
local onames = {}
|
|
|
|
if (outdist) then
|
2007-02-07 03:45:44 +00:00
|
|
|
table.insert(onames, "Distance")
|
|
|
|
end
|
|
|
|
if (xyz_mode) then
|
|
|
|
table.insert(onames, "X")
|
|
|
|
table.insert(onames, "Y")
|
|
|
|
table.insert(onames, "Z")
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
if (outbrng) then
|
|
|
|
table.insert(onames, "Bearing")
|
|
|
|
table.insert(onames, "Elevation")
|
|
|
|
end
|
2007-03-20 05:51:58 +00:00
|
|
|
if (gpscord) then
|
|
|
|
table.insert(onames, "World_X")
|
|
|
|
table.insert(onames, "World_Y")
|
|
|
|
table.insert(onames, "World_Z")
|
|
|
|
end
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
Wire_AdjustOutputs(self.Entity, onames)
|
2007-03-20 05:51:58 +00:00
|
|
|
self:TriggerOutputs(0, Angle(0, 0, 0),Vector(0, 0, 0),Vector(0, 0, 0))
|
2007-02-04 01:16:06 +00:00
|
|
|
self:ShowOutput()
|
|
|
|
end
|
|
|
|
|
2007-03-20 05:51:58 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
function ENT:Think()
|
|
|
|
self.BaseClass.Think(self)
|
2007-03-20 05:51:58 +00:00
|
|
|
|
|
|
|
//if (!self.Inputs.Target.Src or !self.Inputs.Target.Src:IsValid() ) then return end
|
|
|
|
if (!self.ToSense or !self.ToSense:IsValid() ) then return end
|
2007-02-04 01:16:06 +00:00
|
|
|
if (self.Active) then
|
|
|
|
local dist = 0
|
2007-02-07 03:45:44 +00:00
|
|
|
local distc = Vector(0, 0, 0)
|
2007-02-04 01:16:06 +00:00
|
|
|
local brng = Angle(0, 0, 0)
|
2007-03-20 05:51:58 +00:00
|
|
|
local gpscords = Vector(0, 0, 0)
|
2007-02-04 01:16:06 +00:00
|
|
|
local MyPos = self.Entity:GetPos()
|
2007-03-20 05:51:58 +00:00
|
|
|
//local BeaconPos = self.Inputs["Target"].Src:GetBeaconPos(self.Entity)
|
2007-02-04 01:16:06 +00:00
|
|
|
local BeaconPos = self.ToSense:GetBeaconPos(self.Entity)
|
|
|
|
if (self.OutDist) then
|
2007-02-07 03:45:44 +00:00
|
|
|
dist = (BeaconPos-MyPos):Length()
|
|
|
|
end
|
|
|
|
if (self.XYZMode) then
|
|
|
|
local DeltaPos = self.Entity:WorldToLocal(BeaconPos)
|
2007-03-29 04:57:31 +00:00
|
|
|
if (self.SwapYZ) then
|
|
|
|
distc = Vector(DeltaPos.z, DeltaPos.x, -DeltaPos.y)
|
|
|
|
else
|
|
|
|
distc = Vector(-DeltaPos.y, DeltaPos.x, DeltaPos.z)
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
if (self.OutBrng) then
|
|
|
|
local DeltaPos = self.Entity:WorldToLocal(BeaconPos)
|
|
|
|
brng = DeltaPos:Angle()
|
|
|
|
end
|
2007-03-20 05:51:58 +00:00
|
|
|
if (self.GPSCord) then gpscords = BeaconPos end
|
|
|
|
|
|
|
|
self:TriggerOutputs(dist, brng, distc, gpscords)
|
2007-02-04 01:16:06 +00:00
|
|
|
self:ShowOutput()
|
2007-03-20 05:51:58 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
self.Entity:NextThink(CurTime()+0.04)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function ENT:ShowOutput()
|
|
|
|
local txt = "Beacon Sensor"
|
|
|
|
if (self.OutDist) then
|
2007-02-07 03:45:44 +00:00
|
|
|
txt = txt .. "\nDistance = " .. math.Round(self.Outputs.Distance.Value*1000)/1000
|
|
|
|
end
|
|
|
|
if (self.XYZMode) then
|
|
|
|
txt = txt .. "\nOffset = " .. math.Round(self.Outputs.X.Value*1000)/1000 .. "," .. math.Round(self.Outputs.Y.Value*1000)/1000 .. "," .. math.Round(self.Outputs.Z.Value*1000)/1000
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
if (self.OutBrng) then
|
|
|
|
txt = txt .. "\nBearing = " .. math.Round(self.Outputs.Bearing.Value*1000)/1000 .. "," .. math.Round(self.Outputs.Elevation.Value*1000)/1000
|
|
|
|
end
|
2007-03-20 05:51:58 +00:00
|
|
|
if (self.GPSCord) then
|
|
|
|
txt = txt .. "\nWorldPos = " .. math.Round(self.Outputs.World_X.Value*1000)/1000 .. "," .. math.Round(self.Outputs.World_Y.Value*1000)/1000 .. "," .. math.Round(self.Outputs.World_Z.Value*1000)/1000
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self:SetOverlayText(txt)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-03-20 05:51:58 +00:00
|
|
|
function ENT:TriggerOutputs(dist, brng, distc, gpscords)
|
|
|
|
if (self.OutDist) then
|
|
|
|
Wire_TriggerOutput(self.Entity, "Distance", dist)
|
|
|
|
end
|
|
|
|
if (self.XYZMode) then
|
|
|
|
Wire_TriggerOutput(self.Entity, "X", distc.x)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Y", distc.y)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Z", distc.z)
|
|
|
|
end
|
|
|
|
if (self.GPSCord) then
|
|
|
|
Wire_TriggerOutput(self.Entity, "World_X", gpscords.x)
|
|
|
|
Wire_TriggerOutput(self.Entity, "World_Y", gpscords.y)
|
|
|
|
Wire_TriggerOutput(self.Entity, "World_Z", gpscords.z)
|
|
|
|
end
|
|
|
|
if (self.OutBrng) then
|
|
|
|
local pitch = brng.p
|
|
|
|
local yaw = brng.y
|
|
|
|
|
|
|
|
if (pitch > 180) then pitch = pitch - 360 end
|
|
|
|
if (yaw > 180) then yaw = yaw - 360 end
|
|
|
|
|
|
|
|
Wire_TriggerOutput(self.Entity, "Bearing", -yaw)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Elevation", -pitch)
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
2007-03-20 05:51:58 +00:00
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
if (iname == "Target") and ( self.ToSense != self.Inputs.Target.Src ) then
|
|
|
|
self:SetBeacon(self.Inputs.Target.Src)
|
|
|
|
end
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
function ENT:SetBeacon(beacon)
|
|
|
|
if (beacon) and (beacon:IsValid()) then
|
|
|
|
self.ToSense = beacon
|
|
|
|
self.Active = true
|
|
|
|
else
|
|
|
|
self.ToSense = nil
|
|
|
|
self.Active = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-02-07 07:08:19 +00:00
|
|
|
function ENT:OnRestore()
|
|
|
|
//this is to prevent old save breakage
|
2007-03-29 04:57:31 +00:00
|
|
|
self:Setup(self.XYZMode, self.OutDist, self.OutBrng, self.GPSCord, self.SwapYZ)
|
2007-02-07 07:08:19 +00:00
|
|
|
|
|
|
|
self.BaseClass.OnRestore(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
function ENT:BuildDupeInfo()
|
|
|
|
local info = self.BaseClass.BuildDupeInfo(self) or {}
|
|
|
|
|
|
|
|
if (self.ToSense) and (self.ToSense:IsValid()) then
|
|
|
|
info.to_sense = self.ToSense:EntIndex()
|
|
|
|
end
|
|
|
|
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-03-20 05:51:58 +00:00
|
|
|
function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID)
|
|
|
|
self.BaseClass.ApplyDupeInfo(self, ply, ent, info, GetEntByID)
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
if (info.to_sense) then
|
2007-03-20 05:51:58 +00:00
|
|
|
self:SetBeacon(GetEntByID(info.to_sense))
|
|
|
|
if (!self.ToSense) then
|
2007-03-22 03:27:52 +00:00
|
|
|
self:SetBeacon(ents.GetByIndex(info.to_sense))
|
2007-03-20 05:51:58 +00:00
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
end
|