starlit  Diff

Differences From Artifact [910641ec39]:

To Artifact [e60d6be4a9]:


907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940


941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973


974
975
976
977
978
979
980
			local stats = starlit.world.food.effectiveStats(fd)

			return stack
		end;
	};
}

local biointerval = 3.0
starlit.startJob('starlit:bio', biointerval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		local p = u.pheno
		local bmr = p:trait 'metabolism' * biointerval
		-- TODO apply modifiers

		local dehydration = p:trait 'dehydration' * biointerval
		-- you dehydrate faster in higher temp
		dehydration = dehydration * math.max(1, starlit.world.climate.temp(u.entity:get_pos()) / 10)

		u:statDelta('nutrition', -bmr)
		u:statDelta('hydration', -dehydration)

		local moralePenalty = -1 -- 1min/min
		local fatiguePenalty = 1 -- 1min/min
		local heatPenalty = 1 -- stamina regen is divided by this

		do local warmth = u:effectiveStat 'warmth'
			local tempRange = u:species().tempRange
			local tComfMin, tComfMax = tempRange.comfort[1], tempRange.comfort[2]
			local tempDiff = 0
			if warmth < tComfMin then
				tempDiff = math.abs(warmth-tComfMin)
			elseif warmth > tComfMax then
				tempDiff = math.abs(warmth-tComfMax)
			end


			moralePenalty = moralePenalty + tempDiff
			heatPenalty = heatPenalty + tempDiff
		end

		-- penalize heavy phys. activity
		local stamina, sp = u:effectiveStat 'stamina'
		fatiguePenalty = fatiguePenalty * (1 + 9*(1-sp))

		local food = u:effectiveStat 'nutrition'
		local water = u:effectiveStat 'hydration'
		local rads = u:effectiveStat 'irradiation'
		if food < 1000 then moralePenalty = moralePenalty + (1 - (food/1000)) * 5 end
		if water < 1   then moralePenalty = moralePenalty + (1 - (water/1)) * 10 end

		if rads > 0 then
			u:statDelta('irradiation', -0.0001 * biointerval)
			local moraleDrainFac = 2^(rads / 2)
			moralePenalty = moralePenalty * moraleDrainFac
		end

		u:statDelta('morale', moralePenalty * biointerval)
		u:statDelta('fatigue', fatiguePenalty * biointerval)

		if food == 0 then -- starvation
			u:statDelta('health', -5*biointerval)
		end

		if water == 0 then -- dying of thirst
			u:statDelta('health', -20*biointerval)
		end

		if sp < 1.0 then
			u:statDelta('stamina', u:effectiveStat 'staminaRegen' / heatPenalty)


		end
	end
end)

local cbit = {
	up   = 0x001;
	down = 0x002;







|


|
|
|

|
|
|

|
|

|
|
|

|
|
|
|
|
|
|
|
|
>
>
|
|
|

|
|
|

|
|
|
|
|

|
|
|
|
|

|
|

|
|
|

|
|
|

|
|
>
>







907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
			local stats = starlit.world.food.effectiveStats(fd)

			return stack
		end;
	};
}

local biointerval = 1.0
starlit.startJob('starlit:bio', biointerval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		if u:effectiveStat 'health' ~= 0 then
			local bmr = u:phenoTrait 'metabolism' * biointerval
			-- TODO apply modifiers

			local dehydration = u:phenoTrait 'dehydration' * biointerval
			-- you dehydrate faster in higher temp
			dehydration = dehydration * math.max(1, starlit.world.climate.temp(u.entity:get_pos()) / 10)

			u:statDelta('nutrition', -bmr)
			u:statDelta('hydration', -dehydration)

			local moralePenalty = -1 -- 1min/min
			local fatiguePenalty = 1 -- 1min/min
			local heatPenalty = 1 -- stamina regen is divided by this

			do local warmth = u:effectiveStat 'warmth'
				local tempRange = u:species().tempRange
				local tComfMin, tComfMax = tempRange.comfort[1], tempRange.comfort[2]
				local tempDiff = 0
				if warmth < tComfMin then
					tempDiff = tComfMin - warmth
				elseif warmth > tComfMax then
					tempDiff = warmth-tComfMax
				end
-- 				print('tempDiff', tComfMin, tComfMax, tempDiff)
				local tempPenalty = tempDiff/3
				moralePenalty = moralePenalty + tempPenalty
				heatPenalty = heatPenalty + tempPenalty
			end

			-- penalize heavy phys. activity
			local stamina, sp = u:effectiveStat 'stamina'
			fatiguePenalty = fatiguePenalty * (1 + 9*(1-sp))

			local food = u:effectiveStat 'nutrition'
			local water = u:effectiveStat 'hydration'
			local rads = u:effectiveStat 'irradiation'
			if food < 1000 then moralePenalty = moralePenalty + (1 - (food/1000)) * 5 end
			if water < 1   then moralePenalty = moralePenalty + (1 - (water/1)) * 10 end

			if rads > 0 then
				u:statDelta('irradiation', -0.0001 * biointerval)
				local moraleDrainFac = 2^(rads / 2)
				moralePenalty = moralePenalty * moraleDrainFac
			end

			u:statDelta('morale', moralePenalty * biointerval)
			u:statDelta('fatigue', fatiguePenalty * biointerval)

			if food == 0 then -- starvation
				u:statDelta('health', -5*biointerval)
			end

			if water == 0 then -- dying of thirst
				u:statDelta('health', -20*biointerval)
			end

			if sp < 1.0 then
				u:statDelta('stamina', u:phenoTrait('staminaRegen',1) / heatPenalty)
-- 				print('stam', u:effectiveStat 'stamina', u:phenoTrait('staminaRegen',1) / heatPenalty, heatPenalty)
			end
		end
	end
end)

local cbit = {
	up   = 0x001;
	down = 0x002;