home *** CD-ROM | disk | FTP | other *** search
- //==============================================================================
- // Scn22p2: AI Scenario Script for scenario 22 player 2 (revised)
- //==============================================================================
- /*
- AI owner: Dave Leary
- Scenario owner: Joe "The Golem" Gillum
-
- Overview: Basic AI script for the enemy main town in 22.
-
- *** DIFFICULTY LEVEL NOTES ***
-
- Note that most of the difficulty here is handled via trigger - the timing of
- the AI's initial attacks after the player lands is the primary difficulty
- level adjustment for this scenario.
-
- Easy level - Smaller groups in general.
-
- Moderate level - Base level.
-
- Difficult - Larger groups. More towers.
-
- Nightmare - Lots more elephants and scarabs. More towers. Faster upgrades.
- Will go for heavy elephants (ow).
- */
- //==============================================================================
- // Need scn lib for some stuff here.
- include "scn lib.xs";
-
- // Variable for main base.
- int gMainBaseID=-1;
-
- //==============================================================================
- // Set Town Location
- //==============================================================================
- void setTownLocation(void)
- {
- //Look for the "Town Location" marker.
- kbSetTownLocation(kbGetBlockPosition("1851"));
- }
-
- //==============================================================================
- // miscStartup
- //==============================================================================
- void miscStartup(void)
- {
- // Difficulty Level check.
- int difflevel=-1;
- difflevel=aiGetWorldDifficulty();
-
- //Startup message(s).
- aiEcho("");
- aiEcho("");
- aiEcho("Scn22P2 AI Start, filename='"+cFilename+"'.");
- aiEcho("Difficulty Level="+difflevel+".");
- //Spit out the map size.
- aiEcho(" Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
- //Cheat like a bastard. Once only, though.
- kbLookAtAllUnitsOnMap();
- //Calculate some areas.
- kbAreaCalculate(1200.0);
- //Set our town location.
- // setTownLocation();
- //Reset random seed
- aiRandSetSeed();
-
- //Set the base location.
- // gMainBaseID=kbBaseGetMainID(cMyID);
-
- // Drop the AI attack response distance for this player to 5 meters, to simulate the surprise thing
- aiSetAttackResponseDistance(5.0);
- }
-
- //==============================================================================
- //==============================================================================
- // Attack stuff.
- //==============================================================================
- //==============================================================================
- //Shared variables.
- int numberAttacks=0;
- int attackPlayerID=-1;
-
- //TODO: Decide how to rep attack group size.
- int attackMinimumGroupSize=3;
- int attackMaximumGroupSize=5;
-
- //Attack 1 vars.
- int attackPlan1ID=-1;
-
- //Attack 2 vars.
- int attackPlan2ID=-1;
-
- // Defend plans.
- int defendPlan1ID=-1;
-
- // Route and path vars
- int attackRoute1ID=-1;
- int attackPath1ID=-1;
- int attackRoute2ID=-1;
- int attackPath2ID=-1;
-
- // Saved plan IDs
- int maintainPlan1ID=-1;
- int maintainPlan2ID=-1;
- int maintainPlan3ID=-1;
- int maintainPlan4ID=-1;
- int maintainPlanVillagerID=-1;
- int exploreID=-1;
-
- int attackerUnitTypeID1=cUnitTypeSpearman;
- int attackerUnitTypeID2=cUnitTypeSlinger;
- int attackerUnitTypeID3=cUnitTypeWarElephant;
- int attackerUnitTypeID4=cUnitTypeScarab;
-
- // Initial gather percentages
- float totalFoodGathererPercentage = 0.35;
- float totalWoodGathererPercentage = 0.25;
- float totalGoldGathererPercentage = 0.4;
- float totalFavorGathererPercentage = 0.0;
-
- //==============================================================================
- // initMainBase - Mike's spiffy function to relocate the main base.
- //==============================================================================
- /*
- void initMainBase()
- {
- vector basePosition=kbGetBlockPosition("3090");
-
- // Nuke bases, add one base to rule them all
- kbBaseDestroyAll(cMyID);
-
- gMainBaseID = kbBaseCreate(cMyID, "Base "+kbBaseGetNextID(), basePosition, 50.0);
-
- if (gMainBaseID < 0)
- aiEcho("***** Main base creation failed. *****");
-
- vector baseFront=xsVectorNormalize(kbGetMapCenter()-basePosition); // Set front
- kbBaseSetFrontVector(cMyID, gMainBaseID, baseFront);
- kbBaseSetMaximumResourceDistance(cMyID, gMainBaseID, 50.0);
- kbBaseSetMain(cMyID, gMainBaseID, true); // Make this the main base
-
- // Add the buildings
- int buildingQuery = -1;
- int count = 0;
- buildingQuery = kbUnitQueryCreate("Building Query"); // All buildings in the base
- configQuery(buildingQuery, cUnitTypeBuilding, -1, cUnitStateAliveOrBuilding, cMyID, basePosition, false, 50.0);
- kbUnitQueryResetResults(buildingQuery);
- count = kbUnitQueryExecute(buildingQuery);
-
- int i = 0;
- int buildingID = -1;
- echoQuery(buildingID);
- for (i=0; < count)
- {
- buildingID = kbUnitQueryGetResult(buildingQuery, i);
- // Add it to the base
- kbBaseAddUnit( cMyID, gMainBaseID, buildingID );
- }
- }
- */
- //==============================================================================
- // initEcon
- //
- // Set Up the initial Economy.
- //==============================================================================
- void initEcon()
- {
- aiEcho("Economy Init.");
-
- /* Don't need this for what we're doing here.
- // Set our update resource handler.
- aiSetUpdateResourceEventHandler("updateResourceHandler");
- */
-
- //-- Setup AI Cost weights.
- kbSetAICostWeight(cResourceFood, 1.5);
- kbSetAICostWeight(cResourceWood, 1.0);
- kbSetAICostWeight(cResourceGold, 1.5);
- kbSetAICostWeight(cResourceFavor, 10.0);
-
- //-- Dont auto gather favor
- //totalFavorGathererPercentage = 0;
-
- //-- Set initial gatherer percentages.
- aiSetResourceGathererPercentage(cResourceFood, totalFoodGathererPercentage, false, cRGPScript);
- aiSetResourceGathererPercentage(cResourceWood, totalWoodGathererPercentage, false, cRGPScript);
- aiSetResourceGathererPercentage(cResourceGold, totalGoldGathererPercentage, false, cRGPScript);
- aiSetResourceGathererPercentage(cResourceFavor, totalFavorGathererPercentage, false, cRGPScript);
- aiNormalizeResourceGathererPercentages(cRGPScript);
-
- aiSetResourceGathererPercentageWeight(cRGPScript, 1);
- aiSetResourceGathererPercentageWeight(cRGPCost, 0);
-
- //-- Set up the initial resource subtype breakdowns - all farming, all the time.
- // aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeEasy, 1, 50, 0.0, gMainBaseID);
- // aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeHunt, 1, 50, 0.1, gMainBaseID);
- // aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeFarm, 1, 55, 1.0, gMainBaseID);
- aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeFish, 1, 55, 1.0, gMainBaseID);
- // aiSetResourceBreakdown(cResourceWood, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
- // aiSetResourceBreakdown(cResourceGold, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
- // aiSetResourceBreakdown(cResourceFavor, cAIResourceSubTypeEasy, 1, 50, 1.0, gMainBaseID);
-
- //-- Set up auto-gather escrows
- aiSetAutoGatherEscrowID(cRootEscrowID);
- aiSetAutoFarmEscrowID(cRootEscrowID);
-
- //Allocate all resources to the root escrow by setting percentage of military/economy to 0.
- kbEscrowSetPercentage( cEconomyEscrowID, cAllResources, 0.0 );
- kbEscrowSetPercentage( cMilitaryEscrowID, cAllResources, 0.0 );
-
- //Allocate all resources
- kbEscrowAllocateCurrentResources();
- }
-
-
- //==============================================================================
- // MAIN.
- //==============================================================================
-
- void initFishingBaseQuery(void)
- {
- // JG
- //Create bases for all of our docks. Ignore any that already have
- //bases set. If we have an invalid main base, the first base we create
- //will be our main base.
-
- //Kill all previous bases.
- kbBaseDestroyAll(cMyID);
-
- int dockQueryID=kbUnitQueryCreate("MyDocks");
- if (dockQueryID > -1)
- {
- kbUnitQuerySetPlayerID(dockQueryID, cMyID);
- kbUnitQuerySetUnitType(dockQueryID, cUnitTypeAbstractDock);
- kbUnitQuerySetState(dockQueryID, cUnitStateAlive);
- kbUnitQueryResetResults(dockQueryID);
- int numberDocks=kbUnitQueryExecute(dockQueryID);
- aiEcho("Number o' docks:"+numberDocks+".");
- for(i=0; < numberDocks)
- {
- int dockID=kbUnitQueryGetResult(dockQueryID, i);
- //Skip this dock if it already has a base.
- // if (kbUnitGetBaseID(dockID) >= 0)
- // continue;
-
- vector dockPosition=kbUnitGetPosition(dockID);
- //Create a new base.
- int newBaseID=kbBaseCreate(cMyID, "Base"+kbBaseGetNextID(), dockPosition, 70.0);
- if (newBaseID > -1)
- {
- aiEcho("Setting up the dock bases.");
- //Figure out the front vector.
- vector baseFront=xsVectorNormalize(kbGetMapCenter()-dockPosition);
- kbBaseSetFrontVector(cMyID, newBaseID, baseFront);
- //Military gather point.
- vector militaryGatherPoint=dockPosition+baseFront*40.0;
- kbBaseSetMilitaryGatherPoint(cMyID, newBaseID, militaryGatherPoint);
- //Set the other flags.
- kbBaseSetMilitary(cMyID, newBaseID, true);
- kbBaseSetEconomy(cMyID, newBaseID, true);
- //Set the resource distance limit.
- kbBaseSetMaximumResourceDistance(cMyID, newBaseID, 60);
- //Add the settlement to the base.
- kbBaseAddUnit(cMyID, newBaseID, dockID);
- kbBaseSetSettlement(cMyID, newBaseID, true);
- //Set the main-ness of the base.
- kbBaseSetMain(cMyID, newBaseID, true);
- }
- // Create a fishing plan for each dock base.
- int fishGatherer = kbTechTreeGetUnitIDTypeByFunctionIndex(cUnitFunctionFish, 0);
- int fishPlanID=aiPlanCreate("FishPlan"+kbBaseGetNextID(), cPlanFish);
-
- if (fishPlanID > -1)
- {
- aiEcho("Setting up the Fishing Plan.");
- aiPlanSetDesiredPriority(fishPlanID, 90);
- aiPlanSetVariableVector(fishPlanID, cFishPlanLandPoint, 0, kbBaseGetLocation(cMyID, newBaseID));
-
- //-- If you don't explicitly set the water point, the plan will find one for you.
- aiPlanSetVariableBool(fishPlanID, cFishPlanAutoTrainBoats, 6, true); // Maintain plan for fishing
- aiPlanSetEscrowID(fishPlanID, cRootEscrowID);
-
- aiPlanAddUnitType(fishPlanID, fishGatherer, 4, 2, 6);
- aiPlanSetActive(fishPlanID);
- }
-
- // Begin Kidd's hack-o-rific boat solution
- int boatQuery = -1;
- int count = 0;
- boatQuery = kbUnitQueryCreate("Boat Query"); // All fishboats in the base belong to us
- configQuery(boatQuery, cUnitTypeFishingShipNorse, -1, cUnitStateAlive, cMyID, dockPosition, false, 70);
- kbUnitQueryResetResults(boatQuery);
- count = kbUnitQueryExecute(boatQuery);
-
- int j = 0;
- int boatID = -1;
- for (j=0; < count)
- {
- boatID = kbUnitQueryGetResult(boatQuery, j);
- // Add it to the base
- kbBaseAddUnit( cMyID, newBaseID, boatID );
- aiPlanAddUnit( fishPlanID, boatID );
- }
- // Anything after this line ISN'T Kidd's problem
- }
- }
-
- }
-
-
-
- void main(void)
- {
- // Difficulty Level check.
- int difflevel=-1;
- difflevel=aiGetWorldDifficulty();
-
- //Startup.
- miscStartup();
- // initMainBase();
- initEcon();
- initFishingBaseQuery();
- }
-