Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFWD dev to master, added warning receivers (laser/radar) #85

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/acf/entities/components/computers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ do -- Laser guidance computer
OnUpdate = function(Entity, _, _, Computer)
Entity.IsComputer = true
Entity.Lasing = false
Entity.Offset = Computer.Offset
Entity.OnCooldown = false
Entity.HitPos = Vector()
Entity.Distance = 0
Expand Down
9 changes: 9 additions & 0 deletions lua/acf/entities/sensors/receiver_menu_cl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local ACF = ACF
local Text = "Mass : %s kg\n"

function ACF.CreateReceiverMenu(Data, Menu)

Menu:AddLabel(Text:format(Data.Mass))

ACF.SetClientData("PrimaryClass", "acf_receiver")
end
139 changes: 139 additions & 0 deletions lua/acf/entities/sensors/receivers/receivers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
local ACF = ACF
local Sensors = ACF.Classes.Sensors
local TraceLine = util.TraceLine

Sensors.Register("WARN-Receiver", {
Name = "Warning Receiver",
Entity = "acf_receiver",
CreateMenu = ACF.CreateReceiverMenu,
LimitConVar = {
Name = "_acf_receiver",
Amount = 4,
Text = "Maximum amount of ACF receivers a player can create."
},
})

do -- Laser Receiver
local function ReceiveSource(Receiver)
local Lasers = {}

local ReceiverOrigin = Receiver:LocalToWorld(Receiver.Origin)

for k,v in pairs(ACF.ActiveLasers) do
local Dir = k.Dir or k:GetForward()
if v.Distance > 0 then Dir = (v.HitPos - v.Origin):GetNormalized() end

if Dir:Dot((ReceiverOrigin - v.Origin):GetNormalized()) >= Receiver.Cone then Lasers[k] = true end
end

-- Wiremod laser pointer, because it's, you know, a laser
for _,ply in pairs(player.GetAll()) do
local Wep = ply:GetWeapon("laserpointer")
if not IsValid(Wep) then continue end

if Wep.Pointing then
local Las = {Dir = ply:EyeAngles():Forward(),Position = ply:EyePos(),Player = ply}

if Las.Dir:Dot((ReceiverOrigin - Las.Position):GetNormalized()) >= Receiver.Cone then Lasers[Las] = true end
end
end

return Lasers
end

local TraceData = { start = true, endpos = true, mask = MASK_SOLID }
local function CheckLOS(Receiver, Source, Start, End)
TraceData.start = Start
TraceData.endpos = End
if IsValid(Source.Player) then
TraceData.filter = {Receiver,Source.Player}
else TraceData.filter = {Receiver,Source} end

return not TraceLine(TraceData).Hit
end

Sensors.RegisterItem("LAS-Receiver", "WARN-Receiver", {
Name = "Laser Warning Receiver",
Description = "An optical unit designed to detect laser sources and give a precise direction.",
Model = "models/jaanus/wiretool/wiretool_range.mdl",

Mass = 25,
Health = 10,
Armor = 10,
Offset = Vector(0,0,3),

ThinkDelay = 0.25,
Divisor = 2.5, -- Divisor (pre-floor) and then multiplier to give a choppy angle
Cone = math.cos(2.5 / 90),

Detect = ReceiveSource,
CheckLOS = CheckLOS,

Preview = {
FOV = 145,
},
})
end

do -- Radar Receiver

-- ACF.ActiveRadars for radars, need to check for direction and range for these
local ValidMissileRadars = {
["Active Radar"] = true
}

local function ReceiveSource(Receiver)
local RadarSource = {}

local ReceiverOrigin = Receiver:LocalToWorld(Receiver.Origin)

for k in pairs(ACF.ActiveRadars) do -- Radar entities
if k.EntType ~= "Targeting Radar" then continue end
local RadarOrigin = k:LocalToWorld(k.Origin)

if k.Range then -- Spherical
if RadarOrigin:DistToSqr(ReceiverOrigin) <= (k.Range ^ 2) then RadarSource[k] = true end
else -- Directional
if ACFM_ConeContainsPos(RadarOrigin, k:GetForward(), k.ConeDegs, ReceiverOrigin) then RadarSource[k] = true end
end
end

