mirror of
https://github.com/fulpstation/fulpstation.git
synced 2025-12-09 16:09:15 +00:00
Future proofs Easter calculations
This commit is contained in:
47
code/__HELPERS/dates.dm
Normal file
47
code/__HELPERS/dates.dm
Normal file
@@ -0,0 +1,47 @@
|
||||
//Curse you calenders...
|
||||
/proc/IsLeapYear(y)
|
||||
return ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
|
||||
|
||||
//Y, eg: 2017, 2018, 2019, in num form (not string)
|
||||
//etc. Between 1583 and 4099
|
||||
//Adapted from a free algorithm written in BASIC (https://www.assa.org.au/edm#Computer)
|
||||
/proc/EasterDate(y)
|
||||
var/FirstDig, Remain19, temp //Intermediate Results
|
||||
var/tA, tB, tC, tD, tE //Table A-E results
|
||||
var/d, m //Day and Month returned
|
||||
|
||||
FirstDig = round((y / 100))
|
||||
Remain19 = y % 19
|
||||
|
||||
temp = (round((FirstDig - 15) / 2)) + 202 - 11 * Remain19
|
||||
|
||||
switch(FirstDig)
|
||||
if(21,24,25,27,28,29,30,31,32,34,35,38)
|
||||
temp -= 1
|
||||
if(33,36,37,39,40)
|
||||
temp -= 2
|
||||
temp %= 30
|
||||
|
||||
tA = temp + 21
|
||||
if(temp == 29)
|
||||
tA -= 1
|
||||
if(temp == 28 && (Remain19 > 10))
|
||||
tA -= 1
|
||||
tB = (tA - 19) % 7
|
||||
|
||||
tC = (40 - FirstDig) % 4
|
||||
if(tC == 3)
|
||||
tC += 1
|
||||
if(tC > 1)
|
||||
tC += 1
|
||||
temp = y % 100
|
||||
tD = (temp + round((temp / 4))) % 7
|
||||
|
||||
tE = ((20 - tB - tC - tD) % 7) + 1
|
||||
d = tA + tE
|
||||
if(d > 31)
|
||||
d -= 31
|
||||
m = 4
|
||||
else
|
||||
m = 3
|
||||
return list("day" = d, "month" = m)
|
||||
@@ -1,7 +1,3 @@
|
||||
//Easter start
|
||||
/datum/holiday/easter/greet()
|
||||
return "Greetings! Have a Happy Easter and keep an eye out for Easter Bunnies!"
|
||||
|
||||
/datum/round_event_control/easter
|
||||
name = "Easter Eggselence"
|
||||
holidayID = EASTER
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
var/begin_week = FALSE //If set to a number, then this holiday will begin on certain week
|
||||
var/begin_weekday = FALSE //If set to a weekday, then this will trigger the holiday on the above week
|
||||
var/always_celebrate = FALSE // for christmas neverending, or testing.
|
||||
|
||||
var/current_year = 0
|
||||
var/year_offset = 0
|
||||
var/obj/item/drone_hat //If this is defined, drones without a default hat will spawn with this one during the holiday; check drones_as_items.dm to see this used
|
||||
|
||||
// This proc gets run before the game starts when the holiday is activated. Do festive shit here.
|
||||
@@ -447,50 +448,12 @@ Since Ramadan is an entire month that lasts 29.5 days on average, the start and
|
||||
var/const/days_extra = 1
|
||||
|
||||
/datum/holiday/easter/shouldCelebrate(dd, mm, yy, ww, ddd)
|
||||
// Easter's celebration day is as snowflakey as Uhangi's code
|
||||
|
||||
if(!begin_month)
|
||||
current_year = text2num(time2text(world.timeofday, "YYYY"))
|
||||
var/list/easterResults = EasterDate(current_year+year_offset)
|
||||
|
||||
var/yy_string = "[yy]"
|
||||
// year = days after March 22that Easter falls on that year.
|
||||
// For 2015 Easter is on April 5th, so 2015 = 14 since the 5th is 14 days past the 22nd
|
||||
// If it's 2040 and this is still in use, invent a time machine and teach me a better way to do this. Also tell us about HL3.
|
||||
var/list/easters = list(
|
||||
"15" = 14,\
|
||||
"16" = 6,\
|
||||
"17" = 25,\
|
||||
"18" = 10,\
|
||||
"19" = 30,\
|
||||
"20" = 22,\
|
||||
"21" = 13,\
|
||||
"22" = 26,\
|
||||
"23" = 18,\
|
||||
"24" = 9,\
|
||||
"25" = 29,\
|
||||
"26" = 14,\
|
||||
"27" = 6,\
|
||||
"28" = 25,\
|
||||
"29" = 10,\
|
||||
"30" = 30,\
|
||||
"31" = 23,\
|
||||
"32" = 6,\
|
||||
"33" = 26,\
|
||||
"34" = 18,\
|
||||
"35" = 3,\
|
||||
"36" = 22,\
|
||||
"37" = 14,\
|
||||
"38" = 34,\
|
||||
"39" = 19,\
|
||||
"40" = 9,\
|
||||
)
|
||||
|
||||
begin_day = easters[yy_string]
|
||||
if(begin_day <= 9)
|
||||
begin_day += 22
|
||||
begin_month = MARCH
|
||||
else
|
||||
begin_day -= 9
|
||||
begin_month = APRIL
|
||||
begin_day = easterResults["day"]
|
||||
begin_month = easterResults["month"]
|
||||
|
||||
end_day = begin_day + days_extra
|
||||
end_month = begin_month
|
||||
@@ -513,3 +476,9 @@ Since Ramadan is an entire month that lasts 29.5 days on average, the start and
|
||||
GLOB.maintenance_loot += list(
|
||||
/obj/item/reagent_containers/food/snacks/egg/loaded = 15,
|
||||
/obj/item/storage/bag/easterbasket = 15)
|
||||
|
||||
/datum/holiday/easter/greet()
|
||||
return "Greetings! Have a Happy Easter and keep an eye out for Easter Bunnies!"
|
||||
|
||||
/datum/holiday/easter/getStationPrefix()
|
||||
return pick("Fluffy","Bunny","Easter","Egg")
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
#include "code\__HELPERS\areas.dm"
|
||||
#include "code\__HELPERS\AStar.dm"
|
||||
#include "code\__HELPERS\cmp.dm"
|
||||
#include "code\__HELPERS\dates.dm"
|
||||
#include "code\__HELPERS\files.dm"
|
||||
#include "code\__HELPERS\game.dm"
|
||||
#include "code\__HELPERS\global_lists.dm"
|
||||
|
||||
Reference in New Issue
Block a user