home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / global / patrol_path.scr < prev    next >
Encoding:
Text File  |  2002-10-21  |  6.9 KB  |  228 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  MoH: Allied Assault Script File  
  4. //  Global function: For making custom patrol routes with pause points and threads
  5. //  Script Written By: Benson 'elmagoo' Russell
  6. //
  7. ////////////////////////////////////////////////////////////////////////////////////////
  8.  
  9. //**************************************************************************
  10. //*** Will make a guy walk a patrol route with custom commands
  11. //*** syntax --------------------------------
  12. //*** <ai to walk node> patrol <targetname of a node on the path>
  13. //**************************************************************************
  14. patrol local.node:
  15.  
  16. //*** check if the ai passed exists
  17. if (local.self == NULL || !(isalive local.self))
  18. {
  19.     println "^~^~^ PATROL PATH ERROR: designated ai does not exist in the level, aborting patrol!!"
  20.     goto patrol_done
  21. }
  22.  
  23. //*** check if the local.node exists
  24. if (local.node == NULL)
  25. {
  26.     println "^~^~^ PATROL PATH ERROR: the passed path does not exist, aborting patrol!!"
  27.     goto patrol_done    
  28. }
  29.  
  30. //*** check if the level.script variable has been set
  31. if (level.script == NIL)
  32. {
  33.     println "^~^~^ PATROL PATH ERROR: the level.script variable has not been set, aborting patrol!!"
  34.     goto patrol_done    
  35. }
  36.  
  37. //*** process the patrol route into an array
  38. local.index = 1
  39. local.first_node = local.node
  40.  
  41. patrol_process_loop:
  42. if (!(isalive local.self) || local.self == NULL)
  43. {
  44.     goto patrol_done
  45. }
  46.  
  47. local.route[local.index] = local.node
  48.  
  49. if (local.node.target != NIL && $(local.node.target) != NULL)
  50. {
  51.     local.next_node = $(local.node.target)
  52.     local.node.target = NIL
  53.     local.node = local.next_node
  54.     if (local.node != local.first_node)
  55.         {
  56.             local.index ++
  57.             goto patrol_process_loop            
  58.         }
  59. }
  60.  
  61. local.index = 1
  62. //local.self.movedoneradius = 32
  63.  
  64. //local.self exec global/setweaponpose.scr "down"
  65.  
  66. patrol_loop:
  67. //*** begin the patrolling loop
  68. while (isalive local.self && local.self.thinkstate == "idle")
  69. {
  70.     //println "PATROL: top of loop"
  71.     
  72.     //*** walk to the next path
  73.     /*
  74.     println "PATROL: walking to node: " local.route[local.index]
  75.     local.self exec global/walkto.scr local.route[local.index]
  76.     local.self waittill movedone
  77.     */
  78.     
  79.     local.self.patrolpath = local.route[local.index]
  80.     local.self.type_idle = "patrol"
  81.     
  82.     while (vector_within local.self.origin local.route[local.index] 32 == 0 && local.self.thinkstate == "idle")
  83.         {
  84.         //println "PATROL: walking to node: " local.route[local.index]
  85.             wait .75
  86.         }
  87.         
  88.     //*** if there is something to lookat
  89.     if (local.route[local.index].look_point != NIL && $(local.route[local.index].look_point ) != NULL && local.self.islooking != 1)
  90.         {
  91.         //println "PATROL: looking at: " local.route[local.index].look_point
  92.         local.self.islooking = 1
  93.             local.self thread patrol_look local.route[local.index]
  94.         }
  95.  
  96.     //*** if there is something to turnto, but no pause interval, default the invertal to 4 seconds and turn
  97.     if (local.route[local.index].turn_point != NIL)
  98.     {
  99.         if (local.route[local.index].pause_interval == NIL || local.route[local.index].pause_interval == 0)
  100.                 {
  101.             println "PATROL: defaulting pause_interval for turnto"
  102.                     local.route[local.index].pause_interval = 4
  103.                 }
  104.         
  105.         //println "PATROL: turning to: " local.route[local.index].turn_point
  106.         local.self.type_idle = "idle"
  107.  
  108.         local.turn = $(local.route[local.index].turn_point)
  109.  
  110. patrol_turn_loop:
  111.                 //*** start turning to stuff
  112.                 local.self exec global/turnto.scr $(local.turn)
  113.     }
  114.     else
  115.     {
  116.         local.turn = NULL
  117.     }
  118.  
  119.     //*** if the pause_interval is set, wait for it's value
  120.     if (local.route[local.index].pause_interval != NIL)
  121.         {
  122.         //println "PATROL: pausing at: " local.route[local.index] " : for this long: " local.route[local.index].pause_interval
  123.         local.self.type_idle = "idle"
  124.         local.self exec global/stand.scr
  125.             wait local.route[local.index].pause_interval
  126.         
  127.                 if (local.turn != NULL && local.turn.target != NIL && $(local.turn.target) != NULL)
  128.                 {
  129.                     local.turn = $(local.turn.target)
  130.                     //println "PATROL LOOK: next look target: " local.look
  131.                     goto patrol_turn_loop
  132.                 }
  133.         }
  134.     
  135.     //*** if a thread is set, run it and wait for it's completion
  136.     if (local.route[local.index].run_thread != NIL)
  137.         {
  138.         //println "PATROL: running thread at node: " local.route[local.index] " : thread: " local.route[local.index].run_thread
  139.         local.self.type_idle = "idle"
  140.         //local.self exec global/stand.scr
  141.             local.self waitthread level.script::local.route[local.index].run_thread
  142.         }
  143.     
  144.     //*** cancel the turnto and go to the next node
  145.     if (local.route[local.index].turn_point != NIL)
  146.         {
  147.         //println "PATROL: canceling turnto for node: " local.route[local.index]
  148.             local.self exec global/turnto.scr NULL
  149.         }
  150.     
  151.     //*** set the next node to go to
  152.     //println "PATROL: current node: " local.route[local.index]
  153.     local.index ++
  154.     
  155.     if (local.index > local.route.size)
  156.         {
  157.             local.index = 1
  158.         }
  159.     //println "PATROL:  new node: " local.route[local.index]
  160. }
  161.  
  162. //*** wait until he's dead or back to idle
  163. while (isalive local.self && local.self.thinkstate != "idle")
  164. {
  165.     //println "PATROL: currently busy in state: " local.self.thinkstate
  166.     wait 4
  167. }
  168.  
  169. //*** if he died, quit the thread
  170. if !(isalive local.self)
  171. {
  172.     //println "PATROL: patrol guy is dead, abort loop"
  173.     goto patrol_done
  174. }
  175.  
  176. //*** he's still alive and went back to idle, so make him go back to his path
  177. //println "PATROL: returning patrol guy to loop at node: " local.route[local.index]
  178. local.self exec global/walkto.scr local.route[local.index]
  179. local.self waittill movedone
  180.  
  181. goto patrol_loop
  182.  
  183. patrol_done:
  184. end
  185.  
  186.  
  187. //**************************************************************************
  188. //*** Look around thread for patrol path
  189. //*** syntax --------------------------------
  190. //*** <ai to walk node> patrol <current patrol point this was set at>
  191. //**************************************************************************
  192. patrol_look local.node:
  193.  
  194. //println "PATROL LOOK: setting look interval" 
  195. if (local.node.look_interval == NIL || local.node.look_interval == 0)
  196. {
  197.     local.look_interval = 2
  198. }
  199. else
  200. {
  201.     local.look_interval = local.node.look_interval
  202. }
  203.  
  204. //println "PATROL LOOK: look interval: " local.look_interval
  205.  
  206. local.look = $(local.node.look_point)
  207.  
  208. //println "PATROL LOOK: look point: " local.look
  209.  
  210. patrol_look_loop:
  211. //*** start looking at stuff
  212. local.self lookat local.look
  213. wait local.look_interval
  214.  
  215. if (local.look.target != NIL && $(local.look.target) != NULL)
  216. {
  217.     local.look = $(local.look.target)
  218.     //println "PATROL LOOK: next look target: " local.look
  219.     goto patrol_look_loop
  220. }
  221.  
  222. //println "PATROL LOOK: resetting look"
  223. local.self lookat NULL
  224. local.self.islooking = 0
  225.  
  226. end
  227.  
  228.