Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
notifiersmanager.c
Go to the documentation of this file.
1//#define DIAG_NOTIFIER_LOGS
24
25class NotifiersManager
26{
27 static const int MAX_COUNT = 64;
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
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;
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}
map m_Player
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
override Widget Init()
Definition dayzgame.c:127
void OnScheduledTick()
void VirtualHud(PlayerBase player)
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
const int MIN_TICK_NOTIFIERS
Definition constants.c:351
PlayerBase GetPlayer()
string m_System
the manager instance
ref VirtualHud m_VirtualHud
eNotifiers
@ NTF_HEALTHY
@ NTF_HEARTBEAT
@ NTF_BLOOD
@ NTF_THIRSTY
@ NTF_STAMINA
@ NTF_LEGS
@ NTF_FRACTURE
@ NTF_STUFFED
@ NTF_WETNESS
@ NTF_COUNT
@ NTF_PILLS
@ NTF_SICK
@ NTF_WARMTH
@ NTF_FEVERISH
@ NTF_LIVES
@ NTF_BLEEDISH
@ NTF_HUNGRY
int m_MinTickTime
enum eNotifiers MAX_COUNT
NotifierBase m_NotifiersStatic[MAX_COUNT]
ref array< ref NotifierBase > m_Notifiers