Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
notifiersmanager.c
Go to the documentation of this file.
1
//#define DIAG_NOTIFIER_LOGS
2
enum
eNotifiers
3
{
4
NTF_HEALTHY
,
5
NTF_BLEEDISH
,
6
NTF_HUNGRY
,
7
NTF_THIRSTY
,
8
NTF_STUFFED
,
9
NTF_SICK
,
10
NTF_WETNESS
,
11
NTF_WARMTH
,
12
NTF_FEVERISH
,
13
NTF_BLOOD
,
14
NTF_LIVES
,
15
NTF_STAMINA
,
16
//NTF_AGENT_INFECTION,
17
NTF_PILLS
,
18
NTF_HEARTBEAT
,
19
NTF_FRACTURE
,
20
NTF_LEGS
,
21
//----------------------------
22
NTF_COUNT
,
// !!! LAST ITEM !!!
23
}
24
25
class
NotifiersManager
26
{
27
static
const
int
MAX_COUNT
= 64;
28
ref
array<ref NotifierBase>
m_Notifiers
;
29
NotifierBase
m_NotifiersStatic
[
MAX_COUNT
];
//introduced as a seperate array to allow for fast lookup, keeping the old one for quick looping through but also to keep modding compatibility
30
PlayerBase
m_Player
;
31
ref
VirtualHud
m_VirtualHud
;
32
int
m_MinTickTime
;
33
string
m_System
=
"Notifiers"
;
34
private
int
m_LastPolledIndex
= 0;
35
private
ref
array<int>
m_NotifierIDs
=
new
array<int>
();
36
37
void
NotifiersManager
(
PlayerBase
player)
38
{
39
m_Player
= player;
40
m_Notifiers
=
new
array<ref NotifierBase>
;
41
m_MinTickTime
=
MIN_TICK_NOTIFIERS
;
42
m_LastPolledIndex
= 0;
43
44
Init
();
45
}
46
47
void
Init
()
48
{
49
m_Notifiers
.Insert(
new
HealthNotfr
(
this
));
50
m_Notifiers
.Insert(
new
HungerNotfr
(
this
));
51
m_Notifiers
.Insert(
new
ThirstNotfr
(
this
));
52
m_Notifiers
.Insert(
new
StuffedNotfr
(
this
));
53
m_Notifiers
.Insert(
new
SickNotfr
(
this
));
54
m_Notifiers
.Insert(
new
WetnessNotfr
(
this
));
55
m_Notifiers
.Insert(
new
WarmthNotfr
(
this
));
56
m_Notifiers
.Insert(
new
FeverNotfr
(
this
));
57
m_Notifiers
.Insert(
new
BloodNotfr
(
this
));
58
m_Notifiers
.Insert(
new
PillsNotfr
(
this
));
59
m_Notifiers
.Insert(
new
HeartbeatNotfr
(
this
));
60
m_Notifiers
.Insert(
new
FracturedLegNotfr
(
this
));
61
m_Notifiers
.Insert(
new
InjuredLegNotfr
(
this
));
62
}
63
64
void
RegisterItself
(
int
notifier_id,
NotifierBase
modifier)
65
{
66
if
(notifier_id >=
MAX_COUNT
)
67
{
68
ErrorEx
(
"Out of bounds for notifier id: "
+ notifier_id,
ErrorExSeverity
.ERROR);
69
}
70
else
71
{
72
m_NotifiersStatic
[notifier_id] = modifier;
73
m_NotifierIDs
.Insert(notifier_id);
74
#ifdef DIAG_NOTIFIER_LOGS
75
ErrorEx
(
string
.Format(
"Added notifier %1 with id=%2"
, modifier, notifier_id),
ErrorExSeverity
.INFO);
76
#endif
77
}
78
}
79
80
PlayerBase
GetPlayer
()
81
{
82
return
m_Player
;
83
}
84
85
VirtualHud
GetVirtualHud
()
86
{
87
return
m_VirtualHud
;
88
}
89
90
NotifierBase
FindNotifier
(
int
type)
91
{
92
return
m_NotifiersStatic
[type];
93
}
94
95
void
ActivateByType
(
int
notifier,
bool
triggerEvent =
true
)
96
{
97
FindNotifier
(notifier).
SetActive
(
true
);
98
}
99
100
void
DeactivateByType
(
int
notifier,
bool
triggerEvent =
true
)
101
{
102
FindNotifier
(notifier).
SetActive
(
false
);
103
}
104
105
void
OnScheduledTick
()
106
{
107
if
(!
GetPlayer
().IsPlayerSelected())
108
return
;
109
110
TickNotifiers
();
111
}
112
113
void
TickNotifiers
()
114
{
115
int
notifierCount =
m_Notifiers
.Count();
116
#ifdef DIAG_NOTIFIER_LOGS
117
if
(notifierCount == 0)
118
{
119
ErrorEx
(
"Notifier count is 0"
,
ErrorExSeverity
.ERROR);
120
return
;
121
}
122
#endif
123
124
// Wrap around if we've reached the end
125
if
(
m_LastPolledIndex
>= notifierCount)
126
{
127
#ifdef DIAG_NOTIFIER_LOGS
128
ErrorEx
(
string
.Format(
"Last poll index is %1 and notifiers count is %2. Restet poll index!"
,
m_LastPolledIndex
, notifierCount),
ErrorExSeverity
.INFO);
129
#endif
130
m_LastPolledIndex
= 0;
131
}
132
133
int
notifierID =
m_NotifierIDs
[
m_LastPolledIndex
];
134
#ifdef DIAG_NOTIFIER_LOGS
135
ErrorEx
(
string
.Format(
"Got notifier ID %1 for poll index %2."
, notifierID,
m_LastPolledIndex
),
ErrorExSeverity
.INFO);
136
#endif
137
// Get current notifier to process
138
NotifierBase
currentNotifier =
m_NotifiersStatic
[notifierID];
139
if
(currentNotifier && currentNotifier.
IsActive
())
140
{
141
#ifdef DIAG_NOTIFIER_LOGS
142
ErrorEx
(
string
.Format(
"Got notifier %1 with ID %2."
, currentNotifier, notifierID),
ErrorExSeverity
.INFO);
143
#endif
144
int
currentTime =
g_Game
.GetTime();
145
146
// Only tick if it's time (using the notifier's own interval)
147
if
(currentNotifier.
IsTimeToTick
(currentTime))
148
{
149
#ifdef DIAG_NOTIFIER_LOGS
150
ErrorEx
(
string
.Format(
"Time to tick notifier %1."
, currentNotifier),
ErrorExSeverity
.INFO);
151
#endif
152
currentNotifier.
OnTick
(currentTime);
153
}
154
#ifdef DIAG_NOTIFIER_LOGS
155
else
156
{
157
ErrorEx
(
string
.Format(
"Skip tick of notifier %1 .."
, currentNotifier),
ErrorExSeverity
.INFO);
158
}
159
#endif
160
}
161
#ifdef DIAG_NOTIFIER_LOGS
162
else
163
{
164
if
(!currentNotifier)
165
ErrorEx
(
string
.Format(
"Could not get any notifier with ID %1."
, notifierID),
ErrorExSeverity
.ERROR);
166
else
167
ErrorEx
(
string
.Format(
"Could get notifier %1 with ID %2 but notifier is inactive!"
, currentNotifier, notifierID),
ErrorExSeverity
.INFO);
168
}
169
#endif
170
171
// Move to next notifier for next tick
172
m_LastPolledIndex
++;
173
}
174
}
m_Player
map m_Player
BloodNotfr
Definition
bloodnotfr.c:2
FeverNotfr
Definition
fevernotfr.c:2
FracturedLegNotfr
Definition
fracturedlegnotfr.c:2
HealthNotfr
Definition
healthnotfr.c:2
HeartbeatNotfr
Definition
heartbeatnotfr.c:2
HungerNotfr
Definition
hungernotfr.c:2
InjuredLegNotfr
Definition
injuredlegnotfr.c:2
NotifierBase
Definition
notifierbase.c:2
NotifierBase::IsTimeToTick
bool IsTimeToTick(int current_time)
Definition
notifierbase.c:32
NotifierBase::SetActive
void SetActive(bool state)
Definition
notifierbase.c:69
NotifierBase::OnTick
void OnTick(float current_Time)
Definition
notifierbase.c:147
NotifierBase::IsActive
bool IsActive()
Definition
notifierbase.c:64
PillsNotfr
Definition
pillsnotfr.c:2
PlayerBase
Definition
playerbaseclient.c:2
SickNotfr
Definition
sicknotfr.c:2
StuffedNotfr
Definition
stuffednotfr.c:2
ThirstNotfr
Definition
thirstnotfr.c:2
WarmthNotfr
Definition
warmthnotfr.c:2
WetnessNotfr
Definition
wetnessnotfr.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
Init
override Widget Init()
Definition
dayzgame.c:127
VirtualHud
void VirtualHud(PlayerBase player)
Definition
displaystatus.c:36
ErrorExSeverity
ErrorExSeverity
Definition
endebug.c:62
ErrorEx
enum ShapeType ErrorEx
MIN_TICK_NOTIFIERS
const int MIN_TICK_NOTIFIERS
Definition
constants.c:351
GetPlayer
PlayerBase GetPlayer()
Definition
modifierbase.c:51
m_System
string m_System
the manager instance
Definition
modifierbase.c:12
NotifiersManager
void NotifiersManager(PlayerBase player)
Definition
notifiersmanager.c:37
m_VirtualHud
ref VirtualHud m_VirtualHud
Definition
notifiersmanager.c:31
eNotifiers
eNotifiers
Definition
notifiersmanager.c:3
NTF_HEALTHY
@ NTF_HEALTHY
Definition
notifiersmanager.c:4
NTF_HEARTBEAT
@ NTF_HEARTBEAT
Definition
notifiersmanager.c:18
NTF_BLOOD
@ NTF_BLOOD
Definition
notifiersmanager.c:13
NTF_THIRSTY
@ NTF_THIRSTY
Definition
notifiersmanager.c:7
NTF_STAMINA
@ NTF_STAMINA
Definition
notifiersmanager.c:15
NTF_LEGS
@ NTF_LEGS
Definition
notifiersmanager.c:20
NTF_FRACTURE
@ NTF_FRACTURE
Definition
notifiersmanager.c:19
NTF_STUFFED
@ NTF_STUFFED
Definition
notifiersmanager.c:8
NTF_WETNESS
@ NTF_WETNESS
Definition
notifiersmanager.c:10
NTF_COUNT
@ NTF_COUNT
Definition
notifiersmanager.c:22
NTF_PILLS
@ NTF_PILLS
Definition
notifiersmanager.c:17
NTF_SICK
@ NTF_SICK
Definition
notifiersmanager.c:9
NTF_WARMTH
@ NTF_WARMTH
Definition
notifiersmanager.c:11
NTF_FEVERISH
@ NTF_FEVERISH
Definition
notifiersmanager.c:12
NTF_LIVES
@ NTF_LIVES
Definition
notifiersmanager.c:14
NTF_BLEEDISH
@ NTF_BLEEDISH
Definition
notifiersmanager.c:5
NTF_HUNGRY
@ NTF_HUNGRY
Definition
notifiersmanager.c:6
OnScheduledTick
void OnScheduledTick()
Definition
notifiersmanager.c:105
m_NotifierIDs
ref array< int > m_NotifierIDs
Definition
notifiersmanager.c:35
GetVirtualHud
VirtualHud GetVirtualHud()
Definition
notifiersmanager.c:85
TickNotifiers
void TickNotifiers()
Definition
notifiersmanager.c:113
m_MinTickTime
int m_MinTickTime
Definition
notifiersmanager.c:32
FindNotifier
NotifierBase FindNotifier(int type)
Definition
notifiersmanager.c:90
MAX_COUNT
enum eNotifiers MAX_COUNT
m_NotifiersStatic
NotifierBase m_NotifiersStatic[MAX_COUNT]
Definition
notifiersmanager.c:29
DeactivateByType
void DeactivateByType(int notifier, bool triggerEvent=true)
Definition
notifiersmanager.c:100
m_Notifiers
ref array< ref NotifierBase > m_Notifiers
Definition
notifiersmanager.c:28
RegisterItself
void RegisterItself(int notifier_id, NotifierBase modifier)
Definition
notifiersmanager.c:64
m_LastPolledIndex
int m_LastPolledIndex
Definition
notifiersmanager.c:34
ActivateByType
void ActivateByType(int notifier, bool triggerEvent=true)
Definition
notifiersmanager.c:95
Games
Dayz
scripts
4_world
classes
playernotifiers
notifiersmanager.c
Generated by
1.17.0