starlit  Check-in [6469428393]

Overview
Comment:fix batteries, silence debug noise
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6469428393da9f64c77ec8e8735e025dc4d26e02f4892dba09a31c42c159bdcd
User & Date: lexi on 2024-03-29 22:43:49
Other Links: manifest | tags
Context
2024-04-29
22:49
rename again check-in: 187bf04c87 user: lexi tags: trunk
2024-03-29
22:43
fix batteries, silence debug noise check-in: 6469428393 user: lexi tags: trunk
20:50
initial commit check-in: abe3882d1c user: lexi tags: trunk
Changes

Modified mods/starsoul-electronics/init.lua from [e59f2eda8d] to [4ca9d32d80].

    70     70   E.schematicGroups.link('starsoul_electronics:battery', {
    71     71   	title = 'Battery', icon = 'starsoul-item-battery.png';
    72     72   	description = 'Portable power storage cells are essential to all aspects of survival';
    73     73   })
    74     74   
    75     75   E.schematicGroups.link('starsoul_electronics:decayCell', {
    76     76   	title = 'Decay Cell', icon = 'starsoul-item-decaycell.png';
    77         -	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.";
           77  +	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.";
    78     78   })
    79     79   
    80     80   
    81     81   -------------------------
    82     82   -- batteries & dynamos --
    83     83   -------------------------
    84     84   
................................................................................
    96     96   		return fn(stack,
    97     97   		          stack:get_definition()._starsoul[ty],
    98     98   		          stack:get_meta(), ...)
    99     99   	end
   100    100   end
   101    101   
   102    102   -- return a wear level that won't destroy the item
   103         -local function safeWear(fac) return math.min(math.max(fac,0),1) * 0xFFFE end
   104         -local function safeWearToFac(w) return w/0xFFFE end
          103  +-- local function safeWear(fac) return math.min(math.max(fac,0),1) * 0xFFFE end
          104  +-- local function safeWearToFac(w) return w/0xFFFE end
          105  +
          106  +E.battery.update = accessor('battery', function(stack, batClass, meta)
          107  +	-- local cap = E.battery.capacity(stack)
          108  +	local charge = meta:get_float 'starsoul_electronics:battery_charge'
          109  +	meta:set_string('count_meta', string.format('%s%%', math.floor(charge * 100)))
          110  +	meta:set_int('count_alignment', bit.lshift(3, 2) + 2)
          111  +end)
   105    112   
   106    113   -- E.battery.capacity(bat) --> charge (J)
   107    114   E.battery.capacity = accessor('battery', function(stack, batClass, meta)
   108         -	local dmg = meta:get_int('starsoul_electronics:battery_degrade') -- µJ/μW
          115  +	local dmg = meta:get_int 'starsoul_electronics:battery_degrade' -- µJ/μW
   109    116   	local dmg_J = dmg / 1000
   110    117   	return (batClass.capacity - dmg_J)
   111    118   end)
   112    119   
   113    120   -- E.battery.charge(bat) --> charge (J)
   114    121   E.battery.charge = accessor('battery', function(stack, batClass, meta)
   115         -	local fac = 1 - safeWearToFac(stack:get_wear())
          122  +	local fac = meta:get_float 'starsoul_electronics:battery_charge'
          123  +	-- local fac = 1 - safeWearToFac(stack:get_wear())
   116    124   	return E.battery.capacity(stack) * fac
   117    125   end)
   118    126   
   119    127   -- E.battery.dischargeRate(bat) --> dischargeRate (W)
   120    128   E.battery.dischargeRate = accessor('battery', function(stack, batClass, meta)
   121         -	local dmg = meta:get_int('starsoul_electronics:battery_degrade') -- µJ/μW
          129  +	local dmg = meta:get_int 'starsoul_electronics:battery_degrade' -- µJ/μW
   122    130   	local dmg_W = dmg / 1000
   123    131   	return batClass.dischargeRate - dmg_W
   124    132   end);
   125    133   
   126    134   
   127    135   -- E.battery.drawCurrent(bat, power, time, test) --> supply (J), wasteHeat (J)
   128    136   --       bat   = battery stack
