starlit  Diff

Differences From Artifact [aee7410825]:

To Artifact [43bf528964]:


    63     63   	end;
    64     64   	__index = {
    65     65   		pullPersona = function(self)
    66     66   			-- if later records are added in public updates, extend this function to merge them
    67     67   			-- into one object
    68     68   			local s = userStore(self.entity)
    69     69   			self.persona = s.read 'persona'
           70  +			self.pheno = starlit.world.species.pheno(self.persona.species, self.persona.speciesVariant)
    70     71   		end;
    71     72   		pushPersona = function(self)
    72     73   			local s = userStore(self.entity)
    73     74   			s.write('persona', self.persona)
    74     75   		end;
    75     76   		uiColor = function(self) return lib.color {hue=238,sat=.5,lum=.5} end;
    76     77   		statDelta = function(self, stat, d, cause, abs)
................................................................................
    96     97   			end
    97     98   			self:updateHUD()
    98     99   			-- TODO trigger relevant animations?
    99    100   		end;
   100    101   		lookupSpecies = function(self)
   101    102   			return starlit.world.species.lookup(self.persona.species, self.persona.speciesVariant)
   102    103   		end;
   103         -		phenoTrait = function(self, trait)
   104         -			local s,v = self:lookupSpecies()
   105         -			return v.traits[trait] or s.traits[trait] or 0
          104  +		phenoTrait = function(self, trait, dflt)
          105  +-- 			local s,v = self:lookupSpecies()
          106  +-- 			return v.traits[trait] or s.traits[trait] or 0
          107  +			return self.pheno:trait(trait, dflt)
   106    108   		end;
   107    109   		statRange = function(self, stat) --> min, max, base
   108    110   			return starlit.world.species.statRange(
   109    111   				self.persona.species, self.persona.speciesVariant, stat)
   110    112   		end;
   111    113   		effectiveStat = function(self, stat)
   112    114   			local val
................................................................................
   345    347   					local hot = self:effectiveStat 'irradiation'
   346    348   					local color = self:uiColor():lerp(lib.color(0.3, 1, 0), math.min(1, hot/5))
   347    349   					local txt = string.format("%sGy", math.floor(hot))
   348    350   					return (hot/5), txt, color
   349    351   				end;
   350    352   			}
   351    353   			self.hud.elt.crosshair = self:attachImage {
   352         -				name = 'crosshair ';
          354  +				name = 'crosshair';
   353    355   				tex = '';
   354    356   				pos = {x=.5, y=.5};
   355    357   				scale = {x=1,y=1};
   356    358   				ofs = {x=0, y=0};
   357    359   				align = {x=0, y=0};
   358    360   				update = function(user, set)
   359    361   					local imgs = {
................................................................................
   375    377   				align = {x=0, y=-1};
   376    378   				z = -1;
   377    379   				update = function(user, set)
   378    380   					set('text', hudAdjustBacklight(hudCenterBG):render())
   379    381   				end;
   380    382   			};
   381    383   		end;
          384  +		-- horrible horrible HACK
          385  +		setModeHand = function(self)
          386  +			local inv = self.entity:get_inventory()
          387  +			local hnd
          388  +			if self.actMode == 'off'
          389  +				then hnd = ItemStack('starlit:_hand_dig')
          390  +				else hnd = ItemStack()
          391  +			end
          392  +			inv:set_stack('hand', 1, hnd)
          393  +		end;
   382    394   		onModeChange = function(self, oldMode, silent)
   383    395   			self.hud.elt.crosshair.update()
   384    396   			if not silent then
   385    397   				local sfxt = {
   386    398   					off = 'starlit-mode-off';
   387    399   					nano = 'starlit-mode-nano';
   388    400   					psi = 'starlit-mode-psi';
   389    401   					weapon = 'starlit-mode-weapon';
   390    402   				}
   391    403   				local sfx = self.actMode and sfxt[self.actMode] or sfxt.off
   392    404   				self:suitSound(sfx)
          405  +				self:setModeHand()
   393    406   			end
   394    407   		end;
   395    408   		actModeSet = function(self, mode, silent)
   396    409   			if not mode then mode = 'off' end
   397    410   			local oldMode = self.actMode
   398    411   			self.actMode = mode
   399    412   			self:onModeChange(oldMode, silent)
................................................................................
   415    428   			return minetest.get_player_information(self.name)
   416    429   		end;
   417    430   		onSignup = function(self)
   418    431   			local meta = self.entity:get_meta()
   419    432   			local inv = self.entity:get_inventory()
   420    433   			-- the sizes indicated here are MAXIMA. limitations on e.g. the number of elements that may be carried are defined by your suit and enforced through callbacks and UI generation code, not inventory size
   421    434   			inv:set_size('main', 6) -- carried items and tools. main hotbar.
          435  +			inv:set_size('hand', 1) -- horrible hack to allow both tools and intrinsics
   422    436   
   423    437   			inv:set_size('starlit_suit', 1) -- your environment suit (change at wardrobe)
   424    438   			inv:set_size('starlit_cfg', 1) -- the item you're reconfiguring / container you're accessing
   425    439   
   426    440   			local scenario
   427    441   			for _, e in pairs(starlit.world.scenario) do
   428    442   				if e.id == starlit.world.defaultScenario then
................................................................................
   499    513   			self:updateSuit()
   500    514   			return true
   501    515   		end;
   502    516   		onJoin = function(self)
   503    517   			local me = self.entity
   504    518   			local meta = me:get_meta()
   505    519   			self:pullPersona()
          520  +			self:setModeHand()
   506    521   
   507    522   			-- formspec_version and real_coordinates are apparently just
   508    523   			-- completely ignored here
   509    524   			me:set_formspec_prepend [[
   510    525   				bgcolor[#00000000;true]
   511    526   				style_type[button,button_exit,image_button,item_image_button;border=false]
   512    527   				style_type[button;bgimg=starlit-ui-button-hw.png;bgimg_middle=8;content_offset=0,-2]
................................................................................
   781    796   		give = function(self, item)
   782    797   			local inv = self.entity:get_inventory()
   783    798   			local function is(grp)
   784    799   				return minetest.get_item_group(item:get_name(), grp) ~= 0
   785    800   			end
   786    801   			-- TODO notif popups
   787    802   			if is 'specialInventory' then
          803  +			--[[
   788    804   				if is 'powder' then
   789    805   					if self:naked() then return item end
   790    806   					local cans = inv:get_list 'starlit_suit_canisters'
   791    807   					if cans and next(cans) then for i, st in ipairs(cans) do
   792    808   						local lst = string.format('starlit_canister_%u_elem', i)
   793    809   						item = inv:add_item(lst, item)
   794    810   						if item:is_empty() then break end
   795    811   					end end
   796    812   					self:forSuit(function(x) x:pushCanisters(inv) end)
   797    813   				end
   798    814   				return item
          815  +				]]
   799    816   			else
   800    817   				return inv:add_item('main', item)
   801    818   			end
   802    819   		end;
   803    820   		thrustUpon = function(self, item)
   804    821   			local r = self:give(st)
   805    822   			if not r:is_empty() then
   806    823   				return minetest.add_item(self.entity:get_pos(), r)
   807    824   			end
   808    825   		end;
          826  +		consume = function(self, stack, n)
          827  +			n = n or 1
          828  +			if n == 0 then n = stack:get_count() end
          829  +			local fd = stack:take_item(n)
          830  +			local stats = starlit.world.food.effectiveStats(fd)
          831  +
          832  +			return stack
          833  +		end;
   809    834   	};
   810    835   }
   811    836   
   812    837   local biointerval = 3.0
   813    838   starlit.startJob('starlit:bio', biointerval, function(delta)
   814    839   	for id, u in pairs(starlit.activeUsers) do
          840  +		local p = u.pheno
          841  +		local bmr = p:trait 'metabolism' * biointerval
          842  +		-- TODO apply modifiers
          843  +
          844  +		local dehydration = p:trait 'dehydration' * biointerval
          845  +		-- you dehydrate faster in higher temp
          846  +		dehydration = dehydration * math.max(1, starlit.world.climate.temp(u.entity:get_pos()) / 10)
   815    847   
          848  +		u:statDelta('hunger', bmr)
          849  +		u:statDelta('thirst', dehydration)
   816    850   	end
   817    851   end)
   818    852   
   819    853   local cbit = {
   820    854   	up   = 0x001;
   821    855   	down = 0x002;
   822    856   	left = 0x004;