home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / PatrolRespond.tpl < prev    next >
Encoding:
Text File  |  2001-07-16  |  9.2 KB  |  268 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. UIFIELDS
  7. {
  8. FIELD<         INT,attackRange,"Attack Range",500>;        // At what range do I start shooting?
  9. FIELD<         INT,withdrawRange,"Withdraw Range",750>;        // At what range do I withdraw from combat entirely?
  10. FIELD<          INT,piloting,"Piloting Skill",50>;            // Piloting skill
  11. FIELD<          INT,gunnery,"Gunnery Skill",50>;            // Gunnery skill/chance to hit
  12. FIELD<          FLOAT,minDelay,"Minimum fire Delay",1.0>;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  13. FIELD<          FLOAT,maxDelay,"Maximum fire Delay",2.0>;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  14. FIELD<          INT,eliteLevel,"Elite Level",60>;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  15.                                                     // and other things.  It indicates a general level of combat experience.
  16. FIELD<           INT,isShotRadius,"Is Shot Radius",120>;        // How far away from me will I detect an enemy shot?        
  17. FIELD<INT,    takeOffDistance,"Take Off Distance (ignored if not a plane)",160>;
  18. FIELD<INT,    attackThrottle,"Percent throttle when in combat",80>;
  19.  
  20. FIELD<          INT,path,"First Path",-1>;                // My path
  21. FIELD<          INT,path2,"Second Path",-1>;                // My path
  22. FIELD<          INT,moveType,"Nocycle = 1, Circle = 2, Seesaw = 3",2>;            // How I move along the path
  23. FIELD<INT, speed,"Movement Speed",600>;        
  24.  
  25. FIELD<         INT,attackRange2,"Attack Range on second path",500>;        // At what range do I start shooting?
  26. FIELD<         INT,withdrawRange2,"Withdraw Range on second path",750>;        // At what range do I withdraw from combat entirely?
  27. FIELD<          INT,moveType2,"(path 2) Nocycle = 1, Circle = 2, Seesaw = 3",2>;            // How I move along the path
  28. FIELD<INT, trigger,"ID of trigger that makes the unit swap paths",1>;        
  29. FIELD<INT, trigger,"ID of trigger that makes the unit wake up",1>;
  30.  
  31. }
  32.  
  33.  
  34. fsm Generic_PatrolRespond : integer;
  35.  
  36.  
  37. //------------------------------------------------------------------
  38.  
  39. // Generic_PatrolRespond:
  40. //   Follows a path.  If anything comes near, it goes off and attacks it,
  41. //   and then comes back to the path when there's nothing left to attack.
  42. //   When a specific trigger is set, it goes to another point or path
  43. //   and does the same thing.
  44.  
  45. //   I.e. this is the same as Generic_Patrol, except that it
  46. //   goes to a second point or path upon firing of a trigger.
  47.  
  48. //------------------------------------------------------------------
  49.  
  50.  
  51.  
  52. //------------------------------------------------------------------
  53. //     Constants
  54. //------------------------------------------------------------------
  55.  
  56.     const
  57.         #include_ <content\ABLScripts\mwconst.abi>
  58.  
  59. //------------------------------------------------------------------
  60. //     Types
  61. //------------------------------------------------------------------
  62.  
  63.     type
  64.         #include_ <content\ABLScripts\mwtype.abi>
  65.     
  66.  
  67. //------------------------------------------------------------------
  68. //     Variables
  69. //------------------------------------------------------------------
  70.  
  71.     var
  72.         static integer            attackRange1;        // The range at which I start attacking if in the original patrol
  73.         static integer            withdrawRange1;        // The range at which I withdraw from combat entirely
  74.         static integer            path1;                // My original path
  75.         static integer            moveType1;            // How I move along the path
  76.         static boolean            canLeavePath1;        // Can I leave the path if attacked? (TRUE by default)
  77.         static integer            speed1;                // The speed at which I move along the path
  78.  
  79.         static integer            triggerID;            // The trigger that will move me from my original patrol state to my new patrol state
  80.  
  81.         static integer            attackRange2;        // The range at which I start attacking after the trigger has fired
  82.         static integer            withdrawRange2;        // The range at which I withdraw from combat entirely
  83.         static integer            path2;                // My path after the trigger fires
  84.         static integer            moveType2;            // How I move along the second path
  85.         static boolean            canLeavePath2;        // Can I leave the second path if attacked? (TRUE by default)
  86.         static integer            speed2;                // The speed at which I move along the second path
  87.  
  88.         static integer            piloting;            // Piloting skill
  89.         static integer            gunnery;            // Gunnery skill/chance to hit
  90.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  91.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  92.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  93.                                                     // and other things.  It indicates a general level of combat experience.
  94.         static integer            attackThrottle;        // My attack throttle
  95.         static integer            findTypes;            // What kind of enemies to look for
  96.  
  97.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  98.  
  99.         static integer             attackSound;        // The attack sound I play when I first attack
  100.         static integer             deathSound;            // The sound I play when I die
  101.         
  102.         static integer            mood;                // My default mood.
  103.  
  104.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  105.  
  106. //------------------------------------------------------------------
  107. //     Init: my initialization function
  108. //------------------------------------------------------------------
  109.  
  110. function Init;
  111.     code
  112.         
  113.         // Variables set by editor
  114.         attackRange1        = <attackRange>;
  115.         withdrawRange1    = <withdrawRange>;
  116.         takeOffDistance    = <takeOffDistance>;
  117.          piloting        = <piloting>;
  118.         gunnery            = <gunnery>;
  119.         minDelay        = <minDelay>;
  120.         maxDelay        = <maxDelay>;
  121.         eliteLevel        = <eliteLevel>;
  122.         isShotRadius    = <isShotRadius>;
  123.     attackThrottle    = <attackThrottle>;
  124.  
  125.         path1            = <path>;
  126.         path2            = <path2>;
  127.         moveType1        = <moveType>;
  128.         speed1            = <speed>;
  129.         
  130.         attackRange2        = <attackRange>;
  131.         withdrawRange2    = <withdrawRange>;
  132.         moveType2        = <moveType>;
  133.         speed2            = <speed>;
  134.         triggerID        = <trigger>;
  135.         
  136.         // script-specific variables
  137.         canLeavePath1    = true;
  138.  
  139.         canLeavePath2    = true;
  140.         attackSound        = -1; // no sound
  141.         deathSound        = -1; // no sound
  142.         mood            = NEUTRAL_START;
  143.         findTypes        = FT_DEFAULT;
  144.  
  145. endfunction;
  146.  
  147. //------------------------------------------------------------------
  148. //    StartState: my initial state
  149. //------------------------------------------------------------------
  150.  
  151. state StartState;
  152.  
  153.     code
  154.         SetFiringDelay            (ME,minDelay,maxDelay);
  155.         SetIgnoreFriendlyFire    (ME,true);
  156.         SetIsShotRadius            (ME,isShotRadius);
  157.         SetEntropyMood            (ME,mood);
  158.         SetCurMood                (ME,mood);
  159.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  160.         SetAttackThrottle        (ME,attackThrottle);
  161.                 
  162.         if (orderTakeOff(takeOffDistance) == true) then
  163.             trans FollowPath1State;
  164.         endif;
  165.  
  166. endstate;            
  167.  
  168. //------------------------------------------------------------------
  169. //    FollowPath1State: follow the original path, but keep an eye out for enemies
  170. //------------------------------------------------------------------
  171.  
  172. state FollowPath1State;
  173.     code
  174.         if (GetGlobalTrigger(triggerID)) then
  175.             trans FollowPath2State;
  176.         endif;
  177.  
  178.         if (FindEnemy(attackRange1,findTypes)) then
  179.             trans Attack1State;
  180.         endif;
  181.  
  182.         if (path1 <> -1) then
  183.             OrderMoveResumePatrol(path1,speed1,moveType1,true,false);
  184.         else
  185.             OrderMoveLookOut;
  186.         endif;
  187. endstate;
  188.  
  189. //------------------------------------------------------------------
  190. //    Attack1State: attack my current target, or return to original path if done
  191. //------------------------------------------------------------------
  192.  
  193. state Attack1State;
  194.     code
  195.         if (GetGlobalTrigger(triggerID)) then
  196.             trans Attack2State;
  197.         endif;
  198.  
  199.         if (LeaveAttackState(withdrawRange1)) then
  200.             OrderStopAttacking;
  201.             SetTarget(ME,NO_UNIT);
  202.             trans FollowPath1State;
  203.         endif;
  204.  
  205.         if (attackSound <> -1) then    
  206.             PlaySoundOnce(attackSound);
  207.         endif;
  208.  
  209.         OrderAttack(canLeavePath1);
  210.  
  211. endstate;
  212.  
  213. //------------------------------------------------------------------
  214. //    FollowPath2State: follow the second path, but keep an eye out for enemies
  215. //------------------------------------------------------------------
  216.  
  217. state FollowPath2State;
  218.     code
  219.         if (FindEnemy(attackRange2,findTypes)) then
  220.             trans Attack2State;
  221.         endif;
  222.  
  223.         if (path2 <> -1) then
  224.             OrderMoveResumePatrol(path2,speed2,moveType2,true,false);
  225.         else
  226.             OrderMoveLookOut;
  227.         endif;
  228. endstate;
  229.  
  230. //------------------------------------------------------------------
  231. //    Attack2State: attack my current target, or return to second path if done
  232. //------------------------------------------------------------------
  233.  
  234. state Attack2State;
  235.     code
  236.         if (LeaveAttackState(withdrawRange2)) then
  237.             OrderStopAttacking;
  238.             SetTarget(ME,NO_UNIT);
  239.             trans FollowPath2State;
  240.         endif;
  241.  
  242.         if (attackSound <> -1) then    
  243.             PlaySoundOnce(attackSound);
  244.         endif;
  245.  
  246.         OrderAttack(canLeavePath2);
  247.  
  248. endstate;
  249.  
  250.  
  251. //------------------------------------------------------------------
  252. //    DeadState: OK, I kicked the bucket.
  253. //------------------------------------------------------------------
  254.  
  255. state DeadState;
  256.     code
  257.         if (deathSound <> -1) then    
  258.             PlaySoundOnce(deathSound);
  259.         endif;        
  260.  
  261.         orderDie;
  262.  
  263. endstate;
  264.  
  265.  
  266. endfsm.
  267.  
  268.