geyserarea.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. enum EGeyserState
  2. {
  3. DORMANT = 0,
  4. ERUPTION_SOON = 1, // bubbling
  5. ERUPTING_PRIMARY = 2, // main particle
  6. ERUPTING_SECONDARY = 4 // secondary tall particle
  7. }
  8. class GeyserArea : EffectArea
  9. {
  10. protected const int UPDATE_RATE = 1000; // ms
  11. protected const float PRE_ERUPTION_DURATION = 10; // delay before the geysier activates (sec)
  12. protected const float ERUPTION_TALL_DURATION = 3; // lenght of secondary eruption (sec)
  13. protected const float ERUPTION_TALL_DELAY = 3; // min delay between secondary eruptions (sec)
  14. protected bool m_SecondaryActive;
  15. protected int m_TimeElapsed; // seconds
  16. protected int m_TimeSecondaryElapsed; // seconds
  17. protected float m_RandomizedInterval; // randomized interval to 80% - 120% of the set value
  18. protected float m_RandomizedDuration; // randomized duration to 80% - 120% of the set value
  19. protected GeyserTrigger m_GeyserTrigger;
  20. override void DeferredInit()
  21. {
  22. super.DeferredInit();
  23. InitZone();
  24. }
  25. override void EEDelete( EntityAI parent )
  26. {
  27. if (GetGame().IsClient() && m_GeyserTrigger)
  28. m_GeyserTrigger.StopEffects();
  29. super.EEDelete( parent );
  30. }
  31. override void InitZoneServer()
  32. {
  33. super.InitZoneServer();
  34. if ( m_TriggerType != "" )
  35. {
  36. CreateTrigger(m_PositionTrigger, m_Radius);
  37. m_GeyserTrigger = GeyserTrigger.Cast(m_Trigger);
  38. }
  39. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(TickState, UPDATE_RATE, true);
  40. RandomizeIntervals();
  41. }
  42. void TickState()
  43. {
  44. m_TimeElapsed += UPDATE_RATE * 0.001;
  45. if (m_GeyserTrigger.CheckGeyserState(EGeyserState.DORMANT))
  46. {
  47. if (m_TimeElapsed > PRE_ERUPTION_DURATION)
  48. {
  49. #ifdef ENABLE_LOGGING
  50. Debug.Log(m_Name + ": ERUPTION_SOON, interval: " + m_RandomizedInterval + " sec");
  51. #endif
  52. m_GeyserTrigger.AddGeyserState(EGeyserState.ERUPTION_SOON);
  53. m_TimeElapsed = 0;
  54. }
  55. }
  56. else if (m_GeyserTrigger.CheckGeyserState(EGeyserState.ERUPTION_SOON))
  57. {
  58. if (m_TimeElapsed > m_RandomizedInterval)
  59. {
  60. #ifdef ENABLE_LOGGING
  61. Debug.Log(m_Name + ": ERUPTING_PRIMARY, interval: " + m_RandomizedDuration + " sec");
  62. #endif
  63. m_GeyserTrigger.RemoveGeyserState(EGeyserState.ERUPTION_SOON);
  64. m_GeyserTrigger.AddGeyserState(EGeyserState.ERUPTING_PRIMARY);
  65. KillEntitiesInArea();
  66. m_TimeSecondaryElapsed = -1;
  67. m_SecondaryActive = false;
  68. m_TimeElapsed = 0;
  69. }
  70. }
  71. else if (m_GeyserTrigger.CheckGeyserState(EGeyserState.ERUPTING_PRIMARY))
  72. {
  73. if (m_TimeElapsed > m_RandomizedDuration)
  74. {
  75. RandomizeIntervals();
  76. #ifdef ENABLE_LOGGING
  77. Debug.Log(m_Name + ": ERUPTION_SOON, interval: " + m_RandomizedInterval + " sec");
  78. #endif
  79. m_GeyserTrigger.RemoveGeyserState(EGeyserState.ERUPTING_PRIMARY);
  80. m_GeyserTrigger.RemoveGeyserState(EGeyserState.ERUPTING_SECONDARY);
  81. m_GeyserTrigger.AddGeyserState(EGeyserState.ERUPTION_SOON);
  82. m_TimeElapsed = 0;
  83. }
  84. else if (Math.IsInRange(m_TimeElapsed, ERUPTION_TALL_DELAY, m_RandomizedDuration - ERUPTION_TALL_DURATION)) // Ensure burst do not overlap with state transitions
  85. {
  86. if (!m_SecondaryActive && m_TimeSecondaryElapsed < 0)
  87. {
  88. if (Math.RandomBool()) // 50% chance to start secondary eruption every update
  89. {
  90. m_GeyserTrigger.AddGeyserState(EGeyserState.ERUPTING_SECONDARY);
  91. m_TimeSecondaryElapsed = 0;
  92. m_SecondaryActive = true;
  93. }
  94. }
  95. else if (m_TimeSecondaryElapsed >= 0)
  96. {
  97. m_TimeSecondaryElapsed += UPDATE_RATE * 0.001;
  98. if (m_SecondaryActive && m_TimeSecondaryElapsed > ERUPTION_TALL_DURATION)
  99. {
  100. m_GeyserTrigger.RemoveGeyserState(EGeyserState.ERUPTING_SECONDARY);
  101. m_SecondaryActive = false;
  102. }
  103. else if (m_TimeSecondaryElapsed > (ERUPTION_TALL_DURATION + ERUPTION_TALL_DELAY))
  104. {
  105. m_TimeSecondaryElapsed = -1;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. private void RandomizeIntervals()
  112. {
  113. m_RandomizedInterval = Math.RandomInt(m_EffectInterval * 0.8, m_EffectInterval * 1.2);
  114. m_RandomizedDuration = Math.RandomInt(m_EffectDuration * 0.8, m_EffectDuration * 1.2);
  115. }
  116. void KillEntitiesInArea()
  117. {
  118. array<Object> nearestObjects = new array<Object>();
  119. GetGame().GetObjectsAtPosition(m_Position, m_Radius, nearestObjects, null);
  120. foreach (Object obj : nearestObjects)
  121. {
  122. EntityAI entity = EntityAI.Cast(obj);
  123. if (entity)
  124. entity.ProcessDirectDamage(DamageType.CUSTOM, this, "", "HeatDamage", "0 0 0", 1000);
  125. }
  126. }
  127. }