From 48293327a6d73318533ae2136dee1a7f885bdb49 Mon Sep 17 00:00:00 2001 From: LiddulBOFH <13317534+LiddulBOFH@users.noreply.github.com> Date: Mon, 20 May 2024 01:18:42 -0500 Subject: [PATCH] Ballistic computer changes, turret changes 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 --- lua/acf/core/utilities/util_cl.lua | 27 ++++++------- lua/acf/entities/turrets/turrets.lua | 30 +++++++++----- lua/entities/acf_turret/init.lua | 14 +++++-- lua/entities/acf_turret_computer/init.lua | 48 ++++++++++++++++------- 4 files changed, 75 insertions(+), 44 deletions(-) diff --git a/lua/acf/core/utilities/util_cl.lua b/lua/acf/core/utilities/util_cl.lua index 834d3707e..1aa17a723 100644 --- a/lua/acf/core/utilities/util_cl.lua +++ b/lua/acf/core/utilities/util_cl.lua @@ -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) @@ -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) @@ -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) diff --git a/lua/acf/entities/turrets/turrets.lua b/lua/acf/entities/turrets/turrets.lua index 655fff00c..531bd7c13 100644 --- a/lua/acf/entities/turrets/turrets.lua +++ b/lua/acf/entities/turrets/turrets.lua @@ -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", }, @@ -356,8 +356,8 @@ do -- Turret motors }, Torque = { - Min = 40, - Max = 800 + Min = 50, + Max = 1000 } }) end @@ -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 }, }) @@ -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 diff --git a/lua/entities/acf_turret/init.lua b/lua/entities/acf_turret/init.lua index 2fcbc8cbc..6ff8543e7 100644 --- a/lua/entities/acf_turret/init.lua +++ b/lua/entities/acf_turret/init.lua @@ -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 @@ -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) diff --git a/lua/entities/acf_turret_computer/init.lua b/lua/entities/acf_turret_computer/init.lua index 5e18c3eba..47196b845 100644 --- a/lua/entities/acf_turret_computer/init.lua +++ b/lua/entities/acf_turret_computer/init.lua @@ -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) @@ -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 @@ -302,9 +312,17 @@ 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 @@ -312,11 +330,11 @@ do -- Metamethods and other important stuff 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) @@ -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) @@ -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()