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

  1. //==============================================================================
  2. // Scn14p2: AI Scenario Script for scenario 14 player 2
  3. //==============================================================================
  4. /*
  5.    AI owner:  Mike Kidd
  6.    Scenario owner: Jeff Brown
  7.  
  8.    Overview:
  9.    The player needs to dig our a relic on the south side of the map.  He must choose
  10.    between dedicating villagers to digging, and using the to collect resources, build
  11.    buildings, and raise defenses.
  12.    
  13.    The CP units spawn and the north end of three channel, each blocked by an HP wall.  
  14.    When these units spawn, a trigger calls the spawn() function, with an int parameter
  15.    that identifies the channel.  The script then counts how many unassigned military units
  16.    exist at the head of that channel, and creates and attack plan for them.
  17.  
  18.    Initially, the attack plans start with three queries for targets:  Military units, then 
  19.    buildings, then walls (necessary to allow wall-busting).  After the time indicated by 
  20.    "timeToGetAggressive" (adjusted by the wakeup time), the first query is modified to 
  21.    allow the attack plans to attack any units, including the villagers.
  22.  
  23.    Difficulty: Not implemented (to be driven by triggers).
  24. */
  25. //==============================================================================
  26.  
  27.  
  28. include "scn lib.xs";
  29.  
  30. // Globals
  31.  
  32.  
  33. // Cinematic block markers
  34. const string   cbPit = "2844";         // The primary target
  35. const string   cbPlainEast = "2845";   // Near the HP's buildings
  36. const string   cbGateEast = "2846";
  37. const string   cbGateCenter = "2847";
  38. const string   cbGateWest = "2848";
  39. const string   cbSpawnEast = "RMU6";
  40. const string   cbSpawnCenter = "RMU5";
  41. const string   cbSpawnWest = "RMU4";
  42.  
  43. int timeToGetAggressive = 480000;        // Time to switch AI to aggressive mode.  Will add wake-up delay time to this number.
  44.  
  45. int   queryMilitaryUnits = -1;           // Used before timeToGetAggressive to hit mil units 
  46. int   queryBuildingsEast = -1;               // Ditto for buildings
  47. int   queryAllUnits = -1;                    // Used after timeToGetAggressive to hit all units and buildings
  48. int   queryAllBuildings = -1;                // ditto
  49. int   queryWalls = -1;
  50.  
  51. int   querySpawnWest = -1;
  52. int   querySpawnCenter = -1;  
  53. int   querySpawnEast = -1;                   // Used to search for spawned CP military units
  54. // *****************************************************************************
  55. //
  56. //                                FUNCTIONS
  57. //
  58. // *****************************************************************************
  59.  
  60.  
  61.  
  62. // Called by a trigger, to let AI know that the game has started
  63. void wakeup(int parm=-1)
  64. {
  65.    aiEcho("Wakeup running at "+xsGetTime()/1000);
  66.    timeToGetAggressive = timeToGetAggressive + xsGetTime();    // Adjust for delay in wakeup. 
  67.    
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void age2EventHandler(int bogus=-1)
  74. {
  75. }
  76.  
  77.  
  78.  
  79. void age3EventHandler(int bogus=-1)
  80. {
  81. }
  82.  
  83.  
  84. void age4EventHandler(int bogus=-1)
  85. {
  86. }
  87.  
  88.  
  89. void launchAttack(vector start=vector(-1,-1,-1), int query=-1, int count=-1)
  90. {
  91.  
  92.    int attackID = aiPlanCreate("Attack at "+(xsGetTime()/1000), cPlanAttack);
  93.    if (attackID < 0)
  94.       return;
  95.    if (aiPlanSetVariableInt(attackID, cAttackPlanPlayerID, 0, 1) == false)
  96.       return;
  97.  
  98.  
  99.    aiPlanSetVariableVector(attackID, cAttackPlanGatherPoint, 0, start);
  100.    aiPlanSetVariableFloat(attackID, cAttackPlanGatherDistance, 0, 400.0);  // In case units from opposite ends get called  
  101.    aiPlanSetInitialPosition( attackID, start);
  102.    aiPlanAddUnitType(attackID, cUnitTypeMilitary, 1, count, count);
  103.   
  104.    aiPlanSetNumberVariableValues( attackID, cAttackPlanQueryID, 3);
  105.  
  106.    
  107.    if (xsGetTime() > timeToGetAggressive)
  108.    {
  109.       aiPlanSetVariableInt(attackID, cAttackPlanQueryID, 0, queryAllUnits);
  110.       aiPlanSetVariableInt(attackID, cAttackPlanQueryID, 1, queryAllBuildings);
  111.       aiEcho("Attack plan "+attackID+" will attack any units or buildings.");
  112. //      aiPlanSetVariableInt(attackID, cAttackPlanAttackRouteID, 0, routeGate);
  113. //      aiPlanSetInitialPosition(attackID, kbGetBlockPosition(cbGate));
  114.    }
  115.    else
  116.    {
  117.       aiPlanSetVariableInt(attackID, cAttackPlanQueryID, 0, queryMilitaryUnits);
  118.       aiPlanSetVariableInt(attackID, cAttackPlanQueryID, 1, queryBuildingsEast);
  119.       aiEcho("Attack plan "+attackID+" will attack buildings or military units in the east.");
  120. //      aiPlanSetVariableInt(attackID, cAttackPlanAttackRouteID, 0, routeGate);
  121. //      aiPlanSetInitialPosition(attackID, kbGetBlockPosition(cbGate));
  122.    }
  123.  
  124.    aiPlanSetVariableInt(attackID, cAttackPlanQueryID, 2, queryWalls);
  125.  
  126.    aiPlanSetRequiresAllNeedUnits(attackID, true);
  127.    aiPlanSetActive(attackID);
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. // Called via trigger when an army is available in one of the channels.  ChannelID indicates which channel has the units.
  138. void spawn(int channelID=-1)
  139. {    
  140.    int targetCount = -1;
  141.  
  142.    aiEcho("Spawn firing, channelID = "+channelID);
  143.    switch(channelID)
  144.    {
  145.    case 0:
  146.       {
  147.          //check east
  148.          targetCount = getUnassignedUnitCount(kbGetBlockPosition(cbSpawnEast), 25.0, 2, cUnitTypeMilitary);
  149.          aiEcho("Found "+targetCount+" units in the east channel.");
  150.          if (targetCount > 0)
  151.          {
  152.             launchAttack(kbGetBlockPosition(cbSpawnEast), querySpawnEast, targetCount);
  153.          }
  154.       break;
  155.       }
  156.    case 1:
  157.       {
  158.          //check center
  159.          targetCount = getUnassignedUnitCount(kbGetBlockPosition(cbSpawnCenter), 25.0, 2, cUnitTypeMilitary);
  160.          aiEcho("Found "+targetCount+" units in the center channel.");
  161.          if (targetCount > 0)
  162.          {
  163.             launchAttack(kbGetBlockPosition(cbSpawnCenter), querySpawnCenter, targetCount);
  164.          }
  165.          break;
  166.       }
  167.    case 2:
  168.       {
  169.          //check west
  170.          targetCount = getUnassignedUnitCount(kbGetBlockPosition(cbSpawnWest), 25.0, 2, cUnitTypeMilitary); 
  171.          aiEcho("Found "+targetCount+" units in the west channel.");
  172.          if (targetCount > 0)
  173.          {
  174.             launchAttack(kbGetBlockPosition(cbSpawnWest), querySpawnWest, targetCount);
  175.          }
  176.          break;
  177.       }
  178.    }
  179. }
  180.  
  181.  
  182.  
  183. void main()
  184. {
  185.    aiEcho("Starting Scn14p2.xs");
  186. //   kbSetTownLocation(kbGetBlockPosition(cbGate));
  187.  
  188.    //Calculate some areas.
  189.    kbAreaCalculate(1200.0);
  190.  
  191.    aiRandSetSeed();
  192.  
  193.    aiSetAgeEventHandler(cAge2, "age2EventHandler");
  194.    aiSetAgeEventHandler(cAge3, "age3EventHandler");
  195.    aiSetAgeEventHandler(cAge4, "age4EventHandler");
  196.  
  197.    // Create all the attack targeting queries
  198.    queryMilitaryUnits = kbUnitQueryCreate("East military units");
  199.    if (queryMilitaryUnits < 0)
  200.       aiEcho("Query failed");
  201.    // Hacked out the east geo limit for now...see if that's more fun.
  202.    configQuery(queryMilitaryUnits, cUnitTypeMilitary, -1, cUnitStateAlive, 1/*, kbGetBlockPosition(cbPlainEast), false, 50.0*/);
  203.  
  204.    queryBuildingsEast = kbUnitQueryCreate("East buildings");
  205.    if (queryBuildingsEast < 0)
  206.       aiEcho("Query failed");
  207.    configQuery(queryBuildingsEast, cUnitTypeBuilding, -1, cUnitStateAliveOrBuilding, 1, kbGetBlockPosition(cbPlainEast), false, 50.0);
  208.  
  209.    queryAllUnits = kbUnitQueryCreate("All units");
  210.    if (queryAllUnits < 0)
  211.       aiEcho("Query failed");
  212.    configQuery(queryAllUnits, cUnitTypeUnit, -1, cUnitStateAlive, 1);
  213.  
  214.    queryAllBuildings = kbUnitQueryCreate("All buildings");
  215.    if (queryAllBuildings < 0)
  216.       aiEcho("Query failed");
  217.    configQuery(queryAllBuildings, cUnitTypeBuilding, -1, cUnitStateAliveOrBuilding, 1);
  218.  
  219.    queryWalls = kbUnitQueryCreate("All walls");
  220.    if (queryWalls < 0)
  221.       aiEcho("Query failed");
  222.    configQuery(queryWalls, cUnitTypeAbstractWall, -1, cUnitStateAliveOrBuilding, 1);
  223.  
  224.    querySpawnWest = kbUnitQueryCreate("checkWestStart");    // Look for CP units
  225.    if ( configQuery(querySpawnWest, cUnitTypeMilitary, -1, cUnitStateAlive, 2, kbGetBlockPosition(cbSpawnWest), true, 30) == false)
  226.       aiEcho("Query failed");
  227.    querySpawnCenter = kbUnitQueryCreate("checkCenterStart");    // Look for CP units
  228.    if ( configQuery(querySpawnCenter, cUnitTypeMilitary, -1, cUnitStateAlive, 2, kbGetBlockPosition(cbSpawnCenter), true, 30) == false)
  229.       aiEcho("Query failed");
  230.    querySpawnEast = kbUnitQueryCreate("checkEastStart");    // Look for CP units
  231.    if ( configQuery(querySpawnEast, cUnitTypeMilitary, -1, cUnitStateAlive, 2, kbGetBlockPosition(cbSpawnEast), true, 30) == false)
  232.       aiEcho("Query failed");
  233. }
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. // *****************************************************************************
  241. //
  242. // RULES
  243. //
  244. // *****************************************************************************
  245.  
  246.  
  247.  
  248. rule changeQuery        // Changes the initial attack plan target query from cUnitTypeMilitary to cUnitTypeUnit.
  249.    active
  250.    minInterval 10
  251. {
  252.       if (xsGetTime() < timeToGetAggressive)
  253.          return;
  254.  
  255.    kbUnitQuerySetUnitType(queryMilitaryUnits, cUnitTypeUnit);
  256.    xsDisableSelf();
  257. }