Skip to content

Commit

Permalink
Pushed some absolutely vital changes
Browse files Browse the repository at this point in the history
- Fixed a typo
- Localized some tables
- Removed some debris filtering on something that doesn't generate debris
- Added spacing between some function arguments
- Replaced a few divisions with multiplications.

Now the addon should run one trillion times faster and my stash uncommited should be empty.
  • Loading branch information
TwistedTail committed Oct 9, 2023
1 parent 25276a9 commit afefc2a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ do -- Terminal ballistics --------------------------
)
end

if HitRes.Kill and IsValid(Entity) then
if HitRes.Kill then
ACF.APKill(Entity, Bullet.Flight:GetNormalized(), Energy.Kinetic, DmgInfo)
end

Expand Down
51 changes: 28 additions & 23 deletions lua/acf/core/utilities/util_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ do -- Special squishy functions

-- The goal of this is to provide a much sturdier way to get the part of a player that got hit with a bullet
-- This will ignore any bone manipulation too
function ACF.GetBestSquishyHitBox(Entity,RayStart,RayDir)
local Bones = {}
function ACF.GetBestSquishyHitBox(Entity, RayStart, RayDir)
local CheckList = {}
local Bones = {}

for k,v in pairs(BoneList) do
CheckList[k] = v
Expand Down Expand Up @@ -540,22 +540,22 @@ do -- Special squishy functions
return CheckList[BestChoice].group
end

ACF.SquishyFuncs = {}

function ACF.SquishyFuncs.DamageHelmet(Entity,HitRes,DmgResult)
local Damage = 0
ACF.SquishyFuncs = ACF.SquishyFuncs or {}

function ACF.SquishyFuncs.DamageHelmet(Entity, HitRes, DmgResult)
DmgResult:SetThickness(12.5) -- helmet armor, sorta just shot in the dark for thickness
HitRes = DmgResult:Compute()

if HitRes.Overkill > 0 then -- Went through helmet
return ACF.SquishyFuncs.DamageHead(Entity,HitRes,DmgResult)
else return Damage,HitRes end
return ACF.SquishyFuncs.DamageHead(Entity, HitRes, DmgResult)
end

return 0, HitRes
end

function ACF.SquishyFuncs.DamageHead(Entity,HitRes,DmgResult)
function ACF.SquishyFuncs.DamageHead(Entity, HitRes, DmgResult)
local Mass = Entity:GetPhysicsObject():GetMass() or 100
local Damage = 0
local Mass = Entity:GetPhysicsObject():GetMass() or 100

DmgResult:SetThickness(Mass * 0.075) -- skull is around 7-8mm on average for humans, but this gets thicker with bigger creatures

Expand All @@ -564,26 +564,29 @@ do -- Special squishy functions

if HitRes.Overkill > 0 then -- Went through skull
DmgResult:SetThickness(0.01) -- squishy squishy brain matter, no resistance

HitRes = DmgResult:Compute()
Damage = Damage + (HitRes.Damage * 50 * math.max(1,HitRes.Overkill / 4)) -- yuge damage, yo brains just got scrambled by a BOOLET
return Damage,HitRes
else return Damage,HitRes end
end
Damage = Damage + (HitRes.Damage * 50 * math.max(1,HitRes.Overkill * 0.25)) -- yuge damage, yo brains just got scrambled by a BOOLET
end

function ACF.SquishyFuncs.DamageVest(Entity,HitRes,DmgResult)
local Damage = 0
return Damage, HitRes
end

function ACF.SquishyFuncs.DamageVest(Entity, HitRes, DmgResult)
DmgResult:SetThickness(15) -- Vest armor, also a shot in the dark for thickness

HitRes = DmgResult:Compute()

if HitRes.Overkill > 0 then -- Went through vest
return ACF.SquishyFuncs.DamageChest(Entity,HitRes,DmgResult)
else return Damage,HitRes end
return ACF.SquishyFuncs.DamageChest(Entity, HitRes, DmgResult)
end

return 0, HitRes
end

function ACF.SquishyFuncs.DamageChest(Entity,HitRes,DmgResult)
function ACF.SquishyFuncs.DamageChest(Entity, HitRes, DmgResult)
local Size = Entity:BoundingRadius()
local Damage = 0
local Size = Entity:BoundingRadius()

DmgResult:SetThickness(Size * 0.25 * 0.02) -- the SKIN and SKELETON, just some generic trashy "armor"

Expand All @@ -592,9 +595,11 @@ do -- Special squishy functions

if HitRes.Overkill > 0 then -- Went through body surface
DmgResult:SetThickness(0.05) -- fleshy organs, ain't much here

HitRes = DmgResult:Compute()
Damage = Damage + (HitRes.Damage * 25 * math.max(1,HitRes.Overkill / 5)) -- some decent damage, vital organs got hurt for sure
return Damage,HitRes
else return Damage,HitRes end
Damage = Damage + (HitRes.Damage * 25 * math.max(1, HitRes.Overkill * 0.2)) -- some decent damage, vital organs got hurt for sure
end

