From 0bcc8dc4437761e36d3dae8a516dccca5a11eaf5 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 9 Jan 2016 19:28:12 -0500 Subject: [PATCH] exportlegends: fix day/month issues more reliably Fixes #783, #791 --- library/modules/World.cpp | 4 +++- scripts/exportlegends.lua | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 66390da6e..3be400515 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -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) diff --git a/scripts/exportlegends.lua b/scripts/exportlegends.lua index cc83dbf5f..a0a04d9a2 100644 --- a/scripts/exportlegends.lua +++ b/scripts/exportlegends.lua @@ -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)