Skip to content

Commit

Permalink
Moved item expansion start into expansion build request
Browse files Browse the repository at this point in the history
To follow strategy priorities
  • Loading branch information
SMUnlimited committed Dec 18, 2024
1 parent 8341b0a commit e5772bd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Jobs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions Jobs/ITEM_EXPANSION.eai
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 0 additions & 28 deletions Jobs/ITEM_EXPANSION_CHECK.eai

This file was deleted.

36 changes: 13 additions & 23 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -10929,15 +10929,22 @@ 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

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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e5772bd

Please sign in to comment.