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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
96
97
98
99
100
101
102
103
104







105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
...
154
155
156
157
158
159
160
161


162
163
164
165
166
167
168







169
170
171
172
173
174
175
...
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
...
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
E.schematicGroups.link('starsoul_electronics:battery', {
	title = 'Battery', icon = 'starsoul-item-battery.png';
	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.";
})


-------------------------
-- batteries & dynamos --
-------------------------

................................................................................
		return fn(stack,
		          stack:get_definition()._starsoul[ty],
		          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








-- 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_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())
	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_W = dmg / 1000
	return batClass.dischargeRate - dmg_W
end);


-- E.battery.drawCurrent(bat, power, time, test) --> supply (J), wasteHeat (J)
--       bat   = battery stack
................................................................................

	if not test then
		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))))


	end

	return maxPower, 0 -- FIXME specify waste heat
end)

-- E.battery.recharge(bat, power, time) --> draw (J)
--     bat   = battery stack
................................................................................
--    time s = the amount of time available for this transaction
--    draw J = how much power was actually drawn in $time seconds
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)))


	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)))







end)

E.dynamo = { kind = {} }

E.dynamo.drawCurrent = accessor('dynamo', function(s,c,m, power, time, test)
	return c.vtable.drawCurrent(s, power, time, test)
end)
................................................................................
				{ title = 'Size', affinity = 'info';
					desc = lib.math.si('m', def.fab.size.print) };
			};
		};
		_starsoul = {
			event = {
				create = function(st, how)
					if not how.gift then -- cheap hack to make starting batteries fully charged
						E.battery.setCharge(st, 0)
					end

				end;
			};
			fab = def.fab;
			dynamo = {
				vtable = E.dynamo.kind.battery;
			};
			battery = def;
................................................................................
	end;
	__index = {
		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)
			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)
			E.chip.write(self.chip, dat)
			self.inode = nil







|







 







|
|
>
>
>
>
>
>
>



|






>
|





|







 







|
>
>







 







|
>
>






|
>
>
>
>
>
>
>







 







|

|
>







 







|







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
E.schematicGroups.link('starsoul_electronics:battery', {
	title = 'Battery', icon = 'starsoul-item-battery.png';
	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 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 --
-------------------------

................................................................................
		return fn(stack,
		          stack:get_definition()._starsoul[ty],
		          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

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_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 = 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_W = dmg / 1000
	return batClass.dischargeRate - dmg_W
end);


-- E.battery.drawCurrent(bat, power, time, test) --> supply (J), wasteHeat (J)
--       bat   = battery stack
................................................................................

	if not test then
		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))))
		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)

-- E.battery.recharge(bat, power, time) --> draw (J)
--     bat   = battery stack
................................................................................
--    time s = the amount of time available for this transaction
--    draw J = how much power was actually drawn in $time seconds
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)))
	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)))
	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)
	return c.vtable.drawCurrent(s, power, time, test)
end)
................................................................................
				{ title = 'Size', affinity = 'info';
					desc = lib.math.si('m', def.fab.size.print) };
			};
		};
		_starsoul = {
			event = {
				create = function(st, how)
					--[[if not how.gift then -- cheap hack to make starting batteries fully charged
						E.battery.setCharge(st, 0)
					end]]
					E.battery.update(st)
				end;
			};
			fab = def.fab;
			dynamo = {
				vtable = E.dynamo.kind.battery;
			};
			battery = def;
................................................................................
	end;
	__index = {
		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)
			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)
			E.chip.write(self.chip, dat)
			self.inode = nil

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

54
55
56
57
58
59
60






61
62
63
64
65
66
67
68
69
70
71
72
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	misfortune = makeChip("Sold1er0fMisf0rtune TOP Schematic Crackz REPACK", {
		{'starsoul_electronics:battery_chemical_usukwinya_mid', 0};
		{'starsoul_electronics:battery_hybrid_imperial_small', 0};
		-- ammunition
	}, {});
}








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.";

	species = 'human';
	speciesVariant = 'female';
	soul = {
		externalChannel = true; -- able to touch other souls in the spiritual realm
		physicalChannel = true; -- able to extend influence into physical realm
		damage = 1;
................................................................................
	social = {
		empire = 'workingClass';
		commune = 'metic';
	};

	startingItems = {
		suit = ItemStack('starsoul_suit:suit_survival_commune');
		suitBatteries = {ItemStack('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.
			-- E V E R Y T H I N G.
		};
................................................................................
	};
	social = {
		empire = 'lord';
	};

	startingItems = {
		suit = 'starsoul_suit:suit_survival_imperial';
		suitBatteries = {ItemStack('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
			-- husband she endures, you suffered to humor her, and made a big show of
			-- installing it your brand-new nanosuit before you fled the family seat.







>
>
>
>
>
>




|







 







|







 







|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	misfortune = makeChip("Sold1er0fMisf0rtune TOP Schematic Crackz REPACK", {
		{'starsoul_electronics:battery_chemical_usukwinya_mid', 0};
		{'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 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
		physicalChannel = true; -- able to extend influence into physical realm
		damage = 1;
................................................................................
	social = {
		empire = 'workingClass';
		commune = 'metic';
	};

	startingItems = {
		suit = ItemStack('starsoul_suit:suit_survival_commune');
		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.
			-- E V E R Y T H I N G.
		};
................................................................................
	};
	social = {
		empire = 'lord';
	};

	startingItems = {
		suit = 'starsoul_suit:suit_survival_imperial';
		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
			-- husband she endures, you suffered to humor her, and made a big show of
			-- installing it your brand-new nanosuit before you fled the family seat.

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

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
			shred = 3;
		};
		cost = {
			shredPower = 3;
		};
	};
	recover_vary = function(rng, ctx)
		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);
			}
		};







|







220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
			shred = 3;
		};
		cost = {
			shredPower = 3;
		};
	};
	recover_vary = function(rng, ctx)
		-- 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);
			}
		};