From a7665f057aaf1d185779987419ab6fa093e5cb09 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:46:31 -0500 Subject: [PATCH] Document some magic numbers Closes #179 --- lua/acf/core/globals.lua | 1 + lua/acf/core/validation_sv.lua | 7 ++++--- lua/acf/damage/explosion_sv.lua | 2 +- lua/entities/acf_ammo/init.lua | 2 +- lua/entities/acf_armor/init.lua | 2 +- lua/entities/acf_engine/init.lua | 2 +- lua/entities/acf_fueltank/init.lua | 2 +- lua/entities/acf_gun/init.lua | 2 +- lua/entities/acf_piledriver/init.lua | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index f9995668d..8db20eb5c 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -38,6 +38,7 @@ do -- ACF global vars ACF.gCmToKgIn = 0.016387064 -- g/cm³ to kg/in³ :face_vomiting: :face_vomiting: :face_vomiting: ACF.MmToInch = 0.0393701 -- Millimeters to inches ACF.InchToMm = 25.4 -- Inches to millimeters + ACF.InchToCmSq = 6.45 -- in² to cm² -- Fuzes ACF.MinFuzeCaliber = 20 -- Minimum caliber in millimeters that can be fuzed diff --git a/lua/acf/core/validation_sv.lua b/lua/acf/core/validation_sv.lua index d764540f3..92f4c3694 100644 --- a/lua/acf/core/validation_sv.lua +++ b/lua/acf/core/validation_sv.lua @@ -125,15 +125,16 @@ function ACF.UpdateArea(Entity, PhysObj) local Area = PhysObj:GetSurfaceArea() if Area then -- Normal collisions - Area = Area * 6.45 * 0.52505066107 + local AreaMult = 0.52505066107 -- This seems to be a conversion from cm to grid units on the architectural scale (approx. 1 / 1.905) + Area = Area * ACF.InchToCmSq * AreaMult elseif PhysObj:GetMesh() then -- Box collisions local Size = Entity:OBBMaxs() - Entity:OBBMins() - Area = ((Size.x * Size.y) + (Size.x * Size.z) + (Size.y * Size.z)) * 6.45 + Area = ((Size.x * Size.y) + (Size.x * Size.z) + (Size.y * Size.z)) * ACF.InchToCmSq else -- Spherical collisions local Radius = Entity:BoundingRadius() - Area = 4 * 3.1415 * Radius * Radius * 6.45 + Area = 4 * 3.1415 * Radius * Radius * ACF.InchToCmSq end Entity.ACF.Area = Area diff --git a/lua/acf/damage/explosion_sv.lua b/lua/acf/damage/explosion_sv.lua index 8153af42c..0b8711a1c 100644 --- a/lua/acf/damage/explosion_sv.lua +++ b/lua/acf/damage/explosion_sv.lua @@ -399,7 +399,7 @@ do -- Experimental HE code local displacement = targetPos - origin local distance = displacement:Length() local sphereAtRange = 4 * 3.1415 * distance^2 - local circleArea = ent.ACF.Area / 6.45 / 4 -- Surface area converted to a circle + local circleArea = ent.ACF.Area / ACF.InchToCmSq / 4 -- Surface area converted to a circle local shadowArea = circleArea / sphereAtRange * blastSurfaceArea -- How much power goes to the target diff --git a/lua/entities/acf_ammo/init.lua b/lua/entities/acf_ammo/init.lua index 8f0f76145..5d74a68b4 100644 --- a/lua/entities/acf_ammo/init.lua +++ b/lua/entities/acf_ammo/init.lua @@ -457,7 +457,7 @@ do -- ACF Activation and Damage ----------------- function ENT:ACF_Activate(Recalc) local PhysObj = self.ACF.PhysObj - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Armour = ACF.AmmoArmor * ACF.ArmorMod local Health = Area / ACF.Threshold local Percent = 1 diff --git a/lua/entities/acf_armor/init.lua b/lua/entities/acf_armor/init.lua index 14b6e299c..a7449cf51 100644 --- a/lua/entities/acf_armor/init.lua +++ b/lua/entities/acf_armor/init.lua @@ -164,7 +164,7 @@ do -- ACF Activation and Damage function ENT:ACF_Activate(Recalc) local PhysObj = self.ACF.PhysObj - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Health = Area / ACF.Threshold * self.Tensile local Percent = 1 diff --git a/lua/entities/acf_engine/init.lua b/lua/entities/acf_engine/init.lua index e0746f53e..f1358c03b 100644 --- a/lua/entities/acf_engine/init.lua +++ b/lua/entities/acf_engine/init.lua @@ -555,7 +555,7 @@ end) function ENT:ACF_Activate(Recalc) local PhysObj = self.ACF.PhysObj local Mass = PhysObj:GetMass() - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Armour = Mass * 1000 / Area / 0.78 * ACF.ArmorMod -- Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick local Health = Area / ACF.Threshold local Percent = 1 diff --git a/lua/entities/acf_fueltank/init.lua b/lua/entities/acf_fueltank/init.lua index 625c84a7e..a9a1059bd 100644 --- a/lua/entities/acf_fueltank/init.lua +++ b/lua/entities/acf_fueltank/init.lua @@ -320,7 +320,7 @@ end function ENT:ACF_Activate(Recalc) local PhysObj = self:GetPhysicsObject() - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Armour = self.EmptyMass * 1000 / Area / 0.78 * ACF.ArmorMod -- So we get the equivalent thickness of that prop in mm if all it's weight was a steel plate local Health = Area / ACF.Threshold local Percent = 1 diff --git a/lua/entities/acf_gun/init.lua b/lua/entities/acf_gun/init.lua index 17f4cc86a..7cfe2928f 100644 --- a/lua/entities/acf_gun/init.lua +++ b/lua/entities/acf_gun/init.lua @@ -800,7 +800,7 @@ do -- Metamethods -------------------------------- do -- Misc ---------------------------------- function ENT:ACF_Activate(Recalc) local PhysObj = self.ACF.PhysObj - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Armour = self.Caliber * ACF.ArmorMod local Health = Area / ACF.Threshold local Percent = 1 diff --git a/lua/entities/acf_piledriver/init.lua b/lua/entities/acf_piledriver/init.lua index 4152ed207..03f6747a5 100644 --- a/lua/entities/acf_piledriver/init.lua +++ b/lua/entities/acf_piledriver/init.lua @@ -249,7 +249,7 @@ end -------------------------------------------- do -- Entity Activation ------------------------ function ENT:ACF_Activate(Recalc) local PhysObj = self.ACF.PhysObj - local Area = PhysObj:GetSurfaceArea() * 6.45 + local Area = PhysObj:GetSurfaceArea() * ACF.InchToCmSq local Armour = self.Caliber * ACF.ArmorMod local Health = Area / ACF.Threshold local Percent = 1