Index: mods/starsoul-electronics/init.lua ================================================================== --- mods/starsoul-electronics/init.lua +++ mods/starsoul-electronics/init.lua @@ -72,11 +72,11 @@ description = 'Portable power storage cells are essential to all aspects of survival'; }) E.schematicGroups.link('starsoul_electronics:decayCell', { title = 'Decay Cell', icon = 'starsoul-item-decaycell.png'; - description = "Radioisotope generators can pack much more power into a smaller amount of space than conventional battery, but they can't be recharged, dump power and heat whether they're in use or not, and their power yield drop towards zero over their usable lifetime."; + description = "Radioisotope generators can pack much more power into a smaller amount of space than conventional batteries, but they can't be recharged, dump power and heat whether they're in use or not, and their power yield drops towards zero over their usable lifetime."; }) ------------------------- -- batteries & dynamos -- @@ -98,29 +98,37 @@ stack:get_meta(), ...) end end -- return a wear level that won't destroy the item -local function safeWear(fac) return math.min(math.max(fac,0),1) * 0xFFFE end -local function safeWearToFac(w) return w/0xFFFE end +-- local function safeWear(fac) return math.min(math.max(fac,0),1) * 0xFFFE end +-- local function safeWearToFac(w) return w/0xFFFE end + +E.battery.update = accessor('battery', function(stack, batClass, meta) + -- local cap = E.battery.capacity(stack) + local charge = meta:get_float 'starsoul_electronics:battery_charge' + meta:set_string('count_meta', string.format('%s%%', math.floor(charge * 100))) + meta:set_int('count_alignment', bit.lshift(3, 2) + 2) +end) -- E.battery.capacity(bat) --> charge (J) E.battery.capacity = accessor('battery', function(stack, batClass, meta) - local dmg = meta:get_int('starsoul_electronics:battery_degrade') -- µJ/μW + local dmg = meta:get_int 'starsoul_electronics:battery_degrade' -- µJ/μW local dmg_J = dmg / 1000 return (batClass.capacity - dmg_J) end) -- E.battery.charge(bat) --> charge (J) E.battery.charge = accessor('battery', function(stack, batClass, meta) - local fac = 1 - safeWearToFac(stack:get_wear()) + local fac = meta:get_float 'starsoul_electronics:battery_charge' + -- local fac = 1 - safeWearToFac(stack:get_wear()) return E.battery.capacity(stack) * fac end) -- E.battery.dischargeRate(bat) --> dischargeRate (W) E.battery.dischargeRate = accessor('battery', function(stack, batClass, meta) - local dmg = meta:get_int('starsoul_electronics:battery_degrade') -- µJ/μW + local dmg = meta:get_int 'starsoul_electronics:battery_degrade' -- µJ/μW local dmg_W = dmg / 1000 return batClass.dischargeRate - dmg_W end); @@ -140,11 +148,13 @@ local degrade = m:get_int 'starsoul_electronics:battery_degrade' or 0 degrade = degrade + maxPower * bc.decay -- for each joule of power drawn, capacity degrades by `decay` J -- this should ordinarily be on the order of mJ or smaller m:set_int('starsoul_electronics:battery_degrade', degrade) - s:set_wear(safeWear(1 - (ch / E.battery.capacity(s)))) + -- s:set_wear(safeWear(1 - (ch / E.battery.capacity(s)))) + m:set_float('starsoul_electronics:battery_charge', ch / E.battery.capacity(s)) + E.battery.update(s) end return maxPower, 0 -- FIXME specify waste heat end) @@ -156,18 +166,27 @@ E.battery.recharge = accessor('battery', function(s, bc, m, power, time) local ch = E.battery.charge(s) local cap = E.battery.capacity(s) local maxPower = math.min(E.battery.dischargeRate(s)*time, power) local total = math.min(ch + maxPower, cap) - s:set_wear(safeWear(1 - (total/cap))) + -- s:set_wear(safeWear(1 - (total/cap))) + m:set_float('starsoul_electronics:battery_charge', total/cap) + E.battery.update(s) return maxPower, 0 -- FIXME end) E.battery.setCharge = accessor('battery', function(s, bc, m, newPower) local cap = E.battery.capacity(s) local power = math.min(cap, newPower) - s:set_wear(safeWear(1 - (power/cap))) + -- s:set_wear(safeWear(1 - (power/cap))) + m:set_float('starsoul_electronics:battery_charge', power/cap) + E.battery.update(s) +end) +E.battery.setChargeF = accessor('battery', function(s, bc, m, newPowerF) + local power = math.min(1.0, newPowerF) + m:set_float('starsoul_electronics:battery_charge', power) + E.battery.update(s) end) E.dynamo = { kind = {} } E.dynamo.drawCurrent = accessor('dynamo', function(s,c,m, power, time, test) @@ -209,13 +228,14 @@ }; }; _starsoul = { event = { create = function(st, how) - if not how.gift then -- cheap hack to make starting batteries fully charged + --[[if not how.gift then -- cheap hack to make starting batteries fully charged E.battery.setCharge(st, 0) - end + end]] + E.battery.update(st) end; }; fab = def.fab; dynamo = { vtable = E.dynamo.kind.battery; @@ -834,11 +854,11 @@ read = function(self) local dat = E.chip.read(self.chip) return dat.files[self.inode] end; write = function(self,data) - print('writing', self.chip, self.inode) + -- print('writing', self.chip, self.inode) return E.chip.fileWrite(self.chip, self.inode, data) end; erase = function(self) local dat = E.chip.read(self.chip) table.remove(dat.files, self.inode) Index: mods/starsoul-scenario/init.lua ================================================================== --- mods/starsoul-scenario/init.lua +++ mods/starsoul-scenario/init.lua @@ -56,15 +56,21 @@ {'starsoul_electronics:battery_hybrid_imperial_small', 0}; -- ammunition }, {}); } +local battery = function(name) + local s = ItemStack(name) + starsoul.mod.electronics.battery.setChargeF(s, 1.0) + return s +end + table.insert(scenario, { id = 'starsoul_scenario:imperialExpat'; name = 'Imperial Expat'; - desc = "Hoping to escape a miserable life deep in the grinding gears of the capitalist machine for the bracing freedom of the frontier, you sought entry as a colonist to the new Commune world of Thousand Petal. Fate -- which is to say, terrorists -- intervened, and you wound up stranded on Farthest Shadow with little more than the nanosuit on your back, ship blown to tatters and your soul thoroughly mauled by the explosion of some twisted alien artifact -- which SOMEONE neglected to inform you your ride would be carrying.\nAt least you got some nifty psionic powers out of this whole clusterfuck. Hopefully they're safe to use."; + desc = "Hoping to escape a miserable life deep in the grinding gears of the capitalist machine for the bracing freedom of the frontier, you sought entry as a colonist to the new Commune world of Thousand Petal. Fate -- which is to say, terrorists -- intervened, and you wound up stranded on Farthest Shadow with little more than the nanosuit on your back, ship blown to tatters and your soul thoroughly mauled by the explosion of a twisted alien artifact -- which SOMEONE neglected to inform you your ride would be carrying.\nAt least you got some nifty psionic powers out of this whole clusterfuck. Hopefully they're safe to use."; species = 'human'; speciesVariant = 'female'; soul = { externalChannel = true; -- able to touch other souls in the spiritual realm @@ -76,11 +82,11 @@ commune = 'metic'; }; startingItems = { suit = ItemStack('starsoul_suit:suit_survival_commune'); - suitBatteries = {ItemStack('starsoul_electronics:battery_carbon_commune_small')}; + suitBatteries = {battery 'starsoul_electronics:battery_carbon_commune_small'}; suitChips = { chipLibrary.survivalware; -- you didn't notice it earlier, but your Commune environment suit -- came with this chip already plugged in. it's apparently true -- what they say: the Commune is always prepared for everything. @@ -117,11 +123,11 @@ empire = 'lord'; }; startingItems = { suit = 'starsoul_suit:suit_survival_imperial'; - suitBatteries = {ItemStack('starsoul_electronics:battery_supercapacitor_imperial_mid')}; + suitBatteries = {battery 'starsoul_electronics:battery_supercapacitor_imperial_mid'}; suitChips = { chipLibrary.compendium; -- Mother, bless her soul, simply insisted on buying you this as a parting -- gift. "it's dangerous out there for a young man," she proclaimed as -- if she had profound firsthand experience of the matter. mindful of the Index: mods/starsoul/terrain.lua ================================================================== --- mods/starsoul/terrain.lua +++ mods/starsoul/terrain.lua @@ -222,11 +222,11 @@ cost = { shredPower = 3; }; }; recover_vary = function(rng, ctx) - print('vary!', rng:int(), rng:int(0,10)) + -- print('vary!', rng:int(), rng:int(0,10)) return starsoul.type.fab { element = { aluminum = rng:int(0,4); potassium = rng:int(0,2); calcium = rng:int(0,2);