diff --git a/CHANGELOG.md b/CHANGELOG.md index 789e4f113..0b2adbfbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed a bug where all special racial expansions could not run on the first expansion. - Lots of fixes to ancient expansion logic improving overall reliability. - Fixed bug where ancient attacks didn't take account of ancient strength in retreat calculations. +- Item expansion now only occurs when the AI naturally wants to expand instead of making the AI expand earlier. - (DevTools) Removed use of hardcoded ids in expansion tracking for custom mod support. ## [3.4.1] - 2024-12-07 diff --git a/Jobs.txt b/Jobs.txt index a71fe95a6..b56c8df91 100644 --- a/Jobs.txt +++ b/Jobs.txt @@ -44,6 +44,5 @@ SEND_HOME 20 SendUnitHomeJob(unit_par, par) false 0 0 RESET_WINDWALKER 9 ResetWindWalkerGuardPosition(unit_par) false 0 0 BUILD_EXPANSION 10 BuildExpansionJob(unit_par, unit_par2) false 0 0 ITEM_EXPANSION 20 ItemExpansionJob() false 0 0 -ITEM_EXPANSION_CHECK 30 ItemExpansionCheck() false 0 0 ITEM_REPEAT_CHECK 160 ItemRepeatCheck() true 200 220 RESET_ANCIENT 10 ResetAncient(unit_par) false 0 0 diff --git a/Jobs/ITEM_EXPANSION.eai b/Jobs/ITEM_EXPANSION.eai index 6f802617b..590930e7c 100644 --- a/Jobs/ITEM_EXPANSION.eai +++ b/Jobs/ITEM_EXPANSION.eai @@ -1,7 +1,8 @@ #IFDEF GLOBAL integer item_exp_state = 0 unit itemhero = null - boolean item_attack_running = false + boolean item_expanding = false + boolean item_job_running = false boolean expitem_buy = false location item_exp_guard_loc = null #ELSE @@ -16,7 +17,7 @@ function ItemExpansionJob takes nothing returns nothing if (itemhero != null and GetUnitState(itemhero, UNIT_STATE_LIFE) <= 0) or town_threatened or current_expansion == null then call RecycleGuardPosition(itemhero) call Trace("Expansion cannot or no Expansion") // no call ChooseExpansion() , this is passive expansion , avoidance buy repeat item - set item_attack_running = false + set item_job_running = false set item_expanding = false set expitem_buy = false set item_exp_state = 0 @@ -25,6 +26,7 @@ function ItemExpansionJob takes nothing returns nothing endif set exp_time_count = ai_time set u = GetExpFoe(u) + set item_job_running = true if item_exp_state == 0 then call Trace("Expansion Distance: " + Int2Str(R2I(GetExpansionDistance()))) call Trace("Expansion state 0: Check Expansion Hero and Location") @@ -35,11 +37,11 @@ function ItemExpansionJob takes nothing returns nothing endif endif if u == null then - set item_attack_running = false if itemhero == null and expitem_buy == false then - if GetGold() < gold_price[race_item_expansion_item_id] + 120 or GetWood() < wood_price[race_item_expansion_item_id] + 80 then + if GetGold() < gold_price[race_item_expansion_item_id] or GetWood() < wood_price[race_item_expansion_item_id] then call Trace("Expansion no gold or wood") set item_expanding = false + set item_job_running = false set item_exp_state = 0 set itemhero = null return @@ -84,8 +86,8 @@ function ItemExpansionJob takes nothing returns nothing else call Trace("Expansion Done") call RecycleGuardPosition(itemhero) - set item_attack_running = false set item_expanding = false + set item_job_running = false set expitem_buy = false set item_exp_state = 0 set itemhero = null diff --git a/Jobs/ITEM_EXPANSION_CHECK.eai b/Jobs/ITEM_EXPANSION_CHECK.eai deleted file mode 100644 index 8c5dc65fc..000000000 --- a/Jobs/ITEM_EXPANSION_CHECK.eai +++ /dev/null @@ -1,28 +0,0 @@ -#IFDEF GLOBAL - boolean item_expanding = false -#ELSE - -// ######################## Item Expansion Check ################# -// # Created by JZY 20/05/23. Conditions that check that . reference ANCIENT_EXPANSION -// # an item expansion can start. -// ################################################################## - -function ItemExpansionCheck takes nothing returns nothing - call DisplayToAllJobDebug("ITEM_EXPANSION_CHECK JOB START") - if not item_expanding then - if take_exp and current_expansion != null and not CheckExpansionTaken(current_expansion) and GetResourceAmount(current_expansion) > (gold_price[race_item_expansion_item_id] + 300) and not_taken_expansion == null and shop_unit != null and race_item_expansion_item_id != 0 then - call Trace("Item expansion check - Could expand if available") // this is passive expansion , no set not_taken_expansion , but need current_expansion not not_taken_expansion - if tier >= race_item_sale_level then - call Trace("Item expansion check - Begin Job") - set item_expanding = true - call TQAddJob(1, ITEM_EXPANSION, 0) - endif - endif - endif - if not item_expanding then - call Trace("Item expansion check - Not available") - endif - call TQAddJob(50, ITEM_EXPANSION_CHECK, 0) -endfunction - -#ENDIF \ No newline at end of file diff --git a/common.eai b/common.eai index 476304b07..2eba4c44e 100644 --- a/common.eai +++ b/common.eai @@ -10929,6 +10929,13 @@ function StartExpansionAM takes integer qty, integer hall returns integer // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion choosen") set gold_cost = GetUnitGoldCost2(hall) set wood_cost = GetUnitWoodCost2(hall) + if item_expanding then + set gold_cost = gold_price[race_item_expansion_item_id] + set wood_cost = wood_price[race_item_expansion_item_id] + endif + if item_expanding and not item_job_running then + call TQAddJob(1, ITEM_EXPANSION, 0) + endif set total_gold = total_gold - gold_cost set total_wood = total_wood - wood_cost @@ -10936,8 +10943,8 @@ function StartExpansionAM takes integer qty, integer hall returns integer set take_exp = (GetExpFoe(u) != null) set u = null - if ancient_expanding then - return BUILT_SOME + if ancient_expanding or militia_expanding then + return BUILT_SOME // Just safety check to prevent normal expansion running while these are both running endif if take_exp then @@ -10956,6 +10963,10 @@ function StartExpansionAM takes integer qty, integer hall returns integer if total_wood < 0 and wood_cost > 0 then return NOT_ENOUGH_RES endif + + if item_expanding then + return BUILT_SOME + endif // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion rescources sorted") if expansion_peon == null or not UnitAlive(expansion_peon) then @@ -11419,8 +11430,6 @@ if exp_prepared and race_item_expansion_available and not item_expanding and spe set specialexpand = false if GetRandomInt(1, 100) <= race_item_expansion_probability and shop_unit != null and race_item_expansion_item_id != 0 and tier >= race_item_sale_level then set item_expanding = true - call TQAddJob(1, ITEM_EXPANSION, 0) - return endif endif @@ -13299,25 +13308,6 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, integer return // Don't do new attacks yet as nearly ready to help expansion endif endif - - // item expansion attack - // - if item_expanding then - call Trace("An Item Expansion Attack or Guard") - set item_attack_running = true - - if item_exp_state == 1 then - call AttackMoveKillCreep(GetExpFoe(creep), false) - set item_attack_running = false - set creep = null - elseif item_exp_state > 0 then - call FromGroupAndGhoulsAM(3) - call AttackMoveKillXYAAM(R2I(GetLocationX(item_exp_guard_loc)),R2I(GetLocationY(item_exp_guard_loc))) //Prevent the army from leaving before using the item , so no set item_attack_running - endif - return - endif - - if rushcreep_target != null and UnitAlive(rushcreep_target) and GetLocationCreepStrength(GetUnitX(rushcreep_target), GetUnitY(rushcreep_target), 510) < own_strength + 5 then // Matches getOwnStrength +5 addition for ancient set battle_radius = creep_battle_radius