................................................................................
   138    146   
   139    147   	if not test then
   140    148   		local degrade = m:get_int 'starsoul_electronics:battery_degrade' or 0
   141    149   		degrade = degrade + maxPower * bc.decay
   142    150   		-- for each joule of power drawn, capacity degrades by `decay` J
   143    151   		-- this should ordinarily be on the order of mJ or smaller
   144    152   		m:set_int('starsoul_electronics:battery_degrade', degrade)
   145         -		s:set_wear(safeWear(1 - (ch / E.battery.capacity(s))))
          153  +		-- s:set_wear(safeWear(1 - (ch / E.battery.capacity(s))))
          154  +		m:set_float('starsoul_electronics:battery_charge', ch / E.battery.capacity(s))
          155  +		E.battery.update(s)
   146    156   	end
   147    157   
   148    158   	return maxPower, 0 -- FIXME specify waste heat
   149    159   end)
   150    160   
   151    161   -- E.battery.recharge(bat, power, time) --> draw (J)
   152    162   --     bat   = battery stack
................................................................................
   154    164   --    time s = the amount of time available for this transaction
   155    165   --    draw J = how much power was actually drawn in $time seconds
   156    166   E.battery.recharge = accessor('battery', function(s, bc, m, power, time)
   157    167   	local ch = E.battery.charge(s)
   158    168   	local cap = E.battery.capacity(s)
   159    169   	local maxPower = math.min(E.battery.dischargeRate(s)*time, power)
   160    170   	local total = math.min(ch + maxPower, cap)
   161         -	s:set_wear(safeWear(1 - (total/cap)))
          171  +	-- s:set_wear(safeWear(1 - (total/cap)))
          172  +	m:set_float('starsoul_electronics:battery_charge', total/cap)
          173  +	E.battery.update(s)
   162    174   	return maxPower, 0 -- FIXME
   163    175   end)
   164    176   
   165    177   E.battery.setCharge = accessor('battery', function(s, bc, m, newPower)
   166    178   	local cap = E.battery.capacity(s)
   167    179   	local power = math.min(cap, newPower)
   168         -	s:set_wear(safeWear(1 - (power/cap)))
          180  +	-- s:set_wear(safeWear(1 - (power/cap)))
          181  +	m:set_float('starsoul_electronics:battery_charge', power/cap)
          182  +	E.battery.update(s)
          183  +end)
          184  +E.battery.setChargeF = accessor('battery', function(s, bc, m, newPowerF)
          185  +	local power = math.min(1.0, newPowerF)
          186  +	m:set_float('starsoul_electronics:battery_charge', power)
          187  +	E.battery.update(s)
   169    188   end)
   170    189   
   171    190   E.dynamo = { kind = {} }
   172    191   
   173    192   E.dynamo.drawCurrent = accessor('dynamo', function(s,c,m, power, time, test)
   174    193   	return c.vtable.drawCurrent(s, power, time, test)
   175    194   end)
