Skip to content

Commit

Permalink
Various HEAT changes, new wrapped library for debugoverlay
Browse files Browse the repository at this point in the history
Modified HEAT to simply cut off after a certain distance dependent on the breakup distance, to help cull the absolutely ridiculous jet distances; also penetration amount is modified by the jet mass percentage
Removed the filter being passed along to createExplosions when a HEAT round detonates; was causing issues regarding close explosions ignoring the entirety of the source gun's barrel filter (meaning potentially the entire front of a turret), it was also not consistent with HE
Stopped HEAT from instantly detonating whatever was able to detonate, leave that to normal damage! It was also completely bypassing damage perms

New debug library accessed with ACF.Debug, exactly the same as normal debugoverlay except it requires an extra convar, acf_developer, to be on. This should allow someone to debug certain things while using ACF while allowing them to not also see every single line drawn from ballistics or what have you
  • Loading branch information
LiddulBOFH committed Jun 10, 2024
1 parent bc37168 commit 10c0199
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 38 deletions.
3 changes: 2 additions & 1 deletion lua/acf/ballistics/ballistics_cl.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local ACF = ACF
local Debug = ACF.Debug
local Yellow = Color(255, 255, 0)

ACF.BulletEffect = ACF.BulletEffect or {}
Expand All @@ -15,7 +16,7 @@ local function BulletFlight(Bullet, DeltaTime)
Bullet.Effect:ApplyMovement(Bullet)
end

debugoverlay.Line(Bullet.SimPosLast, Bullet.SimPos, 15, Yellow)
Debug.Line(Bullet.SimPosLast, Bullet.SimPos, 15, Yellow)
end

