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

Slight cluster missile rework #33

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
45 changes: 25 additions & 20 deletions lua/acf/shared/fuzes/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,54 @@ Fuze.MaxDistance = 5000
if CLIENT then
Fuze.Description = "This fuze fires a beam directly ahead and releases bomblets when the beam hits something close-by. Distance in inches."
else
Fuze.Spread = 15
Fuze.Spread = 500

function Fuze:HandleDetonation(Entity, BulletData)
local FillerMass = BulletData.FillerMass
local Bomblets = math.Clamp(math.Round(FillerMass * 0.5), 10, 100)
local MuzzleVec = BulletData.Flight:GetNormalized()
-- Seven circles packed in a circle: https://en.wikipedia.org/wiki/Circle_packing_in_a_circle
local Layers = math.Clamp(math.Round(FillerMass * 0.5 / 7), 1, 4)
local Bomblets = Layers * 7
local Density = 0.77778 -- Volume density of the circle packing
local RoundData = Entity.RoundData
local Velocity = BulletData.Flight

BulletData.Caliber = BulletData.Caliber / Bomblets
BulletData.Diameter = BulletData.Diameter / Bomblets
BulletData.Caliber = BulletData.Caliber / 3
BulletData.Diameter = BulletData.Diameter / 3
BulletData.ProjArea = math.pi * (BulletData.Diameter * 0.5) ^ 2
BulletData.ProjLength = BulletData.ProjLength / Bomblets
BulletData.ProjMass = BulletData.ProjMass / Bomblets
BulletData.ProjLength = BulletData.ProjLength / Layers
BulletData.ProjMass = BulletData.ProjMass * Density / Bomblets
BulletData.DragCoef = BulletData.ProjArea * 0.0001 / BulletData.ProjMass
BulletData.FillerMass = FillerMass / Bomblets
BulletData.FillerMass = FillerMass * Density / Bomblets
BulletData.Tracer = 0

if BulletData.Type == "HEAT" then
BulletData.SlugMass = BulletData.SlugMass / Bomblets
BulletData.SlugCaliber = BulletData.SlugCaliber / Bomblets
BulletData.SlugDragCoef = BulletData.SlugDragCoef / Bomblets
BulletData.SlugMV = BulletData.SlugMV / Bomblets
BulletData.CasingMass = BulletData.CasingMass / Bomblets
BulletData.BoomFillerMass = BulletData.BoomFillerMass / Bomblets
BulletData.SlugMass = BulletData.SlugMass * Density / Bomblets
BulletData.SlugCaliber = BulletData.SlugCaliber * Density / Bomblets
BulletData.SlugDragCoef = BulletData.SlugDragCoef * Density / Bomblets
BulletData.SlugMV = BulletData.SlugMV * Density / Bomblets
BulletData.CasingMass = BulletData.CasingMass * Density / Bomblets
BulletData.BoomFillerMass = BulletData.BoomFillerMass * Density / Bomblets
end

RoundData:Network(Entity, BulletData)

local Effect = EffectData()
Effect:SetOrigin(Entity.Position)
Effect:SetNormal(Entity.CurDir)
Effect:SetScale(math.max(FillerMass ^ 0.33 * 8 * 39.37, 1))
Effect:SetScale(math.max(BulletData.Caliber * 20, 1))
Effect:SetRadius(BulletData.Caliber)

util.Effect("ACF_Explosion", Effect)

local Angle = 0
local Increment = 2 * math.pi * (Layers + 1) / Layers / 7 -- Equally spaces the bomblets angle-wise
local Velocity = BulletData.Flight

for _ = 1, Bomblets do
local Cone = math.tan(math.rad(self.Spread * ACF.GunInaccuracyScale))
local Spread = (Entity:GetUp() * math.Rand(-1, 1) + Entity:GetRight() * math.Rand(-1, 1)):GetNormalized()
local ShootDir = (MuzzleVec + Cone * Spread * (math.random() ^ (1 / ACF.GunInaccuracyBias))):GetNormalized()
local SpreadVec = Entity:GetUp() * math.sin(Angle) + Entity:GetRight() * math.cos(Angle)
local SpreadVel = SpreadVec * self.Spread * math.random() ^ 0.5
BulletData.Flight = Velocity + SpreadVel

BulletData.Flight = ShootDir * Velocity:Length()
Angle = Angle + Increment

RoundData:Create(Entity, BulletData)
end
Expand Down