mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-21 14:16:40 +01:00
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request update time related procs & glob too (i was originally targeting that lmao). also **stop** using byondtime for sql stuff, we have `NOW()`!! <!-- Describe The Pull Request. Please be sure every change is documented or this can delay review and even discourage maintainers from merging your PR! --> ## Why It's Good For The Game <!-- Argue for the merits of your changes and how they benefit the game, especially if they are controversial and/or far reaching. If you can't actually explain WHY what you are doing will improve the game, then it probably isn't good for the game in the first place. --> ## Changelog <!-- If your PR modifies aspects of the game that can be concretely observed by players or admins you should add a changelog. If your change does NOT meet this description, remove this section. Please note that maintainers freely reserve the right to remove and add tags should they deem it appropriate. You can attempt to finagle the system all you want, but it's best to shoot for clear communication right off the bat. --> <!-- Both 🆑's are required for the changelog to work! You can put your name to the right of the first 🆑 if you want to overwrite your GitHub username as author ingame. --> <!-- You can use multiple of the same prefix (they're only used for the icon ingame) and delete the unneeded ones. Despite some of the tags, changelogs should generally represent how a player might be affected by the changes rather than a summary of the PR's contents. -->
181 lines
6.6 KiB
Plaintext
181 lines
6.6 KiB
Plaintext
SUBSYSTEM_DEF(events)
|
|
name = "Events"
|
|
wait = 2 SECONDS
|
|
init_order = INIT_ORDER_EVENTS
|
|
|
|
runlevels = RUNLEVEL_GAME
|
|
|
|
/// Current holidays
|
|
var/list/holidays = list()
|
|
|
|
var/tmp/list/currentrun = null
|
|
|
|
var/list/datum/event/active_events = list()
|
|
var/list/datum/event/finished_events = list()
|
|
|
|
var/list/datum/event/allEvents
|
|
var/list/datum/event_container/event_containers
|
|
|
|
var/datum/event_meta/new_event = new
|
|
|
|
/datum/controller/subsystem/events/PreInit(recovering)
|
|
// unfortunately, character setup server startup hooks fire before /Initialize so :/
|
|
// SScharactersetup but not shit when :)
|
|
InitializeHolidays(force = TRUE)
|
|
return ..()
|
|
|
|
/datum/controller/subsystem/events/Initialize()
|
|
SSticker.OnRoundstart(CALLBACK(src, PROC_REF(HolidayRoundstart)))
|
|
allEvents = typesof(/datum/event) - /datum/event
|
|
event_containers = list(
|
|
new/datum/event_container/mundane,
|
|
new/datum/event_container/moderate,
|
|
new/datum/event_container/major
|
|
)
|
|
// unfortunately, character setup server startup hooks fire before /Initialize so :/
|
|
// SScharactersetup but not shit when :)
|
|
InitializeHolidays()
|
|
return SS_INIT_SUCCESS
|
|
|
|
/datum/controller/subsystem/events/fire(resumed)
|
|
if (!resumed)
|
|
src.currentrun = active_events.Copy()
|
|
|
|
//cache for sanic speed (lists are references anyways)
|
|
var/list/currentrun = src.currentrun
|
|
var/dt = nominal_dt_s
|
|
while (currentrun.len)
|
|
var/datum/event/E = currentrun[currentrun.len]
|
|
currentrun.len--
|
|
if(E.processing_active)
|
|
E.process(dt)
|
|
if (MC_TICK_CHECK)
|
|
return
|
|
|
|
for(var/i = EVENT_LEVEL_MUNDANE to EVENT_LEVEL_MAJOR)
|
|
var/datum/event_container/EC = event_containers[i]
|
|
EC.process(dt)
|
|
|
|
/datum/controller/subsystem/events/stat_entry()
|
|
return ..() + " E:[active_events.len]"
|
|
|
|
/datum/controller/subsystem/events/Recover()
|
|
if(SSevents.active_events)
|
|
active_events |= SSevents.active_events
|
|
if(SSevents.finished_events)
|
|
finished_events |= SSevents.finished_events
|
|
|
|
/datum/controller/subsystem/events/proc/event_complete(var/datum/event/E)
|
|
active_events -= E
|
|
|
|
if(!E.event_meta || !E.severity) // datum/event is used here and there for random reasons, maintaining "backwards compatibility"
|
|
log_debug(SPAN_DEBUG("Event of '[E.type]' with missing meta-data has completed."))
|
|
return
|
|
|
|
finished_events += E
|
|
|
|
// Add the event back to the list of available events
|
|
var/datum/event_container/EC = event_containers[E.severity]
|
|
var/datum/event_meta/EM = E.event_meta
|
|
if(EM.add_to_queue)
|
|
EC.available_events += EM
|
|
|
|
log_debug(SPAN_DEBUG("Event '[EM.name]' has completed at [worldtime2stationtime(world.time)]."))
|
|
|
|
/datum/controller/subsystem/events/proc/delay_events(var/severity, var/delay)
|
|
var/datum/event_container/EC = event_containers[severity]
|
|
EC.next_event_time += delay
|
|
|
|
/datum/controller/subsystem/events/proc/RoundEnd()
|
|
if(!report_at_round_end)
|
|
return
|
|
|
|
to_chat(world, "<br><br><br><font size=3><b>Random Events This Round:</b></font>")
|
|
for(var/datum/event/E in active_events|finished_events)
|
|
var/datum/event_meta/EM = E.event_meta
|
|
if(EM.name == "Nothing")
|
|
continue
|
|
var/message = "'[EM.name]' began at [worldtime2stationtime(E.startedAt)] "
|
|
if(E.isRunning)
|
|
message += "and is still running."
|
|
else
|
|
if(E.endedAt - E.startedAt > MinutesToTicks(5)) // Only mention end time if the entire duration was more than 5 minutes
|
|
message += "and ended at [worldtime2stationtime(E.endedAt)]."
|
|
else
|
|
message += "and ran to completion."
|
|
to_chat(world, message)
|
|
|
|
|
|
//////////////
|
|
// HOLIDAYS //
|
|
//////////////
|
|
//Uncommenting ALLOW_HOLIDAYS in config.txt will enable holidays
|
|
|
|
//It's easy to add stuff. Just add a holiday datum in code/modules/holiday/holidays.dm
|
|
//You can then check if it's a special day in any code in the game by doing if(SSevents.holidays["Groundhog Day"])
|
|
|
|
//You can also make holiday random events easily thanks to Pete/Gia's system.
|
|
//simply make a random event normally, then assign it a holidayID string which matches the holiday's name.
|
|
//Anything with a holidayID, which isn't in the holidays list, will never occur.
|
|
|
|
//Please, Don't spam stuff up with stupid stuff (key example being april-fools Pooh/ERP/etc),
|
|
//And don't forget: CHECK YOUR CODE!!!! We don't want any zero-day bugs which happen only on holidays and never get found/fixed!
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//ALSO, MOST IMPORTANTLY: Don't add stupid stuff! Discuss bonus content with Project-Heads first please!//
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//sets up the holidays and holidays list
|
|
/datum/controller/subsystem/events/proc/InitializeHolidays(force = FALSE)
|
|
if(holidays)
|
|
QDEL_LIST_ASSOC_VAL(holidays)
|
|
holidays = list()
|
|
if(!force && !CONFIG_GET(flag/allow_holidays))
|
|
return // Holiday stuff was not enabled in the config!
|
|
|
|
var/YY = text2num(time2text(world.timeofday, "YY", world.timezone)) // get the current year
|
|
var/MM = text2num(time2text(world.timeofday, "MM", world.timezone)) // get the current month
|
|
var/DD = text2num(time2text(world.timeofday, "DD", world.timezone)) // get the current day
|
|
var/DDD = time2text(world.timeofday, "DDD", world.timezone) // get the current weekday
|
|
var/W = weekdayofthemonth() // is this the first monday? second? etc.
|
|
|
|
for(var/H in subtypesof(/datum/holiday))
|
|
var/datum/holiday/holiday = new H
|
|
if(holiday.ShouldCelebrate(DD, MM, YY, W, DDD))
|
|
holiday.OnInit()
|
|
holidays[holiday.name] = holiday
|
|
else
|
|
qdel(holiday)
|
|
|
|
tim_sort(holidays, GLOBAL_PROC_REF(cmp_holiday_priority), associative = TRUE)
|
|
// // regenerate station name because holiday prefixes.
|
|
// set_station_name(new_station_name())
|
|
// world.update_status()
|
|
|
|
/datum/controller/subsystem/events/proc/HolidayRoundstart()
|
|
for(var/name in holidays)
|
|
var/datum/holiday/holiday = holidays[name]
|
|
holiday.OnRoundstart()
|
|
|
|
// handle announcing holidays where needed
|
|
if(SSevents.holidays.len != 0)
|
|
var/list/holiday_names = list()
|
|
var/list/holiday_blurbs = list()
|
|
for(var/holiday_name in SSevents.holidays)
|
|
var/datum/holiday/H = SSevents.holidays[holiday_name]
|
|
if(H.announce)
|
|
holiday_names.Add(holiday_name)
|
|
holiday_blurbs.Add("[H.desc]")
|
|
if(!length(holiday_names))
|
|
return
|
|
var/holidays_string = english_list(holiday_names, nothing_text = "nothing", and_text = " and ", comma_text = ", ", final_comma_text = "" )
|
|
to_chat(world, "<font color=#4F49AF>and...</font>")
|
|
to_chat(world, "<h4>Happy [holidays_string] Everybody!</h4>")
|
|
if(holiday_blurbs.len != 0)
|
|
for(var/blurb in holiday_blurbs)
|
|
to_chat(world, "<div align='center'><font color=#4F49AF>[blurb]</font></div>")
|
|
|
|
/proc/IsHoliday(name)
|
|
return SSevents.holidays[name]? TRUE : FALSE
|