bot_testspawndeadbury.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifdef BOT
  2. class BotEventEntitySpawned : BotEventBase { };
  3. class BotSpawnDead extends BotStateBase
  4. {
  5. string m_Type;
  6. void BotSpawnDead (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  7. {
  8. if (new_type == string.Empty)
  9. m_Type = "ZmbM_HermitSkinny_Beige";
  10. else
  11. m_Type = new_type;
  12. }
  13. override void OnEntry (BotEventBase e)
  14. {
  15. super.OnEntry(e);
  16. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  17. {
  18. EntityAI Z = EntityAI.Cast(GetGame().CreateObject(m_Type, m_Owner.GetPosition()));
  19. Z.SetHealth( "", "", 0 );
  20. Error("TODO");
  21. //m_Bot.PostEvent(new BotEventEntitySpawned(m_Owner, Z));
  22. }
  23. }
  24. };
  25. class Bot_TestSpawnDeadSelectBury extends BotStateBase
  26. {
  27. string m_Type;
  28. ref BotSpawnDead m_SpawnDead;
  29. ref BotSpawnEntityInHands m_SpawnShovel;
  30. ref BotSelectZombieTarget m_Selecting;
  31. ref BotPerformAction m_Burying;
  32. void Bot_TestSpawnDeadSelectBury (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "ZmbM_HermitSkinny_Beige")
  33. {
  34. m_Type = new_type;
  35. // setup nested state machine
  36. m_FSM = new BotFSM(this); // @NOTE: set owner of the submachine fsm
  37. m_SpawnDead = new BotSpawnDead(m_Bot, this, m_Type);
  38. m_SpawnShovel = new BotSpawnEntityInHands(m_Bot, this, "Shovel");
  39. m_Selecting = new BotSelectZombieTarget(m_Bot, this);
  40. m_Burying = new BotPerformAction(m_Bot, this, AT_BURY_BODY);
  41. // events
  42. BotEventBase __SpwnZ__ = new BotEventEntitySpawned;
  43. BotEventBase __EntInH__ = new BotEventEntityInHands;
  44. BotEventBase __Select__ = new BotEventSelectedTarget;
  45. // transitions
  46. m_FSM.AddTransition(new BotTransition( m_SpawnDead, NULL, m_SpawnShovel));
  47. m_FSM.AddTransition(new BotTransition( m_SpawnShovel, __EntInH__, m_Selecting));
  48. m_FSM.AddTransition(new BotTransition( m_Selecting, __Select__, m_Burying));
  49. m_FSM.AddTransition(new BotTransition( m_Burying, NULL, NULL));
  50. m_FSM.SetInitialState(m_SpawnDead);
  51. }
  52. override void OnEntry (BotEventBase e) { super.OnEntry(e); }
  53. override void OnExit (BotEventBase e) { super.OnExit(e); }
  54. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  55. };
  56. class BotEventSelectedTarget : BotEventBase { };
  57. class BotSelectZombieTarget extends BotStateBase
  58. {
  59. ZombieMaleBase m_Target;
  60. float m_dtAccumulator = 0.0;
  61. void SelectTarget ()
  62. {
  63. //m_Target = NearestTargetSelector<ZombieMaleBase>.Find(GetPlayerOwner(), NULL);
  64. botDebugPrint("[bot] + " + m_Owner + " hunt SelectTarget target=" + m_Target);
  65. }
  66. override void OnEntry (BotEventBase e)
  67. {
  68. super.OnEntry(e);
  69. m_dtAccumulator = 0.0;
  70. SelectTarget();
  71. }
  72. override void OnExit (BotEventBase e)
  73. {
  74. m_dtAccumulator = 0.0;
  75. m_Target = null;
  76. super.OnExit(e);
  77. }
  78. override void OnUpdate (float dt)
  79. {
  80. super.OnUpdate(dt);
  81. m_dtAccumulator += dt;
  82. if (m_Target == null)
  83. {
  84. if (m_dtAccumulator > 2.0)
  85. {
  86. botDebugPrint("[bot] + " + m_Owner + " searching...");
  87. SelectTarget();
  88. if (m_Target)
  89. {
  90. Error("TODO");
  91. //m_Bot.PostEvent(new BotEventSelectedTarget(m_Owner, m_Target));
  92. }
  93. m_dtAccumulator = 0.0;
  94. }
  95. }
  96. else
  97. {
  98. Error("TODO");
  99. //m_Bot.PostEvent(new BotEventSelectedTarget(m_Owner, m_Target));
  100. }
  101. }
  102. };
  103. class BotPerformAction extends BotStateBase
  104. {
  105. EntityAI m_Entity;
  106. int m_ActionID;
  107. void BotPerformAction (Bot bot = NULL, BotStateBase parent = NULL, int action = AT_EAT)
  108. {
  109. m_ActionID = action;
  110. }
  111. override void OnEntry (BotEventBase e)
  112. {
  113. super.OnEntry(e);
  114. if (e.m_Entity)
  115. {
  116. botDebugPrint("[bot] + " + m_Owner + " performing action on item=" + e.m_Entity);
  117. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  118. {
  119. #ifdef BOT
  120. ActionManagerClient cli_mgr = ActionManagerClient.Cast(m_Owner.GetActionManager());
  121. if (cli_mgr)
  122. cli_mgr.PerformAction(m_ActionID, new ActionTarget(e.m_Entity, null, -1, vector.Zero, -1), e.m_Entity);
  123. #endif
  124. }
  125. }
  126. }
  127. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  128. override void OnExit (BotEventBase e) { super.OnExit(e); }
  129. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  130. };
  131. /*class BotHunt extends BotStateBase
  132. {
  133. float m_dtAccumulator = 0.0;
  134. override void OnEntry (BotEventBase e)
  135. {
  136. super.OnEntry(e);
  137. m_dtAccumulator = 0.0;
  138. }
  139. override void OnExit (BotEventBase e)
  140. {
  141. m_dtAccumulator = 0.0;
  142. super.OnExit(e);
  143. }
  144. override void OnUpdate (float dt)
  145. {
  146. super.OnUpdate(dt);
  147. m_dtAccumulator += dt;
  148. float rescanTime = 3.0;
  149. if (m_dtAccumulator >= rescanTime)
  150. if (m_weapon.CanProcessWeaponEvents())
  151. m_Bot.ProcessEvent(new WeaponEventReloadTimeout(p));
  152. }
  153. };
  154. */
  155. #endif