Skip to content
Snippets Groups Projects
Commit e69e6dd7 authored by dg's avatar dg
Browse files

calendars

git-svn-id: http://svn.net-core.org/repos/t-engine4@36 51575b47-30f0-44d4-a5cc-537603b46e54
parent 2afd6200
No related branches found
No related tags found
No related merge requests found
require "engine.class"
--- Defines factions
module(..., package.seeall, class.make)
seconds_per_turn = 10
MINUTE = 60 / seconds_per_turn
HOUR = MINUTE * 60
DAY = HOUR * 24
YEAR = DAY * 365
DAY_START = HOUR * 6
--- Create a calendar
-- @param definition the file to load that returns a table containing calendar months
-- @param datestring a string to format the date when requested, in the format "%s %s %s %d %d", standing for, day, month, year, hour, minute
function _M:init(definition, datestring, start_year)
local data = dofile(definition)
self.calendar = {}
local days = 0
for _, e in ipairs(data) do
if not e[3] then e[3] = 0 end
table.insert(self.calendar, { days=days, name=e[2], length=e[1], offset=e[3] })
days = days + e[1]
end
assert(days == 365, "Calendar incomplete, days ends at "..days.." instead of 365")
self.datestring = datestring
self.start_year = start_year
end
function _M:getTimeDate(turn)
local doy, year = self:getDayOfYear(turn)
local hour, min = self:getTimeOfDay(turn)
return self.datestring:format(tostring(self:getDayOfMonth(doy)):ordinal(), self:getMonthName(doy), tostring(year):ordinal(), hour, min)
end
function _M:getDayOfYear(turn)
local d, y
d = math.floor(turn / self.DAY)
y = math.floor(d / 365)
d = math.floor(d % 365)
print(turn, d, y, self.YEAR)
return d, self.start_year + y
end
function _M:getTimeOfDay(turn)
local hour, min
min = math.floor((turn % self.DAY) / self.MINUTE)
hour = math.floor(min / 60)
min = math.floor(min % 60)
print(turn, hour, min, self.HOUR)
return hour, min
end
function _M:getMonthNum(dayofyear)
local i = #self.calendar
-- Find the period name
while ((i > 1) and (dayofyear < self.calendar[i].days)) do
i = i - 1
end
return i
end
function _M:getMonthName(dayofyear)
local month = self:getMonthNum(dayofyear)
return self.calendar[month].name
end
function _M:getDayOfMonth(dayofyear)
local month = self:getMonthNum(dayofyear)
return dayofyear - self.calendar[month].days + 1 + self.calendar[month].offset
end
function _M:getMonthLength(dayofyear)
local month = self:getMonthNum(dayofyear)
return self.calendar[month].length
end
......@@ -10,6 +10,7 @@ module(..., package.seeall, class.inherit(engine.GameEnergyBased))
--- See engine.GameEnergyBased
function _M:init(keyhandler, energy_to_act, energy_per_tick)
self.turn = 0
self.paused = false
engine.GameEnergyBased.init(self, keyhandler, energy_to_act, energy_per_tick)
end
......@@ -17,5 +18,6 @@ end
function _M:tick()
while not self.paused do
engine.GameEnergyBased.tick(self)
self.turn = self.turn + 1
end
end
function string.ordinal(number)
local suffix = "th"
number = tonumber(number)
if number == 1 then
suffix = "st"
elseif number == 2 then
suffix = "nd"
elseif number == 3 then
suffix = "rd"
end
return number..suffix
end
function string.capitalize(str)
if #str > 1 then
return string.upper(str:sub(1, 1))..str:sub(2)
......
......@@ -3,6 +3,7 @@ require "engine.GameTurnBased"
require "engine.KeyCommand"
require "engine.LogDisplay"
local Tooltip = require "engine.Tooltip"
local Calendar = require "engine.Calendar"
local Zone = require "engine.Zone"
local Map = require "engine.Map"
local Level = require "engine.Level"
......@@ -24,6 +25,8 @@ function _M:run()
Map:setViewPort(self.w, math.floor(self.h * 0.80), 16, 16)
Map:setViewerFaction("players")
self.calendar = Calendar.new("/data/calendar_rivendell.lua", "Today is the %s %s of the %s year of the Fourth Age of Middle-earth.\nThe time is %02d:%02d.", 122)
self.zone = Zone.new("ancient_ruins")
self.tooltip = engine.Tooltip.new(nil, nil, {255,255,255}, {30,30,30})
......@@ -154,7 +157,7 @@ function _M:setupCommands()
end,
_GREATER = {"alias", "_LESS"},
-- Toggle tactical displau
[{"_t","ctrl"}] = function()
[{"_t","alt"}] = function()
if Map.view_faction then
Map:setViewerFaction(nil)
self.log("Tactical dislpay disabled.")
......@@ -165,6 +168,10 @@ function _M:setupCommands()
self.level.map.changed = true
end
end,
-- Toggle tactical displau
[{"_t","ctrl"}] = function()
self.log(self.calendar:getTimeDate(self.turn))
end,
}
self.key:setCurrent()
end
return {
{ 1, "Yestarë", },
{ 54, "Tuilë" },
{ 72, "Lairë" },
{ 54, "Yávië" },
{ 3, "Enderi" },
{ 54, "Quellë" },
{ 72, "Hrívë" },
{ 54, "Coirë" },
{ 1, "Mettarë" },
}
name = "Tales of Middle Earth"
name = "Tales of Middle Earth: 4th Age"
short_name = "tome"
author = { "DarkGod", "darkgod@t-o-m-e.net" }
description = [[
Morgoth is banned in the Void, Sauron has been vanquished, the One Ring destroyed.
The nations of Men, Dwarves, Elves and Hobbits are freed from the tyranny of the Rings.
This is a golden age, or at least it should be...
Trouble is brewing in the east. Rumours in Lake-town near the Lonely Mountain have it
that some power is growing in the far east, orc have started to multiply in sigthings.
However you do not think this concerns you, you set out to discover the old, explore
old places, venture into the unknown for wealth and glory.
But beware, the eastern troubles could be yours all too soon...
]]
version = {4,0,0}
starter = "mod.load"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment