starlit  Check-in [467a75e0dc]

Overview
Comment:genericize impacts
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 467a75e0dc50798c83a00b86806bd58cba398d555f0b3754c4ed3eee6c73feb7
User & Date: lexi on 2024-05-03 15:31:29
Other Links: manifest | tags
Context
2024-05-03
21:00
add primitive thermal hazard LEDs; further documentation check-in: 511814aace user: lexi tags: trunk
15:31
genericize impacts check-in: 467a75e0dc user: lexi tags: trunk
13:40
ui latency/performance improvements, bugfixes check-in: f1e68eb97e user: lexi tags: trunk
Changes

Modified mods/starlit-eco/plants.lua from [f0b6b474f2] to [798314c789].

   122    122   	leaf = {
   123    123   		color = lib.color(.6, .8, .8);
   124    124   		drop = simpleDrop(2, 'starlit_eco:moondrop_petal');
   125    125   	};
   126    126   	berries = {
   127    127   		desc = "The fruits of the moondrop are not very nutritious, but their peculiar sweet-sour flavor profile makes them one of Farthest Shadow's great delicacies";
   128    128   		color = lib.color(1,0,.4);
   129         -		nourish = 10;
   130         -		hydrate = 0.05;
   131         -		taste = 1 * 60;
   132    129   		mass = 1;
          130  +		impact = starlit.type.impact {
          131  +			nutrition = 10;
          132  +			hydration = 0.05;
          133  +			taste = 1*60;
          134  +		};
   133    135   	};
   134    136   	decoration = {
   135    137   		place_on = 'starlit:greengraze';
   136    138   		fill_ratio = 0.03;
   137    139   		biomes = {'starlit:steppe', 'starlit:forest'};
   138    140   		y_min = 10;
   139    141   		y_max = 100;

Modified mods/starlit-eco/trees.lua from [9fe2b3bf5d] to [a9d406a1cb].

    58     58   })
    59     59   
    60     60   
    61     61   starlit.item.food.link('starlit_eco:lambent_pine_berry', {
    62     62   	name = 'Lambent Pine Berry';
    63     63   	desc = 'Though packed with human-compatible nutrients, these berries are almost painfully sour when eaten raw.';
    64     64   	tex = lib.image('starlit-eco-plant-berry-bunch.png'):shift{hue=180,sat=-30,lum=30}:render();
    65         -	nourish = 150;
    66         -	taste = -2 * 60;
           65  +	impact = starlit.type.impact {
           66  +		nutrition = 150;
           67  +		taste = -2 * 60;
           68  +	};
    67     69   	mass = 2;
    68     70   })
    69     71   
    70     72   starlit.item.seed.link('starlit_eco:lambent_pine_seed', {
    71     73   	name = 'Lambent Pine Seed';
    72     74   	tex = lib.image('starlit-eco-plant-seeds.png'):shift{hue=150, sat=-50, lum=80}:render();
    73     75   	grow = {kind = 'tree', id = 'starlit_eco:lambent_pine'};

Modified mods/starlit/interfaces.lua from [db0300e682] to [6c49562563].

    86     86   	flush()
    87     87   
    88     88   	for _, i in ipairs(l) do
    89     89   		local bw = w/max
    90     90   		if i.cfg then w = w - rh end
    91     91   
    92     92   		table.insert(bar, {
    93         -			kind = 'button', close = i.close;
           93  +			kind = i.img and 'contact' or 'button', close = i.close;
    94     94   			color = i.color;
    95     95   			fg = i.fg;
    96     96   			label = i.label;
    97         -			icon = i.img;
           97  +			img = i.img;
    98     98   			id = i.id;
    99     99   			w = bw, h = rh;
   100    100   		})
   101    101   		if i.cfg then 
   102    102   			table.insert(bar, {
   103    103   				kind = 'button';
   104    104   				color = i.color;
   105    105   				fg = i.fg;
   106    106   				label = "CFG";
   107         -				icon = i.img;
          107  +				img = i.img;
   108    108   				id = i.id .. '_cfg';
   109    109   				w = rh, h = rh;
   110    110   			})
   111    111   		end
   112    112   
   113    113   		if bar[max] then flush() end
   114    114   	end
................................................................................
   353    353   				local statBars = {'nutrition', 'hydration', 'fatigue', 'morale', 'irradiation', 'illness'}
   354    354   				for idx, id in ipairs(statBars) do
   355    355   					local s = starlit.world.stats[id]
   356    356   					local amt, sv = user:effectiveStat(id)
   357    357   					local min, max = starlit.world.species.statRange(user.persona.species, user.persona.speciesVariant, id)
   358    358   					local st = string.format('%s / %s', s.desc(amt, true), s.desc(max))
   359    359   					table.insert(tb, {kind = 'hztl', padding = 0.25;
   360         -						{kind = 'label', w=2, h=barh, text = s.name};
          360  +						{kind = 'label', w=2, h=barh, text = lib.str.capitalize(s.name)};
   361    361   						{kind = 'hbar',  w=4, h=barh, fac = sv, text = st, color=s.color};
   362    362   					})
   363    363   				end
   364    364   				local abilities = {
   365    365   					maneuver = {};
   366    366   					direct = {};
   367    367   					passive = {};
................................................................................
   370    370   				for i, a in pairs(user:species().abilities) do
   371    371   					local id = 'abl_'..a.id;
   372    372   					state.abilityMap[id] = a;
   373    373   					table.insert(abilities[a.powerKind], {
   374    374   						id = id;
   375    375   						label = a.name;
   376    376   						desc = a.desc;
   377         -						img = a.img;
          377  +-- 						img = a.img;
   378    378   
   379    379   						-- HACK
   380    380   						color = pptrMatch(user.power.maneuver, {ref=a}) and
   381    381   							{hue = 150, sat = 0, lum = .3} or nil;
   382    382   					});
   383    383   				end
   384    384   				for i, n in ipairs {'maneuver', 'direct', 'passive'} do

Modified mods/starlit/stats.lua from [255a217522] to [3922a2ec73].

    18     18   	end
    19     19   end
    20     20   
    21     21   local function C(h, s, l)
    22     22   	return lib.color {hue = h, sat = s or 1, lum = l or .7}
    23     23   end
    24     24   starlit.world.stats = {
    25         -	psi        = {min = 0, max = 500, base = 0, desc = U('ψ', 10), color = C(320), name = 'Numina'};
           25  +	psi        = {min = 0, max = 500, base = 0, desc = U('ψ', 10), color = C(320), name = 'numina'};
    26     26   	-- numina is measured in daψ
    27         -	warmth     = {min = -1000, max = 1000, base = 0, desc = U('°C', 10, true), color = C(5), name = 'Warmth'};
           27  +	warmth     = {min = -1000, max = 1000, base = 0, desc = U('°C', 10, true), color = C(5), name = 'warmth'};
    28     28   	-- warmth in measured in d°C
    29         -	fatigue    = {min = 0, max = 76 * 60, base = 0, desc = U('hr', 60, true), color = C(288,.3,.5), name = 'Fatigue', srzType = T.decimal};
           29  +	fatigue    = {min = 0, max = 76 * 60, base = 0, desc = U('hr', 60, true), color = C(288,.3,.5), name = 'fatigue', harm=true, srzType = T.decimal};
    30     30   	-- fatigue is measured in minutes one needs to sleep to cure it
    31         -	stamina    = {min = 0, max = 10 * 20, base = true, desc = U('m', 100), color = C(88), name = 'Stamina'};
           31  +	stamina    = {min = 0, max = 10 * 20, base = true, desc = U('m', 100), color = C(88), name = 'stamina'};
    32     32   	-- stamina is measured in how many 10th-nodes (== cm) one can sprint
    33         -	nutrition  = {min = 0, max = 8000, base = 0, desc = U('kCal', 1, true), color = C(43,.5,.4), name = 'Nutrition', srzType = T.decimal};
           33  +	nutrition  = {min = 0, max = 8000, base = 0, desc = U('kCal', 1, true), color = C(43,.5,.4), name = 'nutrition', srzType = T.decimal};
    34     34   	-- hunger is measured in kcalories one must consume to cure it. at 0, you start dying
    35         -	hydration  = {min = 0, max = 4, base = 0, desc = U('L', 1), color = C(217, .25,.4), name = 'Hydration', srzType = T.decimal};
           35  +	hydration  = {min = 0, max = 4, base = 0, desc = U('L', 1), color = C(217, .25,.4), name = 'hydration', srzType = T.decimal};
    36     36   	-- thirst is measured in L of H²O required to cure it
    37         -	morale     = {min = 0, max = 10 * 24 * 60, base = true, desc = U('hr', 60, true), color = C(0,0,.8), name = 'Morale', srzType = T.decimal};
           37  +	morale     = {min = 0, max = 10 * 24 * 60, base = true, color = C(0,0,.8), name = 'morale', srzType = T.decimal;
           38  +		desc = function(amt, excU) return lib.math.timespec(amt) end};
    38     39   	-- morale is measured in minutes. e.g. at base rate morale degrades by
    39     40   	-- 60 points every hour. morale can last up to 10 earthdays
    40         -	irradiation = {min = 0, max = 10, base = 0, desc = U('Gy', 1), color = C(141,1,.5), name = 'Irradiation', srzType = T.decimal};
           41  +	irradiation = {min = 0, max = 10, base = 0, desc = U('Gy', 1), color = C(141,1,.5), name = 'irradiation', harm=true, srzType = T.decimal};
    41     42   	-- irrad is measured is milligreys
    42     43   	-- 1Gy counters natural healing
    43     44   	-- ~3Gy counters basic nanomedicine
    44     45   	-- 5Gy causes death within two weeks without nanomedicine
    45     46   	-- radiation speeds up psi regen
    46     47   	-- morale drain doubles with each 2Gy
    47         -	illness    = {min = 0, max = 1, base = 0, desc = U('%', .01, true), color = C(71,.4,.25), name = 'Illness', srzType = T.factor};
           48  +	illness    = {min = 0, max = 1, base = 0, desc = U('%', .01, true), color = C(71,.4,.25), name = 'illness', harm=true, srzType = T.factor};
    48     49   	-- as illness increases, maximum stamina and health gain a corresponding limit
    49     50   	-- illness is increased by certain conditions, and decreases on its own as your
    50     51   	-- body heals when those conditions wear off. some drugs can lower accumulated illness
    51     52   	-- but illness-causing conditions require specific cures
    52     53   	-- illness also causes thirst and fatigue to increase proportionately
    53     54   }
           55  +
           56  +starlit.world.statOrder = {
           57  +	'health', 'stamina', 'psi', 'warmth';
           58  +
           59  +	'nutrition', 'hydration', 'irradiation';
           60  +	'illness', 'morale', 'fatigue';
           61  +}
           62  +
           63  +local impactStruct = G.struct {
           64  +	base = G.array(8, G.struct {id = T.str, val = T.decimal});
           65  +-- 	alt = G.array(8, )
           66  +}
           67  +
           68  +starlit.type.impact = lib.class {
           69  +	__name = 'starlit.type.impact';
           70  +	construct = function(p)
           71  +		-- deltaPack {
           72  +		-- 	nutrition = 5.0;
           73  +		-- 	hydration = -1;
           74  +		--		{"Taste", 'good'; {'morale', 1}};
           75  +		--		{"Narcotic", 'mixed'; {'morale', 10};
           76  +		--                          {'addiction', function(user) ... end}};
           77  +		-- 	{"Magic", 'info'; 'casts an magic spell', function(user) ... end};
           78  +		-- }
           79  +		return p
           80  +	end;
           81  +-- 	__tostring = function(me)
           82  +-- 	end;
           83  +	__index = {
           84  +		pushProps = function(me, p)
           85  +			for i,k in pairs(starlit.world.statOrder) do
           86  +				if me[k] then
           87  +					local s = starlit.world.stats[k]
           88  +
           89  +					local v = me[k]
           90  +					local good = v > 0
           91  +					if s.harm then good = not good end
           92  +					local d = s.desc(v)
           93  +					if v > 0 then d = '+' .. d end
           94  +
           95  +					table.insert(p, {
           96  +						title = lib.str.capitalize(s.name);
           97  +						affinity = good and 'good' or 'bad';
           98  +						desc = d;
           99  +					})
          100  +				end
          101  +			end
          102  +			for i,v in ipairs(me) do
          103  +				local label, aff = v[1], v[2]
          104  +				local effectStrs = {}
          105  +				for i = 3, #v do
          106  +					local t = v[i]
          107  +					local str
          108  +					if type(t) == 'table' then
          109  +						local id, amt = t[1], t[2]
          110  +						local s = starlit.world.stats[id]
          111  +						local desc = s.desc(amt)
          112  +						if amt > 0 then desc = '+' .. desc end
          113  +						str = string.format('%s to %s', desc, s.name)
          114  +					-- elseif type(v[i]) == 'function' then
          115  +					elseif type(t) == 'string' then
          116  +						str = t
          117  +					end
          118  +					if str then table.insert(effectStrs, str) end
          119  +				end
          120  +
          121  +				table.insert(p, {
          122  +					title = lib.str.capitalize(label);
          123  +					affinity = aff;
          124  +					desc = next(effectStrs) and table.concat(effectStrs, ', ') or nil;
          125  +				})
          126  +			end
          127  +		end;
          128  +		propTable = function(me)
          129  +			local t = {}
          130  +			me:pushProps(t)
          131  +			return t
          132  +		end;
          133  +		addToItem = function(me, stack, key)
          134  +			key = key or 'starlit:impact'
          135  +			local m = stack:get_meta()
          136  +			local tbl = {base={}}
          137  +			for k,v in pairs(me) do
          138  +				if type(k) == 'string' then
          139  +					tbl.base[k] = v
          140  +				end
          141  +			end
          142  +			local armored = lib.str.meta_armor(impactStruct.enc(tbl))
          143  +			m:set_string(key, armored)
          144  +			return stack
          145  +		end;
          146  +		effective = function(me, stack, key)
          147  +			key = key or 'starlit:impact'
          148  +			local c = starlit.type.impact.clone(me)
          149  +
          150  +			local m = stack:get_meta()
          151  +			if m:contains(key) then
          152  +				local tbl = impactStruct.dec(lib.str.meta_dearmor(m:get_string(key)))
          153  +				for k,v in pairs(tbl.base) do c[k] = v end
          154  +			end
          155  +
          156  +			return c
          157  +		end;
          158  +		apply = function(me, user)
          159  +			for k,v in pairs(me) do
          160  +				if starlit.world.stats[k] then
          161  +					user:statDelta(k, v)
          162  +				elseif type(k) == 'number' then
          163  +					for i = 3, #v do
          164  +						local t = v[i]
          165  +						if type(t) == 'table' then
          166  +							local id, amt = t[1], t[2]
          167  +							user:statDelta(id, amt)
          168  +						elseif type(t) == 'function' then
          169  +							t(user)
          170  +						end
          171  +					end
          172  +				end
          173  +			end
          174  +		end;
          175  +	};
          176  +}

Modified mods/vtlib/math.lua from [6a568676fe] to [54a7601a0f].

   134    134   }
   135    135   -- function fn.vlerp
   136    136   
   137    137   function fn.timespec(n)
   138    138   	if n == 0 then return '0s' end
   139    139   	if n < 0 then return '-' .. fn.timespec(n*-1) end
   140    140   
   141         -	local sec = n % 60
          141  +	local sec = math.floor(n % 60)
   142    142   	local hr = math.floor(n / 60)
   143    143   	local spec = {}
   144    144   
   145         -	if sec ~= 0 then table.insert(spec, string.format("%ss",  sec)) end
   146    145   	if hr  ~= 0 then table.insert(spec, string.format("%shr", hr))  end
          146  +	if sec ~= 0 then table.insert(spec, string.format("%ss",  sec)) end
   147    147   	return table.concat(spec, ' ')
   148    148   end
   149    149   return fn