................................................................................
   207    226   				{ title = 'Size', affinity = 'info';
   208    227   					desc = lib.math.si('m', def.fab.size.print) };
   209    228   			};
   210    229   		};
   211    230   		_starsoul = {
   212    231   			event = {
   213    232   				create = function(st, how)
   214         -					if not how.gift then -- cheap hack to make starting batteries fully charged
          233  +					--[[if not how.gift then -- cheap hack to make starting batteries fully charged
   215    234   						E.battery.setCharge(st, 0)
   216         -					end
          235  +					end]]
          236  +					E.battery.update(st)
   217    237   				end;
   218    238   			};
   219    239   			fab = def.fab;
   220    240   			dynamo = {
   221    241   				vtable = E.dynamo.kind.battery;
   222    242   			};
   223    243   			battery = def;
................................................................................
   832    852   	end;
   833    853   	__index = {
   834    854   		read = function(self)
   835    855   			local dat = E.chip.read(self.chip)
   836    856   			return dat.files[self.inode]
   837    857   		end;
   838    858   		write = function(self,data)
   839         -			print('writing', self.chip, self.inode)
          859  +			-- print('writing', self.chip, self.inode)
   840    860   			return E.chip.fileWrite(self.chip, self.inode, data)
   841    861   		end;
   842    862   		erase = function(self)
   843    863   			local dat = E.chip.read(self.chip)
   844    864   			table.remove(dat.files, self.inode)
   845    865   			E.chip.write(self.chip, dat)
   846    866   			self.inode = nil

Modified mods/starsoul-scenario/init.lua from [dcc87d6f8a] to [d3b56b60b6].

    54     54   	misfortune = makeChip("Sold1er0fMisf0rtune TOP Schematic Crackz REPACK", {
    55     55   		{'starsoul_electronics:battery_chemical_usukwinya_mid', 0};
    56     56   		{'starsoul_electronics:battery_hybrid_imperial_small', 0};
    57     57   		-- ammunition
    58     58   	}, {});
    59     59   }
    60     60   
           61  +local battery = function(name)
           62  +	local s = ItemStack(name)
           63  +	starsoul.mod.electronics.battery.setChargeF(s, 1.0)
           64  +	return s
           65  +end
           66  +
    61     67   
    62     68   table.insert(scenario, {
    63     69   	id = 'starsoul_scenario:imperialExpat';
    64     70   	name = 'Imperial Expat';
    65         -	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.";
           71  +	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.";
    66     72   
    67     73   	species = 'human';
    68     74   	speciesVariant = 'female';
    69     75   	soul = {
    70     76   		externalChannel = true; -- able to touch other souls in the spiritual realm
    71     77   		physicalChannel = true; -- able to extend influence into physical realm
    72     78   		damage = 1;
................................................................................
    74     80   	social = {
    75     81   		empire = 'workingClass';
    76     82   		commune = 'metic';
    77     83   	};
    78     84   
    79     85   	startingItems = {
    80     86   		suit = ItemStack('starsoul_suit:suit_survival_commune');
    81         -		suitBatteries = {ItemStack('starsoul_electronics:battery_carbon_commune_small')};
           87  +		suitBatteries = {battery 'starsoul_electronics:battery_carbon_commune_small'};
    82     88   		suitChips = {
    83     89   			chipLibrary.survivalware;
    84     90   			-- you didn't notice it earlier, but your Commune environment suit
    85     91   			-- came with this chip already plugged in. it's apparently true
    86     92   			-- what they say: the Commune is always prepared for everything.
    87     93   			-- E V E R Y T H I N G.
    88     94   		};
................................................................................
   115    121   	};
   116    122   	social = {
   117    123   		empire = 'lord';
   118    124   	};
   119    125   
   120    126   	startingItems = {
   121    127   		suit = 'starsoul_suit:suit_survival_imperial';
   122         -		suitBatteries = {ItemStack('starsoul_electronics:battery_supercapacitor_imperial_mid')};
          128  +		suitBatteries = {battery 'starsoul_electronics:battery_supercapacitor_imperial_mid'};
   123    129   		suitChips = {
   124    130   			chipLibrary.compendium;
   125    131   			-- Mother, bless her soul, simply insisted on buying you this as a parting
   126    132   			-- gift. "it's dangerous out there for a young man," she proclaimed as
   127    133   			-- if she had profound firsthand experience of the matter. mindful of the
   128    134   			-- husband she endures, you suffered to humor her, and made a big show of
   129    135   			-- installing it your brand-new nanosuit before you fled the family seat.

Modified mods/starsoul/terrain.lua from [cc82288cf4] to [faca82716c].

   220    220   			shred = 3;
   221    221   		};
   222    222   		cost = {
   223    223   			shredPower = 3;
   224    224   		};
   225    225   	};
   226    226   	recover_vary = function(rng, ctx)
   227         -		print('vary!', rng:int(), rng:int(0,10))
          227  +		-- print('vary!', rng:int(), rng:int(0,10))
   228    228   		return starsoul.type.fab {
   229    229   			element = {
   230    230   				aluminum  = rng:int(0,4);
   231    231   				potassium = rng:int(0,2);
   232    232   				calcium   = rng:int(0,2);
   233    233   			}
   234    234   		};