Not a member yet? Why not Sign up today
Create an account  

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 
Passive Steam Controller(Combat, Cruise, Idle)

#1
Here's a custom script for passively managing your boiler burn rates(Combat, Cruise, and Idle burns).

It comes with two modes:

Using the existence of enemies to turn on combat burn(good fps)
or
Using the lowest distance between your craft and all the enemies(avg fps)

Code:
--Passive Steam Manager Utility
--Settings
--Which AI mainframe to get the target from
mainframeIndex = 0
-- if the enemy is below this range go into high alert, use combat_burn
--Format x * x where x is the real distance in meters
--Reasoning: Efficiency gains by not calling math.sqrt in live calc
critical_distance = 2048 * 2048

--Boiler settings only 0.0-1.0
combat_burn = 1.0
cruise_burn = 0.5
idle_burn = 0
--Simple check if an enemy exists to turn on combat burn, higher fps
--Set to 0 if using lowest distance of all enemies
use_existence_of_enemies = 1

--water = 0 land = 1 air = 2 -- make sure this is set correctly
craft_mode = 0

--how often checks are made, higher numbers are better for fps, but less responsive
pollRate = 1

--do not change anything below this point
--Yes, this is an intentional hard coding for perf boost
--boiler_type = 17 --special code denoting boiler controller
--maindrive_id = 8 --special code denoting primary drive of craft
itime = 0

--2D Planar Distance -- using square distance instead of sqr root for perf
function D2(x1,z1,x2,z2)
  return (((x1-x2)*(x1-x2)) + ((z1-z2)*(z1-z2)))
end

function Update(I)
    if itime >= pollRate then
        itime = 0
        -- arbitrary high number to find min range
        local lowest_distance = 2147483647
        if use_existence_of_enemies == 0 then
            local craft_pos = I:GetConstructPosition()
            --Get min distance among all enemies
            for g = 0, I:GetNumberOfTargets(mainframeIndex)-1 do
                local targ = I:GetTargetInfo(mainframeIndex, g)
                --Accessing using [] instead of Position.x is faster
                local distance = D2(targ.Position[1], targ.Position[3], craft_pos[1], craft_pos[3])
                if distance < lowest_distance then
                    lowest_distance = distance
                end
            end
        end
        --Determine burn rate
        local targ = I:GetTargetInfo(mainframeIndex, 0)
        if targ.Valid and lowest_distance < critical_distance
            and use_existence_of_enemies == 0 then
            I:Component_SetFloatLogicAll(17, combat_burn)
        elseif targ.Valid and use_existence_of_enemies == 1 then
            I:Component_SetFloatLogicAll(17, combat_burn)
        else
            m_mode = I:GetAIMovementMode(mainframeIndex)
            if m_mode == "Fleet" or m_mode == "Manual" then
                I:Component_SetFloatLogicAll(17, cruise_burn)
            else
                        I:Component_SetFloatLogicAll(17, idle_burn)
            end
        end
    end
    itime = itime + 1
end

*Updated for and tested on 2.4.4.11

Feel free to edit, insert, or do whatever you want with the code.
Reply



Messages In This Thread
Passive Steam Controller(Combat, Cruise, Idle) - by SLK18 - 2018-12-17, 04:39 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)