notifiersmanager.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. enum eNotifiers
  2. {
  3. NTF_HEALTHY,
  4. NTF_BLEEDISH,
  5. NTF_HUNGRY,
  6. NTF_THIRSTY,
  7. NTF_STUFFED,
  8. NTF_SICK,
  9. NTF_WETNESS,
  10. NTF_WARMTH,
  11. NTF_FEVERISH,
  12. NTF_BLOOD,
  13. NTF_LIVES,
  14. NTF_STAMINA,
  15. //NTF_AGENT_INFECTION,
  16. NTF_PILLS,
  17. NTF_HEARTBEAT,
  18. NTF_FRACTURE,
  19. NTF_LEGS,
  20. //----------------------------
  21. NTF_COUNT,// !!! LAST ITEM !!!
  22. }
  23. class NotifiersManager
  24. {
  25. static const int MAX_COUNT = 64;
  26. ref array<ref NotifierBase> m_Notifiers;
  27. ref 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
  28. PlayerBase m_Player;
  29. ref VirtualHud m_VirtualHud;
  30. int m_MinTickTime;
  31. string m_System = "Notifiers";
  32. void NotifiersManager(PlayerBase player)
  33. {
  34. m_Player = player;
  35. m_Notifiers = new array<ref NotifierBase>;
  36. m_MinTickTime = MIN_TICK_NOTIFIERS;
  37. Init();
  38. }
  39. void Init()
  40. {
  41. m_Notifiers.Insert(new HungerNotfr(this));
  42. m_Notifiers.Insert(new ThirstNotfr(this));
  43. m_Notifiers.Insert(new WarmthNotfr(this));
  44. m_Notifiers.Insert(new WetnessNotfr(this));
  45. m_Notifiers.Insert(new HealthNotfr(this));
  46. m_Notifiers.Insert(new FeverNotfr(this));
  47. m_Notifiers.Insert(new SickNotfr(this));
  48. m_Notifiers.Insert(new StuffedNotfr(this));
  49. m_Notifiers.Insert(new BloodNotfr(this));
  50. m_Notifiers.Insert(new PillsNotfr(this));
  51. m_Notifiers.Insert(new HeartbeatNotfr(this));
  52. m_Notifiers.Insert(new FracturedLegNotfr(this));
  53. m_Notifiers.Insert(new InjuredLegNotfr(this));
  54. }
  55. void RegisterItself(int notifier_id, NotifierBase modifier)
  56. {
  57. if (notifier_id >= MAX_COUNT)
  58. Error("out of bounds for notifier id: " + notifier_id);
  59. else
  60. m_NotifiersStatic[notifier_id] = modifier;
  61. }
  62. PlayerBase GetPlayer()
  63. {
  64. return m_Player;
  65. }
  66. VirtualHud GetVirtualHud()
  67. {
  68. return m_VirtualHud;
  69. }
  70. NotifierBase FindNotifier(int type)
  71. {
  72. return m_NotifiersStatic[type];
  73. }
  74. void ActivateByType(int notifier, bool triggerEvent = true)
  75. {
  76. FindNotifier(notifier).SetActive(true);
  77. }
  78. void DeactivateByType(int notifier, bool triggerEvent = true)
  79. {
  80. FindNotifier(notifier).SetActive(false);
  81. }
  82. void OnScheduledTick()
  83. {
  84. if (!GetPlayer().IsPlayerSelected())
  85. return;
  86. TickNotifiers();
  87. }
  88. void TickNotifiers()
  89. {
  90. int currentTime = GetGame().GetTime();
  91. foreach (NotifierBase notifier: m_Notifiers)
  92. {
  93. if (notifier.IsActive() && notifier.IsTimeToTick(currentTime))
  94. notifier.OnTick(currentTime);
  95. }
  96. }
  97. }