//------------------------------------------------------------------- // INCLUDES: //------------------------------------------------------------------- include "aiHeader.xs"; // Gets global vars, function forward declarations include "aiUtil.xs"; // Misc. shared AI utility functions include "aiEcon.xs"; // All of the AI's econ functionality include "aiMilitary.xs"; // All of the AI's military functionality include "aiNavy.xs"; // All of the AI's naval functionality include "aiEventHandlers.xs"; // Event handler methods for the AI include "aiMain.xs"; // The bulk of the AI //------------------------------------------------------------------- extern int gAIAttackRoute01PlanID = -1; extern int gAIAttackRoute02PlanID = -1; extern int gAIAttackRoute03PlanID = -1; extern int gAIAttackDefenseSmash = -1; extern int gAIAttackPriest = -1; extern vector Route1Temple1 = vector(444,0,244); extern vector Route2Temple1 = vector(529,0,257); extern vector SharedTemple1 = vector(493,0,183); extern vector SharedTemple2 = vector(431,0,126); extern vector SharedTemple3 = vector(431,0,126); extern vector SharedTemple4 = vector(379,0,169); extern vector SharedTemple5 = vector(295,0,163); extern vector SharedTemple6 = vector(221,0,145); //------------------------------------------------------------------- void preInit(void) { aiEcho("preInit() starting."); cvOkToBuild = false; cvOKToDefend = false; cvOkToAttack = false; cvOkToExplore = false; cvOkToSelectMissions = false; cvGuardAlliedBases = false; cvOkToGatherFood = false; cvOkToGatherGold = false; cvOkToGatherWood = false; cvOkToGatherStone = false; xsDisableRule("checkForGold"); xsDisableRule("checkForEnemyBases"); } //------------------------------------------------------------------- void postInit(void) { aiEcho("postInit() starting."); } //------------------------------------------------------------------- rule RevealMapLocations active minInterval 5 { kbLookAtAllUnitsOnMap(); aiCheatReveal(); aiEcho("RevealMapLocations: --- now revealing enemy"); xsSetRuleMinIntervalSelf(123); } //------------------------------------------------------------------- rule AIAttack_Route01_MGR active minInterval 11 { int PlanID = gAIAttackRoute01PlanID; if (PlanID > 0) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, Route1Temple1) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple1, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple2, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple3) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple4) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple5, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple6) ) return; int P1TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 1, cUnitStateAlive); if (P1TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1TownCenterID)) ) return; } int P3TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 3, cUnitStateAlive); if (P3TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3TownCenterID)) ) return; } int P1VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 1, cUnitStateAlive); if (P1VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1VictoryUnitID)) ) return; } int P3VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 3, cUnitStateAlive); if (P3VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3VictoryUnitID)) ) return; } } } //------------------------------------------------------------------- rule AIAttack_Route02_MGR active minInterval 12 { int PlanID = gAIAttackRoute02PlanID; if (PlanID > 0) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, Route2Temple1) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple1, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple2, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple3) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple4) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple5, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple6) ) return; int P1TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 1, cUnitStateAlive); if (P1TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1TownCenterID)) ) return; } int P3TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 3, cUnitStateAlive); if (P3TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3TownCenterID)) ) return; } int P1VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 1, cUnitStateAlive); if (P1VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1VictoryUnitID)) ) return; } int P3VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 3, cUnitStateAlive); if (P3VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3VictoryUnitID)) ) return; } } } //------------------------------------------------------------------- rule AIAttack_Route03_MGR active minInterval 13 { int PlanID = gAIAttackRoute03PlanID; if (PlanID > 0) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple1, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple2, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple3) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple4) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple5, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple6) ) return; int P1TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 1, cUnitStateAlive); if (P1TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1TownCenterID)) ) return; } int P3TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 3, cUnitStateAlive); if (P3TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3TownCenterID)) ) return; } int P1VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 1, cUnitStateAlive); if (P1VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1VictoryUnitID)) ) return; } int P3VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 3, cUnitStateAlive); if (P3VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3VictoryUnitID)) ) return; } } } //------------------------------------------------------------------- // update this much less frequently, it does a bit more than the other rules rule AIAttack_DefenseSmash_MGR active minInterval 43 { int PlanID = gAIAttackDefenseSmash; if (PlanID > 0) { int BestTarget = -1; // Start with clearing defensive structures around SharedTemple1 BestTarget = getUnitByLocation(cUnitTypeUnitTypeBldgFortress, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple1, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } BestTarget = getUnitByLocation(cUnitTypeUnitTypeBldgTower, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple1, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } BestTarget = getUnitByLocation(cUnitTypeAbstractWall, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple1, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } // Now proceed to clearing defensive structures around SharedTemple3 BestTarget = getUnitByLocation(cUnitTypeUnitTypeBldgFortress, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple3, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } BestTarget = getUnitByLocation(cUnitTypeUnitTypeBldgTower, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple3, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } BestTarget = getUnitByLocation(cUnitTypeAbstractWall, cPlayerRelationEnemyNotGaia, cUnitStateABQ, SharedTemple3, 80, true); if (BestTarget > -1) { UpdateSpawnedUnitDefenseForcedLoc(PlanID, kbUnitGetPosition(BestTarget)); return; } // now follow the normal Route3 if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple1, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple2, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple3) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple4) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple5, 40) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple6) ) return; int P1TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 1, cUnitStateAlive); if (P1TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1TownCenterID)) ) return; } int P3TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 3, cUnitStateAlive); if (P3TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3TownCenterID)) ) return; } int P1VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 1, cUnitStateAlive); if (P1VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1VictoryUnitID)) ) return; } int P3VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 3, cUnitStateAlive); if (P3VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3VictoryUnitID)) ) return; } } } //------------------------------------------------------------------- rule AIAttack_Priest_MGR active minInterval 15 { int PlanID = gAIAttackPriest; if (PlanID > 0) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple1, 30, cUnitTypeStandardConvertable) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple2, 30, cUnitTypeStandardConvertable) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple3, 30, cUnitTypeStandardConvertable) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple4, 30, cUnitTypeStandardConvertable) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple5, 30, cUnitTypeStandardConvertable) ) return; if ( UpdateSpawnedUnitDefenseLoc(PlanID, SharedTemple6, 30, cUnitTypeStandardConvertable) ) return; int P1TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 1, cUnitStateAlive); if (P1TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1TownCenterID)) ) return; } int P3TownCenterID = getUnit(cUnitTypeAbstractTownCenter, 3, cUnitStateAlive); if (P3TownCenterID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3TownCenterID)) ) return; } int P1VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 1, cUnitStateAlive); if (P1VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P1VictoryUnitID)) ) return; } int P3VictoryUnitID = getUnit(cUnitTypeLogicalTypeNeededForVictory, 3, cUnitStateAlive); if (P3VictoryUnitID > -1) { if ( UpdateSpawnedUnitDefenseLoc(PlanID, kbUnitGetPosition(P3VictoryUnitID)) ) return; } } } //------------------------------------------------------------------- void AIAttack_Route01(int val = -1) { if (val > -1) { // create the initial plan, if needed if (gAIAttackRoute01PlanID < 0) { gAIAttackRoute01PlanID = CreateSpawnedUnitDefensePlan("AIAttack_Route01"); AIAttack_Route01_MGR(); } // update the plan with the new units UpdateSpawnedUnitDefenseUnits(gAIAttackRoute01PlanID, val); } } //------------------------------------------------------------------- void AIAttack_Route02(int val = -1) { if (val > -1) { // create the initial plan, if needed if (gAIAttackRoute02PlanID < 0) { gAIAttackRoute02PlanID = CreateSpawnedUnitDefensePlan("AIAttack_Route02"); AIAttack_Route02_MGR(); } // update the plan with the new units UpdateSpawnedUnitDefenseUnits(gAIAttackRoute02PlanID, val); } } //------------------------------------------------------------------- void AIAttack_Route03(int val = -1) { if (val > -1) { // create the initial plan, if needed if (gAIAttackRoute03PlanID < 0) { gAIAttackRoute03PlanID = CreateSpawnedUnitDefensePlan("AIAttack_Route03"); AIAttack_Route03_MGR(); } // update the plan with the new units UpdateSpawnedUnitDefenseUnits(gAIAttackRoute03PlanID, val); } } //------------------------------------------------------------------- void AIAttack_DefenseSmash(int val = -1) { if (val > -1) { // create the initial plan, if needed if (gAIAttackDefenseSmash < 0) { gAIAttackDefenseSmash = CreateSpawnedUnitDefensePlan("AIAttack_DefenseSmash"); AIAttack_DefenseSmash_MGR(); } // update the plan with the new units UpdateSpawnedUnitDefenseUnits(gAIAttackDefenseSmash, val); } } //------------------------------------------------------------------- void AIAttack_Priest(int val = -1) { if (val > -1) { // create the initial plan, if needed if (gAIAttackPriest < 0) { gAIAttackPriest = CreateSpawnedUnitDefensePlan("AIAttack_Priest", 30, cUnitTypeAbstractPriest); AIAttack_Priest_MGR(); } // update the plan with the new units UpdateSpawnedUnitDefenseUnits(gAIAttackPriest, val); } }