bot_timedwait.c 920 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class BotEventWaitTimeout : BotEventBase { };
  2. class BotTimedWait extends BotStateBase
  3. {
  4. protected float m_dtAccumulator = 0.0;
  5. protected float m_Timeout = 3.0;
  6. protected bool m_Periodic = true;
  7. void BotTimedWait (Bot bot = NULL, BotStateBase parent = NULL, float timeout = 3.0)
  8. {
  9. m_Timeout = timeout;
  10. }
  11. override void OnEntry (BotEventBase e)
  12. {
  13. m_dtAccumulator = 0.0;
  14. super.OnEntry(e);
  15. }
  16. override void OnExit (BotEventBase e)
  17. {
  18. m_dtAccumulator = 0.0;
  19. super.OnExit(e);
  20. }
  21. override void OnUpdate (float dt)
  22. {
  23. super.OnUpdate(dt);
  24. m_dtAccumulator += dt;
  25. float rescanTime = m_Timeout;
  26. if (m_dtAccumulator >= rescanTime)
  27. {
  28. OnTimeout();
  29. if (m_Periodic)
  30. m_dtAccumulator = 0.0;
  31. else
  32. m_dtAccumulator = -1.0;
  33. }
  34. }
  35. void OnTimeout ()
  36. {
  37. botDebugSpam("[bot] + " + m_Owner + " BotTimedWait::OnTimeout");
  38. m_Bot.ProcessEvent(new BotEventWaitTimeout(m_Owner));
  39. }
  40. };