Skip to content

Commit

Permalink
Ballistic computer changes, turret changes
Browse files Browse the repository at this point in the history
New super elevation output for direct ballistic computers
- This will only run once, and writes to a different output, Elevation
- This is a global pitch, to be used to replace the pitch you are writing to the turret's global angles
Reduced cooldown on both direct and indirect computers
Reduced delay between calculation ticks

Limited arc of vertical turret drives to -85/85, no sense for them to freely spin
Removed checkbox for arc limits, the -180/180 limit disabling will still take effect for horizontal turrets, just made this a little easier to use

Slight torque boost to hydraulic motors, to further incentivize them for extremely heavy turrets
Adjusted handcrank to be more speed and less torque, to incentivize motors and protecting them
  • Loading branch information
LiddulBOFH committed May 20, 2024
1 parent c8ffc03 commit 4829332
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 44 deletions.
27 changes: 11 additions & 16 deletions lua/acf/core/utilities/util_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,8 @@ do -- Default turret menus
local RingStats = Menu:AddLabel(TurretText:format(0,0))
local MassLbl = Menu:AddLabel(MassText:format(0))

Menu:AddLabel("If the total arc is less than 360, then it will use the limits set here.\nIf it is 360, then it will have free rotation.\nUnchecking this will disable the limits as well.")
Menu:AddLabel("If the total arc is less than 360, then it will use the limits set here.\nIf it is 360, then it will have free rotation.")

local ArcToggle = Menu:AddCheckBox("Use Arc Settings")
local ArcSettings = Menu:AddCollapsible("Arc Settings")

local MinDeg = ArcSettings:AddSlider("Minimum Degrees", -180, 0, 1)
Expand Down Expand Up @@ -563,7 +562,6 @@ do -- Default turret menus
return N
end)
MinDeg:SetValue(-180)
MinDeg:SetEnabled(false)

MaxDeg:SetClientData("MaxDeg", "OnValueChanged")
MaxDeg:DefineSetter(function(Panel, _, _, Value)
Expand All @@ -574,22 +572,19 @@ do -- Default turret menus
return N
end)
MaxDeg:SetValue(180)
MaxDeg:SetEnabled(false)

ACF.SetClientData("MinDeg", -180)
ACF.SetClientData("MaxDeg", 180)
if Data.ID == "Turret-V" then
MinDeg:SetMin(-85)
MaxDeg:SetMax(85)

ArcToggle.OnChange = function(_, Value)
MinDeg:SetEnabled(Value)
MaxDeg:SetEnabled(Value)
MinDeg:SetValue(-85)
MaxDeg:SetValue(85)

if Value == true then
ACF.SetClientData("MinDeg", MinDeg:GetValue())
ACF.SetClientData("MaxDeg", MaxDeg:GetValue())
else
ACF.SetClientData("MinDeg", -180)
ACF.SetClientData("MaxDeg", 180)
end
ACF.SetClientData("MinDeg", -85)
ACF.SetClientData("MaxDeg", 85)
else
ACF.SetClientData("MinDeg", -180)
ACF.SetClientData("MaxDeg", 180)
end

local EstMass = Menu:AddSlider("Est. Mass (kg)", 0, 100000, 0)
Expand Down
30 changes: 21 additions & 9 deletions lua/acf/entities/turrets/turrets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ do -- Turret drives

HandGear = { -- Fallback incase a motor is unavailable
Teeth = 12, -- For use in calculating end effective speed of a turret
Speed = 220, -- deg/s
Torque = 14, -- 0.1m * 140N * sin(90), torque to turn a small handwheel 90 degrees with slightly more than recommended force for a human
Speed = 420, -- deg/s
Torque = 10, -- 0.1m * 100N * sin(90), torque to turn a small handwheel 90 degrees
Efficiency = 0.99, -- Gearbox efficiency, won't be too punishing for handcrank
Accel = 5,
Accel = 4,
Sound = "acf_base/fx/turret_handcrank.wav",
},

Expand Down Expand Up @@ -356,8 +356,8 @@ do -- Turret motors
},

Torque = {
Min = 40,
Max = 800
Min = 50,
Max = 1000
}
})
end
Expand Down Expand Up @@ -446,15 +446,27 @@ do -- Turret computers

Mass = 100,

