XaiJu
Shattered Pixel
Shattered Pixel

patreon


Lunar Cycles | Patreon Weekly #234

Hey Patrons, in this weekly I’m going to change gears a little bit. I fell down a bit of a rabbit hole while working on some side content, and thought I’d share some of that journey with you.

This weekly also includes an audio Q&A! Go and give it a listen if you’d like. You can find audio timestamps at the end of this weekly.

Figuring out Holiday Dates

As mentioned in the last weekly, new holiday items did reasonably well in the most recent patreon poll. I don’t intend to add them all in one go but I wanted to spend a little time implementing backend functionality for them in v2.3.0. Mainly that meant coming up with what holidays I want Shattered to celebrate, and creating a better system to tell whether a particular holiday was occurring.

Most holidays occur on the same date each year, and so coding in support for them was easy, but there were two exceptions: Easter, and Lunar New Year.

Easter Sunday occurs on the first Sunday after the first full moon on or after March 21st, placing it some time between March 22nd and April 25th each year. Because of this, rigidly coding a specific date just doesn’t work, the game needs to algorithmically compute when Easter occurs in a given year. The good news is that algorithms for doing this do exist, the bad news is that they look like this:

I’m not even going to pretend that I understand what’s going on here. The short answer is that a bunch of unexplained numerical bullshit happens and at the end of it n is equal to our month (3 for March, 4 for April), and o+1 is equal to our day. Done.

Lunar New Year is also a moving target, occurring on the first new moon of the Chinese lunar calendar, which places it between January 21st and February 20th. As we can see with Easter, moon cycles can be calculated algorithmically, but we have the added complication of the date being based on an entirely different calendar system. Converting from Chinese Lunar to Gregorian is possible of course, but it’s another moving target that varies on a per-year basis.

This time that variance does not have an existing algorithmic solution (or at least none that I could find). So, for Lunar New Year, there’s nothing for it but to hard-code dates. Yuck.

Figuring these two out, as well as concepting work for other holidays, ended up eating quite a bit of my time this week. It’s all coded out properly now (at least until 2051), but I expected this to take much less time than it did. At the very least I’m now all set up to slowly add holiday items to the game as we move through 2024.

Lunar New Year occurs on February 10th this year, and I’m very confident that I’ll release v2.3.0 before then, so that’ll be the first of the new holiday celebrations. If you’re curious about which holidays and dates I picked, I shared some info on that in the most recent Shattered Secrets.

Audio TImestamps

This month there were 13 questions from 6 different Patrons.

Comments

Dates do indeed suck, but as annoying as adding this code was, I MUCH prefer it to adding a dependency just for holiday calculations. EDIT: I do think I watched that video a long while ago, but I forgot the specifics. Thankfully this problem is just an extremely small subset of figuring out the local date, I don't even need to think about time or coordination between different zones/standards, so it's a bit more feasible to do it myself.

Shattered Pixel

Oh that's neat, I had no idea that other games added holiday stuff inspired by Shattered.

Shattered Pixel

I agree with your favorite unique enemy. The Chaos Elemental is by far the one that sparks the most excitement (not necessarily just because of its great reward).

Veek

FYI - This code: [HolidayDates](https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/HolidayDates.kt) was inspired by Shattered. And for the "all eyes evil" question read recent OOTS.

Robert Heinig

And this is why programmers should never make algorithms about dealing with dates or timezones :D Did you consider using some date library that has common holidays dates programmed? Also you reminded me of one Tom Scott video. I recommend if you did not watch it yet :) https://youtube.com/watch?v=-5wpm-gesOY

Alex Allperino Zgabur


More Creators