home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2003 January / maximum-cd-2003-01.iso / Software / Games / AoM / mtrial.exe / AOM / AI / SCN31P2.XS < prev    next >
Encoding:
Text File  |  2002-08-15  |  10.9 KB  |  301 lines

  1. //==============================================================================
  2. // Scn31p2: AI Scenario Script for scenario 31 player
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Joe "The Golem" Gillum
  7.  
  8.    Overview: An AI to handle the massive hordes of spawned units that attack
  9.     and drive the player back during the WTS segment of scneario 31 (after the
  10.     player destroys the gate ram).
  11.     
  12.     This AI takes all units that are spawned and moves them to the 
  13.     well (player entrance).  Pacing and size of attacks are controlled by the
  14.     scenario designer via trigger.  Units spawning at the north gate head
  15.     around the underworld mountains to the north; units spawning at the south
  16.     gate head around the underworld mountains to the south.  Both groups end
  17.     up at the bridge, and will cross to attack the well if not stopped.
  18. */
  19. //==============================================================================
  20. include "scn lib.xs";
  21.  
  22. // Used to search for spawned CP military units
  23. int leftStartQuery = -1;
  24. int rightStartQuery = -1;
  25.  
  26. int defend1Query = -1;
  27. int defend2Query = -1;
  28. int defend3Query = -1;
  29. int defend4Query = -1;
  30.  
  31. // Route and path vars
  32. int attackRoute1ID=-1;
  33. int attackPath1ID=-1;
  34. int attackRoute2ID=-1;
  35. int attackPath2ID=-1;
  36.  
  37. int defendPlan1ID=-1;
  38. int defendPlan2ID=-1;
  39. int defendPlan3ID=-1;
  40. int defendPlan4ID=-1;
  41.  
  42. //==============================================================================
  43. // Set Town Location
  44. //==============================================================================
  45. void setTownLocation(void)
  46. {
  47.    //Look for the "Town Location" marker.
  48.    kbSetTownLocation(kbGetBlockPosition("3050"));
  49. }
  50.  
  51. //==============================================================================
  52. // miscStartup
  53. //==============================================================================
  54. void miscStartup(void)
  55. {
  56.    //Startup message(s).
  57.    aiEcho("");
  58.    aiEcho("");
  59.    aiEcho("Scn27P2 AI Start, filename='"+cFilename+"'.");
  60.    //Spit out the map size.
  61.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  62.    //Cheat like a bastard.  Once only, though.
  63.     // DAL - this AI uses revealers on the map to cheat.
  64.    //kbLookAtAllUnitsOnMap();
  65.    //Calculate some areas.
  66.    kbAreaCalculate(1200.0);
  67.    //Set our town location.
  68.    setTownLocation();
  69.     //Reset random seeds
  70.     aiRandSetSeed();
  71.    //Allocate all resources
  72.    kbEscrowAllocateCurrentResources();
  73.  
  74.     // Attack path/route setup.
  75.  
  76.     //Setup attack path 1 - the northern route.
  77.    attackPath1ID=kbPathCreate("Attack Path North");
  78.    kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3089"));
  79.     kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3090"));
  80.     kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3088"));
  81.    //Create attack route 1.
  82.    attackRoute1ID=kbCreateAttackRouteWithPath("Attack Route North", kbGetBlockPosition("3050"), kbGetBlockPosition("193"));
  83.    
  84.     if (attackRoute1ID >= 0)
  85.       kbAttackRouteAddPath(attackRoute1ID, attackPath1ID);
  86.  
  87.    //Setup attack path 2 - the southern route
  88.    kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3086"));
  89.     kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3087"));
  90.     kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3088"));
  91.    attackPath2ID=kbPathCreate("Attack Path South");
  92.    
  93.     //Create attack route 2.
  94.    attackRoute2ID=kbCreateAttackRouteWithPath("Attack Route South", kbGetBlockPosition("3051"), kbGetBlockPosition("193"));
  95.  
  96.     if (attackRoute2ID >= 0)
  97.       kbAttackRouteAddPath(attackRoute2ID, attackPath2ID);
  98. }
  99.  
  100. void launchAttack(vector start=vector(-1,-1,-1), int query=-1, int count=-1)
  101. {
  102.    int attackID = aiPlanCreate("Attack at "+(xsGetTime()/1000), cPlanAttack);
  103.     
  104.     // Locations for spawning fun
  105.     vector spawnLocationLeft=kbGetBlockPosition("3050");
  106.     vector spawnLocationRight=kbGetBlockPosition("3051");
  107.  
  108.  
  109.    if (attackID < 0)
  110.       return;
  111.  
  112.    // Attack player #1.
  113.     if (aiPlanSetVariableInt(attackID, cAttackPlanPlayerID, 0, 1) == false)
  114.       return;
  115.  
  116.     // Set up the actual attack.
  117.  
  118.    aiPlanSetVariableVector(attackID, cAttackPlanGatherPoint, 0, start);
  119.    aiPlanSetVariableFloat(attackID, cAttackPlanGatherDistance, 0, 50.0);
  120.    aiPlanSetInitialPosition(attackID, start);
  121.     aiPlanAddUnitType(attackID, cUnitTypeUnit, 1, count, count);
  122.  
  123.         // "Left" (north) means use Route 1; otherwise, use Route 2.
  124.     if ( start == spawnLocationLeft )
  125.     {
  126.         aiPlanSetVariableInt(attackID, cAttackPlanAttackRouteID, 0, attackRoute2ID);
  127.         aiEcho("Attack going south.");
  128.     }
  129.     else
  130.     {
  131.         aiPlanSetVariableInt(attackID, cAttackPlanAttackRouteID, 0, attackRoute1ID);
  132.         aiEcho("Attack going north.");
  133.     }
  134.  
  135.     //Target unit types to attack.
  136.     aiPlanSetVariableInt(attackID, cAttackPlanTargetTypeID, 0, cUnitTypeBuilding);
  137.    aiPlanSetVariableInt(attackID, cAttackPlanTargetTypeID, 1, cUnitTypeUnit);
  138.     
  139.     //Needs all units listed - get 'em all!
  140.    aiPlanSetRequiresAllNeedUnits(attackID, true);
  141.    aiPlanSetActive(attackID);
  142. }
  143.  
  144. //==============================================================================
  145. // TWO TRIGGERED FUNCTIONS - both called via AI FUNC triggers in the scenario.
  146. //==============================================================================
  147. // channelID indicates which channel has the units.
  148. void spawnArmy(int channelID=-1)
  149. {
  150.     // Locations for spawning fun
  151.     vector spawnLocationLeft=kbGetBlockPosition("3050");
  152.     vector spawnLocationRight=kbGetBlockPosition("3051");
  153.  
  154.    int targetCount = -1;
  155.  
  156.    aiEcho("Spawn Army firing, channelID = "+channelID);
  157.  
  158.     // Destroy the defend plans so they don't suck any more.
  159.     aiPlanDestroy(defendPlan1ID);
  160.     aiPlanDestroy(defendPlan2ID);
  161.     aiPlanDestroy(defendPlan3ID);
  162.     aiPlanDestroy(defendPlan4ID);
  163.  
  164.    switch(channelID)
  165.    {
  166.         case 0:
  167.       {
  168.          //check left
  169.          targetCount = getUnassignedUnitCount(spawnLocationLeft, 25.0, 2, cUnitTypeUnit);
  170.          aiEcho("Found "+targetCount+" units near the left channel.");
  171.          if (targetCount > 0)
  172.          {
  173.             launchAttack(spawnLocationLeft, leftStartQuery, targetCount);
  174.          }
  175.             break;
  176.       }
  177.  
  178.         case 1:
  179.       {
  180.          //check right
  181.          targetCount = getUnassignedUnitCount(spawnLocationRight, 25.0, 2, cUnitTypeUnit);
  182.          aiEcho("Found "+targetCount+" units near the right channel.");
  183.          if (targetCount > 0)
  184.          {
  185.             launchAttack(spawnLocationRight, rightStartQuery, targetCount);
  186.          }
  187.          break;
  188.       }
  189.    }
  190. }
  191.  
  192. /*
  193. // DAL - Don't think we need this
  194. //
  195. // Sets up the stuff
  196. void counterAttack(int channelID=-1)
  197. {
  198. }
  199. */
  200.  
  201. //==============================================================================
  202. // MAIN.
  203. //==============================================================================
  204. void main(void)
  205. {
  206.     // Locations for spawning fun
  207.     int defendCount = -1;
  208.  
  209.     vector spawnLocationLeft=kbGetBlockPosition("3050");
  210.     vector spawnLocationRight=kbGetBlockPosition("3051");
  211.  
  212.     // Defend plans
  213.     vector defendLoc1=kbGetBlockPosition("3760");
  214.     vector defendLoc2=kbGetBlockPosition("3761");
  215.     vector defendLoc3=kbGetBlockPosition("3762");
  216.     vector defendLoc4=kbGetBlockPosition("3763");
  217.  
  218.     miscStartup();
  219.  
  220.     // Set up the two queries
  221.     leftStartQuery = kbUnitQueryCreate("checkLeftStart");    // Look for CP units 
  222.    if ( configQuery(leftStartQuery, cUnitTypeMilitary, -1, cUnitStateAlive, 2, spawnLocationLeft, true, 30) == false)
  223.       aiEcho("Query setup failed");
  224.  
  225.    rightStartQuery = kbUnitQueryCreate("checkRightStart");    // Look for CP units
  226.    if ( configQuery(rightStartQuery, cUnitTypeMilitary, -1, cUnitStateAlive, 2, spawnLocationRight, true, 30) == false)
  227.       aiEcho("Query setup failed");
  228.  
  229.     // Make low-priority defend plans for the various spots.
  230.     defendCount = getUnassignedUnitCount(defendLoc1, 10.0, 2, cUnitTypeUnit);
  231.     defendPlan1ID=aiPlanCreate("Defend 1", cPlanDefend);
  232.     if (defendPlan1ID >= 0)
  233.    {
  234.       //Add the unit(s).
  235.       aiPlanAddUnitType(defendPlan1ID, cUnitTypeUnit, 0, defendCount, defendCount);
  236.         
  237.       //Setup the vars.
  238.       aiPlanSetDesiredPriority(defendPlan1ID, 30);
  239.       aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendLoc1);
  240.         aiPlanSetInitialPosition(defendPlan1ID, defendLoc1);
  241.         aiPlanSetVariableFloat(defendPlan1ID, cDefendPlanGatherDistance, 0, 10.0);
  242.       aiPlanSetVariableFloat(defendPlan1ID, cDefendPlanEngageRange, 0, 20);
  243.         aiPlanSetUnitStance(defendPlan1ID, cUnitStanceDefensive);
  244.         aiPlanSetAllowUnderAttackResponse(defendPlan1ID, false);
  245.       aiPlanSetActive(defendPlan1ID);
  246.     }
  247.  
  248.     defendCount = getUnassignedUnitCount(defendLoc2, 8.0, 2, cUnitTypeUnit);
  249.     defendPlan2ID=aiPlanCreate("Defend 2", cPlanDefend);
  250.    if (defendPlan2ID >= 0)
  251.    {
  252.       //Add the unit(s).
  253.       aiPlanAddUnitType(defendPlan2ID, cUnitTypeUnit, 0, defendCount, defendCount);
  254.         
  255.       //Setup the vars.
  256.       aiPlanSetDesiredPriority(defendPlan2ID, 30);
  257.       aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendLoc2);
  258.         aiPlanSetInitialPosition(defendPlan2ID, defendLoc2);
  259.         aiPlanSetVariableFloat(defendPlan2ID, cDefendPlanGatherDistance, 0, 8.0);
  260.       aiPlanSetVariableFloat(defendPlan2ID, cDefendPlanEngageRange, 0, 20);
  261.         aiPlanSetUnitStance(defendPlan2ID, cUnitStanceDefensive);
  262.         aiPlanSetAllowUnderAttackResponse(defendPlan2ID, false);
  263.       aiPlanSetActive(defendPlan2ID);
  264.     }
  265.  
  266.     defendCount = getUnassignedUnitCount(defendLoc3, 8.0, 2, cUnitTypeUnit);
  267.     defendPlan3ID=aiPlanCreate("Defend 3", cPlanDefend);
  268.    if (defendPlan3ID >= 0)
  269.    {
  270.       //Add the unit(s).
  271.       aiPlanAddUnitType(defendPlan3ID, cUnitTypeUnit, 0, defendCount, defendCount);
  272.         
  273.       //Setup the vars.
  274.       aiPlanSetDesiredPriority(defendPlan3ID, 30);
  275.       aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, defendLoc3);
  276.         aiPlanSetInitialPosition(defendPlan3ID, defendLoc3);
  277.         aiPlanSetVariableFloat(defendPlan3ID, cDefendPlanGatherDistance, 0, 8.0);
  278.       aiPlanSetVariableFloat(defendPlan3ID, cDefendPlanEngageRange, 0, 20);
  279.         aiPlanSetUnitStance(defendPlan3ID, cUnitStanceDefensive);
  280.         aiPlanSetAllowUnderAttackResponse(defendPlan3ID, false);
  281.       aiPlanSetActive(defendPlan3ID);
  282.     }
  283.  
  284.     defendCount = getUnassignedUnitCount(defendLoc4, 8.0, 2, cUnitTypeUnit);
  285.     defendPlan4ID=aiPlanCreate("Defend 4", cPlanDefend);
  286.    if (defendPlan4ID >= 0)
  287.    {
  288.       //Add the unit(s).
  289.       aiPlanAddUnitType(defendPlan4ID, cUnitTypeUnit, 0, defendCount, defendCount);
  290.         
  291.       //Setup the vars.
  292.       aiPlanSetDesiredPriority(defendPlan4ID, 30);
  293.       aiPlanSetVariableVector(defendPlan4ID, cDefendPlanDefendPoint, 0, defendLoc4);
  294.         aiPlanSetInitialPosition(defendPlan4ID, defendLoc4);
  295.         aiPlanSetVariableFloat(defendPlan4ID, cDefendPlanGatherDistance, 0, 8.0);
  296.       aiPlanSetVariableFloat(defendPlan4ID, cDefendPlanEngageRange, 0, 20);
  297.         aiPlanSetUnitStance(defendPlan4ID, cUnitStanceDefensive);
  298.         aiPlanSetAllowUnderAttackResponse(defendPlan4ID, false);
  299.       aiPlanSetActive(defendPlan4ID);
  300.     }
  301. }