return Damage, HitRes
end
end
10 changes: 5 additions & 5 deletions lua/acf/damage/damage_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end
-- @param DmgInfo A DamageInfo object.
-- @return The output of the DamageResult object.
function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo)
local Hitbox = ACF.GetBestSquishyHitBox(Entity,DmgInfo:GetHitPos(),(DmgInfo:GetHitPos() - DmgInfo:GetOrigin()):GetNormalized())
local Hitbox = ACF.GetBestSquishyHitBox(Entity, DmgInfo:GetHitPos(), (DmgInfo:GetHitPos() - DmgInfo:GetOrigin()):GetNormalized())
local Size = Entity:BoundingRadius()
local HitRes = DmgResult:GetBlank()
local Damage = 0
Expand All @@ -63,13 +63,13 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo)
-- Using player armor for fake armor works decently, as even if you don't take actual damage, the armor takes 1 point of damage, so it can potentially wear off
-- These funcs are also done on a hierarchy sort of system, so if the helmet is penetrated, then DamageHead is called, same for Vest -> Chest
if Hitbox == "helmet" then
Damage,HitRes = ACF.SquishyFuncs.DamageHelmet(Entity,HitRes,DmgResult)
Damage, HitRes = ACF.SquishyFuncs.DamageHelmet(Entity, HitRes, DmgResult)
elseif Hitbox == "head" then
Damage,HitRes = ACF.SquishyFuncs.DamageHead(Entity,HitRes,DmgResult)
Damage, HitRes = ACF.SquishyFuncs.DamageHead(Entity, HitRes, DmgResult)
elseif Hitbox == "vest" then
Damage,HitRes = ACF.SquishyFuncs.DamageVest(Entity,HitRes,DmgResult)
Damage, HitRes = ACF.SquishyFuncs.DamageVest(Entity, HitRes, DmgResult)
elseif Hitbox == "chest" then
Damage,HitRes = ACF.SquishyFuncs.DamageChest(Entity,HitRes,DmgResult)
Damage, HitRes = ACF.SquishyFuncs.DamageChest(Entity, HitRes, DmgResult)
else
DmgResult:SetThickness(Size * 0.2 * 0.02)

Expand Down
5 changes: 4 additions & 1 deletion lua/acf/damage/debris_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ function ACF.HEKill(Entity, Normal, Energy, BlastPos, DmgInfo) -- blast pos is a
end

function ACF.APKill(Entity, Normal, Power, DmgInfo)
ACF.KillChildProps(Entity, Entity:GetPos(), Power) -- kill the children of this ent, instead of disappearing them from removing parent
if not IsValid(Entity) then return end

local Class = Entity:GetClass()
local CanBreak = (Class == "prop_physics") and (Entity:Health() > 0)

ACF.KillChildProps(Entity, Entity:GetPos(), Power) -- kill the children of this ent, instead of disappearing them from removing parent

if not CanBreak then DebrisNetter(Entity, Normal, Power, true, false) end -- if we can't break the prop into its own gibs, then use ACF's system

constraint.RemoveAll(Entity)
Expand Down
2 changes: 1 addition & 1 deletion lua/acf/damage/explosion_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function Damage.createExplosion(Position, FillerMass, FragMass, Filter, DmgInfo)
util.ScreenShake(Position, Amp, Amp, Amp / 15, Radius * 10)
end

-- Quickly getting rid of all the entity we can't damage
-- Quickly getting rid of all the entities we can't damage
for Index, Entity in ipairs(Found) do
if Damage.isValidTarget(Entity) then
Targets[Entity] = true
Expand Down
5 changes: 3 additions & 2 deletions lua/acf/entities/ammo_types/ap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ if SERVER then

function Ammo:PropImpact(Bullet, Trace)
local Target = Trace.Entity
local Filter = Bullet.Filter

if ACF.Check(Target) then
local Speed = Bullet.Flight:Length() / ACF.Scale
Expand All @@ -141,7 +142,7 @@ if SERVER then
local HitRes = Ballistics.DoRoundImpact(Bullet, Trace)

if HitRes.Overkill > 0 then
table.insert(Bullet.Filter, Target) --"Penetrate" (Ingoring the prop for the retry trace)
table.insert(Filter, Target) --"Penetrate" (Ingoring the prop for the retry trace)

Bullet.Flight = Bullet.Flight:GetNormalized() * (Energy.Kinetic * (1 - HitRes.Loss) * 2000 / Bullet.ProjMass) ^ 0.5 * 39.37

Expand All @@ -152,7 +153,7 @@ if SERVER then
return false
end
else
table.insert(Bullet.Filter, Target)
table.insert(Filter, Target)

return "Penetrated"
end
Expand Down
8 changes: 2 additions & 6 deletions lua/acf/entities/ammo_types/heat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ if SERVER then
local JetResult = Damage.dealDamage(Ent, JetDmg, JetInfo)

if JetResult.Kill then
local Debris = ACF.APKill(Ent, Direction, 0, JetInfo)

table.insert(Filter , Debris)
ACF.APKill(Ent, Direction, 0, JetInfo)
end
end
-- Reduce the jet mass by the lost mass
Expand Down Expand Up @@ -387,9 +385,7 @@ if SERVER then
local JetResult = Damage.dealDamage(Entity, SpallDmg, SpallInfo)

if JetResult.Kill then
local Debris = ACF.APKill(Entity, Direction, 0, SpallInfo)

table.insert(Filter , Debris)
ACF.APKill(Entity, Direction, 0, SpallInfo)
end
end

Expand Down
7 changes: 4 additions & 3 deletions lua/entities/acf_ammo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,11 @@ do -- ACF Activation and Damage -----------------
self.Exploding = true

local Position = self:LocalToWorld(self:OBBCenter() + VectorRand() * self:GetSize() * 0.5)
local Filler = self.BulletData.FillerMass or 0
local Propellant = self.BulletData.PropMass or 0
local BulletData = self.BulletData
local Filler = BulletData.FillerMass or 0
local Propellant = BulletData.PropMass or 0
local Explosive = (Filler + Propellant * (ACF.PropImpetus / ACF.HEPower)) * self.Ammo
local FragMass = self.BulletData.ProjMass or Explosive * 0.5
local FragMass = BulletData.ProjMass or Explosive * 0.5
local DmgInfo = Objects.DamageInfo(self, self.Inflictor)

ACF.KillChildProps(self, Position, Explosive)
Expand Down

0 comments on commit afefc2a

Please sign in to comment.