SetupInputs = function(_,List)
local Count = #List

List[Count + 1] = "Calculate Superelevation (One-time calculation to collect super-elevation)"
end,

SetupOutputs = function(_,List)
local Count = #List

List[Count + 1] = "Elevation (Super-elevation, set global pitch to this for automatic ranging)"
end,

ComputerInfo = {
ThinkTime = 0.04, -- Speed of the actual think time
ThinkTime = 0.03, -- Speed of the actual think time
MaxThinkTime = 4, -- Maximum time to spend on a simulation
DeltaTime = 0.2, -- Simulation speed (affects calculations directly, higher numbers mean the simulation runs faster but will be less accurate)
CalcError = 0.25, -- Lee-way in units per 100u of lateral distance
HighArc = false, -- Starts with simulation pointed directly at target if false, otherwise starts pointing up and moves down
Constant = true, -- Will constantly run as long as Calculate is 1
Bulk = 8, -- Number of calculations to perform per tick
Delay = 2 -- Time after finishing before another calculation can run
Delay = 0.2 -- Time after finishing before another calculation can run
},
})

Expand All @@ -470,14 +482,14 @@ do -- Turret computers
Mass = 150,

ComputerInfo = {
ThinkTime = 0.04, -- Speed of the actual think time
ThinkTime = 0.03, -- Speed of the actual think time
MaxThinkTime = 6, -- Maximum time to spend on a simulation
DeltaTime = 0.06, -- Simulation speed (affects calculations directly, higher numbers mean the simulation runs faster but will be less accurate)
CalcError = 0.05, -- Lee-way in units per 100u of lateral distance
HighArc = true, -- Starts with simulation pointed directly at target if false, otherwise starts pointing up and moves down
Constant = false,
Bulk = 10, -- Number of calculations to perform per tick
Delay = 3, -- Time after finishing before another calculation can run
Delay = 1, -- Time after finishing before another calculation can run
},
})
end
Expand Down
14 changes: 10 additions & 4 deletions lua/entities/acf_turret/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,15 @@ do -- Spawn and Update funcs
Entity.MaxSlewRate = 0
Entity.SlewAccel = 0

Entity.MinDeg = Data.MinDeg
Entity.MaxDeg = Data.MaxDeg
Entity.HasArc = not ((Data.MinDeg == -180) and (Data.MaxDeg == 180))
if Data.Turret == "Turret-H" then
Entity.MinDeg = Data.MinDeg
Entity.MaxDeg = Data.MaxDeg
Entity.HasArc = not ((Data.MinDeg == -180) and (Data.MaxDeg == 180))
else
Entity.MinDeg = math.max(Data.MinDeg,-85)
Entity.MaxDeg = math.min(Data.MaxDeg,85)
Entity.HasArc = true
end

Entity.MotorMaxSpeed = 1
Entity.MotorGearRatio = 1
Expand Down Expand Up @@ -778,7 +784,7 @@ do -- Metamethods
function ENT:SetSoundState(State)
if State ~= self.SoundPlaying then
if State == true then
Sounds.CreateAdjustableSound(self, self.SoundPath, 0, 0)
Sounds.CreateAdjustableSound(self, self.SoundPath, 100, 0)
self.CurrentSound = self.SoundPath
else
Sounds.SendAdjustableSound(self, true)
Expand Down
48 changes: 33 additions & 15 deletions lua/entities/acf_turret_computer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,36 @@ do -- Metamethods and other important stuff
do -- Wire stuff
ACF.AddInputAction("acf_turret_computer", "Calculate", function(Entity,Value)
if Entity.Disabled then return end
if Entity.Thinking then return end

if tobool(Value) == true then
Entity:StartSimulation()
Entity:StartSimulation(false)
end
end)

ACF.AddInputAction("acf_turret_computer", "Calculate Superelevation", function(Entity,Value)
if Entity.Disabled then return end
if Entity.Thinking then return end

if tobool(Value) == true then
Entity:StartSimulation(true)
end
end)
end

do -- Simulation stuff
-- Starts fresh simulation with fresh data
function ENT:StartSimulation()
function ENT:StartSimulation(OneShot)
if Clock.CurTime < self.NextRun then return end
if not IsValid(self.Gun) then return end

local Gun = self.Gun
local BD = Gun.BulletData

