Skip to content

Commit

Permalink
Document some magic numbers
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
thecraftianman committed Feb 22, 2024
1 parent 1f62be4 commit a7665f0
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions lua/acf/core/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lua/acf/core/validation_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_ammo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_armor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_engine/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_fueltank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_gun/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/acf_piledriver/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7665f0

Please sign in to comment.