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

  1. //==============================================================================
  2. // Scn22p2: AI Scenario Script for scenario 22 player 2 (revised)
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Joe "The Golem" Gillum
  7.  
  8.    Overview: Basic AI script for the enemy main town in 22.
  9.  
  10.                                   *** DIFFICULTY LEVEL NOTES ***
  11.  
  12.     Note that most of the difficulty here is handled via trigger - the timing of
  13.     the AI's initial attacks after the player lands is the primary difficulty
  14.     level adjustment for this scenario.
  15.  
  16.    Easy level - Smaller groups in general.
  17.  
  18.    Moderate level - Base level.
  19.  
  20.    Difficult - Larger groups.  More towers.
  21.  
  22.    Nightmare - Lots more elephants and scarabs.  More towers.  Faster upgrades.
  23.     Will go for heavy elephants (ow).
  24. */
  25. //==============================================================================
  26. // Need scn lib for some stuff here.
  27. include "scn lib.xs";
  28.  
  29. // Variable for main base.
  30. int gMainBaseID=-1;
  31.  
  32. //==============================================================================
  33. // Set Town Location
  34. //==============================================================================
  35. void setTownLocation(void)
  36. {
  37.    //Look for the "Town Location" marker.
  38.    kbSetTownLocation(kbGetBlockPosition("1851"));
  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("Scn22P2 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.  
  66.     //Set the base location.
  67. //    gMainBaseID=kbBaseGetMainID(cMyID);
  68.  
  69.     // Drop the AI attack response distance for this player to 5 meters, to simulate the surprise thing
  70.     aiSetAttackResponseDistance(5.0);
  71. }
  72.  
  73. //==============================================================================
  74. //==============================================================================
  75. // Attack stuff.
  76. //==============================================================================
  77. //==============================================================================
  78. //Shared variables.
  79. int numberAttacks=0;
  80. int attackPlayerID=-1;
  81.  
  82. //TODO: Decide how to rep attack group size.
  83. int attackMinimumGroupSize=3;
  84. int attackMaximumGroupSize=5;
  85.  
  86. //Attack 1 vars.
  87. int attackPlan1ID=-1;
  88.  
  89. //Attack 2 vars.
  90. int attackPlan2ID=-1;
  91.  
  92. // Defend plans.
  93. int defendPlan1ID=-1;
  94.  
  95. // Route and path vars
  96. int attackRoute1ID=-1;
  97. int attackPath1ID=-1;
  98. int attackRoute2ID=-1;
  99. int attackPath2ID=-1;
  100.  
  101. // Saved plan IDs
  102. int maintainPlan1ID=-1;
  103. int maintainPlan2ID=-1;
  104. int maintainPlan3ID=-1;
  105. int maintainPlan4ID=-1;
  106. int maintainPlanVillagerID=-1;
  107. int exploreID=-1;
  108.  
  109. int attackerUnitTypeID1=cUnitTypeSpearman;
  110. int attackerUnitTypeID2=cUnitTypeSlinger;
  111. int attackerUnitTypeID3=cUnitTypeWarElephant;
  112. int attackerUnitTypeID4=cUnitTypeScarab;
  113.  
  114. // Initial gather percentages
  115. float totalFoodGathererPercentage  = 0.35;
  116. float totalWoodGathererPercentage  = 0.25;
  117. float totalGoldGathererPercentage  = 0.4;
  118. float totalFavorGathererPercentage = 0.0;
  119.  
  120. //==============================================================================
  121. // initMainBase - Mike's spiffy function to relocate the main base.
  122. //==============================================================================
  123. /*
  124. void initMainBase()
  125. {
  126.     vector basePosition=kbGetBlockPosition("3090");
  127.  
  128.    // Nuke bases, add one base to rule them all
  129.    kbBaseDestroyAll(cMyID);
  130.  
  131.    gMainBaseID = kbBaseCreate(cMyID, "Base "+kbBaseGetNextID(), basePosition, 50.0);
  132.    
  133.     if (gMainBaseID < 0)
  134.       aiEcho("***** Main base creation failed. *****");
  135.  
  136.    vector baseFront=xsVectorNormalize(kbGetMapCenter()-basePosition);     // Set front
  137.    kbBaseSetFrontVector(cMyID, gMainBaseID, baseFront);                 
  138.    kbBaseSetMaximumResourceDistance(cMyID, gMainBaseID, 50.0);
  139.    kbBaseSetMain(cMyID, gMainBaseID, true);     // Make this the main base
  140.  
  141.    // Add the buildings
  142.    int buildingQuery = -1;
  143.    int count = 0;
  144.    buildingQuery = kbUnitQueryCreate("Building Query");     // All buildings in the base
  145.    configQuery(buildingQuery, cUnitTypeBuilding, -1, cUnitStateAliveOrBuilding, cMyID, basePosition, false, 50.0);
  146.    kbUnitQueryResetResults(buildingQuery);
  147.    count = kbUnitQueryExecute(buildingQuery);
  148.  
  149.    int i = 0;
  150.    int buildingID = -1;
  151.     echoQuery(buildingID);
  152.    for (i=0; < count)
  153.    {
  154.       buildingID = kbUnitQueryGetResult(buildingQuery, i);
  155.       // Add it to the base
  156.       kbBaseAddUnit( cMyID, gMainBaseID, buildingID );
  157.    }
  158. }
  159. */
  160. //==============================================================================
  161. // initEcon
  162. //
  163. // Set Up the initial Economy.
  164. //==============================================================================
  165. void initEcon()
  166. {
  167.    aiEcho("Economy Init.");
  168.  
  169.     /* Don't need this for what we're doing here.
  170.    // Set our update resource handler.
  171.    aiSetUpdateResourceEventHandler("updateResourceHandler");
  172.     */
  173.  
  174.    //-- Setup AI Cost weights.
  175.    kbSetAICostWeight(cResourceFood, 1.5);
  176.    kbSetAICostWeight(cResourceWood, 1.0);
  177.    kbSetAICostWeight(cResourceGold, 1.5);
  178.    kbSetAICostWeight(cResourceFavor, 10.0);
  179.  
  180.    //-- Dont auto gather favor
  181.    //totalFavorGathererPercentage = 0;
  182.  
  183.    //-- Set initial gatherer percentages.
  184.    aiSetResourceGathererPercentage(cResourceFood, totalFoodGathererPercentage, false, cRGPScript);
  185.    aiSetResourceGathererPercentage(cResourceWood, totalWoodGathererPercentage, false, cRGPScript);
  186.    aiSetResourceGathererPercentage(cResourceGold, totalGoldGathererPercentage, false, cRGPScript);
  187.    aiSetResourceGathererPercentage(cResourceFavor, totalFavorGathererPercentage, false, cRGPScript);
  188.    aiNormalizeResourceGathererPercentages(cRGPScript);
  189.  
  190.    aiSetResourceGathererPercentageWeight(cRGPScript, 1);
  191.    aiSetResourceGathererPercentageWeight(cRGPCost, 0);
  192.  
  193.    //-- Set up the initial resource subtype breakdowns - all farming, all the time.
  194.     // aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeEasy, 1, 50, 0.0, gMainBaseID);
  195.     // aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeHunt, 1, 50, 0.1, gMainBaseID);
  196.     //    aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeFarm, 1, 55, 1.0, gMainBaseID);
  197.     aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeFish, 1, 55, 1.0, gMainBaseID);
  198.     //    aiSetResourceBreakdown(cResourceWood, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
  199.     //    aiSetResourceBreakdown(cResourceGold, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
  200.     //   aiSetResourceBreakdown(cResourceFavor, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
  201.     
  202.    //-- Set up auto-gather escrows
  203.    aiSetAutoGatherEscrowID(cRootEscrowID);
  204.    aiSetAutoFarmEscrowID(cRootEscrowID);
  205.  
  206.     //Allocate all resources to the root escrow by setting percentage of military/economy to 0.
  207.     kbEscrowSetPercentage( cEconomyEscrowID, cAllResources, 0.0 );
  208.     kbEscrowSetPercentage( cMilitaryEscrowID, cAllResources, 0.0 );
  209.  
  210.     //Allocate all resources
  211.    kbEscrowAllocateCurrentResources();
  212. }
  213.  
  214.  
  215. //==============================================================================
  216. // MAIN.
  217. //==============================================================================
  218.  
  219. void initFishingBaseQuery(void)
  220. {
  221.     // JG
  222.    //Create bases for all of our docks.  Ignore any that already have
  223.    //bases set.  If we have an invalid main base, the first base we create
  224.    //will be our main base.
  225.  
  226.     //Kill all previous bases.
  227.     kbBaseDestroyAll(cMyID);
  228.  
  229.    int dockQueryID=kbUnitQueryCreate("MyDocks");
  230.    if (dockQueryID > -1)
  231.    {
  232.         kbUnitQuerySetPlayerID(dockQueryID, cMyID);
  233.       kbUnitQuerySetUnitType(dockQueryID, cUnitTypeAbstractDock);
  234.       kbUnitQuerySetState(dockQueryID, cUnitStateAlive);
  235.       kbUnitQueryResetResults(dockQueryID);
  236.        int numberDocks=kbUnitQueryExecute(dockQueryID);
  237.         aiEcho("Number o' docks:"+numberDocks+".");
  238.       for(i=0; < numberDocks)
  239.       {
  240.          int dockID=kbUnitQueryGetResult(dockQueryID, i);
  241.          //Skip this dock if it already has a base.
  242.          // if (kbUnitGetBaseID(dockID) >= 0)
  243.             // continue;
  244.  
  245.          vector dockPosition=kbUnitGetPosition(dockID);
  246.          //Create a new base.
  247.          int newBaseID=kbBaseCreate(cMyID, "Base"+kbBaseGetNextID(), dockPosition, 70.0);
  248.             if (newBaseID > -1)
  249.          {
  250.                 aiEcho("Setting up the dock bases.");
  251.             //Figure out the front vector.
  252.             vector baseFront=xsVectorNormalize(kbGetMapCenter()-dockPosition);
  253.             kbBaseSetFrontVector(cMyID, newBaseID, baseFront);
  254.             //Military gather point.
  255.             vector militaryGatherPoint=dockPosition+baseFront*40.0;
  256.             kbBaseSetMilitaryGatherPoint(cMyID, newBaseID, militaryGatherPoint);
  257.             //Set the other flags.
  258.             kbBaseSetMilitary(cMyID, newBaseID, true);
  259.             kbBaseSetEconomy(cMyID, newBaseID, true);
  260.             //Set the resource distance limit.
  261.             kbBaseSetMaximumResourceDistance(cMyID, newBaseID, 60);
  262.             //Add the settlement to the base.
  263.             kbBaseAddUnit(cMyID, newBaseID, dockID);
  264.             kbBaseSetSettlement(cMyID, newBaseID, true);
  265.             //Set the main-ness of the base.
  266.             kbBaseSetMain(cMyID, newBaseID, true);
  267.            }
  268.             // Create a fishing plan for each dock base.
  269.             int fishGatherer = kbTechTreeGetUnitIDTypeByFunctionIndex(cUnitFunctionFish, 0);
  270.             int fishPlanID=aiPlanCreate("FishPlan"+kbBaseGetNextID(), cPlanFish);
  271.  
  272.             if (fishPlanID > -1)
  273.             {
  274.                 aiEcho("Setting up the Fishing Plan.");
  275.                  aiPlanSetDesiredPriority(fishPlanID, 90);
  276.                 aiPlanSetVariableVector(fishPlanID, cFishPlanLandPoint, 0, kbBaseGetLocation(cMyID, newBaseID));
  277.         
  278.                 //-- If you don't explicitly set the water point, the plan will find one for you.
  279.                 aiPlanSetVariableBool(fishPlanID, cFishPlanAutoTrainBoats, 6, true);   // Maintain plan for fishing
  280.                 aiPlanSetEscrowID(fishPlanID, cRootEscrowID);
  281.  
  282.                 aiPlanAddUnitType(fishPlanID, fishGatherer, 4, 2, 6);
  283.                 aiPlanSetActive(fishPlanID);
  284.             }
  285.  
  286.             // Begin Kidd's hack-o-rific boat solution
  287.             int boatQuery = -1;
  288.             int count = 0;
  289.             boatQuery = kbUnitQueryCreate("Boat Query");     // All fishboats in the base belong to us
  290.             configQuery(boatQuery, cUnitTypeFishingShipNorse, -1, cUnitStateAlive, cMyID, dockPosition, false, 70);
  291.             kbUnitQueryResetResults(boatQuery);
  292.             count = kbUnitQueryExecute(boatQuery);
  293.  
  294.             int j = 0;
  295.             int boatID = -1;
  296.             for (j=0; < count)
  297.             {
  298.                 boatID = kbUnitQueryGetResult(boatQuery, j);
  299.                 // Add it to the base
  300.                 kbBaseAddUnit( cMyID, newBaseID, boatID );
  301.                 aiPlanAddUnit( fishPlanID, boatID );
  302.             }
  303.             // Anything after this line ISN'T Kidd's problem
  304.       }
  305.    }
  306.  
  307. }
  308.  
  309.  
  310.  
  311. void main(void)
  312. {
  313.     // Difficulty Level check.
  314.     int difflevel=-1;        
  315.     difflevel=aiGetWorldDifficulty();
  316.  
  317.    //Startup.
  318.    miscStartup();
  319. //    initMainBase();
  320.     initEcon();
  321.     initFishingBaseQuery();
  322. }
  323.