//------------------------------------------------------------------- // 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 //------------------------------------------------------------------- // RM USED PARAMS: These are the parameters typically updated via RM extern int tcID = -1; extern int tcOwnerID = -1; //============================================================================== // Unit Queries //============================================================================== extern int customCaravanQuery = -1; //============================================================================== // internal vars extern bool caravansSentBackToMarket = false; //------------------------------------------------------------------- // for anything defined in SetCampaignDefaults, if needed, override it here void OverrideCampaignDefaults() { btStrengthATK = 0.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 } //------------------------------------------------------------------- // for anything calculated in CalculateCampaignSettings, if needed, override it here void OverrideCampaignSettings() { cvOkToCaravan = false; } //------------------------------------------------------------------- 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..."); } void setTargetTCID(int newTCID = -1) { tcID = newTCID; } void setAssociatedTCOwnerID(int newOwnerID = -1) { tcOwnerID = newOwnerID; } //used Matt's work in aiEcon as an example for this rule. rule customCaravans active minInterval 8 { //early outs //check if the tcid has been set. if (tcID == -1) { return; } //check if the associated owner has been set. if(tcOwnerID == -1) { return; } //setup the caravan query if it isn't already. if(customCaravanQuery == -1) { customCaravanQuery = kbUnitQueryCreate("Caravan Query"); kbUnitQuerySetPlayerID(customCaravanQuery, cMyID); kbUnitQuerySetUnitType(customCaravanQuery, cUnitTypeUnitTypeCaravan1); kbUnitQuerySetState(customCaravanQuery, cUnitStateAlive); } //reset and run the query. kbUnitQueryResetResults(customCaravanQuery); int count = kbUnitQueryExecute(customCaravanQuery); int i = 0; int ID = -1; //move to TC if(tcOwnerID == kbUnitGetPlayerID(tcID)) { //reset the sendBackBool caravansSentBackToMarket = false; for(i = 0; < count) { ID = kbUnitQueryGetResult(customCaravanQuery, i); //check if the caravan is targeting anything. If not, it is probably idle. if (kbUnitGetTargetUnitID(ID) == -1) { //send the caravans to the tc. aiTaskUnitWork(ID, tcID); } } } //move to Market else { //only send them back to the market once. if(caravansSentBackToMarket == false) { for(i = 0; < count) { ID = kbUnitQueryGetResult(customCaravanQuery, i); aiTaskUnitMove(ID, kbUnitGetPosition(getUnit(cUnitTypeUnitTypeBldgMarket))); } caravansSentBackToMarket = true; } } }