home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 8 (DVD) / XENIADVD08.iso / Fragzone / Files / AOM_MiniCampaign.exe / AI / mc02p3.xs < prev    next >
Encoding:
Text File  |  2003-01-16  |  17.4 KB  |  468 lines

  1. //==============================================================================
  2. // mc02p2.xs
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Dave Leary
  7.  
  8.    This AI handles "Bjarnar's Brigands" - 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. // Ship types
  18. int attackerUnitTypeIDBoat1=cUnitTypeSiegeShipNorse;
  19. int attackerUnitTypeIDBoat2=cUnitTypeRammingShipNorse;
  20.  
  21. // Land unit types
  22. int attackerUnitTypeID1=cUnitTypeUlfsark;
  23. int attackerUnitTypeID2=cUnitTypeJarl;
  24.  
  25. // Defend plans.
  26. int defendPlan1ID=-1;
  27. int defendPlan2ID=-1;
  28. int defendPlan3ID=-1;
  29.  
  30. // One attack plan for the landing troops.
  31. int attackPlan1ID=-1;
  32.  
  33. // Functions to check to see what's hanging around the point.
  34. int checkForMilitary(vector point = vector(-1,-1,-1))
  35. {
  36.    return(getUnassignedUnitCount(point, 30.0, cMyID, cUnitTypeLogicalTypeLandMilitary));
  37. }
  38.  
  39. //==============================================================================
  40. // Set Town Location
  41. //==============================================================================
  42. void setTownLocation(void)
  43. {
  44.    //Look for the "Town Location" marker.
  45.    kbSetTownLocation(kbGetBlockPosition("859"));
  46. }
  47.  
  48. //==============================================================================
  49. // miscStartup
  50. //==============================================================================
  51. void miscStartup(void)
  52. {
  53.     // Difficulty Level check.
  54.     int difflevel=-1;        
  55.     difflevel=aiGetWorldDifficulty();
  56.  
  57.    //Startup message(s).
  58.    aiEcho("");
  59.    aiEcho("");
  60.    aiEcho("mc02p2 AI Start, filename='"+cFilename+"'.");
  61.     aiEcho("Difficulty Level="+difflevel+".");
  62.    //Spit out the map size.
  63.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  64.    //Cheat like a bastard.  Once only, though.
  65.    kbLookAtAllUnitsOnMap();
  66.    //Calculate some areas.
  67.    kbAreaCalculate(1200.0);
  68.    //Set our town location.
  69.    setTownLocation();
  70.     //Reset random seed
  71.     aiRandSetSeed();
  72.    //Allocate all resources to the root escrow.
  73.    kbEscrowAllocateCurrentResources();
  74.     
  75.     // Large AI attack response distance for this player 
  76.     aiSetAttackResponseDistance(50.0);
  77. }
  78.  
  79. //==============================================================================
  80. // Favor cheat.
  81. //==============================================================================
  82. rule favorCheat
  83.    minInterval 60
  84.    active
  85.    group AttackRules
  86. {
  87.     // Cheat for favor - 20 every minute
  88.     aiResourceCheat( 2, cResourceFavor, 20.0 );
  89. }
  90.  
  91.  
  92. //==============================================================================
  93. // Move Defend Plans - changes (randomly) the water location the AI defends. 
  94. //==============================================================================
  95. rule moveDefendPlans
  96.    minInterval 65
  97.    inactive
  98.    group AttackRules
  99. {
  100.     int randomDefendPoint1=aiRandInt(3);
  101.     int randomDefendPoint2=aiRandInt(3);
  102.  
  103.     // Set up defend points for crazy AI behavior.
  104.     vector defendPoint1=kbGetBlockPosition("842");
  105.     vector defendPoint2=kbGetBlockPosition("845");
  106.     vector defendPoint3=kbGetBlockPosition("844");
  107.  
  108.     
  109.     // First Defend Plan - choose a point.
  110.     if ( randomDefendPoint1 == 0 )
  111.     {
  112.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint1);
  113.     }
  114.     else if ( randomDefendPoint1 == 1 )
  115.     {
  116.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint2);
  117.     }
  118.     else
  119.     {
  120.         aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint3);
  121.     }
  122.  
  123.     // Second Defend Plan - choose a point.
  124.     if ( randomDefendPoint2 == 0 )
  125.     {
  126.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint1);
  127.     }
  128.     else if ( randomDefendPoint2 == 1 )
  129.     {
  130.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint2);
  131.     }
  132.     else
  133.     {
  134.         aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint3);
  135.     }
  136. }
  137.  
  138. // Secondary rule to send one ship to annoy the player.
  139. rule annoyPlayer
  140.    minInterval 80
  141.    inactive
  142.    group AttackRules
  143.  
  144. {
  145.     int randomBotherPlayer=aiRandInt(2);
  146.  
  147.     vector annoyPoint1=kbGetBlockPosition("863");
  148.     vector annoyPoint2=kbGetBlockPosition("862");
  149.  
  150.     // Activate the "annoy the player" defend plan.
  151.     if ( randomBotherPlayer == 0 )
  152.     {
  153.         aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint1);
  154.     }
  155.     else
  156.     {
  157.         aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint2);
  158.     }
  159. }
  160.  
  161.  
  162. // Send transport every three minutes.
  163. rule activateTransport
  164.     minInterval 180
  165.     inactive
  166.     group AttackRules
  167. {
  168.     int transportPlanID=aiPlanCreate("Transport Group", cPlanTransport);
  169.     int randomUnits=aiRandInt(2);
  170.  
  171.     // Difficulty Level check.
  172.     int difflevel=-1;        
  173.     difflevel=aiGetWorldDifficulty();
  174.  
  175.     vector gatherPoint=kbGetBlockPosition("892");
  176.     vector targetPoint=kbGetBlockPosition("893");
  177.     
  178.     // Only send the transport on difficulty levels greater than moderate.
  179.     if ( difflevel > 1 )
  180.     {
  181.         if (transportPlanID >= 0)
  182.         {
  183.             aiEcho("*** PLAYER 3 SENDING TRANSPORT ***");
  184.             
  185.             aiPlanAddUnitType(transportPlanID, cUnitTypeTransportShipNorse, 1, 1, 1);
  186.             aiPlanAddUnitType(transportPlanID, cUnitTypeUlfsark, 0, 5, 5);
  187.  
  188.             aiPlanAddUnitType(transportPlanID, cUnitTypeJarl, 0, 3, 3);
  189.             aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypeTransportShipNorse);
  190.  
  191.             aiPlanSetVariableBool(transportPlanID, cTransportPlanMaximizeXportMovement, 0, true);
  192.             
  193.             aiPlanSetVariableVector(transportPlanID, cTransportPlanGatherPoint, 0, gatherPoint);
  194.             aiPlanSetVariableVector(transportPlanID, cTransportPlanTargetPoint, 0, targetPoint);
  195.  
  196.             aiPlanSetDesiredPriority(transportPlanID, 75);
  197.  
  198.             // Don't return when finished.
  199.             // aiPlanSetVariableBool(transportPlanID, cTransportPlanReturnWhenDone, 0, false);
  200.             
  201.             // Specific transport hackery
  202.             // aiPlanAddUnit(transportPlanID, whichTransport);
  203.             aiPlanSetActive(transportPlanID);
  204.         }
  205.     }
  206. }
  207.  
  208. //==============================================================================
  209. // Check the landing spot for unassigned dudes.
  210. //==============================================================================
  211. rule pollForMilitary
  212.    minInterval 15
  213.    inactive
  214. {
  215.     vector landingBeach=kbGetBlockPosition("893");
  216.     
  217.     int attackPlanSize = -1;
  218.     attackPlanSize = checkForMilitary(landingBeach);
  219.    if (attackPlanSize > 0)
  220.    {
  221.       aiEcho("P3 Attack Plan: Found "+attackPlanSize+" units on the beach.");
  222.         int newAttackPlanID=aiPlanCreate("Beach Attack", cPlanAttack);
  223.         if (newAttackPlanID >= 0)
  224.         {
  225.            //Target player.
  226.             aiPlanSetVariableInt(newAttackPlanID, cAttackPlanPlayerID, 0, 1);
  227.  
  228.            aiPlanSetVariableVector(newAttackPlanID, cAttackPlanGatherPoint, 0, landingBeach);
  229.            aiPlanSetVariableFloat(newAttackPlanID, cAttackPlanGatherDistance, 0, 40.0);
  230.  
  231.             //Add the unit(s).
  232.             aiPlanAddUnitType(newAttackPlanID, cUnitTypeUlfsark, 0, 4, 4);
  233.             aiPlanAddUnitType(newAttackPlanID, cUnitTypeJarl, 0, 3, 3);
  234.             
  235.             aiPlanSetNumberVariableValues(newAttackPlanID, cAttackPlanTargetTypeID, 2, true);
  236.  
  237.            //Unit types to attack.
  238.             aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 0, cUnitTypeBuilding);
  239.             aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 1, cUnitTypeUnit);
  240.  
  241.             aiPlanSetInitialPosition(newAttackPlanID, landingBeach);
  242.                         
  243.             //Setup the vars.
  244.             aiPlanSetDesiredPriority(newAttackPlanID, 40);
  245.             aiPlanSetActive(newAttackPlanID);
  246.  
  247.             //Save this off and orphan the previous attack.
  248.             aiPlanSetOrphan(attackPlan1ID, true);
  249.             attackPlan1ID=newAttackPlanID;
  250.         }
  251.    }
  252. }
  253.  
  254. // Rule to activate some other rules after an extra three minutes.
  255. rule threeMinuteWarning
  256.    minInterval 180
  257.    inactive
  258.    group AttackRules
  259. {
  260.     vector annoyPoint1=kbGetBlockPosition("863");
  261.  
  262.     // The "annoy player" plan.
  263.     defendPlan3ID=aiPlanCreate("Annoy Player Defense Plan", cPlanDefend);
  264.    if (defendPlan3ID >= 0)
  265.    {
  266.       // Add the unit(s).
  267.       aiPlanAddUnitType(defendPlan3ID, attackerUnitTypeIDBoat2, 0, 1, 1);
  268.                 
  269.       // Set up the vars.
  270.       aiPlanSetDesiredPriority(defendPlan3ID, 40);
  271.         // Starts at the first point, for grins. 
  272.       aiPlanSetVariableVector(defendPlan3ID, cDefendPlanDefendPoint, 0, annoyPoint1);
  273.       aiPlanSetVariableFloat(defendPlan3ID, cDefendPlanEngageRange, 0, 30);
  274.       aiPlanSetActive(defendPlan3ID);
  275.     }
  276.  
  277.     xsEnableRule("annoyPlayer");
  278.     xsEnableRule("activateTransport");
  279.     xsEnableRule("pollForMilitary");
  280.  
  281.     xsDisableSelf();
  282. }
  283.  
  284. //==============================================================================
  285. // Player Builds Dock - first objective.  Called when the player builds his
  286. // first dock (a prerequisite for what comes later).  This gets the AI exploring
  287. // and causes all kinds of mayhem.
  288. //==============================================================================
  289. void playerBuildsDock(int scriptCall = -1)
  290. {
  291.     // Declare the vectors for the defend plan.
  292.     vector defendPoint1=kbGetBlockPosition("842");
  293.     vector defendPoint2=kbGetBlockPosition("845");
  294.  
  295.     // Create two explore plans with different patterns (one doing loops,
  296.     // the other not doing loops).
  297.     aiEcho("*** PLAYER BUILDS A DOCK ***");
  298.  
  299.    int explorePlan1ID=aiPlanCreate("Siege Explore 1", cPlanExplore);
  300.     if (explorePlan1ID >= 0)
  301.     {
  302.       aiPlanAddUnitType(explorePlan1ID, attackerUnitTypeIDBoat1, 1, 1, 1);
  303.         aiPlanSetDesiredPriority(explorePlan1ID, 1);
  304.       aiPlanSetVariableBool(explorePlan1ID, cExplorePlanDoLoops, 0, false);
  305.       aiPlanSetActive(explorePlan1ID);
  306.     }
  307.  
  308.     // Set up two crazy defend plans.
  309.     defendPlan1ID=aiPlanCreate("Ship Defense Plan 1", cPlanDefend);
  310.    if (defendPlan1ID >= 0)
  311.    {
  312.       // Add the unit(s).
  313.       aiPlanAddUnitType(defendPlan1ID, attackerUnitTypeIDBoat1, 0, 2, 2);
  314.         aiPlanAddUnitType(defendPlan1ID, attackerUnitTypeIDBoat2, 0, 2, 2);
  315.                 
  316.       // Set up the vars.
  317.       aiPlanSetDesiredPriority(defendPlan1ID, 50);
  318.         // Starts at the first point, for grins.
  319.       aiPlanSetVariableVector(defendPlan1ID, cDefendPlanDefendPoint, 0, defendPoint1);
  320.       aiPlanSetVariableFloat(defendPlan1ID, cDefendPlanEngageRange, 0, 40);
  321.       aiPlanSetActive(defendPlan1ID);
  322.     }
  323.  
  324.     defendPlan2ID=aiPlanCreate("Ship Defense Plan 2", cPlanDefend);
  325.    if (defendPlan2ID >= 0)
  326.    {
  327.       // Add the unit(s).
  328.       aiPlanAddUnitType(defendPlan2ID, attackerUnitTypeIDBoat1, 0, 2, 2);
  329.         aiPlanAddUnitType(defendPlan2ID, attackerUnitTypeIDBoat2, 0, 2, 2);
  330.                 
  331.       // Set up the vars.
  332.       aiPlanSetDesiredPriority(defendPlan2ID, 50);
  333.         // Starts at the second point, for grins
  334.       aiPlanSetVariableVector(defendPlan2ID, cDefendPlanDefendPoint, 0, defendPoint2);
  335.       aiPlanSetVariableFloat(defendPlan2ID, cDefendPlanEngageRange, 0, 40);
  336.       aiPlanSetActive(defendPlan2ID);
  337.     }
  338.  
  339.     // Activate the rules that changes where the defend plans are defending, and annoying
  340.     // attacks are sent at the player.
  341.     xsEnableRule("moveDefendPlans");
  342.     xsEnableRule("threeMinuteWarning");
  343. }
  344.  
  345. //==============================================================================
  346. // MAIN  
  347. //==============================================================================
  348. void main(void)
  349. {
  350.     //Startup.
  351.    miscStartup();
  352.  
  353.    //Gather points - ships
  354.    vector gatherPointSiegeShip=kbGetBlockPosition("860");
  355.     vector gatherPointRammingShip=kbGetBlockPosition("861");
  356.  
  357.     //Gather point for land units.
  358.     vector gatherPointLandUnits=kbGetBlockPosition("891");
  359.  
  360.     // Set up defend points for crazy AI behavior.
  361.     vector defendPoint1=kbGetBlockPosition("842");
  362.     vector defendPoint2=kbGetBlockPosition("845");
  363.     vector defendPoint3=kbGetBlockPosition("844");
  364.     
  365.    //Maintain seven siege ships.
  366.    int maintainPlan1ID=aiPlanCreate("Maintain 7 "+kbGetProtoUnitName(attackerUnitTypeIDBoat1), cPlanTrain);
  367.    if (maintainPlan1ID >= 0)
  368.    {
  369.         //Must set the type of unit to train.
  370.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanUnitType, 0, attackerUnitTypeIDBoat1);
  371.       //You can limit the number of units that are ever trained by this plan with this call.
  372.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  373.       //Set the number of units to maintain in the world at one time.
  374.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanNumberToMaintain, 0, 7);
  375.       aiPlanSetVariableInt(maintainPlan1ID, cTrainPlanFrequency, 0, 20);
  376.       //Turn off training from multiple buildings.
  377.       aiPlanSetVariableBool(maintainPlan1ID, cTrainPlanUseMultipleBuildings, 0, false);
  378.       //Set a gather target ID.
  379.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  380.       //Set a gather point.
  381.       aiPlanSetVariableVector(maintainPlan1ID, cTrainPlanGatherPoint, 0, gatherPointSiegeShip);
  382.       //Activate the plan.
  383.       aiPlanSetActive(maintainPlan1ID);
  384.    }
  385.  
  386.    //Maintain four ramming ships.
  387.    int maintainPlan2ID=aiPlanCreate("Maintain 4 "+kbGetProtoUnitName(attackerUnitTypeIDBoat2), cPlanTrain);
  388.    if (maintainPlan2ID >= 0)
  389.    {
  390.         //Must set the type of unit to train.
  391.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanUnitType, 0, attackerUnitTypeIDBoat2);
  392.       //You can limit the number of units that are ever trained by this plan with this call.
  393.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  394.       //Set the number of units to maintain in the world at one time.
  395.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanNumberToMaintain, 0, 4);
  396.       aiPlanSetVariableInt(maintainPlan2ID, cTrainPlanFrequency, 0, 30);
  397.       //Turn off training from multiple buildings.
  398.       aiPlanSetVariableBool(maintainPlan2ID, cTrainPlanUseMultipleBuildings, 0, false);
  399.       //Set a gather target ID.
  400.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  401.       //Set a gather point.
  402.       aiPlanSetVariableVector(maintainPlan2ID, cTrainPlanGatherPoint, 0, gatherPointRammingShip);
  403.       //Activate the plan.
  404.       aiPlanSetActive(maintainPlan2ID);
  405.    }
  406.  
  407.     // Maintain a transport for a little transport-guys action.
  408.    int maintainPlan3ID=aiPlanCreate("Maintain 1 Transport", cPlanTrain);
  409.    if (maintainPlan3ID >= 0)
  410.    {
  411.         //Must set the type of unit to train.
  412.       aiPlanSetVariableInt(maintainPlan3ID, cTrainPlanUnitType, 0, cUnitTypeTransportShipNorse);
  413.       //You can limit the number of units that are ever trained by this plan with this call.
  414.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  415.       //Set the number of units to maintain in the world at one time.
  416.       aiPlanSetVariableInt(maintainPlan3ID, cTrainPlanNumberToMaintain, 0, 1);
  417.       aiPlanSetVariableInt(maintainPlan3ID, cTrainPlanFrequency, 0, 45);
  418.       //Turn off training from multiple buildings.
  419.       aiPlanSetVariableBool(maintainPlan3ID, cTrainPlanUseMultipleBuildings, 0, false);
  420.       //Set a gather target ID.
  421.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  422.       //Set a gather point.
  423.       aiPlanSetVariableVector(maintainPlan3ID, cTrainPlanGatherPoint, 0, gatherPointSiegeShip);
  424.       //Activate the plan.
  425.       aiPlanSetActive(maintainPlan3ID);
  426.    }
  427.  
  428.     // Maintain some military units...Jarls and Ulfsarks.
  429.    int maintainPlan4ID=aiPlanCreate("Maintain Ulfsarks", cPlanTrain);
  430.    if (maintainPlan4ID >= 0)
  431.    {
  432.         //Must set the type of unit to train.
  433.       aiPlanSetVariableInt(maintainPlan4ID, cTrainPlanUnitType, 0, attackerUnitTypeID1);
  434.       //You can limit the number of units that are ever trained by this plan with this call.
  435.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  436.       //Set the number of units to maintain in the world at one time.
  437.       aiPlanSetVariableInt(maintainPlan4ID, cTrainPlanNumberToMaintain, 0, 6);
  438.       aiPlanSetVariableInt(maintainPlan4ID, cTrainPlanFrequency, 0, 15);
  439.       //Turn off training from multiple buildings.
  440.       //aiPlanSetVariableBool(maintainPlan4ID, cTrainPlanUseMultipleBuildings, 0, false);
  441.       //Set a gather target ID.
  442.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  443.       //Set a gather point.
  444.       aiPlanSetVariableVector(maintainPlan4ID, cTrainPlanGatherPoint, 0, gatherPointLandUnits);
  445.       //Activate the plan.
  446.       aiPlanSetActive(maintainPlan4ID);
  447.    }
  448.  
  449.    int maintainPlan5ID=aiPlanCreate("Maintain Jarls", cPlanTrain);
  450.    if (maintainPlan5ID >= 0)
  451.    {
  452.         //Must set the type of unit to train.
  453.       aiPlanSetVariableInt(maintainPlan5ID, cTrainPlanUnitType, 0, attackerUnitTypeID2);
  454.       //You can limit the number of units that are ever trained by this plan with this call.
  455.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanNumberToTrain, 0, 25);
  456.       //Set the number of units to maintain in the world at one time.
  457.       aiPlanSetVariableInt(maintainPlan5ID, cTrainPlanNumberToMaintain, 0, 4);
  458.       aiPlanSetVariableInt(maintainPlan5ID, cTrainPlanFrequency, 0, 20);
  459.       //Turn off training from multiple buildings.
  460.       //aiPlanSetVariableBool(maintainPlan4ID, cTrainPlanUseMultipleBuildings, 0, false);
  461.       //Set a gather target ID.
  462.       //aiPlanSetVariableInt(maintainPlanID, cTrainPlanGatherTargetID, 0, 1234);
  463.       //Set a gather point.
  464.       aiPlanSetVariableVector(maintainPlan5ID, cTrainPlanGatherPoint, 0, gatherPointLandUnits);
  465.       //Activate the plan.
  466.       aiPlanSetActive(maintainPlan5ID);
  467.    }
  468. }