-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenvironment.lua
More file actions
62 lines (55 loc) · 2.01 KB
/
Copy pathenvironment.lua
File metadata and controls
62 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local M = {}
function M.getTemperatureLevel(temperature, biomeTypes)
for _, biomeType in ipairs(biomeTypes) do
if biomeType == "nether" then
return 3 --地狱
end
end
if temperature <= 0 then
return -2 --严寒
elseif temperature < 0.35 then
return -1 --寒冷
elseif temperature < 0.85 then
return 0 --一般
elseif temperature <= 1 then
return 1 --温暖
else
return 2 --炙热
end
end
function M.getHumidityLevel(rainfall)
if rainfall <= 0.2 then
return -1 --干旱
elseif rainfall <= 0.8 then
return 0 --一般
else
return 1 --潮湿
end
end
function M.getTemperatureRange(temperatureGene, toleranceGene)
if not temperatureGene or not toleranceGene then
return nil
end
local temperatureUpperLimit, temperatureLowerLimit = temperatureGene, temperatureGene
if toleranceGene:sub(1,3) == "BOT" or toleranceGene:sub(1,3) == "UP_" then
temperatureUpperLimit = temperatureUpperLimit + tonumber(toleranceGene:sub(-1))
end
if toleranceGene:sub(1,3) == "BOT" or toleranceGene:sub(1,3) == "DOW" then
temperatureLowerLimit = temperatureLowerLimit - tonumber(toleranceGene:sub(-1))
end
return math.max(temperatureLowerLimit, -2), math.min(temperatureUpperLimit, 3)
end
function M.getHumidityRange(humidityGene, toleranceGene)
if not humidityGene or not toleranceGene then
return nil
end
local humidityUpperLimit, humidityLowerLimit = humidityGene, humidityGene
if toleranceGene:sub(1,3) == "BOT" or toleranceGene:sub(1,3) == "UP_" then
humidityUpperLimit = humidityUpperLimit + tonumber(toleranceGene:sub(-1))
end
if toleranceGene:sub(1,3) == "BOT" or toleranceGene:sub(1,3) == "DOW" then
humidityLowerLimit = humidityLowerLimit - tonumber(toleranceGene:sub(-1))
end
return math.max(humidityLowerLimit, -1), math.min(humidityUpperLimit, 1)
end
return M