for k in pairs(ACF.ActiveMissiles) do -- Missile entities
if not k.UseGuidance then continue end -- Don't waste time on missiles that don't have functional guidance
if not ValidMissileRadars[k.Guidance] then continue end -- Further filter for anything without radar on the missile itself

if ACFM_ConeContainsPos(k.Position, k:GetForward(), k.ViewCone, ReceiverOrigin) then RadarSource[k] = true end
end

return RadarSource
end

local TraceData = { start = true, endpos = true, mask = MASK_SOLID_BRUSHONLY }
local function CheckLOS(_, _, Start, End)
TraceData.start = Start
TraceData.endpos = End

return not TraceLine(TraceData).Hit
end

Sensors.RegisterItem("RAD-Receiver", "WARN-Receiver", {
Name = "Radar Warning Receiver",
Description = "An unit designed to detect radar sources and give a vague direction.",
Model = "models/jaanus/wiretool/wiretool_siren.mdl",

Mass = 25,
Health = 10,
Armor = 10,
Offset = Vector(0,0,6),

ThinkDelay = 0.5,
Divisor = 30, -- Divisor (pre-floor) and then multiplier to give a choppy angle

Detect = ReceiveSource,
CheckLOS = CheckLOS,

Preview = {
FOV = 145,
},
})
end
1 change: 1 addition & 0 deletions lua/acf/missiles/acfm_roundinject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ else
Guidance:Configure(Entity)
Fuze:Configure(Entity)

Entity.Guidance = Data.Guidance
Entity.IsMissileAmmo = true
Entity.GuidanceData = Guidance
Entity.FuzeData = Fuze
Expand Down
15 changes: 11 additions & 4 deletions lua/entities/acf_radar/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,14 @@ local function ScanForEntities(Entity)
local Velocity = TargetInfo.Velocity
local Distance = TargetInfo.Distance

local Damage = Entity.Damage
local Spread = ACF.MaxDamageInaccuracy * Damage

for Ent in pairs(Detected) do
local EntPos = Ent.Position or Ent:GetPos()

if CheckLOS(Origin, EntPos) then
local Spread = VectorRand(-Entity.Spread, Entity.Spread)
if CheckLOS(Origin, EntPos) and (math.Rand(0,1) >= (Damage / 10)) then
local Spread = VectorRand(-Spread, Spread)
local EntVel = Ent.Velocity or Ent:GetVelocity()
local Owner = GetEntityOwner(Entity.Owner, Ent)
local Index = GetEntityIndex(Ent)
Expand Down Expand Up @@ -400,7 +403,7 @@ do -- Spawn and Update functions
Radar.Active = false
Radar.Scanning = false
Radar.TargetCount = 0
Radar.Spread = 0
Radar.Damage = 0
Radar.Weapons = {}
Radar.Targets = {}
Radar.DataStore = Entities.GetArguments("acf_radar")
Expand Down Expand Up @@ -494,11 +497,15 @@ end
function ENT:ACF_OnDamage(DmgResult, DmgInfo)
local HitRes = Damage.doPropDamage(self, DmgResult, DmgInfo)

self.Spread = ACF.MaxDamageInaccuracy * (1 - math.Round(self.ACF.Health / self.ACF.MaxHealth, 2))
self.Damage = (1 - math.Round(self.ACF.Health / self.ACF.MaxHealth, 2))

return HitRes
end

function ENT:ACF_OnRepaired() -- OldArmor, OldHealth, Armor, Health
self.Damage = (1 - math.Round(self.ACF.Health / self.ACF.MaxHealth, 2))
end

function ENT:Enable()
if not CheckLegal(self) then return end

Expand Down
5 changes: 5 additions & 0 deletions lua/entities/acf_receiver/cl_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ("shared.lua")

language.Add("Cleanup_acf_receiver", "ACF Receiver")
language.Add("Cleaned_acf_receiver", "Cleaned up all ACF Receiverss")
language.Add("SBoxLimit__acf_receiver", "You've hit the ACF Receiver limit!")
Loading
Loading