Add Engine Controller Component

This commit is contained in:
2022-06-30 23:18:54 +01:00
parent 3a4bf205cf
commit 6cc5ed68ef
5 changed files with 38 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item identifier="flipflopcomponent" category="Electrical" scale="0.5" impactsoundtag="impact_metal_light">
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
@@ -102,4 +102,28 @@
<output name="fuel_low_out" displayname="connection.fuel_low_out" />
</ConnectionPanel>
</item>
<Item identifier="enginecontrollercomponent" category="Electrical" Tags="smallitem,logic" maxstacksize="8" scale="0.5" impactsoundtag="impact_metal_light">
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
<Sprite texture="luacomp_sprite.png" depth="0.8" sourcerect="0,0,32,32" origin="0.5,0.5" />
<Body width="32" height="24" density="30" />
<Holdable selectkey="Select" pickkey="Use" aimpos="65,-10" handle1="0,0" attachable="true" aimable="true" PickingTime="5.0" slots="Any,RightHand,LeftHand" msg="ItemMsgDetachWrench">
<RequiredItem items="wrench" type="Equipped" />
<StatusEffect type="Always" target="This" stackable="false">
<LuaHook name="enginecontrollercomponent.update" />
</StatusEffect>
</Holdable>
<ConnectionPanel selectkey="Action" canbeselected="true" msg="ItemMsgRewireScrewdriver" hudpriority="10">
<GuiFrame relativesize="0.2,0.32" minsize="400,350" maxsize="480,420" anchor="Center" style="ConnectionPanel" />
<RequiredItem items="screwdriver" type="Equipped" />
<input name="velocity_x_in" displayname="connection.velocity_x_in" />
<input name="current_velocity_x_in" displayname="connection.current_velocity_x_in" />
<input name="set_trm_target" displayname="connection.set_trm_target" />
<input name="set_trm_aggression" displayname="connection.set_trm_aggression" />
<input name="set_mode" displayname="connection.set_mode" />
<input name="set_silent" displayname="connection.set_silent" />
<output name="main_force_out" displayname="connection.force_out" />
<output name="boost_force_out" displayname="connection.boost_force_out" />
</ConnectionPanel>
</Item>
</Items>

View File

@@ -4,9 +4,10 @@ local moduleNames = {
"countercomponent",
-- "activecountercomponent",
"reactorcontrollercomponent",
"enginecontrollercomponent",
}
modPath = table.pack(...)[1] .. "/Lua/"
local modPath = table.pack(...)[1] .. "/Lua/"
for _, moduleName in ipairs(moduleNames) do
dofile(modPath .. moduleName .. ".lua")

View File

@@ -4,7 +4,7 @@ local defaultTable = {
velocity_x_in = 0,
current_velocity_x_in = 0,
set_trm_target = 20,
set_trm_aggression = 600,
set_trm_aggression = 200,
set_mode = 1,
set_silent = 0,
acceleration = 0,
@@ -25,6 +25,10 @@ local signalReceived = function(signal, connection)
local signalNum = tonumber(signal.value) or defaultTable[connection.Name]
if mem[connection.Name] == signalNum then
return
end
if connection.Name == "current_velocity_x_in" then
mem.acceleration = (signalNum - mem.current_velocity_x_in)
mem.current_velocity_x_in = signalNum
@@ -32,11 +36,6 @@ local signalReceived = function(signal, connection)
mem[connection.Name] = signalNum
end
-- Skip signals for optimization
if connection.Name ~= "velocity_x_in" then
return
end
local main_force_out
local boost_force_out
@@ -50,8 +49,7 @@ local signalReceived = function(signal, connection)
elseif mem.set_mode == 0 then
local absolute_current_velocity = math.abs(mem.current_velocity_x_in)
if mem.set_trm_target -0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then
if mem.set_trm_target - 0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then
local target_acceleration = - (absolute_current_velocity * mem.set_trm_aggression) + (mem.set_trm_target * mem.set_trm_aggression)
if math.abs(mem.velocity_x_in) > math.abs(target_acceleration) then

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<infotexts language="English" nowhitespace="false" translatedname="English">
<entityname.flipflopcomponent>Flip-Flop Component</entityname.flipflopcomponent>
<entitydescription.flipflopcomponent>Switches state when receiving 1, forces state to X when receiving -X.</entitydescription.flipflopcomponent>
@@ -14,4 +14,7 @@
<entityname.reactorcontrollercomponent>Reactor Controller Component</entityname.reactorcontrollercomponent>
<entitydescription.reactorcontrollercomponent>Automatically sets a reactor's Fission Rate and Turbine Output.</entitydescription.reactorcontrollercomponent>
<entityname.enginecontrollercomponent>Engine Controller Component</entityname.enginecontrollercomponent>
<entitydescription.enginecontrollercomponent>Sets an Engine's thrust according to the selected mode.</entitydescription.enginecontrollercomponent>
</infotexts>

View File

@@ -10,4 +10,5 @@
<Other file="%ModDir%/Lua/countercomponent.lua" />
<Other file="%ModDir%/Lua/activecountercomponent.lua" />
<Other file="%ModDir%/Lua/reactorcontrollercomponent.lua" />
<Other file="%ModDir%/Lua/enginecontrollercomponent.lua" />
</contentpackage>