Seasons use 13-month calendar
This commit is contained in:
parent
562ad43736
commit
fe0b19f1c8
@ -1,9 +1,26 @@
|
||||
local DAY_LENGTH_TIME = 1200
|
||||
seasons = {}
|
||||
|
||||
seasons.months = {
|
||||
"Unuber",
|
||||
"Duober",
|
||||
"Treber",
|
||||
"Quattuorber",
|
||||
"Quinber",
|
||||
"Sexber",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
"Undecimber",
|
||||
"Duodecimber",
|
||||
"Tredecimber"
|
||||
}
|
||||
|
||||
realtest.get_day = function()
|
||||
local f = io.open(minetest.get_worldpath()..'/season', "r")
|
||||
local n
|
||||
if f then
|
||||
local n = f:read("*n")
|
||||
n = f:read("*n")
|
||||
io.close(f)
|
||||
end
|
||||
return n or 1
|
||||
@ -30,9 +47,10 @@ end
|
||||
|
||||
realtest.get_year = function()
|
||||
local f = io.open(minetest.get_worldpath()..'/season', "r")
|
||||
local y
|
||||
if f then
|
||||
f:read("*n")
|
||||
local y = f:read("*n")
|
||||
y = f:read("*n")
|
||||
io.close(f)
|
||||
end
|
||||
return y or 0
|
||||
@ -46,26 +64,53 @@ realtest.set_year = function(y)
|
||||
io.close(f)
|
||||
end
|
||||
|
||||
realtest.get_season = function()
|
||||
local day = realtest.get_day()
|
||||
if day > 0 and day < 91 then return "spring" end
|
||||
if day > 90 and day < 181 then return "summer" end
|
||||
if day > 180 and day < 241 then return "autumn" end
|
||||
if day > 240 and day < 361 then return "winter" end
|
||||
realtest.leap_year = function()
|
||||
return realtest.get_year() % 62 > 51
|
||||
end
|
||||
|
||||
local add_day = function()
|
||||
if realtest.get_day() + 1 >= 360 then
|
||||
realtest.get_season = function()
|
||||
local day = realtest.get_day()
|
||||
if day > 0 and day <= 91 then return "Spring" end
|
||||
if day > 91 and day <= 182 then return "Summer" end
|
||||
if day > 181 and day <= 273 then return "Autumn" end
|
||||
if realtest.leap_year then
|
||||
if day > 272 and day <= 371 then return "Winter" end
|
||||
else
|
||||
if day > 272 and day <= 364 then return "Winter" end
|
||||
end
|
||||
end
|
||||
|
||||
realtest.get_month = function()
|
||||
local n = math.floor(realtest.get_day() / 28)
|
||||
if n < 13 then n = n + 1 end
|
||||
return seasons.months[n], n
|
||||
end
|
||||
|
||||
realtest.get_day_of_month = function()
|
||||
local n = math.floor(realtest.get_day() / 28)
|
||||
local n2 = realtest.get_day() % 28
|
||||
if n == 13 then n2 = n2 + 28 end
|
||||
return n2
|
||||
end
|
||||
|
||||
add_day = function()
|
||||
local f
|
||||
if realtest.leap_year() then
|
||||
f = 371
|
||||
else
|
||||
f = 364
|
||||
end
|
||||
if realtest.get_day() + 1 > f then
|
||||
realtest.set_year(realtest.get_year() + 1)
|
||||
realtest.set_day(1)
|
||||
else
|
||||
realtest.set_day(realtest.get_day() + 1)
|
||||
end
|
||||
minetest.after(DAY_LENGTH_TIME, add_day)
|
||||
minetest.after(math.floor(86400 / minetest.setting_get("time_speed")), add_day)
|
||||
end
|
||||
|
||||
if minetest.setting_get("time_speed") ~= 0 then
|
||||
minetest.after(DAY_LENGTH_TIME, add_day)
|
||||
minetest.after(math.floor(86400 / minetest.setting_get("time_speed")), add_day)
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("calendar", {
|
||||
@ -73,9 +118,8 @@ minetest.register_chatcommand("calendar", {
|
||||
description = "get the calendar",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
minetest.chat_send_player(name, "Day: "..realtest.get_day())
|
||||
minetest.chat_send_player(name, "Date: "..realtest.get_month().." "..realtest.get_day_of_month()..", "..realtest.get_year())
|
||||
minetest.chat_send_player(name, "Season: "..realtest.get_season())
|
||||
minetest.chat_send_player(name, "Year: "..realtest.get_year())
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user