DayZ 1.24
Loading...
Searching...
No Matches
DisplayStatus.c
Go to the documentation of this file.
2{
3 NORMAL = 0,//no bit, default
4 WARNING = 1,//first bit
5 CRITICAL = 2,//second bit
6 BLINKING = 3,//first + second bit
7 EXTRA = 4,//third bit
8}
9
10enum DSLevelsTemp
11{
12 NORMAL = 0,//no bit, default
19}
20
21class VirtualHud
22{
23 const int NUMBER_OF_MASKS = 2;//how many INT numbers we need to accommodate all elements
25 //ref map<int, ref DisplayElement> m_Elements;
32 string m_System = "VirtualHud";
33
35
37 {
39 m_LastTick = 0;
40
41 RegisterElement(new BadgeStuffed(m_Player));
42 RegisterElement(new BadgeWet(m_Player));
43 RegisterElement(new BadgeSick(m_Player));
44 RegisterElement(new BadgePills(m_Player));
45 RegisterElement(new BadgePoisoned(m_Player));
46 RegisterElement(new BadgeFracture(m_Player));
47 RegisterElement(new TendencyHealth(m_Player));
48 RegisterElement(new TendencyBlood(m_Player));
49 RegisterElement(new TendencyTemperature(m_Player));
50
51 RegisterElement(new TendencyHunger(m_Player));
52 RegisterElement(new TendencyThirst(m_Player));
53 RegisterElement(new TendencyBacteria(m_Player));
54 RegisterElement(new BadgeHeartbeat(m_Player));
55 RegisterElement(new BadgeLegs(m_Player));
56
57
58 RegisterElement(new ElementStance(m_Player));// client only
59 RegisterElement(new BadgeBleeding(m_Player));// client only
60
61
62 mission = GetGame().GetMission();
63 if (mission)
65 //UpdateStatus();
66 }
67
68
70 {
71 if (GetGame().IsServer())
72 {
74 {
75 SendRPC();
76 m_LastTick = GetGame().GetTime();
77 }
78 }
79 if (!GetGame().IsDedicatedServer())
80 {
82 //DisplayPresence();
83 }
84 }
85
87 {
88 int id = element.GetType();
90 //Log("adding element:"+id.ToString());
91 }
92
99
100 //this will serialize all elements and 'compresses' them into integer(s) through bit shifting, these integers are placed into an array
102 {
103 int offset = 0;
104 int mask = 0;
105
106 for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
107 {
108 if (GetElement(i) && !GetElement(i).IsClientOnly())
109 {
110 if ((GetElement(i).GetNumberOfBits() + offset) > BIT_INT_SIZE)
111 {
112 mask_array.Insert(mask);
113 offset = 0;
114 mask = 0;
115 }
116 mask = mask | (GetElement(i).GetValue() << offset);
117 offset = offset + GetElement(i).GetNumberOfBits();
118 }
119 }
120 mask_array.Insert(mask);
121 }
122
123 void DeserializeElements(ref array<int> mask_array)//extracts elements from mask
124 {
125 int maskArrayIndex = 0;
126 int offset = 0;
127 int mask = 0;
128
129 for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
130 {
131 if (GetElement(i) && !GetElement(i).IsClientOnly())
132 {
133 //Log("entity> " + ToString(GetElement(i)) );
134 if (offset + GetElement(i).GetNumberOfBits() > BIT_INT_SIZE)
135 {
137 offset = 0;
138 }
140 int value = BitToDec(mask, offset, GetElement(i).GetCompareMask());
141 offset = offset + GetElement(i).GetNumberOfBits();
142 GetElement(i).SetValue(value);
143 }
144 }
145 }
146
147 int BitToDec(int mask, int index, int compareMask)
148 {
149 int value = mask & (compareMask << index);
150 value = value >> index;
151 return value;
152 }
153
154
156 {
157 for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
158 PrintString(i.ToString() + ": " + GetElement(i).m_Value.ToString());
159 }
160
161 void SendRPC()
162 {
166 {
167 ScriptRPC rpc = new ScriptRPC();
168 rpc.Write(mask_array);
169 rpc.Send(m_Player, ERPCs.RPC_SYNC_DISPLAY_STATUS, false, m_Player.GetIdentity());
171 }
172 }
173
175 {
176 if (array_a.Count() != array_b.Count()) return false;
177 for (int i = 0; i < array_a.Count(); i++)
178 {
179 if (array_a.Get(i) != array_b.Get(i))
180 return false;
181 }
182 return true;
183 }
184
186 {
187 for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
188 {
190 if (element && element.IsClientOnly() && element.IsValueChanged())
191 element.UpdateHUD();
192 }
193 }
194
196 {
197 //Log("UpdateStatus called for entity: "+ToString(m_Player));
198 for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
199 {
201 if (element && !element.IsClientOnly() && element.IsValueChanged())
202 element.UpdateHUD();
203 }
204 }
205
206 void OnRPC(ParamsReadContext ctx)//on Client
207 {
208 //Log("OnRPC called");
210 ctx.Read(mask_array);
212 UpdateStatus();
213 }
214
215 void Debug()
216 {
217 Log("debug");
218 PluginPlayerStatus m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
219 m_ModulePlayerStatus.DisplayTendency(NTFKEY_HUNGRY, 2);
220 }
221}
VIRTUAL_HUD_UPDATE_INTERVAL
how often virtual hud checks if there is a difference since last sync
const int NTFKEY_HUNGRY
Definition _constants.c:34
const int BIT_INT_SIZE
Definition BitArray.c:4
void RegisterElement(DisplayElementBase element)
void PrintElements()
ref DisplayElementBase m_Elements[NUMBER_OF_ELEMENTS]
const int NUMBER_OF_ELEMENTS
enum DSLevels WARNING_MINUS
enum DSLevels NUMBER_OF_MASKS
int m_LastTick
void ImmediateUpdate()
enum DSLevels NORMAL
enum DSLevels CRITICAL_PLUS
Hud m_Hud
enum DSLevels BLINKING_PLUS
void SendRPC()
ref array< ref Param > rpcParams
void SerializeElements(ref array< int > mask_array)
enum DSLevels BLINKING_MINUS
DisplayElementBase GetElement(eDisplayElements element_id)
Mission mission
enum DSLevels WARNING_PLUS
void OnRPC(ParamsReadContext ctx)
DSLevels
@ BLINKING
@ WARNING
@ CRITICAL
@ EXTRA
void UpdateStatus()
void DeserializeElements(ref array< int > mask_array)
ref array< int > m_LastSentArray
bool AreArraysSame(notnull array< int > array_a, notnull array< int > array_b)
void VirtualHud(PlayerBase player)
enum DSLevels CRITICAL_MINUS
int BitToDec(int mask, int index, int compareMask)
ERPCs
Definition ERPCs.c:2
DayZPlayer m_Player
Definition Hand_Events.c:42
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
string m_System
PluginPlayerStatus m_ModulePlayerStatus
float GetTime()
void OnScheduledTick()
PluginBase GetPlugin(typename plugin_type)
Mission class.
Definition gameplay.c:668
Hud GetHud()
Definition gameplay.c:701
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
string m_Value
Definition EnEntity.c:805
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.