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 / Generic_Patrol.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  5.1 KB  |  169 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. fsm Generic_Patrol : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_Patrol:
  12. //   Follows a path.  If anything comes near, it goes off and attacks it,
  13. //   and then comes back to the path when there's nothing left to attack.
  14.  
  15. //------------------------------------------------------------------
  16.  
  17.  
  18.  
  19. //------------------------------------------------------------------
  20. //     Constants
  21. //------------------------------------------------------------------
  22.  
  23.     const
  24.         #include_ <content\ABLScripts\mwconst.abi>
  25.  
  26. //------------------------------------------------------------------
  27. //     Types
  28. //------------------------------------------------------------------
  29.  
  30.     type
  31.         #include_ <content\ABLScripts\mwtype.abi>
  32.     
  33.  
  34. //------------------------------------------------------------------
  35. //     Variables
  36. //------------------------------------------------------------------
  37.  
  38.     var
  39.         static integer            attackRange;        // At what range do I start shooting?
  40.         static integer            withdrawRange;        // At what range do I withdraw from combat entirely?
  41.  
  42.         static integer            path;                // My path
  43.         static integer            moveType;            // How I move along the path
  44.         static boolean            canLeavePath;        // Can I leave the path if attacked? (TRUE by default)
  45.  
  46.         static integer            piloting;            // Piloting skill
  47.         static integer            gunnery;            // Gunnery skill/chance to hit
  48.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  49.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  50.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  51.                                                     // and other things.  It indicates a general level of combat experience.
  52.         static integer            attackThrottle;        // My attack throttle
  53.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  54.         static integer            findTypes;            // What kind of enemies to look for
  55.  
  56.         static integer             attackSound;        // The attack sound I play when I first attack
  57.         static integer             deathSound;            // The sound I play when I die
  58.         
  59.         static integer            mood;                // My default mood.
  60.         static integer            speed;                // The speed at which I move along the path
  61.  
  62.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  63.  
  64. //------------------------------------------------------------------
  65. //     Init: my initialization function
  66. //------------------------------------------------------------------
  67.  
  68. function Init;
  69.     code
  70.         // script-specific variables
  71.         attackRange        = 500;
  72.         withdrawRange    = attackrange * 3 / 2;
  73.         path            = -1;
  74.         moveType        = move_circle;
  75.         canLeavePath    = true;
  76.         speed            = 600;
  77.         takeOffDistance    = 150;
  78.  
  79.         // driver settings
  80.         piloting        = 50;
  81.         gunnery            = 30;
  82.         minDelay        = 1.5;
  83.         maxDelay        = 3.0;
  84.         eliteLevel        = 30;
  85.         attackThrottle    = 80;
  86.         isShotRadius    = 120;
  87.         attackSound        = -1; // no sound
  88.         deathSound        = -1; // no sound
  89.         mood            = NEUTRAL_START;
  90.         findTypes        = FT_DEFAULT;
  91.  
  92. endfunction;
  93.  
  94. //------------------------------------------------------------------
  95. //    StartState: my initial state
  96. //------------------------------------------------------------------
  97.  
  98. state StartState;
  99.  
  100.     code
  101.         SetFiringDelay            (ME,minDelay,maxDelay);
  102.         SetIgnoreFriendlyFire    (ME,true);
  103.         SetIsShotRadius            (ME,isShotRadius);
  104.         SetEntropyMood            (ME,mood);
  105.         SetCurMood                (ME,mood);
  106.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  107.         SetAttackThrottle        (ME,attackThrottle);
  108.  
  109.         if (orderTakeOff(takeOffDistance) == true) then
  110.             trans FollowPathState;
  111.         endif;
  112.  
  113. endstate;            
  114.  
  115. //------------------------------------------------------------------
  116. //    FollowPathState: follow our path, but keep an eye out for enemies
  117. //------------------------------------------------------------------
  118.  
  119. state FollowPathState;
  120.     code
  121.         if (FindEnemy(attackRange,findTypes)) then
  122.             trans AttackState;
  123.         endif;
  124.  
  125.         if (path <> -1) then
  126.             OrderMoveResumePatrol(path,speed,moveType,true,false);
  127.         else
  128.             OrderMoveLookOut;
  129.         endif;
  130. endstate;
  131.  
  132. //------------------------------------------------------------------
  133. //    AttackState: attack my current target, or return to path if done
  134. //------------------------------------------------------------------
  135.  
  136. state AttackState;
  137.     code
  138.         if (LeaveAttackState(withdrawRange)) then
  139.             OrderStopAttacking;
  140.             SetTarget(ME,NO_UNIT);
  141.             trans FollowPathState;
  142.         endif;
  143.  
  144.         if (attackSound <> -1) then    
  145.             PlaySoundOnce(attackSound);
  146.         endif;
  147.  
  148.         OrderAttack(canLeavePath);
  149.  
  150. endstate;
  151.  
  152. //------------------------------------------------------------------
  153. //    DeadState: OK, I kicked the bucket.
  154. //------------------------------------------------------------------
  155.  
  156. state DeadState;
  157.     code
  158.         if (deathSound <> -1) then    
  159.             PlaySoundOnce(deathSound);
  160.         endif;        
  161.  
  162.         orderDie;
  163.  
  164. endstate;
  165.  
  166.  
  167. endfsm.
  168.  
  169.