home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 8 (DVD) / XENIADVD08.iso / Fragzone / Files / AOM_MiniCampaign.exe / AI / mc02p2.xs < prev    next >
Encoding:
Text File  |  2002-12-09  |  10.6 KB  |  303 lines

  1. //==============================================================================
  2. // mc02p2.xs
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Dave Leary
  7.  
  8.    This AI handles "Rolf's Raiders" - one of two primarily naval-based AIs that
  9.     bother the player (and each other) in the second scenario of the free
  10.     minicampaign.  It cheats like mad.
  11. */
  12. //==============================================================================
  13. // Need scn lib for some stuff here.
  14. include "scn lib.xs";
  15.  
  16. // Predefined Stuff.
  17. // Unit types
  18. int attackerUnitTypeIDBoat1=cUnitTypeLongboat;
  19. int attackerUnitTypeIDBoat2=cUnitTypeSiegeShipNorse;
  20.  
  21. // Defend plans.
  22. int defendPlan1ID=-1;
  23. int defendPlan2ID=-1;
  24. int defendPlan3ID=-1;
  25.  
  26. // Functions to check to see what's hanging around the point.
  27. int checkForMilitary(vector point = vector(-1,-1,-1))
  28. {
  29.    return(getUnassignedUnitCount(point, 30.0, cMyID, cUnitTypeLogicalTypeLandMilitary));
  30. }
  31.  
  32. //==============================================================================
  33. // Set Town Location
  34. //==============================================================================
  35. void setTownLocation(void)
  36. {
  37.    //Look for the "Town Location" marker.
  38.    kbSetTownLocation(kbGetBlockPosition("807"));
  39. }
  40.  
  41. //==============================================================================
  42. // miscStartup
  43. //==============================================================================
  44. void miscStartup(void)
  45. {
  46.     // Difficulty Level check.
  47.     int difflevel=-1;        
  48.     difflevel=aiGetWorldDifficulty();
  49.  
  50.    //Startup message(s).
  51.    aiEcho("");
  52.    aiEcho("");
  53.    aiEcho("mc02p2 AI Start, filename='"+cFilename+"'.");
  54.     aiEcho("Difficulty Level="+difflevel+".");
  55.    //Spit out the map size.
  56.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  57.    //Cheat like a bastard.  Once only, though.
  58.    kbLookAtAllUnitsOnMap();
  59.    //Calculate some areas.
  60.    kbAreaCalculate(1200.0);
  61.    //Set our town location.
  62.    setTownLocation();
  63.     //Reset random seed
  64.     aiRandSetSeed();
  65.    //Allocate all resources to the root escrow.
  66.    kbEscrowAllocateCurrentResources();
  67.     
  68.     // Large AI attack response distance for this player 
  69.     aiSetAttackResponseDistance(50.0);
  70. }
  71.  
  72. //==============================================================================
  73. // Favor cheat.
  74. //==============================================================================
  75. rule favorCheat
  76.    minInterval 60
  77.    active
  78.    group AttackRules
  79. {
  80.     // Cheat for favor - 20 every minute
  81.     aiResourceCheat( 2, cResourceFavor, 20.0 );
  82. }
  83.  
  84.  
  85. //==============================================================================
  86. // Move Defend Plans - changes (randomly) the water location the AI defends. 
  87. //==============================================================================
  88. rule moveDefendPlans
  89.    minInterval 75
  90.    inactive
  91.    group AttackRules
  92. {
  93.     int randomDefendPoint1=aiRandInt(3);
  94.     int randomDefendPoint2=aiRandInt(3);
  95.  
  96.     // Declare the vectorz.
  97.     vector defendPoint1=kbGetBlockPosition("841");
  98.     vector defendPoint2=kbGetBlockPosition("843");
  99.     vector defendPoint3=kbGetBlockPosition("846");
  100.  
  101.     vector annoyPoint1=kbGetBlockPosition("849");
  102.     vector annoyPoint2=kbGetBlockPosition("848");
  103.     
  104.     // First Defend Plan - choose a point.
  105.     if ( randomDefendPoint1 == 0 )
  106.     {
  107.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint1);
  108.     }
  109.     else if ( randomDefendPoint1 == 1 )
  110.     {
  111.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint2);
  112.     }
  113.     else
  114.     {
  115.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint3);
  116.     }
  117.  
  118.     // Second Defend Plan - choose a point.
  119.     if ( randomDefendPoint2 == 0 )
  120.     {
  121.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint1);
  122.     }
  123.     else if ( randomDefendPoint2 == 1 )
  124.     {
  125.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint2);
  126.     }
  127.     else
  128.     {
  129.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint3);
  130.     }
  131. }
  132.  
  133.  
  134. // Secondary rule to send guys to annoy the player.
  135. rule annoyPlayer
  136.    minInterval 50
  137.    inactive
  138.    group AttackRules
  139. {
  140.     int randomBotherPlayer=aiRandInt(2);
  141.  
  142.     vector annoyPoint1=kbGetBlockPosition("849");
  143.     vector annoyPoint2=kbGetBlockPosition("848");
  144.  
  145.     // Activate the "annoy the player" defend plan.
  146.     if ( randomBotherPlayer == 0 )
  147.     {
  148.         aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint1);
  149.     }
  150.     else
  151.     {
  152.         aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint2);
  153.     }
  154. }
  155.  
  156.  
  157. // Rule to activate some other rules after an extra three minutes.
  158. rule threeMinuteWarning
  159.    minInterval 180
  160.    inactive
  161.    group AttackRules
  162. {
  163.     vector annoyPoint1=kbGetBlockPosition("849");
  164.  
  165.     // The "annoy player" plan.
  166.     defendPlan3ID=aiPlanCreate("Annoy Player Defense Plan", cPlanDefend);
  167.    if (defendPlan3ID >= 0)
  168.    {
  169.       // Add the unit(s).
  170.       aiPlanAddUnitType(defendPlan3ID, attackerUnitTypeIDBoat2, 0, 1, 1);
  171.                 
  172.       // Set up the vars.
  173.       aiPlanSetDesiredPriority(defendPlan3ID, 40);
  174.         // Starts at the first point, for grins. 
  175.       aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint1);
  176.       aiPlanSetVariableFloat(defendPlan3ID, cDefendPlanEngageRange, 0, 30);
  177.       aiPlanSetActive(defendPlan3ID);
  178.     }
  179.     xsEnableRule("annoyPlayer");
  180.     xsDisableSelf();
  181. }
  182.  
  183.  
  184. //==============================================================================
  185. // Player Builds Dock - first objective.  Called when the player builds his
  186. // first dock (a prerequisite for what comes later).  This gets the AI exploring
  187. // and causes all kinds of mayhem.
  188. //==============================================================================
  189. void playerBuildsDock(int scriptCall = -1)
  190. {
  191.     // Declare the vectors for the defend plan.
  192.     vector defendPoint1=kbGetBlockPosition("841");
  193.     vector defendPoint2=kbGetBlockPosition("843");
  194.  
  195.     // Create two explore plans with different patterns (one doing loops,
  196.     // the other not doing loops).
  197.     aiEcho("*** PLAYER BUILDS A DOCK ***");
  198.  
  199.    int explorePlan1ID=aiPlanCreate("Longboat Explore 1", cPlanExplore);
  200.     if (explorePlan1ID >= 0)
  201.     {
  202.       aiPlanAddUnitType(explorePlan1ID, attackerUnitTypeIDBoat1, 1, 1, 1);
  203.         aiPlanSetDesiredPriority(explorePlan1ID, 1);
  204.       aiPlanSetVariableBool(explorePlan1ID, cExplorePlanDoLoops, 0, false);
  205.       aiPlanSetActive(explorePlan1ID);
  206.     }
  207.  
  208.     // Set up two crazy defend plans.
  209.     defendPlan1ID=aiPlanCreate("Ship Defense Plan 1", cPlanDefend);
  210.    if (defendPlan1ID >= 0)
  211.    {
  212.       // Add the unit(s).
  213.       aiPlanAddUnitType(defendPlan1ID, attackerUnitTypeIDBoat1, 0, 3, 3);
  214.         aiPlanAddUnitType(defendPlan1ID, attackerUnitTypeIDBoat2, 0, 2, 2);
  215.                 
  216.       // Set up the vars.
  217.       aiPlanSetDesiredPriority(defendPlan1ID, 50);
  218.         // Starts at the first point, for grins.
  219.       aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint1);
  220.       aiPlanSetVariableFloat(defendPlan1ID, cDefendPlanEngageRange, 0, 40);
  221.       aiPlanSetActive(defendPlan1ID);
  222.     }
  223.  
  224.     defendPlan2ID=aiPlanCreate("Ship Defense Plan 2", cPlanDefend);
  225.    if (defendPlan2ID >= 0)
  226.    {
  227.       // Add the unit(s).
  228.       aiPlanAddUnitType(defendPlan2ID, attackerUnitTypeIDBoat1, 0, 2, 2);
  229.         aiPlanAddUnitType(defendPlan2ID, attackerUnitTypeIDBoat2, 0, 2, 2);
  230.                 
  231.       // Set up the vars.
  232.       aiPlanSetDesiredPriority(defendPlan2ID, 50);
  233.         // Starts at the second point, for grins
  234.       aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint2);
  235.       aiPlanSetVariableFloat(defendPlan2ID, cDefendPlanEngageRange, 0, 40);
  236.       aiPlanSetActive(defendPlan2ID);
  237.     }
  238.  
  239.     // Activate the rules that changes where the defend plans are defending.
  240.     xsEnableRule("moveDefendPlans");
  241.     xsEnableRule("threeMinuteWarning");
  242. }
  243.  
  244. //==============================================================================
  245. // MAIN
  246. //==============================================================================
  247. void main(void)
  248. {
  249.     //Startup.
  250.    miscStartup();
  251.  
  252.    //Gather points 
  253.    vector gatherPointLongboat=kbGetBlockPosition("810");
  254.     vector gatherPointSiegeShip=kbGetBlockPosition("811");
  255.  
  256.     // Set up defend points for crazy AI behavior.
  257.     vector defendPoint1=kbGetBlockPosition("841");
  258.     vector defendPoint2=kbGetBlockPosition("843");
  259.     vector defendPoint3=kbGetBlockPosition("846");
  260.     
  261.    //Maintain six longboats.
  262.    int maintainPlan1ID=aiPlanCreate("Maintain 6 "+kbGetProtoUnitName(attackerUnitTypeIDBoat1), cPlanTrain);
  263.    if (maintainPlan1ID >= 0)
  264.    {
  265.         //Must set the type of unit to train.
  266.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanUnitType, 0, attackerUnitTypeIDBoat1);
  267.       //You can limit the number of units that are ever trained by this plan with this call.
  268.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  269.       //Set the number of units to maintain in the world at one time.
  270.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanNumberToMaintain, 0, 6);
  271.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanFrequency, 0, 15);
  272.       //Turn off training from multiple buildings.
  273.       aiPlanSetVariableBool(maintainPlan1ID, cTrainPlanUseMultipleBuildings, 0, false);
  274.       //Set a gather target ID.
  275.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  276.       //Set a gather point.
  277.       aiPlanSetVariableVector(maintainPlan1ID, cTrainPlanGatherPoint, 0, gatherPointLongboat);
  278.       //Activate the plan.
  279.       aiPlanSetActive(maintainPlan1ID);
  280.    }
  281.  
  282.    //Maintain five siege ships.
  283.    int maintainPlan2ID=aiPlanCreate("Maintain 5 "+kbGetProtoUnitName(attackerUnitTypeIDBoat2), cPlanTrain);
  284.    if (maintainPlan2ID >= 0)
  285.    {
  286.         //Must set the type of unit to train.
  287.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanUnitType, 0, attackerUnitTypeIDBoat2);
  288.       //You can limit the number of units that are ever trained by this plan with this call.
  289.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  290.       //Set the number of units to maintain in the world at one time.
  291.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanNumberToMaintain, 0, 5);
  292.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanFrequency, 0, 35);
  293.       //Turn off training from multiple buildings.
  294.       aiPlanSetVariableBool(maintainPlan2ID, cTrainPlanUseMultipleBuildings, 0, false);
  295.       //Set a gather target ID.
  296.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  297.       //Set a gather point.
  298.       aiPlanSetVariableVector(maintainPlan2ID, cTrainPlanGatherPoint, 0, gatherPointSiegeShip);
  299.       //Activate the plan.
  300.       aiPlanSetActive(maintainPlan2ID);
  301.    }
  302. }
  303.