Files
kOS/library/lib_capacitors.ks

52 lines
1.2 KiB
Plaintext

declare function AutoManageCapacitors{
print "start".
local capacitors to ship:partsnamedpattern("capacitor").
local lock electricity to GetTotalElectiricity().
when electricity < 100 then {
for cap in capacitors {
local capR to cap:resources[0].
if capR:amount = capR:capacity{
local discharge is cap:getmodule("DischargeCapacitor").
discharge:doaction("Discharge Capacitor", true).
wait 1.
break.
}
}
preserve.
}
when throttle = 0 then {
for cap in capacitors {
local capR to cap:resources[0].
local discharge is cap:getmodule("DischargeCapacitor").
if capR:amount = capR:capacity{
discharge:doaction("Disable Recharge", true).
}else{
discharge:doaction("Enable Recharge", true).
}
}
preserve.
}
when throttle > 0 then{
for cap in capacitors {
local capR to cap:resources[0].
local discharge is cap:getmodule("DischargeCapacitor").
discharge:doaction("Disable Recharge", true).
}
preserve.
}
}
declare function GetTotalElectiricity{
LIST RESOURCES IN res.
local e is 0.
FOR resPart IN res {
if resPart:name = "ElectricCharge" {
set e to e + resPart:amount.
}
}
return e.
}