-
Notifications
You must be signed in to change notification settings - Fork 555
/
components.dm
55 lines (46 loc) · 1.66 KB
/
components.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/// Applies to a /datum/nmnode to enforce scenario constraints
/datum/component/nmnode_cond
/// Parameter from scenario storage to check for
var/pname
/// Value to check the parameter against
var/pvalue
/// By default, the condition is required. If true, invert the check
var/negate = FALSE
/datum/component/nmnode_cond/Initialize(pname, pvalue, negate = FALSE)
. = ..()
src.pname = pname
src.pvalue = pvalue
src.negate = negate
/datum/component/nmnode_cond/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_NIGHTMARE_APPLYING_NODE, PROC_REF(check_for_cond))
/datum/component/nmnode_cond/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, COMSIG_NIGHTMARE_APPLYING_NODE)
/datum/component/nmnode_cond/proc/check_for_cond(datum/nmnode/source, datum/nmcontext/context)
SIGNAL_HANDLER
var/value = context.get_scenario_value(src.pname)
#if defined(UNIT_TESTS)
return // Force true for testing (this could potentially make false positives though)
#endif
if(!(negate ^ (value == pvalue)))
return COMPONENT_ABORT_NMNODE
/// Adds a probability to skip the node
/datum/element/nmnode_prob
element_flags = ELEMENT_BESPOKE
id_arg_index = 1
var/probvalue = 1 // factor
/datum/element/nmnode_prob/Attach(target, probvalue)
. = ..()
src.probvalue = probvalue
RegisterSignal(target, COMSIG_NIGHTMARE_APPLYING_NODE, PROC_REF(check_prob))
/datum/element/nmnode_prob/Detach(datum/source, force)
. = ..()
UnregisterSignal(source, COMSIG_NIGHTMARE_APPLYING_NODE)
/datum/element/nmnode_prob/proc/check_prob(datum/nmnode/source)
SIGNAL_HANDLER
#if defined(UNIT_TESTS)
return // Force true for testing
#endif
if(rand() > probvalue)
return COMPONENT_ABORT_NMNODE