-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- | ||
|
||
require "/lib/stardust/power.lua" | ||
|
||
shared.energyReceptor = { } | ||
|
||
function init() | ||
rate = config.getParameter("conversionRate") | ||
end | ||
|
||
function shared.energyReceptor:receive(socket, amount, testOnly) | ||
local fuel = world.getProperty("ship.fuel") | ||
local maxFuel = world.getProperty("ship.maxFuel") | ||
if type(fuel) ~= "number" or type(maxFuel) ~= "number" then return 0 end -- inactive on non-ship worlds | ||
local result = math.min(amount, (maxFuel - fuel) * rate) | ||
if not testOnly then -- commit | ||
world.setProperty("ship.fuel", math.min(fuel + (result / rate), maxFuel)) | ||
end | ||
return result | ||
end | ||
|
||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ // -*- grammar-ext: json -*- | ||
"objectName" : "startech:ftlplug", | ||
"rarity" : "Legendary", | ||
|
||
"shortdescription" : "Erchius Resonator", | ||
"description" : "Fuels a ship's FTL drive with fluxpulse. ^yellow;Power hungry.^reset;", | ||
"category" : "power.transport", | ||
"price" : 500, | ||
"health" : 5.73, | ||
|
||
"inventoryIcon" : [ | ||
{ "image" : "ftlplug.png" } | ||
], | ||
|
||
"orientations" : [ | ||
{ | ||
"image" : "ftlplug.png", | ||
"imagePosition" : [-8, -8], | ||
|
||
"spaces" : [ [0, 0], [-1, 0], [1, 0], [0, -1], [0, 1] ], | ||
"anchors" : [ "background" ] | ||
} | ||
], | ||
|
||
"scripts" : [ "ftlplug.lua" ], | ||
"scriptDelta" : 0, | ||
|
||
"conversionRate" : 5000, // FP per fuel unit | ||
|
||
"inputNodes" : [ [0, 0] ] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ // -*- grammar-ext: json -*- | ||
"input" : [ | ||
{ "item" : "durasteelbar", "count" : 15 }, | ||
{ "item" : "silverbar", "count" : 5 }, | ||
{ "item" : "startech:resonitebar", "count" : 1 }, | ||
{ "item" : "supermatter", "count" : 5 }, | ||
{ "item" : "liquidfuel", "count" : 250 } | ||
], | ||
"output" : { "item" : "startech:ftlplug", "count" : 1 }, | ||
"duration" : 1, | ||
"groups" : [ "startech:tinkertable", "power", "all" ] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- | ||
|
||
require "/lib/stardust/prefabs.lua" | ||
require "/lib/stardust/power.lua" | ||
require "/lib/stardust/network.lua" | ||
|
||
iou = { } -- table of promises for sent power | ||
commit = 0 -- how much of the battery has been committed | ||
baseDelta = 15 -- ticks between updates while active | ||
idleDelta = 60 -- ticks between updates while idle (no charge) | ||
|
||
function init() | ||
local cfg = config.getParameter("batteryStats") | ||
battery = prefabs.power.battery(cfg.capacity, cfg.ioRate):hookUp():autoSave() | ||
range = config.getParameter("tileRange") | ||
packetSize = cfg.ioRate | ||
script.setUpdateDelta(baseDelta) | ||
end | ||
|
||
function update() | ||
local active = false | ||
for k, p in pairs(iou) do | ||
if p:finished() then | ||
if p:succeeded() then | ||
local taken = p:result() | ||
battery.state.energy = battery.state.energy - taken | ||
if taken > 0 then active = true end | ||
end | ||
commit = commit - packetSize | ||
iou[k] = nil | ||
end | ||
end | ||
|
||
if battery.state.energy > commit + packetSize then -- only if more exists than committed | ||
local pl = world.playerQuery(entity.position(), range) | ||
for _, p in pairs(pl) do | ||
local ps = math.min(battery.state.energy - commit, packetSize) | ||
if ps <= 0 then break end -- no energy to give | ||
--active = true | ||
totalGiven = ps | ||
commit = commit + ps | ||
iou[{ }] = world.sendEntityMessage(p, "playerext:fillEquipEnergyAsync", ps, baseDelta) | ||
end | ||
end | ||
|
||
-- slow updates when not actively charging | ||
script.setUpdateDelta(active and baseDelta or idleDelta) | ||
|
||
--object.say(string.format("energy: %0.2f\ncommit: %0.2f\nactive: %s", battery.state.energy, commit, active and "y" or "n")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ // -*- grammar-ext: json -*- | ||
"objectName" : "startech:wirelesscharger", | ||
"rarity" : "Legendary", | ||
|
||
"shortdescription" : "Resonite Transmitter", | ||
"description" : "Charges nearby players' worn fluxpulse equipment wirelessly, in a radius of ^green;25m^reset;.", | ||
"category" : "power.transport", | ||
"price" : 500, | ||
"health" : 5.73, | ||
|
||
"inventoryIcon" : [ | ||
{ "image" : "wirelesscharger.png" } | ||
], | ||
|
||
"orientations" : [ | ||
{ | ||
"image" : "wirelesscharger.png", | ||
"imagePosition" : [-8, -8], | ||
|
||
"spaces" : [ [0, 0], [-1, 0], [1, 0], [0, -1], [0, 1] ], | ||
"anchors" : [ "background" ] | ||
} | ||
], | ||
|
||
"scripts" : [ "wirelesscharger.lua" ], | ||
"scriptDelta" : 5, | ||
|
||
"batteryStats" : { | ||
"capacity" : 25000, | ||
"ioRate" : 1000 | ||
}, | ||
"tileRange" : 50, | ||
|
||
"inputNodes" : [ [0, 0] ] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ // -*- grammar-ext: json -*- | ||
"input" : [ | ||
{ "item" : "durasteelbar", "count" : 15 }, | ||
{ "item" : "silverbar", "count" : 5 }, | ||
{ "item" : "wire", "count" : 25 }, | ||
{ "item" : "startech:resonitebar", "count" : 1 }, | ||
{ "item" : "supermatter", "count" : 1 } | ||
], | ||
"output" : { "item" : "startech:wirelesscharger", "count" : 1 }, | ||
"duration" : 1, | ||
"groups" : [ "startech:tinkertable", "power", "all" ] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters