starlit  Diff

Differences From Artifact [910641ec39]:

To Artifact [e60d6be4a9]:


   907    907   			local stats = starlit.world.food.effectiveStats(fd)
   908    908   
   909    909   			return stack
   910    910   		end;
   911    911   	};
   912    912   }
   913    913   
   914         -local biointerval = 3.0
          914  +local biointerval = 1.0
   915    915   starlit.startJob('starlit:bio', biointerval, function(delta)
   916    916   	for id, u in pairs(starlit.activeUsers) do
   917         -		local p = u.pheno
   918         -		local bmr = p:trait 'metabolism' * biointerval
   919         -		-- TODO apply modifiers
          917  +		if u:effectiveStat 'health' ~= 0 then
          918  +			local bmr = u:phenoTrait 'metabolism' * biointerval
          919  +			-- TODO apply modifiers
          920  +
          921  +			local dehydration = u:phenoTrait 'dehydration' * biointerval
          922  +			-- you dehydrate faster in higher temp
          923  +			dehydration = dehydration * math.max(1, starlit.world.climate.temp(u.entity:get_pos()) / 10)
          924  +
          925  +			u:statDelta('nutrition', -bmr)
          926  +			u:statDelta('hydration', -dehydration)
          927  +
          928  +			local moralePenalty = -1 -- 1min/min
          929  +			local fatiguePenalty = 1 -- 1min/min
          930  +			local heatPenalty = 1 -- stamina regen is divided by this
          931  +
          932  +			do local warmth = u:effectiveStat 'warmth'
          933  +				local tempRange = u:species().tempRange
          934  +				local tComfMin, tComfMax = tempRange.comfort[1], tempRange.comfort[2]
          935  +				local tempDiff = 0
          936  +				if warmth < tComfMin then
          937  +					tempDiff = tComfMin - warmth
          938  +				elseif warmth > tComfMax then
          939  +					tempDiff = warmth-tComfMax
          940  +				end
          941  +-- 				print('tempDiff', tComfMin, tComfMax, tempDiff)
          942  +				local tempPenalty = tempDiff/3
          943  +				moralePenalty = moralePenalty + tempPenalty
          944  +				heatPenalty = heatPenalty + tempPenalty
          945  +			end
          946  +
          947  +			-- penalize heavy phys. activity
          948  +			local stamina, sp = u:effectiveStat 'stamina'
          949  +			fatiguePenalty = fatiguePenalty * (1 + 9*(1-sp))
          950  +
          951  +			local food = u:effectiveStat 'nutrition'
          952  +			local water = u:effectiveStat 'hydration'
          953  +			local rads = u:effectiveStat 'irradiation'
          954  +			if food < 1000 then moralePenalty = moralePenalty + (1 - (food/1000)) * 5 end
          955  +			if water < 1   then moralePenalty = moralePenalty + (1 - (water/1)) * 10 end
   920    956   
   921         -		local dehydration = p:trait 'dehydration' * biointerval
   922         -		-- you dehydrate faster in higher temp
   923         -		dehydration = dehydration * math.max(1, starlit.world.climate.temp(u.entity:get_pos()) / 10)
          957  +			if rads > 0 then
          958  +				u:statDelta('irradiation', -0.0001 * biointerval)
          959  +				local moraleDrainFac = 2^(rads / 2)
          960  +				moralePenalty = moralePenalty * moraleDrainFac
          961  +			end
   924    962   
   925         -		u:statDelta('nutrition', -bmr)
   926         -		u:statDelta('hydration', -dehydration)
   927         -
   928         -		local moralePenalty = -1 -- 1min/min
   929         -		local fatiguePenalty = 1 -- 1min/min
   930         -		local heatPenalty = 1 -- stamina regen is divided by this
          963  +			u:statDelta('morale', moralePenalty * biointerval)
          964  +			u:statDelta('fatigue', fatiguePenalty * biointerval)
   931    965   
   932         -		do local warmth = u:effectiveStat 'warmth'
   933         -			local tempRange = u:species().tempRange
   934         -			local tComfMin, tComfMax = tempRange.comfort[1], tempRange.comfort[2]
   935         -			local tempDiff = 0
   936         -			if warmth < tComfMin then
   937         -				tempDiff = math.abs(warmth-tComfMin)
   938         -			elseif warmth > tComfMax then
   939         -				tempDiff = math.abs(warmth-tComfMax)
          966  +			if food == 0 then -- starvation
          967  +				u:statDelta('health', -5*biointerval)
   940    968   			end
   941         -			moralePenalty = moralePenalty + tempDiff
   942         -			heatPenalty = heatPenalty + tempDiff
   943         -		end
   944    969   
   945         -		-- penalize heavy phys. activity
   946         -		local stamina, sp = u:effectiveStat 'stamina'
   947         -		fatiguePenalty = fatiguePenalty * (1 + 9*(1-sp))
          970  +			if water == 0 then -- dying of thirst
          971  +				u:statDelta('health', -20*biointerval)
          972  +			end
   948    973   
   949         -		local food = u:effectiveStat 'nutrition'
   950         -		local water = u:effectiveStat 'hydration'
   951         -		local rads = u:effectiveStat 'irradiation'
   952         -		if food < 1000 then moralePenalty = moralePenalty + (1 - (food/1000)) * 5 end
   953         -		if water < 1   then moralePenalty = moralePenalty + (1 - (water/1)) * 10 end
   954         -
   955         -		if rads > 0 then
   956         -			u:statDelta('irradiation', -0.0001 * biointerval)
   957         -			local moraleDrainFac = 2^(rads / 2)
   958         -			moralePenalty = moralePenalty * moraleDrainFac
   959         -		end
   960         -
   961         -		u:statDelta('morale', moralePenalty * biointerval)
   962         -		u:statDelta('fatigue', fatiguePenalty * biointerval)
   963         -
   964         -		if food == 0 then -- starvation
   965         -			u:statDelta('health', -5*biointerval)
   966         -		end
   967         -
   968         -		if water == 0 then -- dying of thirst
   969         -			u:statDelta('health', -20*biointerval)
   970         -		end
   971         -
   972         -		if sp < 1.0 then
   973         -			u:statDelta('stamina', u:effectiveStat 'staminaRegen' / heatPenalty)
          974  +			if sp < 1.0 then
          975  +				u:statDelta('stamina', u:phenoTrait('staminaRegen',1) / heatPenalty)
          976  +-- 				print('stam', u:effectiveStat 'stamina', u:phenoTrait('staminaRegen',1) / heatPenalty, heatPenalty)
          977  +			end
   974    978   		end
   975    979   	end
   976    980   end)
   977    981   
   978    982   local cbit = {
   979    983   	up   = 0x001;
   980    984   	down = 0x002;