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

Some zones now have a (purely cosmetic) day/night cycle

The game now starts at 11h inted of midnight


git-svn-id: http://svn.net-core.org/repos/t-engine4@2722 51575b47-30f0-44d4-a5cc-537603b46e54
parent 43852ca9
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ 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, start_day)
function _M:init(definition, datestring, start_year, start_day, start_hour)
local data = dofile(definition)
self.calendar = {}
local days = 0
......@@ -47,6 +47,7 @@ function _M:init(definition, datestring, start_year, start_day)
self.datestring = datestring
self.start_year = start_year
self.start_day = start_day or 1
self.start_hour = start_hour or 8
end
function _M:getTimeDate(turn, dstr)
......@@ -57,6 +58,7 @@ end
function _M:getDayOfYear(turn)
local d, y
turn = turn + self.start_hour * self.HOUR
d = math.floor(turn / self.DAY) + (self.start_day - 1)
y = math.floor(d / 365)
d = math.floor(d % 365)
......@@ -65,6 +67,7 @@ end
function _M:getTimeOfDay(turn)
local hour, min
turn = turn + self.start_hour * self.HOUR
min = math.floor((turn % self.DAY) / self.MINUTE)
hour = math.floor(min / 60)
min = math.floor(min % 60)
......
......@@ -106,7 +106,7 @@ function _M:setZoom(zoom, tmx, tmy)
end
--- Defines the "obscure" factor of unseen map
-- By default it is 0.6, 0.6, 0.6, 1
-- By default it is 0.6, 0.6, 0.6, 0.6
function _M:setObscure(r, g, b, a)
self.color_obscure = {r, g, b, a}
-- If we are used on a real map, set it locally
......
......@@ -85,7 +85,7 @@ function _M:run()
self.player_display = PlayerDisplay.new(0, 230, 200, self.h * 0.8 - 230, {30,30,0})
self.hotkeys_display = HotkeysDisplay.new(nil, self.w * 0.5 + 30, self.h * 0.8 + 7, self.w * 0.5 - 30, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png")
self.npcs_display = ActorsSeenDisplay.new(nil, self.w * 0.5 + 30, self.h * 0.8 + 7, self.w * 0.5 - 30, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png")
self.calendar = Calendar.new("/data/calendar_allied.lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167)
self.calendar = Calendar.new("/data/calendar_allied.lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167, 11)
self.tooltip = Tooltip.new(nil, nil, {255,255,255}, {30,30,30,230})
self.tooltip2 = Tooltip.new(nil, nil, {255,255,255}, {30,30,30,230})
self.flyers = FlyingText.new()
......@@ -125,6 +125,7 @@ function _M:run()
self.real_starttime = os.time()
if self.level then self:setupDisplayMode(false, "postinit") end
if self.level and self.level.data.day_night then self.state:dayNightCycle() end
end
--- Checks if the current character is "tainted" by cheating
......@@ -665,50 +666,8 @@ function _M:onTurn()
-- The following happens only every 10 game turns (once for every turn of 1 mod speed actors)
if self.turn % 10 ~= 0 then return end
-- Day/Night cycle, not worknig properly yet
--[[
if false then
local doTint = function (from, to, amount)
local tint = {r = 0, g = 0, b = 0}
tint.r = (from.r * (1 - amount) + to.r * amount)
tint.g = (from.g * (1 - amount) + to.g * amount)
tint.b = (from.b * (1 - amount) + to.b * amount)
return tint
end
local hour, minute = game.calendar:getTimeOfDay(game.turn)
hour = hour + (minute / 60)
local tint = {r = 0.1, g = 0.1, b = 0.1}
local startTint = {r = 0.1, g = 0.1, b = 0.1}
local endTint = {r = 0.1, g = 0.1, b = 0.1}
local lite = game.level.baseLite or 1
if hour <= 4 then
tint = {r = 0.1, g = 0.1, b = 0.1}
elseif hour > 4 and hour <= 7 then
startTint = { r = 0.1, g = 0.1, b = 0.1 }
endTint = { r = 0.3, g = 0.3, b = 0.5 }
tint = doTint(startTint, endTint, (hour - 4) / 3)
lite = lite + 1
elseif hour > 7 and hour <= 12 then
startTint = { r = 0.3, g = 0.3, b = 0.5 }
endTint = { r = 0.9, g = 0.9, b = 0.9 }
tint = doTint(startTint, endTint, (hour - 7) / 5)
lite = lite + 2
elseif hour > 12 and hour <= 18 then
startTint = { r = 0.9, g = 0.9, b = 0.9 }
endTint = { r = 0.9, g = 0.9, b = 0.6 }
tint = doTint(startTint, endTint, (hour - 12) / 6)
lite = lite + 4
elseif hour > 18 and hour < 24 then
startTint = { r = 0.9, g = 0.9, b = 0.6 }
endTint = { r = 0.1, g = 0.1, b = 0.1 }
tint = doTint(startTint, endTint, (hour - 18) / 6)
lite = lite + 3
end
game.level.map:setShown(tint.r+0.5, tint.g+0.5, tint.b+0.5, 1)
game.level.map:setObscure(tint.r+0.3, tint.g+0.3, tint.b+0.3, 1)
-- game.player.lite = lite
end
]]
-- Day/Night cycle
if self.level.data.day_night then self.state:dayNightCycle() end
-- Process overlay effects
self.level.map:processEffects()
......
......@@ -455,6 +455,48 @@ function _M:displayWeather(level, ps, nb_keyframes)
end
end
local function doTint(from, to, amount)
local tint = {r = 0, g = 0, b = 0}
tint.r = (from.r * (1 - amount) + to.r * amount)
tint.g = (from.g * (1 - amount) + to.g * amount)
tint.b = (from.b * (1 - amount) + to.b * amount)
return tint
end
--- Compute a day/night cycle
-- Works by changing the tint of the map gradualy
function _M:dayNightCycle()
local hour, minute = game.calendar:getTimeOfDay(game.turn)
hour = hour + (minute / 60)
local tint = {r = 0.1, g = 0.1, b = 0.1}
local startTint = {r = 0.1, g = 0.1, b = 0.1}
local endTint = {r = 0.1, g = 0.1, b = 0.1}
if hour <= 4 then
tint = {r = 0.1, g = 0.1, b = 0.1}
elseif hour > 4 and hour <= 7 then
startTint = { r = 0.1, g = 0.1, b = 0.1 }
endTint = { r = 0.3, g = 0.3, b = 0.5 }
tint = doTint(startTint, endTint, (hour - 4) / 3)
elseif hour > 7 and hour <= 12 then
startTint = { r = 0.3, g = 0.3, b = 0.5 }
endTint = { r = 0.9, g = 0.9, b = 0.9 }
tint = doTint(startTint, endTint, (hour - 7) / 5)
elseif hour > 12 and hour <= 18 then
startTint = { r = 0.9, g = 0.9, b = 0.9 }
endTint = { r = 0.9, g = 0.9, b = 0.6 }
tint = doTint(startTint, endTint, (hour - 12) / 6)
elseif hour > 18 and hour < 24 then
startTint = { r = 0.9, g = 0.9, b = 0.6 }
endTint = { r = 0.1, g = 0.1, b = 0.1 }
tint = doTint(startTint, endTint, (hour - 18) / 6)
end
local map = game.level.map
local shown = map.color_shown
local obscure = map.color_obscure
map._map:setShown(shown[1] * (tint.r+0.4), shown[2] * (tint.g+0.4), shown[3] * (tint.b+0.4), shown[4])
map._map:setObscure(obscure[1] * (tint.r+0.2), obscure[2] * (tint.g+0.2), obscure[3] * (tint.b+0.2), obscure[4])
end
--------------------------------------------------------------------
-- Donations
--------------------------------------------------------------------
......
......@@ -27,6 +27,7 @@ return {
width = 50, height = 50,
-- all_remembered = true,
all_lited = true,
day_night = true,
persistent = "zone",
ambient_music = "Rainy Day.ogg",
generator = {
......
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