//============================================================================== /* C:\work\Spartan\main\age4\age4-dev\age4w\ai\CORE\Age2_BarracksRush_Hardcore.xs This file is auto-generated. Edits will be lost when the file is regenerated. */ //============================================================================== 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 "aiSkirmish.xs"; // Skirmish Hall specific overrides void pickSecondaryFocus() { int rand = gRandomSecondaryFocus; if(rand == 0) { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgBarracks; btBiasInf = -0.5; aiEcho("Choosing an infantry secondary focus"); } else if(rand == 1) { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgStables; btBiasCav = 0; aiEcho("Choosing a cavalry secondary focus"); } else { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgSiegeWorkshop; btBiasArt = 0.65; aiEcho("Choosing a siege secondary focus"); } setUnitPickerPreference(gLandUnitPicker); } //============================================================================== /* preInit() This function is called in main() before any of the normal initialization happens. Use it to override default values of variables as needed for personality or scenario effects. */ //============================================================================== void preInit(void) { aiEcho("preInit() RANGED starting."); getDataFromBiases(); setDefaultAIVariables(); //btTargetAge2ArmyCount = 2 + (3 * btDifficulty); btBiasInf = -1; btBiasCav = -1; btBiasArcher = 1; btBiasArt = -1; btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgBarracks; } //============================================================================== /* postInit() This function is called in main() after the normal initialization is complete. Use it to override settings and decisions made by the startup logic. */ //============================================================================== void postInit(void) { aiEcho("postInit() starting."); skirmishPostInit(); if(kbGetCiv() != gEgyptianCivID) { gMilitaryBuildingForInitialize = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); } else { gMilitaryBuildingForInitialize = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); } xsDisableRule("reenableBuildRules"); xsDisableRule("delayInfBiasEgypt"); if(btDifficulty < 3) { xsDisableRule("quicklyBuildArcheryRange"); xsEnableRule("delayedPickSecondaryFocus"); } //xsSetRuleMaxInterval("econBuildMonitor", 6); //xsSetRuleMaxInterval("militaryBuildMonitor", 6); } rule delayedPickSecondaryFocus inactive minInterval 3 { pickSecondaryFocus(); xsDisableSelf(); } //============================================================================== // rule autoExploreEnemyBases // // Cheat and show the AI where all of the enemy bases are. //============================================================================== rule autoExploreEnemyBases active minInterval 5 { float totalTime = xsGetTime() / 1000.0; static bool revealed = false; if (btRevealEnemyBases == false) { xsDisableSelf(); return; } if (totalTime >= cTimeToRevealEnemyBases) { if (revealed == false) { Vector pos = aiCheatReveal(); if (xsVectorIsValid(pos)) { findEnemyBase(pos); } revealed = true; } else { aiCheatUnreveal(); xsDisableSelf(); } } } rule quicklyBuildArcheryRange active group econ minInterval 5 { if(kbGetAge() == cAge1 && agingUp()) { if(kbGetCiv()==gEgyptianCivID) { checkAndBuildBuilding(1, kbFindBuilding(cUnitTypeUnitTypeBldgBarracks), cEconomyEscrowID); if(kbUnitCostPerResource(kbFindBuilding(cUnitTypeUnitTypeBldgBarracks), cResourceWood) > kbResourceGet(cResourceWood)) { kbAdjustResourceByID(cMyID, cResourceWood, kbUnitCostPerResource(kbFindBuilding(cUnitTypeUnitTypeBldgBarracks), cResourceWood) - kbResourceGet(cResourceWood) + 50); } } else { checkAndBuildBuilding(1, kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange), cEconomyEscrowID); if(kbUnitCostPerResource(kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange), cResourceWood) > kbResourceGet(cResourceWood)) { kbAdjustResourceByID(cMyID, cResourceWood, kbUnitCostPerResource(kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange), cResourceWood) - kbResourceGet(cResourceWood) + 50); } } xsDisableRule("econBuildMonitor"); xsDisableRule("houseMonitor"); xsEnableRule("reenableBuildRules"); xsDisableSelf(); } } rule reenableBuildRules inactive group econ minInterval 3 { if(kbUnitCount(cMyID, kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange), cUnitStateAlive) > 0 || (kbGetCiv()==gEgyptianCivID && kbUnitCount(cMyID, kbFindBuilding(cUnitTypeUnitTypeBldgBarracks), cUnitStateAlive) > 0)) { xsEnableRule("econBuildMonitor"); xsEnableRule("houseMonitor"); //cvOkToBuild = true; if(kbGetCiv() == gEgyptianCivID) { xsEnableRule("delayInfBiasEgypt"); } else { pickSecondaryFocus(); } xsDisableSelf(); } } rule delayInfBiasEgypt inactive minInterval 180 { // need to do some goofy stuff with egypt since they are already building barracks as their initial ranged factory int rand = gRandomSecondaryFocus; if(rand == 0) { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgStables; btBiasInf = -0.95; aiEcho("Choosing an infantry secondary focus"); } else if(rand == 1) { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgStables; btBiasCav = 0; aiEcho("Choosing a cavalry secondary focus"); } else { btSecondaryFocusBuilding = cUnitTypeUnitTypeBldgSiegeWorkshop; btBiasArt = 0.65; aiEcho("Choosing a siege secondary focus"); } setUnitPickerPreference(gLandUnitPicker); xsDisableSelf(); } //============================================================================== // setupBuildingInfo() // // Called when we age up--setup the buildings we want for the current age. This // controls the forecast values and what the AI attempts to build automatically. // Some things (like farms and dropsites) are built elsewhere, even though // they're listed in here (for forecast info) //============================================================================== void setupBuildingInfo() { // Create arrays if needed initializeAndClearBuildingArrays(); int currentVillCount = getVillagerCountForBuildOrder(); int bt = 0; int offset = 0; switch (kbGetAge()) { case cAge1: { if(btDifficulty > cStrongDifficulty && kbGetCiv()!=gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, 1, cEconomyEscrowID, cAgeStateEarly, true, offset); } break; } case cAge2: { if(btDifficulty > cStrongDifficulty) { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, currentVillCount / (7 - (btDifficulty - 3)), cMilitaryEscrowID, cAgeStateEarly, true, offset); } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, currentVillCount / (7 - (btDifficulty - 3)), cMilitaryEscrowID, cAgeStateEarly, true, offset); bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, currentVillCount / 15, cMilitaryEscrowID, cAgeStateMid, true, offset); } } else if(btDifficulty > cWeakDifficulty) { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, currentVillCount / 10, cMilitaryEscrowID, cAgeStateEarly, true, offset); } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, currentVillCount / 10, cMilitaryEscrowID, cAgeStateEarly, true, offset); } } else { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, 1, cMilitaryEscrowID, cAgeStateEarly, true, offset); } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, 1, cMilitaryEscrowID, cAgeStateEarly, true, offset); } } break; } default: { if(btDifficulty > cStrongDifficulty) { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, currentVillCount / 8, cMilitaryEscrowID, cAgeStateEarly, true, offset); bt = kbFindBuilding(cUnitTypeUnitTypeBldgStables); offset = addBuildingToList(bt, currentVillCount / 8, cMilitaryEscrowID, cAgeStateMid, true, offset); if(btBiasArt >= 0) { bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, currentVillCount / 15, cMilitaryEscrowID, cAgeStateMid, true, offset); } } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, currentVillCount / (7 - (btDifficulty - 3)), cMilitaryEscrowID, cAgeStateEarly, true, offset); bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, currentVillCount / 15, cMilitaryEscrowID, cAgeStateMid, true, offset); } } else if(btDifficulty > cWeakDifficulty) { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, currentVillCount / 10, cMilitaryEscrowID, cAgeStateEarly, true, offset); bt = kbFindBuilding(cUnitTypeUnitTypeBldgStables); offset = addBuildingToList(bt, currentVillCount / 10, cMilitaryEscrowID, cAgeStateMid, true, offset); if(btBiasArt >= 0) { bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, currentVillCount / 20, cMilitaryEscrowID, cAgeStateMid, true, offset); } } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, currentVillCount / 10, cMilitaryEscrowID, cAgeStateEarly, true, offset); bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, currentVillCount / 20, cMilitaryEscrowID, cAgeStateMid, true, offset); } } else { if(kbGetCiv()==gEgyptianCivID) { bt = kbFindBuilding(cUnitTypeUnitTypeBldgBarracks); offset = addBuildingToList(bt, currentVillCount / 15, cMilitaryEscrowID, cAgeStateEarly, true, offset); } else { bt = kbFindBuilding(cUnitTypeUnitTypeBldgArcheryRange); offset = addBuildingToList(bt, currentVillCount / 15, cMilitaryEscrowID, cAgeStateEarly, true, offset); } bt = kbFindBuilding(btSecondaryFocusBuilding); offset = addBuildingToList(bt, 1, cMilitaryEscrowID, cAgeStateMid, true, offset); } break; } } setupStandardBuildingInfo(offset, currentVillCount); } //============================================================================== // setUnitPickerPreference() // // Updates the unit picker biases. //============================================================================== void setUnitPickerPreference(int upID = -1) { // Add the main unit lines if (upID < 0) return; kbUnitPickSetPreferenceFactor(upID, cUnitTypeAbstractInfantry, 0.5 + (btBiasInf / 2.0)); // Range 0.0 to 1.0 kbUnitPickSetPreferenceFactor(upID, cUnitTypeAbstractArtillery, 0.5 + (btBiasArt / 2.0)); kbUnitPickSetPreferenceFactor(upID, cUnitTypeAbstractCavalry, 0.5 + (btBiasCav / 2.0)); kbUnitPickSetPreferenceFactor(upID, cUnitTypeAbstractArcher, 0.5 + (btBiasArcher / 2.0)); }