Files
Paradise/code/modules/events/event.dm
Migratingcocofruit e609a7faf7 Event system refactor and changes (#29420)
* meta resolution

* emerald resolution

* delta resolution

* fartgas resolution

* box box

* stay out stay out

* metastation fixes

* faragus fix

* delta fix

* Changes to role impact on event weight

* adds disaster level to the event config

* weight changes and starts adding disaster level to the ui

* ui fixes

* adjust disaster level timing

* changes disaster timing, weights, disease outbreak role requirements and weights

* lots of weight an requirement adjustments

* Update tear.dm

* some fixes

* meta changes

* Starting over with farragus

* Starting over in faragus

* faragus changes

* Update cerestation.dmm

* Update cerestation.dmm

* Update cerestation.dmm

* Update cerestation.dmm

* Update cerestation.dmm

* resolving some faragus conflicts

* resolve faragus conflicts

* resolves delta conflicts

* resolves cyberiad conflicts

* resolves emerald conflicts

* fixes cables in faragus

* fixes meta cables

* fixes delta cables

* more meta fixes

* more farragus cable fixes

* more cable fixes

* meta and faragus fixes

* box and delta fixes

* more mapping fixes

* hopefully the last fix

* Update metastation.dmm

* Update metastation.dmm

* fixes shorts on cyberiad cerebron and farragus

* CI fixes

* move new event listing to new system

* Adds tracking and cost calculation for blob

* finishes setting up blob event detection and costs

* minor boolog corrections

* fixes events being created at the wrong severity

* adds ongoing cost to disease outbreak

* moves terror spider event to new system

* moves to component based event cost calculation

* morph abductor and carps adjusted for new system

* various fixes and adjusts rev event

* Update revenant_spawn_event.dm

* various fixes and adjusts demon incursion to the new system

* adjusts some major event weights

* correct wrong values of autoend on vendor uprising and rev

* Update event_container.dm

* more event timing adjustments

* adds requirements to traders and incursion

* slightly lowers requirements for biohazards

* timing changes

* temporarily disable loading event times from the config and increases major nothing chance

* adjustments to costs and weights of various events

* Update event_container.dm

* additional adjustments to weights and requirements. moves rev to major

* typo fix

* ion storm adjustment

* Update event_container.dm

* more moderate changes

* e

* Update meteors_event.dm

* removes cooldown from nothing event and changes its weight based on the number of remaining enabled events in the container

* increases morph event requirements and chance of nothing moderate event

* makes morph a major event

* Update morph_event.dm

* adds viro requirement for disease outbreak and fixes a bug with incorrect resource calculation

* allows varediting extra roles for the event system for debug and testing

* Adjust weights of traders and abductors and corrects wrong nominal severity for demonic incursion

* Adds crew cound to rev weight

* makes disasters start rolling later

* reduces weight of communications blackout and increases weight of major nothing

* adjusts door runtime and prisonbreak weights to make them less frequent. kudzu now scales with total crew

* apc overload made less frequent

* oopsy

* Gives the scrubber clog event a name

* fixes a type in a define name

* adjusts demonic incursion weight

* changes brand intelligence weight an d reduces door runtime weight

* more adjustments to demon incursion. Makes additional weight from surplus roles diminish

* adjustments to some minor events

* Increases event length and requirements of some engineering events and lowers their weight slightly. Also increases cost of ongoing diseases events

* fixes a type

* Update meteors_event.dm

* corrects traders nominal severity and adjusts demon weights

* shifts anomaly weights down and increases costs

* rebalance rod requirements

* Update cerestation.dmm

* moves net resource calculation to its own proc and changes the ASSIGNMENT_TOTAL macro to ASSIGNMENT_CREW.

* Adds individual first run time for some events and makes majors start rolling slightly later

* reduces weight of major nothing

* minor reduction to rev and apc overload weight

* Changes the way event weight is calculated

* end time corrections for anomaly rod and meteors

* slightly adjusts down the weights of nothing and some minor events

* Adjusts moedrates towards about 3.5 per round and mundanes towards 8 per round

* adds first run restrictions on traders and incursion and increases the cooldown time of events

* resolve faragus conflicts

* resolve emerald conflict

* fix some faragus cabling

* more cabling correction in faragus

* more cable fixes

* Update cerestation.dmm

* remove doubled scrubber pipe on tile

* reduces moderates nothing chance

* slightly reduces crew requirements for disasters and also reduces crew weight for disasters

* fixes meteor event not removing the alert, and makes it announce a bit later

* Adds an event debugging window for real time midround event data

* Revert "Adds an event debugging window for real time midround event data"

This reverts commit ecd99a6c9e.

* Adds a resource view button to the event manager window and fixes a null in the total resource list

* various bug fixes

* slightly lowers chance of meteor and similar events

* Slightly lowers requirement weights on disaster level events

* resolves faragus conflict

* changes the default power input of engineering SMES to 200kw and 80kW respectively

* connects power monitoring computers to the grid that weren't

* meta station elec maints improvements

* adds missing power monitoring computers on box and delta

* removes dirt from wall

* corrects area boundry on meta

* adds missing cable on box sci

* removes dirt from wall on box

* connects cyberiad bridge to the rest of the powernet

* connects box brig to powernet

* Adds catwalks to box maints

* adds catwalks to meta

* Adds catwalks to delta

* Update deltastation.dmm

* adds ability to insulate cables

* Moves stations to using extra insulated cables for high power network

* Removes catwalks from meta

* Removes catwalks from box

* Removes catwalks from delta

* Delays moderates and majors more and increases disaster chance

* resolves box conflicts

* Update cable.dm

* remove floating request console

* corrects position of fire alarm and removes extra intercom on metastation

* resolves faragus conflict

* reduces meteor variant weights. meaty ores event now has the correct nominal severity

* meaty ore weight to 8

* fixes a stray light bulb and light switch in maints as well as a doubled power

* Delays meteor type events to 40 minutes at the earliest. Moves the time check to be against round time instead of world time

* wires kerberos security checkpoint to the grid

* Update cerestation.dmm

* Removes stray extinguisher cabinet from meta station

* resolves area conflict on faragus

* resolves more faragus issues

* fixes faragus cabling issues

* Update cerestation.dmm

* removes another stray fire extinguisher cabinet

* insulates the APC in delta PTL room

* increases pop requirement and weight for demons and increases medbay and viro weights for diseases

* connect delta fore starboard solars to the high power grid instead of the low power

* Update deltastation.dmm

* deconflict

* solves some unconnected cables

* connects delta customs to network and finishes resolving conflicts

* Update deltastation.dmm

* adds the new cables. needs coils and mapping

* moves connection perms to the heavy duty cables. toggled with engineering permission ID. box gets new cables

* sorts cables on stations

* faragus cable connections

* cable corrections. Adds heavy duty cables to the autolathe

* CI fix

* more fixes and makes the new cables show up on t ray scanners

* box station mapping fixes

* delta mapping fixes

* meta fix

* Update deltastation.dmm

* delta and faragus fixes

* Update emeraldstation.dmm

* removes APC overloard(major) from event pool

* adds diagonal sprites to heavy duty cables. allows sillicons to toggle them and

* Makes borg versions of the heavy duty cable coil

* palete consolidation

* Improves visibility of high power cables

* converts shuttle event to new system

* makes disaster event last run calc use round time instead of world time

* fixes wrong define being used in some event requirements. further increases requirements for demons and meteors. lowers weight of major diseases

* Update slaughterevent.dm

* reduces cargo requirements for shuttle load event

* reduces base weight of major disease event and further increases medical requirements

* fixes a wrong wire under the pet store maints door in delta station

* resolve mapping conflicts

* Revert "resolve mapping conflicts"

This reverts commit 129db52501.

* Revert "Merge branch 'HighPowerMaints' into event_timing"

This reverts commit 2594ac8928, reversing
changes made to a738b5f2f2.

* fixes some wonky stuff with xeno code

* Adds a crew cost to diseases

* makes player contribution towards events variable

* changes major event weights and slightly increases demon requirements

* slightly increases major disease outbreak weight

* comment changes

* Adds safeties to protect against null events getting into container or the active list

* blob fix

* Adds a confirmation to random event toggle

* Adjust particulate event weight to fit the new moderate weights

* Adds additional security costs to changeling and vamp

* Update revenant_spawn_event.dm

* uses correct path for rev event cost proc

* changes some lists to alists

* correctly accesses the event container list and actually uses the config for the event timing

---------

Co-authored-by: FunnyMan3595 (Charlie Nolan) <funnyman3595@gmail.com>
Co-authored-by: warriorstar-orion <orion@snowfrost.garden>
2025-11-07 16:29:47 +00:00

253 lines
7.8 KiB
Plaintext

/datum/event_meta
var/name = ""
/// Whether or not the event is available for random selection at all.
var/enabled = TRUE
/// The base weight of this event. A zero means it may never fire, but see get_weight()
var/weight
/// The minimum weight that this event will have. Only used if non-zero.
var/min_weight
/// The maximum weight that this event will have.
var/max_weight
/// If true, then the event will not be re-added to the list of available events
var/one_shot
/// A modifier applied to all event weights (role and base), respects min and max
var/weight_mod = 1
/// Event held by this meta event. Used to do things like calculate weight.
var/datum/event/skeleton
/// How early this specific event can run
var/first_run_time = 0
/datum/event_meta/New(event_severity, type, event_weight, is_one_shot = FALSE, min_event_weight = 0, max_event_weight = INFINITY, _first_run_time)
if(type)
skeleton = new type(EM = src, skeleton = TRUE, _severity = event_severity)
name = skeleton.name
one_shot = is_one_shot
weight = event_weight
min_weight = min_event_weight
max_weight = max_event_weight
first_run_time = _first_run_time
/datum/event_meta/proc/change_event(type)
var/event_severity = 0
if(skeleton)
event_severity = skeleton.severity
skeleton.event_meta = null
qdel(skeleton)
skeleton = new type(EM = src, skeleton = TRUE, _severity = event_severity)
/datum/event_meta/proc/get_weight(list/total_resources)
if(!enabled || !skeleton)
return 0
var/resource_effect = skeleton.get_weight(total_resources)
var/new_weight = weight
if(resource_effect > 0)
new_weight *= (1.003 ** resource_effect)
if(resource_effect < 0)
new_weight *= 0.95 ** -resource_effect
return clamp((new_weight) * weight_mod, min_weight, max_weight)
/*/datum/event_meta/ninja/get_weight(var/list/active_with_role)
if(toggle_space_ninja)
return ..(active_with_role)
return 0*/
/// NOTE: Times are measured in master controller ticks!
/datum/event
/// The human-readable name of the event
var/name
/// When in the lifetime to call start().
var/startWhen = 0
/// When in the lifetime to call announce().
var/announceWhen = 0
/// When in the lifetime the event should end.
var/endWhen = 0
/// Severity. Lower means less severe, higher means more severe. Does not have to be supported. Is set on New().
var/severity = 0
/// The severity the event has normally
var/nominal_severity = EVENT_LEVEL_MUNDANE
/// How long the event has existed. You don't need to change this.
var/activeFor = 0
/// If this event is currently running. You should not change this.
var/isRunning = TRUE
/// When this event started.
var/startedAt = 0
/// When this event ended.
var/endedAt = 0
/// Does the event end automatically after endWhen passes?
var/noAutoEnd = FALSE
/// The area the event will hit
var/area/impact_area
var/datum/event_meta/event_meta = null
/// The base weight of each role on the event for the purpose of calculating event weight and resource cost
var/list/role_weights = list()
/// A baseline requirement of different roles the event has at it's nominal severity
var/list/role_requirements = list()
/datum/event/nothing
name = "Nothing"
/datum/event/nothing/has_cooldown()
return FALSE
/datum/event/nothing/is_relative()
return TRUE
/// Calculate the weight for rolling the event based on round circumstances.
/datum/event/proc/get_weight(list/total_resources)
var/job_weight = 0
for(var/role in role_weights)
var/role_available = total_resources[role] ? total_resources[role] : 0
var/difference = (role_available - role_requirements[role] * (severity / nominal_severity)) * role_weights[role]
// We add difference if it's negative, or the square root if it's positive
job_weight += difference
return job_weight
/**
* Called first before processing.
*
* Allows you to setup your event, such as randomly
* setting the startWhen and or announceWhen variables.
* Only called once.
*/
/datum/event/proc/setup()
return
/**
* Called when the tick is equal to the startWhen variable.
*
* Allows you to start before announcing or vice versa.
* Only called once.
* Ensure no sleep is called. Use INVOKE_ASYNC to call procs which do.
*/
/datum/event/proc/start()
SHOULD_NOT_SLEEP(TRUE)
return
/**
* Called when the tick is equal to the announceWhen variable.
*
* Allows you to announce before starting or vice versa.
* Only called once.
* Ensure no sleep is called. Use INVOKE_ASYNC to call procs which do.
*/
/datum/event/proc/announce(false_alarm = FALSE)
SHOULD_NOT_SLEEP(TRUE)
return
/**
* Called on or after the tick counter is equal to startWhen.
*
* You can include code related to your event or add your own
* time stamped events.
* Called more than once.
* Ensure no sleep is called. Use INVOKE_ASYNC to call procs which do.
*/
/datum/event/proc/tick()
SHOULD_NOT_SLEEP(TRUE)
return
/**
* Called on or after the tick is equal or more than endWhen
*
* You can include code related to the event ending.
* Do not place spawn() in here, instead use tick() to check for
* the activeFor variable.
* For example: if(activeFor == myOwnVariable + 30) doStuff()
* Only called once.
* Ensure no sleep is called. Use INVOKE_ASYNC to call procs which do.
*/
/datum/event/proc/end()
SHOULD_NOT_SLEEP(TRUE)
return
/**
* Returns the latest point of event processing.
*/
/datum/event/proc/lastProcessAt()
return max(startWhen, max(announceWhen, endWhen))
/**
* Do not override this proc, instead use the appropiate procs.
*
* This proc will handle the calls to the appropiate procs.
* Ensure none of the code paths have a sleep in them. Use INVOKE_ASYNC to call procs which do.
*/
/datum/event/process()
if(activeFor > startWhen && activeFor < endWhen || noAutoEnd)
tick()
if(activeFor == startWhen)
isRunning = TRUE
start()
if(activeFor == announceWhen)
announce()
if(activeFor == endWhen && !noAutoEnd)
isRunning = FALSE
end()
// Everything is done, let's clean up.
if(activeFor >= lastProcessAt() && !noAutoEnd)
kill()
activeFor++
/**
* Called when start(), announce() and end() has all been called.
*/
/datum/event/proc/kill()
// If this event was forcefully killed run end() for individual cleanup
if(isRunning)
isRunning = FALSE
end()
endedAt = world.time
SSevents.active_events -= src
SSevents.event_complete(src)
// Events have cooldown by default
/datum/event/proc/has_cooldown()
return TRUE
/datum/event/proc/is_relative()
return FALSE
/datum/event/New(datum/event_meta/EM, skeleton = FALSE, _severity)
// event needs to be responsible for this, as stuff like APLUs currently make their own events for curious reasons
if(!skeleton)
SSevents.active_events += src
event_meta = EM
severity = _severity ? _severity : nominal_severity
if(severity < EVENT_LEVEL_MUNDANE)
severity = EVENT_LEVEL_MUNDANE
log_debug("Event of '[type]' with severity below mundane run has run")
if(severity > EVENT_LEVEL_DISASTER)
severity = EVENT_LEVEL_DISASTER
log_debug("Event of '[type]' with severity above disaster has run")
startedAt = world.time
if(!skeleton)
setup()
..()
//Called after something followable has been spawned by an event
//Provides ghosts a follow link to an atom if possible
//Only called once.
/datum/event/proc/announce_to_ghosts(atom/atom_of_interest)
if(atom_of_interest)
notify_ghosts("[name] has an object of interest: [atom_of_interest]!", title = "Something's Interesting!", source = atom_of_interest, flashwindow = FALSE, action = NOTIFY_FOLLOW)
/// Override this to make a custom fake announcement that differs from the normal announcement.
/// Used for false alarms.
/// If this proc returns TRUE, the regular Announce() won't be called.
/datum/event/proc/fake_announce()
return FALSE
/// The amount of people in different roles needed to handle an ongoing event.
/datum/event/proc/event_resource_cost()
return role_requirements