Skip to content

Commit

Permalink
Ballistic computer update
Browse files Browse the repository at this point in the history
Reduce delay between starting calculations, and increase max calculation time for direct computers
Actually allow cancelling a current calculation by setting Calculate to 0 (same for superelevation calculate), this means Calculate needs to stay at 1 to continue calculating
Add status output, so users can see part of what is going on
Add another catch for direct computers incase they skip the target position; this is probably going to lead to some inaccuracy in calculated flight time if this goes off, but this was only showing up for *very* low velocity rounds where it might be more appropriate to use an indirect computer anyway
  • Loading branch information
LiddulBOFH committed Sep 30, 2024
1 parent d81e392 commit b377cfc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lua/acf/entities/turrets/turrets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ do -- Turret computers

ComputerInfo = {
ThinkTime = 0.03, -- Speed of the actual think time
MaxThinkTime = 4, -- Maximum time to spend on a simulation
MaxThinkTime = 6, -- 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 = 0.2 -- Time after finishing before another calculation can run
Delay = 0.1 -- Time after finishing before another calculation can run
},
})

Expand All @@ -524,7 +524,7 @@ do -- Turret computers
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 = 1, -- Time after finishing before another calculation can run
Delay = 0.1, -- Time after finishing before another calculation can run
},
})
end
Expand Down
31 changes: 20 additions & 11 deletions lua/entities/acf_turret_computer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ do -- Spawn and Update funcs
local Outputs = {
"Angle (Angle the gun should point in to hit the target) [ANGLE]",
"Flight Time (The estimated time of arrival for the current round to hit the target.)",
"Status (The current status of the computer) [STRING]",
"Entity (The computer itself.) [ENTITY]"
}

Expand Down Expand Up @@ -64,7 +65,7 @@ do -- Spawn and Update funcs
Entity.Active = true

Entity.ComputerInfo = Computer.ComputerInfo
Entity.Status = ""
Entity.Status = "Ready"

Entity:HaltSimulation()

Expand Down Expand Up @@ -184,6 +185,8 @@ do -- Metamethods and other important stuff
Status = Status .. "\n" .. self.Status
end

WireLib.TriggerOutput(self, "Status", self.Status)

return Status
end
end
Expand Down Expand Up @@ -218,19 +221,21 @@ 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(false)
if not Entity.Thinking then Entity:StartSimulation(false) end
else
Entity:HaltSimulation("Halted by user")
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)
if not Entity.Thinking then Entity:StartSimulation(true) end
else
Entity:HaltSimulation("Halted by user")
end
end)
end
Expand Down Expand Up @@ -460,7 +465,7 @@ do -- Metamethods and other important stuff
if Reason then
self.Status = Reason
else
self.Status = ""
self.Status = "Ready"
end

self.NextRun = Clock.CurTime + self.ComputerInfo.Delay
Expand All @@ -483,7 +488,7 @@ do -- Metamethods and other important stuff

Sim.TotalTime = Sim.TotalTime + DeltaTime

Debug.Line(Sim.StartPos + Sim.Pos, Sim.StartPos + Sim.NextPos, 5, Color(255, 0, 0), true)
Debug.Line(Sim.StartPos + Sim.Pos, Sim.StartPos + Sim.NextPos, 5, ColorRand(false), true)

local Dir = (Sim.NextPos - Sim.Pos):GetNormalized()

Expand All @@ -506,6 +511,10 @@ do -- Metamethods and other important stuff
Debug.Cross(Sim.StartPos + Point, 15, 8, Color(255, 255, 255), true)
Debug.Cross(Sim.StartPos + Sim.NextPos, 15, 8, Color(0, 255, 0), true)

return self:AdjustSimulation()
elseif Dir:Dot((Point - Sim.NextPos):GetNormalized()) < 0 then
Debug.Cross(Sim.StartPos + Sim.Pos, 30, 8, Color(255, 0, 0), true)

return self:AdjustSimulation()
else
Sim.FlightTime = Sim.FlightTime + DeltaTime
Expand Down Expand Up @@ -549,22 +558,22 @@ do -- Metamethods and other important stuff

self:HaltSimulation("Gun unlinked!")

self:NextThink(Clock.CurTime + 0.1)
self:NextThink(Clock.CurTime + 0.05)
return true
end
else
self:NextThink(Clock.CurTime + 0.1)
self:NextThink(Clock.CurTime + 0.05)
return true
end

if self.Thinking == false then
self:NextThink(Clock.CurTime + 0.1)
self:NextThink(Clock.CurTime + 0.05)
return true
else
if Clock.CurTime > self.SimData.EndTime then
self:HaltSimulation("Took too long!")

self:NextThink(Clock.CurTime + 0.1)
self:NextThink(Clock.CurTime + self.ComputerInfo.Delay)
return true
end
end
Expand Down

0 comments on commit b377cfc

Please sign in to comment.