hook.Add("ACF_OnClock", "ACF_ManageBulletEffects", function(_, DeltaTime)
Expand Down
3 changes: 2 additions & 1 deletion lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local ACF = ACF
local Ballistics = ACF.Ballistics
local Damage = ACF.Damage
local Clock = ACF.Utilities.Clock
local Debug = ACF.Debug

Ballistics.Bullets = Ballistics.Bullets or {}
Ballistics.UnusedIndexes = Ballistics.UnusedIndexes or {}
Expand Down Expand Up @@ -245,7 +246,7 @@ function Ballistics.DoBulletsFlight(Bullet)

local traceRes = ACF.trace(FlightTr) -- Does not modify the bullet's original filter

debugoverlay.Line(Bullet.Pos, traceRes.HitPos, 15, Bullet.Color)
Debug.Line(Bullet.Pos, traceRes.HitPos, 15, Bullet.Color)

if Bullet.Fuze and Bullet.Fuze <= Clock.CurTime then
if not util.IsInWorld(Bullet.Pos) then -- Outside world, just delete
Expand Down
3 changes: 2 additions & 1 deletion lua/acf/ballistics/world_pen_sv.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local ACF = ACF
local Ballistics = ACF.Ballistics
local Debug = ACF.Debug

function Ballistics.DigTrace(From, To, Filter)
local Dig = util.TraceLine({
Expand All @@ -8,7 +9,7 @@ function Ballistics.DigTrace(From, To, Filter)
mask = MASK_NPCSOLID_BRUSHONLY, -- Map and brushes only
})

debugoverlay.Line(From, Dig.StartPos, 30, ColorRand(100, 255), true)
Debug.Line(From, Dig.StartPos, 30, ColorRand(100, 255), true)

if Dig.StartSolid then -- Started inside solid map volume
if Dig.FractionLeftSolid == 0 then -- Trace could not move inside
Expand Down
12 changes: 12 additions & 0 deletions lua/acf/core/utilities/debug/debug_sh.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local ACF = ACF
ACF.Debug = {}

local CVar = CreateConVar("acf_developer", 0, FCVAR_REPLICATED, "Extra wrapper convar for debugoverlay, requires 'developer 1' as well. Only applies to ACF", 0, 1)

for k in pairs(debugoverlay) do
ACF.Debug[k] = function(...)
if CVar:GetBool() == false then return end

debugoverlay[k](...)
end
end
16 changes: 8 additions & 8 deletions lua/acf/damage/explosion_sv.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local ents = ents
local math = math
local util = util
local debugoverlay = debugoverlay
local ACF = ACF
local Damage = ACF.Damage
local Objects = Damage.Objects
Expand All @@ -12,9 +11,10 @@ local TraceData = {
start = true,
endpos = true,
filter = true,
mask = MASK_SOLID,
mask = MASK_SOLID + CONTENTS_AUX,
}
local Ballistics = ACF.Ballistics
local Debug = ACF.Debug

--- Checks whether an entity can be affected by ACF explosions.
-- @param Entity The entity to be checked.
Expand Down Expand Up @@ -93,8 +93,8 @@ function Damage.createExplosion(Position, FillerMass, FragMass, Filter, DmgInfo)

if not Filter then Filter = {} end

debugoverlay.Cross(Position, 15, 15, White, true)
--debugoverlay.Sphere(Position, Radius, 15, White, true)
Debug.Cross(Position, 15, 15, White, true)
--Debug.Sphere(Position, Radius, 15, White, true)

do -- Screen shaking
local Amp = math.min(Power * 0.0005, 50)
Expand Down Expand Up @@ -154,7 +154,7 @@ function Damage.createExplosion(Position, FillerMass, FragMass, Filter, DmgInfo)
local PowerFraction = Power * AreaFraction -- How much of the total power goes to that prop
local BlastResult, FragResult, Losses

debugoverlay.Line(Position, HitPos, 15, Red, true) -- Red line for a successful hit
Debug.Line(Position, HitPos, 15, Red, true) -- Red line for a successful hit

DmgInfo:SetHitPos(HitPos)
DmgInfo:SetHitGroup(Trace.HitGroup)
Expand Down Expand Up @@ -196,7 +196,7 @@ function Damage.createExplosion(Position, FillerMass, FragMass, Filter, DmgInfo)
local Min = HitEnt:OBBMins()
local Max = HitEnt:OBBMaxs()

debugoverlay.BoxAngles(HitEnt:GetPos(), Min, Max, HitEnt:GetAngles(), 15, Red) -- Red box on destroyed entities
Debug.BoxAngles(HitEnt:GetPos(), Min, Max, HitEnt:GetAngles(), 15, Red) -- Red box on destroyed entities

Filter[#Filter + 1] = HitEnt -- Filter from traces
Targets[HitEnt] = nil -- Remove from list
Expand All @@ -218,14 +218,14 @@ function Damage.createExplosion(Position, FillerMass, FragMass, Filter, DmgInfo)

PowerSpent = PowerSpent + PowerFraction * Losses -- Removing the energy spent killing props
elseif not Damaged[HitEnt] then
debugoverlay.Line(Position, HitPos, 15, Blue, true) -- Blue line for an invalid entity
Debug.Line(Position, HitPos, 15, Blue, true) -- Blue line for an invalid entity

Filter[#Filter + 1] = HitEnt -- Filter from traces
Targets[HitEnt] = nil -- Remove from list
end
else
-- Not removed from future damage sweeps so as to provide multiple chances to be hit
debugoverlay.Line(Position, HitPos, 15, White, true) -- White line for a miss.
Debug.Line(Position, HitPos, 15, White, true) -- White line for a miss.
end
end

Expand Down
28 changes: 17 additions & 11 deletions lua/acf/entities/ammo_types/heat.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local ACF = ACF
local Classes = ACF.Classes
local Damage = ACF.Damage
local Debug = ACF.Debug
local AmmoTypes = Classes.AmmoTypes
local Ammo = AmmoTypes.Register("HEAT", "AP")

Expand Down Expand Up @@ -232,12 +233,14 @@ if SERVER then

local SpallingSin = math.sqrt(1 - ACF.HEATSpallingArc * ACF.HEATSpallingArc)
function Ammo:Detonate(Bullet, HitPos)
if Bullet.Detonated then return end -- Prevents GLATGM spawned HEAT projectiles from detonating twice, or for that matter this running twice at all
Bullet.Detonated = true

local Filler = Bullet.BoomFillerMass
local Fragments = Bullet.CasingMass
local Filter = Bullet.Filter
local DmgInfo = Objects.DamageInfo(Bullet.Owner, Bullet.Gun)

Damage.createExplosion(HitPos, Filler, Fragments, Filter, DmgInfo)
Damage.createExplosion(HitPos, Filler, Fragments, nil, DmgInfo)

-- Find ACF entities in the range of the damage (or simplify to like 6m)
local FoundEnts = ents.FindInSphere(HitPos, 250)
Expand All @@ -252,9 +255,14 @@ if SERVER then
end

-- Move the jet start to the impact point and back it up by the passive standoff
local Start = Bullet.Standoff * 39.37
local End = Bullet.BreakupDist * 10 * 39.37
local Direction = Bullet.Flight:GetNormalized()
local JetStart = HitPos - Direction * Bullet.Standoff * 39.37
local JetEnd = HitPos + Direction * 3000
local JetStart = HitPos - Direction * Start
local JetEnd = HitPos + Direction * End

Debug.Cross(JetStart, 15, 15, Color(0,255,0), true)
Debug.Cross(JetEnd, 15, 15, Color(255,0,0), true)

local TraceData = {start = JetStart, endpos = JetEnd, filter = {}, mask = Bullet.Mask}
local Penetrations = 0
Expand All @@ -264,13 +272,16 @@ if SERVER then
local TraceRes = ACF.trace(TraceData)
local PenHitPos = TraceRes.HitPos
local Ent = TraceRes.Entity
debugoverlay.Line(JetStart, PenHitPos, 15, ColorRand(100, 255))

if TraceRes.Fraction == 1 and not IsValid(Ent) then break end

Debug.Line(JetStart, PenHitPos, 15, ColorRand(100, 255))

if Ballistics.TestFilter(Ent, Bullet) == false then TraceData.filter[#TraceData.filter + 1] = TraceRes.Entity print("Skipped",Ent) continue end

-- Get the (full jet's) penetration
local Standoff = (PenHitPos - JetStart):Length() * 0.0254 -- Back to m
local Penetration = self:GetPenetration(Bullet, Standoff)
local Penetration = self:GetPenetration(Bullet, Standoff) * math.max(0, JetMassPct)
-- If it's out of range, stop here
if Penetration == 0 then break end

Expand Down Expand Up @@ -322,11 +333,6 @@ if SERVER then

if JetMassPct < 0 then break end

-- If the target is explosive and the armor is penetrated, detonate
if Ent.Detonate then
Ent:Detonate()
end

-- Filter the hit entity
if TraceRes.Entity then TraceData.filter[#TraceData.filter + 1] = TraceRes.Entity end

Expand Down
5 changes: 3 additions & 2 deletions lua/effects/acf_explosion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local TraceLine = util.TraceLine
local GetIndex = ACF.GetAmmoDecalIndex
local GetDecal = ACF.GetRicochetDecal
local Sounds = ACF.Utilities.Sounds
local Debug = ACF.Debug
local White = Color(255, 255, 255)
local Yellow = Color(255, 255, 0)

Expand All @@ -29,8 +30,8 @@ function EFFECT:Init(Data)
local Emitter = ParticleEmitter(Origin)
local Mult = LocalPlayer():GetInfoNum("acf_cl_particlemul", 1)

debugoverlay.Cross(Origin, 15, 15, Yellow, true)
--debugoverlay.Sphere(Origin, Size, 15, Yellow, true)
Debug.Cross(Origin, 15, 15, Yellow, true)
--Debug.Sphere(Origin, Size, 15, Yellow, true)

TraceData.start = Origin - Normal * 5
TraceData.endpos = Origin + Normal * Radius
Expand Down
8 changes: 5 additions & 3 deletions lua/entities/acf_armor/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ ENT.WireDebugName = "ACF Armor"
ENT.PluralName = "ACF Armor"
ENT.IsACFArmor = true

local Debug = ACF.Debug

local function FindOtherSide(Ent, Origin, Dire)
local Mesh = Ent:GetPhysicsObject():GetMeshConvexes()
local Min = math.huge
Expand Down Expand Up @@ -77,9 +79,9 @@ function ENT:GetArmor(Trace)
local Enter = Trace.HitPos
local Length, Exit = TraceThroughObject(Trace)

debugoverlay.Cross(Enter, 3, 0.015, Color(0, 255, 0), true)
debugoverlay.Cross(Exit, 3, 0.015, Color(255, 0, 0), true)
debugoverlay.Line(Enter, Exit, 0.015, Color(0, 255, 255), true)
Debug.Cross(Enter, 3, 0.015, Color(0, 255, 0), true)
Debug.Cross(Exit, 3, 0.015, Color(255, 0, 0), true)
Debug.Line(Enter, Exit, 0.015, Color(0, 255, 255), true)

return ACF.RHAe(Length, self.Density)
end
2 changes: 0 additions & 2 deletions lua/entities/acf_turret/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ do -- Overlay
local Pos = self:LocalToWorld(self:OBBCenter())
local Origin = Pos + (FWD * X * 1.1)

--debugoverlay.Text(Origin, tostring(Axis), 0.015, false)

render.DrawQuad(Pos, Pos, Pos + (FWD * X * 1.1) + (WorldRightDir * -UX / 4), Pos + (FWD * X * 1.1) + (WorldRightDir * UX / 4), orange)
render.DrawQuad(Origin + FWD * UX, Origin + WorldRightDir * UX + FWD * (-UX / 2), Origin, Origin + WorldRightDir * -UX + FWD * (-UX / 2), orange)
end
Expand Down
19 changes: 10 additions & 9 deletions lua/entities/acf_turret_computer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local ACF = ACF
local Contraption = ACF.Contraption
local Classes = ACF.Classes
local Utilities = ACF.Utilities
local Debug = ACF.Debug
local Sounds = Utilities.Sounds
local Clock = Utilities.Clock
local HookRun = hook.Run
Expand Down Expand Up @@ -262,7 +263,7 @@ do -- Metamethods and other important stuff

StartAngle:Normalize()

debugoverlay.Line(Gun:LocalToWorld(Gun.Muzzle),Gun:LocalToWorld(Gun.Muzzle) + StartAngle:Forward() * 32,3,Color(255,0,0),true)
Debug.Line(Gun:LocalToWorld(Gun.Muzzle),Gun:LocalToWorld(Gun.Muzzle) + StartAngle:Forward() * 32,3,Color(255,0,0),true)

self.SimData = {
MuzzleVel = BD.MuzzleVel,
Expand Down Expand Up @@ -379,7 +380,7 @@ do -- Metamethods and other important stuff
self.SimData.StartAngle = StartAngle
self.SimData.Flight = StartAngle:Forward() * Sim.MuzzleVel * 39.37

debugoverlay.Cross(Sim.StartPos + LocalPosition,3,5,Color(0,0,255),true)
Debug.Cross(Sim.StartPos + LocalPosition,3,5,Color(0,0,255),true)

self.SimData.Pos = Vector()

Expand Down Expand Up @@ -415,7 +416,7 @@ do -- Metamethods and other important stuff
local ErrorDir2D = ((Sim.TargetPos - (Sim.StartPos + Sim.Pos)) * Vector(1,1,0)):GetNormalized()
local ErrorDist = (Sim.StartPos + Sim.Pos):Distance2D(Sim.TargetPos)

debugoverlay.Line(Sim.StartPos + Sim.Pos,(Sim.StartPos + Sim.Pos) + ErrorDir2D * ErrorDist, 3, Color(255,0,0), true)
Debug.Line(Sim.StartPos + Sim.Pos,(Sim.StartPos + Sim.Pos) + ErrorDir2D * ErrorDist, 3, Color(255,0,0), true)

local LocalPosition = (Sim.AdjustedTargetPos - Sim.StartPos)

Expand All @@ -430,7 +431,7 @@ do -- Metamethods and other important stuff
self.SimData.StartAngle = StartAngle
self.SimData.Flight = StartAngle:Forward() * Sim.MuzzleVel * 39.37

debugoverlay.Cross(Sim.StartPos + LocalPosition,3,5,Color(0,0,255),true)
Debug.Cross(Sim.StartPos + LocalPosition,3,5,Color(0,0,255),true)

self.SimData.Pos = Vector()

Expand Down Expand Up @@ -482,7 +483,7 @@ do -- Metamethods and other important stuff

Sim.TotalTime = Sim.TotalTime + DeltaTime

debugoverlay.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,5,Color(255,0,0),true)
Debug.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,5,Color(255,0,0),true)

local Dir = (Sim.NextPos - Sim.Pos):GetNormalized()

Expand All @@ -495,15 +496,15 @@ do -- Metamethods and other important stuff
local Ratio = (Sim.Pos:Distance(Point)) / FlightDistance
Sim.FlightTime = Sim.FlightTime + (DeltaTime * Ratio)

debugoverlay.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,8,Color(0,255,0),true)
debugoverlay.Cross(Sim.StartPos + Sim.Pos,15,8,Color(255,0,0),true)
Debug.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,8,Color(0,255,0),true)
Debug.Cross(Sim.StartPos + Sim.Pos,15,8,Color(255,0,0),true)

Sim.Pos = Point

Sim.FlightDistance = Sim.FlightDistance + (FlightDistance * Ratio)

debugoverlay.Cross(Sim.StartPos + Point,15,8,Color(255,255,255),true)
debugoverlay.Cross(Sim.StartPos + Sim.NextPos,15,8,Color(0,255,0),true)
Debug.Cross(Sim.StartPos + Point,15,8,Color(255,255,255),true)
Debug.Cross(Sim.StartPos + Sim.NextPos,15,8,Color(0,255,0),true)

return self:AdjustSimulation()
else
Expand Down

0 comments on commit 10c0199

Please sign in to comment.