Check future full moon

Discuss modding questions and implementation details.
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Check future full moon

Post by Ralzar »

Is there some way to have a mod check how long it is until a full moon?

Most of all: is there a way to check if this night will be a full moon?


For my Lousy Lycans mod I am trying to implement a function where you get warned before a full moon happens so you have some time to get your affairs in order. The best I have managed so far is a text warning each evening when one of the moons is at ThreeWax.
Problem with that, is that it will be a ThreeWax until the second it hits midnight. Then it shifts to the next day which is Full.


What I am hoping to do is something like

DaggerfallUnity.Instance.WorldTime.Now

+

12 hours

=

nextNigth



Then pass nextNight through a formula that checks if it will return a Full Moon?


Anyone have any ideas of ways to pull this off?

User avatar
joshcamas
Posts: 87
Joined: Mon Sep 21, 2020 7:01 am

Re: Check future full moon

Post by joshcamas »

Here's the function that calculates the full moon, found inside DaggerfallDateTime:

Code: Select all

private LunarPhases GetLunarPhase(bool isMasser)
        {
            // Validate
            if (Year < 0)
            {
                Debug.LogError("GetLunarPhase: Year < 0 not supported.");
                return LunarPhases.None;
            }

            // 3 aligns full moon with vanilla DF for Masser, -1 for secunda
            int offset = (isMasser) ? 3 : -1;

            // Find the lunar phase for current day
            int moonRatio = (Day + offset) % 32;
            LunarPhases phase = LunarPhases.None;
            if (moonRatio == 0)
                phase = LunarPhases.Full;
            else if (moonRatio == 16)
                phase = LunarPhases.New;
            else if (moonRatio <= 5)
                phase = LunarPhases.ThreeWane;
            else if (moonRatio <= 10)
                phase = LunarPhases.HalfWane;
            else if (moonRatio <= 15)
                phase = LunarPhases.OneWane;
            else if (moonRatio <= 22)
                phase = LunarPhases.OneWax;
            else if (moonRatio <= 28)
                phase = LunarPhases.HalfWax;
            else if (moonRatio <= 31)
                phase = LunarPhases.ThreeWax;

            return phase;
        }
It looks like for Masser Full Moon happens every 29th day of the month, and Secunda happens every 33rd day of the month? Which is odd because it also looks like there are 3 days in a month so uh.. not sure how Secunda works.

Also it looks like Daggerfall considers it to be full moon if either Masser or Secunda is in full moon

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Check future full moon

Post by Ralzar »

Yup, it sucks to be a lycanthrope in Daggerfall. Two full moons per month :D

Which is also why my mod doesn't tries to just code in the dates. The moon cycles seem a bit too complex for that.


But if I can't figure out some other way to reliably identify the correct dates I might have to go that route.

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Check future full moon

Post by Hazelnut »

I would suggest using the same logic in your mod but where you can set the date it calculates for.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
joshcamas
Posts: 87
Joined: Mon Sep 21, 2020 7:01 am

Re: Check future full moon

Post by joshcamas »

Ralzar, to calculate the next moon all you need to do is calculate the distance between the current Day and the 29th and 33rd day. The smallest number is the number of days until a full moon :)

Question, Hazelnut - why does Secunda's full moon happen on the 33rd if there are only 30 days per month? Doesn't the Day value wrap around to 0 after 30?

User avatar
pango
Posts: 3358
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Check future full moon

Post by pango »

From the look of the code, I assume "Day" is some day number (not the day of the month), and the lunar month is 32 days. Calendar month is not involved.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Check future full moon

Post by Hazelnut »

joshcamas wrote: Mon Oct 05, 2020 2:15 am Question, Hazelnut - why does Secunda's full moon happen on the 33rd if there are only 30 days per month? Doesn't the Day value wrap around to 0 after 30?
No idea, this is the first time I've ever seen this code.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Check future full moon

Post by Ralzar »

I'm working on getting this up and running. However in my testing I noticed soemthing about the phase behaviour that might be a bug?

On the 1st of the month, both moons are at ThreeWane.

Then when it ticks over to 2nd, Secunda becomes Full.

Then on the 3rd they are both ThreeWane again.


Shouldn't Secunda have gone from ThreeWax to Full to ThreeWane? A moon doesn't wane and wane. It waxes and wanes.

User avatar
pango
Posts: 3358
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Check future full moon

Post by pango »

pango wrote: Mon Oct 05, 2020 5:44 am From the look of the code, I assume "Day" is some day number (not the day of the month), and the lunar month is 32 days. Calendar month is not involved.
Looking at the whole class, Day is the day of month, so this code is broken.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Check future full moon

Post by Ralzar »

I'm not sure, but another weakness this code has, although that might just be to copy vanilla Daggerfall, is that there's a full moon from midnight until the next midnight.

Which is a bit weird. You don't consider the moon full in the middle of the day. But this leads to werewolfs being forced into beastform for 24 hours

Post Reply