if Gun.State ~= "Loaded" then return end
if BD.Type == "Empty" then return end

self.Status = "Calculating..."

local BD = Gun.BulletData

local LocalPosition = self.Inputs["Position"].Value - Gun:LocalToWorld(Gun.Muzzle)

local StartAngle = Angle(0,0,0)
Expand Down Expand Up @@ -280,7 +289,8 @@ do -- Metamethods and other important stuff
DeltaTime = self.ComputerInfo.DeltaTime,
EndTime = Clock.CurTime + self.ComputerInfo.MaxThinkTime,
LastMaxTime = self.ComputerInfo.MaxThinkTime,
StartTime = Clock.CurTime
StartTime = Clock.CurTime,
IsOneShot = OneShot
}

self.Thinking = true
Expand All @@ -302,21 +312,29 @@ do -- Metamethods and other important stuff
if not self.ComputerInfo.HighArc then
if Sim.Pos:DistToSqr(Sim.AdjustedTargetPos - Sim.StartPos) < ((((Sim.FlightDistance + (Sim.RelativeVel * ElapsedTime):Length()) / 100) * self.ComputerInfo.CalcError) ^ 2) then

WireLib.TriggerOutput(self, "Angle", Sim.StartAngle)
WireLib.TriggerOutput(self, "Elevation", Sim.StartAngle.p)
WireLib.TriggerOutput(self, "Flight Time", Sim.FlightTime)

if Sim.IsOneShot then
self:HaltSimulation("Super elevation calculated!")

return false
end

WireLib.TriggerOutput(self, "Angle", Sim.StartAngle)

if self.ComputerInfo.Constant and tobool(self.Inputs["Calculate"].Value) and IsValid(self.Gun) then
local Gun = self.Gun

Sim.AdjustedTargetPos = Sim.TargetPos + (Sim.RelativeVel * (ElapsedTime + Sim.FlightTime))

Sim.StartPos = Gun:LocalToWorld(Gun.Muzzle)

Sim.Error = Sim.Error + (Sim.AdjustedTargetPos - (Sim.StartPos + Sim.Pos))
Sim.Error = Sim.Error + (Sim.AdjustedTargetPos - (Sim.StartPos + Sim.Pos))

local LocalPosition = (Sim.TargetPos - Sim.StartPos) + Sim.Error
local LocalPosition = (Sim.TargetPos - Sim.StartPos) + Sim.Error

local AngleToTarget = LocalPosition:GetNormalized():Angle()
local AngleToTarget = LocalPosition:GetNormalized():Angle()
AngleToTarget:Normalize()

local StartAngle = Angle(AngleToTarget.p,AngleToTarget.y,0)
Expand Down Expand Up @@ -347,13 +365,13 @@ do -- Metamethods and other important stuff
return false
end
else
Sim.AdjustedTargetPos = Sim.TargetPos + (Sim.RelativeVel * (ElapsedTime + Sim.FlightTime))
Sim.AdjustedTargetPos = Sim.TargetPos + (Sim.RelativeVel * (ElapsedTime + Sim.FlightTime))

Sim.Error = Sim.Error + (Sim.AdjustedTargetPos - (Sim.StartPos + Sim.Pos))
Sim.Error = Sim.Error + (Sim.AdjustedTargetPos - (Sim.StartPos + Sim.Pos))

local LocalPosition = (Sim.TargetPos - Sim.StartPos) + Sim.Error
local LocalPosition = (Sim.TargetPos - Sim.StartPos) + Sim.Error

local AngleToTarget = LocalPosition:GetNormalized():Angle()
local AngleToTarget = LocalPosition:GetNormalized():Angle()
AngleToTarget:Normalize()

local StartAngle = Angle(AngleToTarget.p,AngleToTarget.y,0)
Expand All @@ -371,7 +389,7 @@ do -- Metamethods and other important stuff
self.SimData.LastMaxTime = self.SimData.LastMaxTime * 0.9
self.SimData.EndTime = math.max(self.SimData.EndTime,Clock.CurTime + self.SimData.LastMaxTime)

self.Thinking = true
self.Thinking = true

self.Status = "Adjusting..."
self:UpdateOverlay()
Expand Down

0 comments on commit 4829332

Please sign in to comment.