Skip to content

Instantly share code, notes, and snippets.

@Larkenx
Last active December 30, 2020 23:48
Show Gist options
  • Save Larkenx/7428da37089414eb49b53a88a0e3e828 to your computer and use it in GitHub Desktop.
Save Larkenx/7428da37089414eb49b53a88a0e3e828 to your computer and use it in GitHub Desktop.
Space Exploration Hauler Moon Logic Lua Script
-- Useful Signal Constants
CRUSHED_NAQ_SIGNAL = "se-naquium-ore-crushed"
NAQ_ORE_SIGNAL = "se-naquium-ore"
ARCOSPHERE_SIGNAL = "se-arcosphere"
VOID_PROBE_SIGNAL = "se-void-probe-data"
DISTANCE_SIGNAL = "signal-distance"
ROCKET_FUEL_SIGNAL = "se-liquid-rocket-fuel"
ANTIMATTER_FUEL_SIGNAL = "se-antimatter-stream"
ACCUMULATOR_CHARGE_SIGNAL = "kr-energy-2"
GREEN_SIGNAL = "signal-green"
RED_SIGNAL = "signal-red"
DESTINATION_PLANET_ORBIT_SIGNAL = "se-planet-orbit"
DESTINATION_ASTERIOID_FIELD_SIGNAL = "se-asteroid-field"
LAUNCH_SPACE_SIGNAL = "se-spaceship-launch"
SPEED_SIGNAL = "signal-speed"
ANCHOR_USING_SPACESHIP_LEFT_CLAMP_SIGNAL = "se-anchor-using-left-clamp"
ANCHOR_USING_SPACESHIP_RIGHT_CLAMP_SIGNAL = "se-anchor-using-right-clamp"
ANCHOR_TO_DESTINATION_LEFT_CLAMP_SIGNAL = "se-anchor-to-left-clamp"
ANCHOR_TO_DESTINATION_RIGHT_CLAMP_SIGNAL = "se-anchor-to-right-clamp"
-- Signal Distance Constants
ARRIVED_AT_DESTINATION = -1
ANCHORED_DESTINATION = -2
NO_DESTINATION_SET = -3
-- Naq Hauler Script
nauvisOrbit = 588
naqOutpost = 1100
maxSpeed = 300
numberOfBuffer4Warehouse = 9
numberOfBuffer6WareHouse = 2
numberOfInventorySlots = (numberOfBuffer6WareHouse * 512) +
(numberOfBuffer4Warehouse * 256)
naqStackSize = 10
naqQuantity = red[NAQ_ORE_SIGNAL] == nil and 0 or red[NAQ_ORE_SIGNAL]
currentLocation = nil
currentDistanceFromTarget = red[DISTANCE_SIGNAL]
speed = red[SPEED_SIGNAL]
fuel = red[ANTIMATTER_FUEL_SIGNAL]
accumulatorCharge = red[ACCUMULATOR_CHARGE_SIGNAL]
possibleArrivedLocationSignals = {
DESTINATION_ASTERIOID_FIELD_SIGNAL, DESTINATION_PLANET_ORBIT_SIGNAL
}
for k, signal in pairs(possibleArrivedLocationSignals) do
local possibleCurrentLocationValue = red[signal]
if possibleCurrentLocationValue ~= 0 then
currentLocation = possibleCurrentLocationValue
break
end
end
-- Thresholds
minFullFuel = 300000
minNaqQuantity = naqStackSize * numberOfInventorySlots
minAccumulatorCharge = 98
delay = 60 * 10
-- debug = true
-- Reset output signals
out = {}
function shouldLeaveOutpost() return naqQuantity >= minNaqQuantity end
function shouldLeaveOrbitDepot() return naqQuantity == 0 and fuel >= minFullFuel end
function shouldLaunch()
return (shouldLeaveOrbitDepot() or shouldLeaveOutpost()) and speed ==
ANCHORED_DESTINATION and var["destination"] ~= currentLocation
end
-- Decide which destination we want to set
if shouldLeaveOutpost() then
var["destination"] = nauvisOrbit
out = {[DESTINATION_PLANET_ORBIT_SIGNAL] = nauvisOrbit}
elseif shouldLeaveOrbitDepot() then
var["destination"] = naqOutpost
out = {[DESTINATION_ASTERIOID_FIELD_SIGNAL] = naqOutpost}
end
if shouldLaunch() then out[LAUNCH_SPACE_SIGNAL] = 1 end
if (var["destination"] == nauvisOrbit and currentDistanceFromTarget ~=
ANCHORED_DESTINATION and currentLocation == nauvisOrbit) then
out[ANCHOR_USING_SPACESHIP_RIGHT_CLAMP_SIGNAL] = 4
out[ANCHOR_TO_DESTINATION_LEFT_CLAMP_SIGNAL] = 4
end
if (var["destination"] == naqOutpost and currentDistanceFromTarget ~=
ANCHORED_DESTINATION and currentLocation == naqOutpost) then
out[ANCHOR_USING_SPACESHIP_RIGHT_CLAMP_SIGNAL] = 4
out[ANCHOR_TO_DESTINATION_LEFT_CLAMP_SIGNAL] = 1100
end
-- have reached the naq outpost and anchored, so we should pull arcospheres and deep space probe data into buffers
if (var["destination"] == naqOutpost and currentLocation ~= nauvisOrbit) then
out[ARCOSPHERE_SIGNAL] = 48
out[VOID_PROBE_SIGNAL] = 2400
end
out[SPEED_SIGNAL] = math.floor(maxSpeed * accumulatorCharge / 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment