Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. // baseline thinking frequency may need adjustment on a per-game basis
  2. $AIManager::ThinkCycle = 64;
  3.  
  4.  
  5. // cycle through the list, triggering one bot decision per iteration
  6. // this avoids clumping heavy calculations together trying to run simultaneously
  7. function AIManager::think(%this,%botnum)
  8. {
  9. %thinkrate = $AIManager::ThinkCycle;
  10. if (isObject(%this.bots))
  11. {
  12. %botcount = %this.bots.getCount();
  13. %botnum++;
  14. if (%botnum>%botcount-1)
  15. {
  16. %botnum = -1;
  17. %this.updateTargetlist();
  18. }
  19. else
  20. {
  21. %bot = %this.bots.getObject(%botnum);
  22. if(isObject(%bot)) %bot.aiDecide();
  23. }
  24. // no point cycling through decisions faster than we can ghost the results
  25. if (%botcount<2)
  26. %thinkrate = 2* $AIManager::ThinkCycle;
  27. }
  28. %this.schedule(%thinkrate, think ,%botnum);
  29. }
  30.  
  31.  
  32.  
  33. //planning
  34. function AIPlayer::aiDecide(%this)
  35. {
  36. if(!isObject(%this)||(%this.getState() $="Dead")) return;
  37. if (%this.isFalling) return;
  38.  
  39. %this.Muttering();
  40. if(!isObject(%this.enemy))
  41. {
  42. %this.enemy = -1;
  43. %this.setstate($botstate_PathToNearest);
  44. }
  45.  
  46. if (%this.confused) %this.setstate($botstate_Confused);
  47. if (%this.nextCommandTime>$Sim::Time) return;
  48.  
  49. if( VectorLen(%this.getVelocity()) > 0.1 )
  50. %this.moving = true;
  51. else
  52. %this.moving = false;
  53.  
  54. switch(%this.botstate)
  55. {
  56. case $botstate_Moving:
  57. if (%this.updateNavmesh>1000/$AIManager::ThinkCycle)
  58. {
  59. %this.updateNavmesh = 0;
  60. if( %this.moving)
  61. {
  62. %pos = %this.getPosition();
  63. NavMeshIgnore(%this,true);
  64. NavMeshUpdateBox(%pos,"3 3 3");
  65. schedule(200,0,"NavMeshUpdateBox",%pos,"3 3 3");
  66. return;
  67. }
  68. else
  69. {
  70. %pos = %this.getPosition();
  71. NavMeshIgnore(%this,false);
  72. NavMeshUpdateBox(%pos,"3 3 3");
  73. schedule(200,0,"NavMeshUpdateBox",%pos,"3 3 3");
  74. %this.setstate($botstate_Wander);
  75. }
  76. }
  77. else
  78. %this.updateNavmesh++;
  79.  
  80. case $botstate_Confused:
  81. %this.randomPath();
  82. case $botstate_fire:
  83. %this.aiShoot();
  84. case $botstate_Wander:
  85. %this.randomPath();
  86. case $botstate_Shuffle:
  87. %this.randomPoint(1);
  88. case $botstate_PathToNearest:
  89. %this.PathToNearest();
  90. case $botstate_WaypointMove:
  91. %this.moving = true;
  92. return;
  93. default:
  94. %this.setstate($botstate_Wander);
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement