60 int m_ActiveSymptomIndexPrimary = -1;
61 int m_CurrentCommandID;
63 const int STORAGE_VERSION = 121;
65 bool m_ShowDebug =
false;
66 bool m_ShowDebug2 =
false;
72 RegisterSymptom(
new CoughSymptom);
73 RegisterSymptom(
new VomitSymptom);
74 RegisterSymptom(
new BlindnessSymptom);
75 RegisterSymptom(
new SneezeSymptom);
76 RegisterSymptom(
new FeverBlurSymptom);
77 RegisterSymptom(
new BloodLoss);
78 RegisterSymptom(
new LaughterSymptom);
79 RegisterSymptom(
new FreezeSymptom);
80 RegisterSymptom(
new HotSymptom);
81 RegisterSymptom(
new PainLightSymptom);
82 RegisterSymptom(
new PainHeavySymptom);
83 RegisterSymptom(
new HandShiversSymptom);
87 int GetStorageVersion()
93 void AutoactivateSymptoms()
100 QueueUpSecondarySymptom(SymptomIDs.SYMPTOM_BLOODLOSS);
115 AutoactivateSymptoms();
118 void OnPlayerKilled()
120 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
122 m_SymptomQueuePrimary.Get(i).OnOwnerKilled();
125 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
127 if (m_SymptomQueueSecondary.Get(i)) m_SymptomQueueSecondary.Get(i).OnOwnerKilled();
133 return m_SymptomsUIDs.Get(SYMPTOM_uid);
149 int id = Symptom.GetType();
151 if ( m_AvailableSymptoms.Contains(
id) )
153 Error(
"SymptomBase Symptom already registered !");
157 m_AvailableSymptoms.Insert(
id, Symptom);
165 m_AnimMeta.AnimFinished(type);
169 void OnAnimationStarted()
171 if ( GetCurrentPrimaryActiveSymptom() )
172 GetCurrentPrimaryActiveSymptom().AnimationStart();
177 int uid =
Math.RandomInt( 1, 2147483647);
178 if ( !IsUIDUsed(uid) )
return uid;
179 else return CreateUniqueID();
182 bool IsUIDUsed(
int uid)
184 return m_SymptomsUIDs.Contains(uid);
187 string GetSymptomName(
int symptom_id)
189 return m_AvailableSymptoms.Get(symptom_id).GetName();
194 SmptAnimMetaBase animMeta = m_AvailableSymptoms.Get(symptom_id).SpawnAnimMetaObject();
195 animMeta.m_StateType = symptom_id;
200 void RequestSymptomExit(
int SYMPTOM_uid)
202 if ( m_SymptomsUIDs.Get(SYMPTOM_uid) ) m_SymptomsUIDs.Get(SYMPTOM_uid).RequestDestroy();
205 bool IsSymptomPrimary(
int symptom_id)
207 return m_AvailableSymptoms.Get(symptom_id).IsPrimary();
214 int GetCurrentCommandID()
216 return m_CurrentCommandID;
219 void OnTick(
float deltatime,
int pCurrentCommandID,
HumanMovementState movement_state)
223 m_CurrentCommandID =
m_Player.GetCurrentCommandID();
224 if (m_ActiveSymptomIndexPrimary == -1)
226 m_ActiveSymptomIndexPrimary = FindFirstAvailableSymptomIndex();
229 UpdateActiveSymptoms(deltatime);
233 if ( m_AnimMeta.IsDestroyReqested() )
243 if ( !m_AnimMeta.IsPlaying() )
246 SymptomBase symptom = m_AvailableSymptoms.Get( m_AnimMeta.m_StateType );
247 if ( symptom && !symptom.CanActivate() )
258 m_AnimMeta.Update(movement_state);
262 #ifdef DIAG_DEVELOPER
263 #ifndef SERVER //must be here !!!
268 array<ref Param> secondary_debug = PrepareClientDebug(m_SymptomQueueSecondary);
270 DisplayDebug1(
"Symptoms Client", 50, primary_debug, secondary_debug);
271 DisplayDebug2(
"Symptoms Server", 300, m_SymptomQueueServerDbgPrimary, m_SymptomQueueServerDbgSecondary);
272 ShowAvailableSymptoms();
276 CleanDebug1(
"Symptoms Client", 50);
277 CleanDebug2(
"Symptoms Server", 300);
278 CleanAvailableSymptoms();
294 if (ctx.Read(state_type))
296 m_AnimMeta = SpawnAnimMetaObject(state_type);
299 m_AnimMeta.Init(ctx,
this,
m_Player);
305 void UpdateActiveSymptoms(
float deltatime)
309 if ( GetCurrentPrimaryActiveSymptom() )
311 if ( !GetCurrentPrimaryActiveSymptom().IsActivated() )
313 if ( GetCurrentPrimaryActiveSymptom().CanActivate() )
314 GetCurrentPrimaryActiveSymptom().Activate();
316 if ( GetCurrentPrimaryActiveSymptom().IsActivated() )
318 GetCurrentPrimaryActiveSymptom().Update(deltatime);
322 for (
int i = 0; i < m_SymptomQueueSecondary.Count(); i++)
324 if ( m_SymptomQueueSecondary.Get(i) && !m_SymptomQueueSecondary.Get(i).IsActivated() )
326 m_SymptomQueueSecondary.Get(i).Activate();
330 if (m_SymptomQueueSecondary.Get(i)) m_SymptomQueueSecondary.Get(i).Update(deltatime);
341 is_primary = Symptom.IsPrimary();
342 DecreaseSymptomCount(Symptom.GetType());
345 if ( m_SymptomsUIDs.Contains(uid) )
347 m_SymptomsUIDs.Remove(uid);
351 Debug.LogError(
"Symptom with this UID does not exist",
"PlayerSymptoms");
356 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
358 if ( m_SymptomQueuePrimary.Get(i) == Symptom )
360 m_SymptomQueuePrimary.RemoveOrdered(i);
367 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
369 if ( m_SymptomQueueSecondary.Get(i) == Symptom )
371 m_SymptomQueueSecondary.RemoveOrdered(i);
376 m_ActiveSymptomIndexPrimary = -1;
377 #ifdef DIAG_DEVELOPER
378 if (
GetGame() ) SendServerDebugToClient();
383 int GetSymptomMaxCount(
int symptom_id)
385 return m_AvailableSymptoms.Get(symptom_id).GetMaxCount();
389 int GetSymptomCount(
int symptom_id)
391 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
392 return m_ActiveSymptomTypes.Get(symptom_id);
397 void IncreaseSymptomCount(
int symptom_id)
399 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
401 m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) + 1);
405 m_ActiveSymptomTypes.Insert(symptom_id, 1);
409 void DecreaseSymptomCount(
int symptom_id)
411 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
413 if ( m_ActiveSymptomTypes.Get(symptom_id) == 1)
414 m_ActiveSymptomTypes.Remove(symptom_id);
416 m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) - 1);
420 SymptomBase SpawnSymptom(
int symptom_id,
int uid = -1 )
422 if ( m_AvailableSymptoms.Get(symptom_id) )
427 uid = CreateUniqueID();
430 if ( m_SymptomsUIDs.Contains(uid) )
431 Error(
"Symptoms: Unique ID already exists !");
432 m_SymptomsUIDs.Insert(uid, Symptom);
433 IncreaseSymptomCount(symptom_id);
439 Error(
"Symptom not registered");
445 void CleanUpPrimaryQueue()
447 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
449 m_SymptomQueuePrimary.Get(i).RequestDestroy();
454 SymptomBase QueueUpPrimarySymptom(
int symptom_id,
int uid = -1)
457 if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
459 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++ )
461 if ( m_SymptomQueuePrimary.Get(i).CanBeInterupted() && ComparePriority( GetSymptomPriority(symptom_id), m_SymptomQueuePrimary.Get(i).GetPriority() ) == 1 )
463 Symptom = SpawnSymptom( symptom_id, uid );
464 m_SymptomQueuePrimary.InsertAt(Symptom,i);
475 Symptom = SpawnSymptom( symptom_id, uid );
476 m_SymptomQueuePrimary.Insert(Symptom);
478 #ifdef DIAG_DEVELOPER
479 SendServerDebugToClient();
484 void QueueUpSecondarySymptom(
int symptom_id,
int uid = -1)
486 QueueUpSecondarySymptomEx(symptom_id, uid);
489 SymptomBase QueueUpSecondarySymptomEx(
int symptom_id,
int uid = -1)
491 if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
494 if ( m_AvailableSymptoms.Get(symptom_id).IsPrimary() )
497 SymptomBase Symptom = SpawnSymptom( symptom_id, uid);
499 m_SymptomQueueSecondary.Insert(Symptom);
504 void RemoveSecondarySymptom(
int symptom_id)
506 for (
int i = 0; i < m_SymptomQueueSecondary.Count();i++)
508 if ( m_SymptomQueueSecondary.Get(i) && m_SymptomQueueSecondary.Get(i).GetType() == symptom_id )
510 m_SymptomQueueSecondary.Get(i).RequestDestroy();
520 if ( m_ActiveSymptomIndexPrimary >= 0 && m_ActiveSymptomIndexPrimary < m_SymptomQueuePrimary.Count() )
522 if ( m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary) )
return m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary);
525 if ( !
GetGame().IsDedicatedServer() )
527 if ( m_SymptomQueuePrimary.Count() > 0 )
528 return m_SymptomQueuePrimary.Get(0);
533 int FindFirstAvailableSymptomIndex()
535 for (
int i = 0; i < m_SymptomQueuePrimary.Count();i++)
537 if ( m_SymptomQueuePrimary.Get(i).CanActivate() )
545 int ComparePriority(
int prio1,
int prio2 )
551 else if ( prio2 > prio1 )
558 int GetSymptomPriority(
int symptom_id)
560 return m_AvailableSymptoms.Get(symptom_id).GetPriority();
569 bool is_primary = m_AvailableSymptoms.Get(symptom_id).IsPrimary();
571 if ( rpc_type ==
ERPCs.RPC_PLAYER_SYMPTOM_ON )
575 CleanUpPrimaryQueue();
576 QueueUpPrimarySymptom(symptom_id,uid);
580 QueueUpSecondarySymptom(symptom_id,uid);
583 else if ( rpc_type ==
ERPCs.RPC_PLAYER_SYMPTOM_OFF )
587 CleanUpPrimaryQueue();
591 RemoveSecondarySymptom( symptom_id );
600 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++ )
602 if ( m_SymptomQueuePrimary.Get(i).IsPersistent() )
604 m_SaveQueue.Insert( m_SymptomQueuePrimary.Get(i).GetType() );
608 for ( i = 0; i < m_SymptomQueueSecondary.Count(); i++ )
610 if ( m_SymptomQueueSecondary.Get(i).IsPersistent() )
612 m_SaveQueue.Insert( m_SymptomQueueSecondary.Get(i).GetType() );
616 ctx.Write( m_SaveQueue );
623 if (ctx.Read(m_SaveQueue))
625 for (
int i = 0; i < m_SaveQueue.Count(); i++ )
627 int id = m_SaveQueue.Get(i);
629 if ( IsSymptomPrimary(
id) )
631 QueueUpPrimarySymptom(
id );
635 QueueUpSecondarySymptom(
id );
646 #ifdef DIAG_DEVELOPER
651 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON:
667 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF:
674 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG:
676 int primary_Symptoms_count;
677 int secondary_Symptoms_count;
691 m_SymptomQueueServerDbg.Clear();
692 m_SymptomQueueServerDbgPrimary.Clear();
693 m_SymptomQueueServerDbgSecondary.Clear();
695 int overall_count = primary_Symptoms_count + secondary_Symptoms_count;
696 for (
int i = 0; i < overall_count ; ++i)
700 bool is_primary = p3.param1;
704 m_SymptomQueueServerDbgPrimary.Insert(p3);
708 m_SymptomQueueServerDbgSecondary.Insert(p3);
725 void SendServerDebugToClient()
729 Param1<int> p1 =
new Param1<int>(0);
730 Param1<int> p2 =
new Param1<int>(0);
732 p1.param1 = m_SymptomQueuePrimary.Count();
733 p2.param1 = m_SymptomQueueSecondary.Count();
735 debug_list.Insert(p1);
736 debug_list.Insert(p2);
744 foreach (
SymptomBase symptom : m_SymptomQueuePrimary )
746 is_primary = symptom.IsPrimary();
747 symptom_id = symptom.GetType();
748 SYMPTOM_uid = symptom.GetUID();
751 debug_list.Insert(p);
754 foreach (
SymptomBase secSymptom : m_SymptomQueueSecondary )
756 is_primary = secSymptom.IsPrimary();
757 symptom_id = secSymptom.GetType();
758 SYMPTOM_uid = secSymptom.GetUID();
761 debug_list.Insert(p);
764 GetGame().RPC(GetPlayer(),
ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG, debug_list,
true);
767 void DebugRequestExitSymptom(
int SYMPTOM_uid)
780 for (
int i = 0; i < Symptoms.Count(); i++)
782 bool is_primary = Symptoms.Get(i).IsPrimary();
783 int symptom_id = Symptoms.Get(i).GetType();
784 int SYMPTOM_uid = Symptoms.Get(i).GetUID();
787 debug_array.Insert(p3);
797 DbgUI.BeginCleanupScope();
799 DbgUI.Text(
"Primary: ");
806 for (
int i = 0; i < Symptoms_primary.Count(); i++)
810 is_primary = p3.param1;
811 symptom_id = p3.param2;
812 SYMPTOM_uid = p3.param3;
813 SYMPTOM_name = GetSymptomName(symptom_id);
815 primary += SYMPTOM_name +
" | ";
819 DbgUI.Text(
"Secondary: ");
820 for (i = 0; i < Symptoms_secondary.Count(); i++)
824 is_primary = p3.param1;
825 symptom_id = p3.param2;
826 SYMPTOM_uid = p3.param3;
827 SYMPTOM_name = GetSymptomName(symptom_id);
828 DbgUI.Text(SYMPTOM_name);
832 DbgUI.EndCleanupScope();
840 DbgUI.BeginCleanupScope();
842 DbgUI.Text(
"Primary: ");
849 for (
int i = 0; i < Symptoms_primary.Count(); i++)
853 is_primary = p3.param1;
854 symptom_id = p3.param2;
855 SYMPTOM_uid = p3.param3;
856 SYMPTOM_name = GetSymptomName(symptom_id);
858 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
860 DebugRequestExitSymptom(SYMPTOM_uid);
864 DbgUI.Text(
"Secondary: ");
865 for (i = 0; i < Symptoms_secondary.Count(); i++)
869 is_primary = p3.param1;
870 symptom_id = p3.param2;
871 SYMPTOM_uid = p3.param3;
872 SYMPTOM_name = GetSymptomName(symptom_id);
874 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
876 DebugRequestExitSymptom(SYMPTOM_uid);
881 DbgUI.EndCleanupScope();
884 void ShowAvailableSymptoms()
886 DbgUI.BeginCleanupScope();
887 DbgUI.Begin(
"available Symptoms", 300, 50);
889 for (
int i = 0; i < m_AvailableSymptoms.Count(); i++)
891 SymptomBase Symptom = m_AvailableSymptoms.GetElement(i);
892 string SYMPTOM_name = Symptom.GetName();
893 int symptom_id = Symptom.GetType();
895 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
897 DebugRequestActivateSymptom(symptom_id);
902 DbgUI.EndCleanupScope();
905 void CleanAvailableSymptoms()
907 DbgUI.BeginCleanupScope();
908 DbgUI.Begin(
"available Symptoms", 300, 50);
910 DbgUI.EndCleanupScope();
913 void CleanDebug1(
string name,
int y_offset)
915 DbgUI.BeginCleanupScope();
918 DbgUI.EndCleanupScope();
921 void CleanDebug2(
string name,
int y_offset)
923 DbgUI.BeginCleanupScope();
926 DbgUI.EndCleanupScope();
929 void DebugRequestActivateSymptom(
int symptom_id)