Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
exportlegends: fix day/month issues more reliably
Fixes #783, #791
  • Loading branch information
lethosor committed Jan 10, 2016
1 parent 48b3b38 commit 0bcc8dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion library/modules/World.cpp
Expand Up @@ -78,7 +78,9 @@ uint32_t World::ReadCurrentYear()

uint32_t World::ReadCurrentTick()
{
return DF_GLOBAL_VALUE(cur_year_tick, 0);
// prevent this from returning anything less than 0,
// to avoid day/month calculations with 0xffffffff
return std::max(0, DF_GLOBAL_VALUE(cur_year_tick, 0));
}

bool World::ReadGameMode(t_gamemodes& rd)
Expand Down
5 changes: 2 additions & 3 deletions scripts/exportlegends.lua
Expand Up @@ -85,9 +85,8 @@ end

--create an extra legends xml with extra data, by Mason11987 for World Viewer
function export_more_legends_xml()
local julian_day = math.floor(df.global.cur_year_tick / 1200)
local month = math.floor(julian_day / 28) + 1 --days and months are 1-indexed
local day = julian_day % 28 + 1
local month = dfhack.world.ReadCurrentMonth() + 1 --days and months are 1-indexed
local day = dfhack.world.ReadCurrentDay()
local year_str = string.format('%0'..math.max(5, string.len(''..df.global.cur_year))..'d', df.global.cur_year)
local date_str = year_str..string.format('-%02d-%02d', month, day)

Expand Down

0 comments on commit 0bcc8dc

Please sign in to comment.