DayZ 1.24
Loading...
Searching...
No Matches
StateManager.c
Go to the documentation of this file.
6
7enum SymptomIDs
8{
24};
25
31
38
40const int MAX_QUEUE_SIZE = 5;
41
43{
46 ref map<int, int> m_ActiveSymptomTypes;//for each type(symptom id), keep track of how many times it is in queue
47
50
52
53
57 //ref array<string> m_SymptomQueueSecondaryServerDbg;
59
62
63 const int STORAGE_VERSION = 121;
64
65 bool m_ShowDebug = false;
66 bool m_ShowDebug2 = false;
67
69
86
88 {
89 return STORAGE_VERSION;
90 }
91
92
94 {
95 if (GetGame().IsClient())
96 return;
97
98 QueueUpSecondarySymptom(SymptomIDs.SYMPTOM_BLOODLOSS);
99 }
100
115
117 {
118 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
119 m_SymptomQueuePrimary.Get(i).OnOwnerKilled();
120
121 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
122 {
123 if (m_SymptomQueueSecondary.Get(i)) m_SymptomQueueSecondary.Get(i).OnOwnerKilled();
124 }
125 }
126
131
132
134 {
135 }
136
138 {
139 return m_Player;
140 }
141
143 {
144 Symptom.Init(this, m_Player, 0);
145 int id = Symptom.GetType();
146
147 if (m_AvailableSymptoms.Contains(id))
148 {
149 Error("SymptomBase Symptom already registered !");
150 return;
151 }
152
153 m_AvailableSymptoms.Insert(id, Symptom);
154 //PrintString("inserting id: "+ToString(id));
155 }
156
158 {
159 if (m_AnimMeta)
160 m_AnimMeta.AnimFinished(type);
161 }
162
168
170 {
171 int uid = Math.RandomInt(1, 2147483647);
172 if (!IsUIDUsed(uid)) return uid;
173 else return CreateUniqueID();
174 }
175
176 bool IsUIDUsed(int uid)
177 {
178 return m_SymptomsUIDs.Contains(uid);
179 }
180
182 {
183 return m_AvailableSymptoms.Get(symptom_id).GetName();
184 }
185
187 {
188 SmptAnimMetaBase animMeta = m_AvailableSymptoms.Get(symptom_id).SpawnAnimMetaObject();
189 animMeta.m_StateType = symptom_id;
190 return animMeta;
191 }
192
195 {
196 if (m_SymptomsUIDs.Get(SYMPTOM_uid)) m_SymptomsUIDs.Get(SYMPTOM_uid).RequestDestroy();
197 }
198
200 {
201 return m_AvailableSymptoms.Get(symptom_id).IsPrimary();
202 }
203
207
209 {
210 return m_CurrentCommandID;
211 }
212
214 {
215 // pCurrentCommandID might be the initial value, but the system itself requires
216 // current value, so retrieve the current value from player instead
217 m_CurrentCommandID = m_Player.GetCurrentCommandID();
220
222
223 if (m_AnimMeta)
224 {
225 if (m_AnimMeta.IsDestroyReqested())
227 }
228
229 if (m_AnimMeta)
230 {
231
232 //anim requested
233 if (!m_AnimMeta.IsPlaying())
234 {
235 // not playing yet and not possible to play
237 if (symptom && !symptom.CanActivate())
239 else if (m_AnimMeta.PlayRequest() == EAnimPlayState.FAILED)
241 }
242 else
244 }
245
246#ifdef DIAG_DEVELOPER
247#ifndef SERVER //must be here !!!
248 if (DiagMenu.GetBool(DiagMenuIDs.MISC_PLAYER_SYMPTOMS_SHOW))
249 {
250 //DisplayDebug(true);
253
254 DisplayDebug1("Symptoms Client", 50, primary_debug, secondary_debug);
257 }
258 else
259 {
260 CleanDebug1("Symptoms Client", 50);
261 CleanDebug2("Symptoms Server", 300);
263 }
264#endif
265#endif
266 }
267
269 {
270 if (m_AnimMeta)
271 {
272 // animation meta already exists
273 // pass
274 }
275 else
276 {
277 int state_type;
278 if (ctx.Read(state_type))
279 {
281 if (m_AnimMeta)
282 m_AnimMeta.Init(ctx, this, m_Player);
283 }
284 }
285 }
286
288 {
289 //if( GetGame().IsClient() && !m_Player.IsPlayer() ) return;
290 //primary
292 {
293 if (!GetCurrentPrimaryActiveSymptom().IsActivated())
294 {
295 if (GetCurrentPrimaryActiveSymptom().CanActivate())
297 }
298 if (GetCurrentPrimaryActiveSymptom().IsActivated())
300 }
301 //secondary
302 for (int i = 0; i < m_SymptomQueueSecondary.Count(); i++)
303 {
304 if (m_SymptomQueueSecondary.Get(i) && !m_SymptomQueueSecondary.Get(i).IsActivated())
305 m_SymptomQueueSecondary.Get(i).Activate();
306 else
307 {
309 }
310 }
311 }
312
313
315 {
316 bool is_primary;
317 if (Symptom)
318 {
319 is_primary = Symptom.IsPrimary();
320 DecreaseSymptomCount(Symptom.GetType());
321 }
322
323 if (m_SymptomsUIDs.Contains(uid))
324 m_SymptomsUIDs.Remove(uid);
325 else
326 Debug.LogError("Symptom with this UID does not exist", "PlayerSymptoms");
327
328 if (is_primary)
329 {
330 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
331 {
332 if (m_SymptomQueuePrimary.Get(i) == Symptom)
333 {
334 m_SymptomQueuePrimary.RemoveOrdered(i);
335 break;
336 }
337 }
338 }
339 else
340 {
341 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
342 {
344 {
345 m_SymptomQueueSecondary.RemoveOrdered(i);
346 break;
347 }
348 }
349 }
351#ifdef DIAG_DEVELOPER
353#endif
354 }
355
356
358 {
359 return m_AvailableSymptoms.Get(symptom_id).GetMaxCount();
360 }
361
362
364 {
365 if (m_ActiveSymptomTypes.Contains(symptom_id))
367 else
368 return -1;
369 }
370
378
380 {
381 if (m_ActiveSymptomTypes.Contains(symptom_id))
382 {
383 if (m_ActiveSymptomTypes.Get(symptom_id) == 1)
385 else
387 }
388 }
389
391 {
393 {
394 SymptomBase Symptom = SymptomBase.Cast(m_AvailableSymptoms.Get(symptom_id).ClassName().ToType().Spawn());
395 if (uid == -1)
397 Symptom.Init(this, m_Player, uid);
398 if (m_SymptomsUIDs.Contains(uid))
399 Error("Symptoms: Unique ID already exists !");
400 m_SymptomsUIDs.Insert(uid, Symptom);
402 return Symptom;
403 }
404
405 if (!Symptom)
406 Error("Symptom not registered");
407
408 return NULL;
409 }
410
412 {
413 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
414 m_SymptomQueuePrimary.Get(i).RequestDestroy();
415
416 }
417
419 {
422 return null;
423 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
424 {
425 if (m_SymptomQueuePrimary.Get(i).CanBeInterupted() && ComparePriority(GetSymptomPriority(symptom_id), m_SymptomQueuePrimary.Get(i).GetPriority()) == 1)
426 {
429
431 {
432 m_SymptomQueuePrimary.Get(MAX_QUEUE_SIZE).RequestDestroy();// no need to remove from the array, that's done via Symptom callback on destruct
433 }
434 break;
435 }
436 }
438 {
441 }
442#ifdef DIAG_DEVELOPER
444#endif
445 return Symptom;
446 }
447
452
454 {
456 return null;
457
458 if (m_AvailableSymptoms.Get(symptom_id).IsPrimary())
459 return null;
460
462
464 return Symptom;
465 }
466
469 {
470 for (int i = 0; i < m_SymptomQueueSecondary.Count(); i++)
471 {
472 if (m_SymptomQueueSecondary.Get(i) && m_SymptomQueueSecondary.Get(i).GetType() == symptom_id)
473 {
474 m_SymptomQueueSecondary.Get(i).RequestDestroy();
475 return;
476 }
477 }
478 }
479
481 {
482 if (GetGame().IsServer())
483 {
485 {
487 }
488 }
489 if (!GetGame().IsDedicatedServer())
490 {
491 if (m_SymptomQueuePrimary.Count() > 0)
492 return m_SymptomQueuePrimary.Get(0);
493 }
494 return NULL;
495 }
496
498 {
499 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
500 {
501 if (m_SymptomQueuePrimary.Get(i).CanActivate())
502 return i;
503 }
504 return -1;
505 }
506
508 {
509 if (prio1 > prio2)
510 return 1;
511 else if (prio2 > prio1)
512 return 2;
513 return 0;
514 }
515
517 {
518 return m_AvailableSymptoms.Get(symptom_id).GetPriority();
519 }
520
522 {
526
527 bool is_primary = m_AvailableSymptoms.Get(symptom_id).IsPrimary();
528
529 if (rpc_type == ERPCs.RPC_PLAYER_SYMPTOM_ON)
530 {
531 if (is_primary)
532 {
535 }
536 else
538 }
539 else if (rpc_type == ERPCs.RPC_PLAYER_SYMPTOM_OFF)
540 {
541 if (is_primary)
543 else
545 }
546 }
547
549 {
551
552 for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
553 {
554 if (m_SymptomQueuePrimary.Get(i).IsPersistent())
555 m_SaveQueue.Insert(m_SymptomQueuePrimary.Get(i).GetType());
556 }
557
558 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
559 {
560 if (m_SymptomQueueSecondary.Get(i).IsPersistent())
561 m_SaveQueue.Insert(m_SymptomQueueSecondary.Get(i).GetType());
562 }
563
564 ctx.Write(m_SaveQueue);
565 }
566
568 {
570
571 if (ctx.Read(m_SaveQueue))
572 {
573 for (int i = 0; i < m_SaveQueue.Count(); i++)
574 {
575 int id = m_SaveQueue.Get(i);
576
577 if (IsSymptomPrimary(id))
579 else
581 }
582 return true;
583 }
584 else
585 return false;
586 }
587
588#ifdef DIAG_DEVELOPER
590 {
591 switch (rpc_type)
592 {
593 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON:
594 {
596 {
599 else
601 }
602 break;
603 }
604
605 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF:
606 {
609 break;
610 }
611
612 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG:
613 {
616
617 int symptom_id;
618
621
624
628
630 for (int i = 0; i < overall_count ; ++i)
631 {
633 ctx.Read(p3);
634 bool is_primary = p3.param1;
635
636 if (is_primary)
637 {
638 m_SymptomQueueServerDbgPrimary.Insert(p3);// m_SymptomQueueServerDbg.Insert(p3);
639 }
640 else
642 //PrintString("elements m_SymptomQueueServerDbgPrimary:" + m_SymptomQueueServerDbgPrimary.Count());
643 //PrintString("elements m_SymptomQueueServerDbgSecondary:" + m_SymptomQueueServerDbgSecondary.Count());
644
645 }
646 /*
647 for(i = 0; i < secondary_Symptoms_count; i++)
648 {
649 ctx.Read(CachedObjectsParams.PARAM1_STRING);
650 m_SymptomQueueSecondaryServerDbg.Insert(CachedObjectsParams.PARAM1_STRING.param1);
651 }*/
652 break;
653 }
654 }
655 }
656
658 {
660
661 Param1<int> p1 = new Param1<int>(0);
662 Param1<int> p2 = new Param1<int>(0);
663
664 p1.param1 = m_SymptomQueuePrimary.Count();
665 p2.param1 = m_SymptomQueueSecondary.Count();
666
667 debug_list.Insert(p1);
668 debug_list.Insert(p2);
669
671
672 bool is_primary;
673 int symptom_id;
674 int SYMPTOM_uid;
675
677 {
678 is_primary = symptom.IsPrimary();
679 symptom_id = symptom.GetType();
680 SYMPTOM_uid = symptom.GetUID();
681
683 debug_list.Insert(p);
684 }
685
687 {
688 is_primary = secSymptom.IsPrimary();
689 symptom_id = secSymptom.GetType();
690 SYMPTOM_uid = secSymptom.GetUID();
691
693 debug_list.Insert(p);
694 }
695
696 GetGame().RPC(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG, debug_list, true);
697 }
698
700 {
702 if (GetPlayer())
703 GetGame().RPCSingleParam(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF, CachedObjectsParams.PARAM1_INT, true, GetPlayer().GetIdentity());
704 }
705
707 {
709
711
712 for (int i = 0; i < Symptoms.Count(); i++)
713 {
714 bool is_primary = Symptoms.Get(i).IsPrimary();
715 int symptom_id = Symptoms.Get(i).GetType();
716 int SYMPTOM_uid = Symptoms.Get(i).GetUID();
717
719 debug_array.Insert(p3);
720 }
721 return debug_array;
722 }
723
725 {
726 string primary;
728
730 DbgUI.Begin(name, 50, y_offset);
731 DbgUI.Text("Primary: ");
732
733 bool is_primary;
734 int symptom_id;
735 int SYMPTOM_uid;
736 string SYMPTOM_name;
737
738 for (int i = 0; i < Symptoms_primary.Count(); i++)
739 {
741
742 is_primary = p3.param1;
743 symptom_id = p3.param2;
744 SYMPTOM_uid = p3.param3;
746
747 primary += SYMPTOM_name + " | ";
748 }
749
751 DbgUI.Text("Secondary: ");
752 for (i = 0; i < Symptoms_secondary.Count(); i++)
753 {
755
756 is_primary = p3.param1;
757 symptom_id = p3.param2;
758 SYMPTOM_uid = p3.param3;
761 }
762
763 DbgUI.End();
765 }
766
768 {
769 string primary;
771
773 DbgUI.Begin(name, 50, y_offset);
774 DbgUI.Text("Primary: ");
775
776 bool is_primary;
777 int symptom_id;
778 int SYMPTOM_uid;
779 string SYMPTOM_name;
780
781 for (int i = 0; i < Symptoms_primary.Count(); i++)
782 {
784
785 is_primary = p3.param1;
786 symptom_id = p3.param2;
787 SYMPTOM_uid = p3.param3;
789
790 if (DbgUI.Button(i.ToString() + " " + SYMPTOM_name, 80))
792 }
793
794 DbgUI.Text("Secondary: ");
795 for (i = 0; i < Symptoms_secondary.Count(); i++)
796 {
798
799 is_primary = p3.param1;
800 symptom_id = p3.param2;
801 SYMPTOM_uid = p3.param3;
803
804 if (DbgUI.Button(i.ToString() + " " + SYMPTOM_name, 80))
806 }
807
808 DbgUI.End();
810 }
811
813 {
815 DbgUI.Begin("available Symptoms", 300, 50);
816
817 for (int i = 0; i < m_AvailableSymptoms.Count(); i++)
818 {
820 string SYMPTOM_name = Symptom.GetName();
821 int symptom_id = Symptom.GetType();
822
823 if (DbgUI.Button(i.ToString() + " " + SYMPTOM_name, 80))
825 }
826
827 DbgUI.End();
829 }
830
832 {
834 DbgUI.Begin("available Symptoms", 300, 50);
835 DbgUI.End();
837 }
838
839 void CleanDebug1(string name, int y_offset)
840 {
842 DbgUI.Begin(name, 50, y_offset);
843 DbgUI.End();
845 }
846
847 void CleanDebug2(string name, int y_offset)
848 {
850 DbgUI.Begin(name, 50, y_offset);
851 DbgUI.End();
853 }
854
856 {
858 if (GetPlayer())
859 GetGame().RPCSingleParam(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON, CachedObjectsParams.PARAM1_INT, true, GetPlayer().GetIdentity());
860 }
861
862#endif
863}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DiagMenuIDs
Definition EDiagMenuIDs.c:2
ERPCs
Definition ERPCs.c:2
eAnimFinishType
Definition SmptAnimMeta.c:2
enum AnimType SYMPTOM_BLINDNESS
enum AnimType SYMPTOM_VOMIT
enum AnimType SYMPTOM_BLEEDING_SOURCE
enum AnimType SYMPTOM_UNCONSCIOUS
enum AnimType SYMPTOM_PAIN_LIGHT
enum AnimType SYMPTOM_BULLET_HIT
enum AnimType SYMPTOM_HAND_SHIVER
const int DEBUG_PADDING_OFFSET
enum AnimType SYMPTOM_FEVERBLUR
enum AnimType SYMPTOM_FREEZE
enum AnimType SYMPTOM_BLOODLOSS
enum AnimType SYMPTOM_LAUGHTER
enum AnimType SYMPTOM_COUGH
SymptomTypes
@ PRIMARY
@ SECONDARY
EAnimPlayState
@ OK
@ POSTPONED
@ FAILED
AnimType
Definition StateManager.c:2
@ FULL_BODY
Definition StateManager.c:3
@ ADDITIVE
Definition StateManager.c:4
enum AnimType SYMPTOM_PAIN_HEAVY
enum AnimType SYMPTOM_SNEEZE
enum AnimType SYMPTOM_HOT
const int MAX_QUEUE_SIZE
static ref Param1< int > PARAM1_INT
static ref Param2< int, int > PARAM2_INT_INT
Definition DbgUI.c:60
Definition Debug.c:14
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:341
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
void Activate()
Definition StateBase.c:161
void Update(float deltatime)
Definition StateBase.c:201
void AnimationStart()
Definition StateBase.c:306
const int STORAGE_VERSION
int GetSymptomCount(int symptom_id)
void ~SymptomManager()
void DecreaseSymptomCount(int symptom_id)
void SetAnimation(ParamsReadContext ctx)
void OnInputUserDataReceived(ParamsReadContext ctx)
bool IsUIDUsed(int uid)
PlayerBase m_Player
void QueueUpSecondarySymptom(int symptom_id, int uid=-1)
int GetSymptomMaxCount(int symptom_id)
void OnPlayerKilled()
void AutoactivateSymptoms()
ref SmptAnimMetaBase m_AnimMeta
void OnStoreSave(ParamsWriteContext ctx)
int GetStorageVersion()
ref map< int, int > m_ActiveSymptomTypes
int GetCurrentCommandID()
bool IsSymptomPrimary(int symptom_id)
ref map< int, SymptomBase > m_SymptomsUIDs
ref array< ref Param > m_SymptomQueueServerDbg
string GetSymptomName(int symptom_id)
int GetSymptomPriority(int symptom_id)
void OnSymptomExit(SymptomBase Symptom, int uid)
ref array< ref Param > m_SymptomQueueServerDbgPrimary
ref map< int, ref SymptomBase > m_AvailableSymptoms
SymptomBase GetCurrentPrimaryActiveSymptom()
SymptomBase QueueUpSecondarySymptomEx(int symptom_id, int uid=-1)
bool OnStoreLoad(ParamsReadContext ctx, int version)
void OnTick(float deltatime, int pCurrentCommandID, HumanMovementState movement_state)
void RemoveSecondarySymptom(int symptom_id)
Removes a single Symptom.
SymptomBase QueueUpPrimarySymptom(int symptom_id, int uid=-1)
ref array< ref SymptomBase > m_SymptomQueueSecondary
void IncreaseSymptomCount(int symptom_id)
int m_ActiveSymptomIndexPrimary
ref array< ref SymptomBase > m_SymptomQueuePrimary
void OnAnimationFinished(eAnimFinishType type=eAnimFinishType.SUCCESS)
ref array< ref Param > m_SymptomQueueServerDbgSecondary
SmptAnimMetaBase SpawnAnimMetaObject(int symptom_id)
void SymptomManager(PlayerBase player)
SymptomBase SpawnSymptom(int symptom_id, int uid=-1)
void UpdateActiveSymptoms(float deltatime)
int FindFirstAvailableSymptomIndex()
void OnRPC(int rpc_type, ParamsReadContext ctx)
void RequestSymptomExit(int SYMPTOM_uid)
Exits a specific Symptom with a given UID.
SymptomBase GetSymptomByUID(int SYMPTOM_uid)
void CleanUpPrimaryQueue()
void RegisterSymptom(SymptomBase Symptom)
void OnAnimationStarted()
PlayerBase GetPlayer()
int ComparePriority(int prio1, int prio2)
ref Timer m_Timer
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native bool Button(string txt, int minWidth=0)
static proto native void Text(string label)
static proto void BeginCleanupScope()
static proto native void EndCleanupScope()
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].