//------------------------------------------------------------------- // 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 include "aiCampaignCore.xs"; // The Core Campaign AI data and features include "aiSiegeTowerCore.xs"; // Special Siege Tower functionality //------------------------------------------------------------------- // for anything defined in SetCampaignDefaults, if needed, override it here void OverrideCampaignDefaults() { btStrengthATK = 4.0; // 0.0 - 4.0, weak attack strength to hardcore attack strength btStrengthDEF = 0.0; // 0.0 - 4.0, weak defense strength to hardcore defense strength btStrengthECO = 0.0; // 0.0 - 4.0, weak economy strength to economy attack strength btRushBoom = -1.0; // -1.0 = max rush, 1.0 = max boom cvOkToTrainNavy = false; cvOkToGatherGold = false; cvOkToGatherWood = false; cvOkToGatherStone = false; cvOkToCaravan = false; cvOkToExplore = false; cvMaxAge = cAge1; bAllowAttack = false; bAllowDefend = false; bAllowGuardA = false; bAllowTCBuild = false; bAllowResourcePatrol = false; btTargetAge1VilCount = 0; btTargetAge4VilCount = 0; } //------------------------------------------------------------------- // for anything calculated in CalculateCampaignSettings, if needed, override it here void OverrideCampaignSettings() { } //------------------------------------------------------------------- void preInit(void) { aiEcho("preInit() Starting..."); // force defaults for all internal settings SetCampaignDefaults(); // Override Defaults // do this before any formula based settings are calculated // This allows each parent script to set the intended default overrides before anything is calculated OverrideCampaignDefaults(); // derive any settings from the defaults CalculateCampaignSettings(); // Override Campaign Settings // in some cases, it is valuable blow out even the calculated settings OverrideCampaignSettings(); // print everything out EchoCampaignSettings(); } //------------------------------------------------------------------- void postInit(void) { aiEcho("postInit() Starting..."); setUpSiegeTowerQueries(); } //------------------------------------------------------------------- void CustomRMUpdate_READY(int val = 0) { if ( val > 0 ) { aiEcho("CustomRMUpdate_READY::::::::::::: ATTACK TIME"); cvOkToAttack = true; cvMaxAge = cAge4; bAllowAttack = true; btTargetAge1VilCount = 15; btTargetAge4VilCount = 30; } } //------------------------------------------------------------------- // override the default gather goal management void initGatherGoal() { kbSetTargetSelectorFactor(cTSFactorDistance, -240); kbSetTargetSelectorFactor(cTSFactorPoint, 0); kbSetTargetSelectorFactor(cTSFactorBase, -50); //Set the RGP weights. Script in charge. aiSetResourceGathererPercentageWeight(cRGPScript, 1.0); // Portion driven by forecast aiSetResourceGathererPercentageWeight(cRGPCost, 0.0); // Portion driven by exchange rates //Set initial gatherer percentages. aiSetResourceGathererPercentage(cResourceFood, 1.0, false, cRGPScript); aiSetResourceGathererPercentage(cResourceWood, 0.0, false, cRGPScript); aiSetResourceGathererPercentage(cResourceGold, 0.0, false, cRGPScript); aiSetResourceGathererPercentage(cResourceStone, 0.0, false, cRGPScript); aiNormalizeResourceGathererPercentages(cRGPScript); //Set up the initial resource breakdowns. aiSetResourceBreakdown(cResourceFood, cAIResourceSubTypeFarm, 1, 52, 1.0, kbBaseGetMainID(cMyID)); } //------------------------------------------------------------------- // override the default food plan management void updateFoodPlans() { // basic count of villagers and farms int numVills = kbUnitCount(cMyID, gEconUnit, cUnitStateAlive); int numFarms = kbUnitCount(cMyID, gFarmUnit, cUnitStateABQ); // set the gatherer count // Round to the closest villager instead of truncating float floatVills = numVills; int numGatherers = (floatVills * aiGetResourceGathererPercentage(cResourceFood)) + 0.5; int MainBaseID = kbBaseGetMainID(cMyID); //-------------------------------- // first allocate villagers to any existing farms, fill all farms if possible int farmFoodPlans = numFarms; if (numFarms > numGatherers) { farmFoodPlans = numGatherers; } // update the gatherer count numGatherers = numGatherers - farmFoodPlans; //-------------------------------- // now allocate the remaining villagers to farming if possible if ( (numGatherers > 0) && (kbGetAge() > cAge1) && (numFarms < gMaxFarms) ) { // Make sure we don't already have a farm queued int planID = aiPlanGetIDByTypeAndVariableType(cPlanBuild, cBuildPlanBuildingTypeID, gFarmUnit); if (planID == -1) { createSimpleBuildPlan(gFarmUnit, numGatherers, 90, true, cEconomyEscrowID, MainBaseID, 1); } } aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeEasy, 0, 79, 0.0, MainBaseID ); aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeHerdable, 0, 82, 0.0, MainBaseID ); aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeHunt, 0, 51, 0.0, MainBaseID ); aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeFarm, farmFoodPlans, 81, 1.0, MainBaseID ); aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeHuntAggressive, 0, 79, 0.0, MainBaseID ); aiSetResourceBreakdown( cResourceFood, cAIResourceSubTypeFish, 0, 79, 0.0, MainBaseID ); }