Another little module, this one for handling calendar-based cycles. Right now it specifically handles calculating seasons and the phase of the moon: calendar github repo.
Under the hood the module uses TADS3’s Date
class to keep track of the current date.
Seasons are computed based on fixed-date solstices and equinoxes (which will be accurate to +/- one day).
The phase of the moon is computed using the same approximation method used by nethack. This treats the phase as an integer between 1 and 8, with 1 being a new moon and 4 being a full moon. It should also be accurate to within a day.
For my usage I need something that keeps track of the flow of time, but I’m not concerned about a specific in-game year/date.
Usage is pretty simple, here’s a snippet from the demo “game”:
newGame() {
local c, i;
// Create a calendar with a current date of June 22, 1979.
c = new Calendar(1979, 6, 22);
// Loop through a hundred days.
for(i = 1; i <= 100; i++) {
// Output information about the current date.
_logDate(c);
// Advance the calendar's date by one day.
c.advanceDay();
}
}
// Log some stuff about the date:
_logDate(d) {
"Date: <<d.getMonthName()>> <<toString(d.getDay())>>,
<<toString(d.getYear())>>\n ";
"Season: <<d.getSeasonName()>>\n ";
"Phase of moon: <<toString(d.getMoonPhaseName())>>\n ";
"<.p> ";
}
This just creates a calendar with the date June 22, 1979, and loops over the next 100 days, outputting information about each date. Partial transcript:
Date: June 22, 1979
Season: summer
Phase of moon: new
Date: June 23, 1979
Season: summer
Phase of moon: new
Date: June 24, 1979
Season: summer
Phase of moon: new
Date: June 25, 1979
Season: summer
Phase of moon: new
Date: June 26, 1979
Season: summer
Phase of moon: waxing crescent
Date: June 27, 1979
Season: summer
Phase of moon: waxing crescent
Date: June 28, 1979
Season: summer
Phase of moon: waxing crescent
Date: June 29, 1979
Season: summer
Phase of moon: waxing crescent
Date: June 30, 1979
Season: summer
Phase of moon: first quarter
Date: July 1, 1979
Season: summer
Phase of moon: first quarter
Date: July 2, 1979
Season: summer
Phase of moon: first quarter
Date: July 3, 1979
Season: summer
Phase of moon: first quarter
Date: July 4, 1979
Season: summer
Phase of moon: waxing gibbous
This is another one where I dunno if it’ll help anyone else, but here it is.