Skip to content

Commit

Permalink
Tier block optimizations #457
Browse files Browse the repository at this point in the history
Gold and wood resources now taken into account
Number of expansions now taken into account
Tier lock is one time per tier, moment its unlocked once it stays unlocked
  • Loading branch information
SMUnlimited committed Dec 5, 2024
1 parent 995f581 commit 07d8317
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- (DevTools) New block available for strategies. E.g `SetTierBlock(1, 0.75, 60, true)` that blocks tiering up from tier 1 unless more than 75% of higher priority units are built. Unlocks if over 60 food. Final argument prevents tier up while expanding if set to true. Tier block overrides previous tier level block if repeated in a strategy.

### Changed
- When we enhanced the build code to build other things if it can't build the current priorities it caused strategies to tier up much earlier than designed, so now tier ups can only happen once most higher priority unit production is done honoring the strategy and they are not currently expanding.
- When we enhanced the build code to build other things if it can't build the current priorities it caused strategies to tier up much earlier than designed. Now tier ups can only occur as follows:
- once most higher priority unit production is done honoring the strategy.
- No expansion occurring unless we already have multiple mines to support the cost.
- Or we have lots and lots of spare gold and wood so should just use it to tier up.
- Building additional factory buildings should not be done while actively tiering up as the buildings needed for tier 2/3 may be different.
- Harass will correctly keep harassing if no units can harm its air harass.
- Harass attacks will return harassing units faster to the ai's control when complete.
Expand Down
11 changes: 8 additions & 3 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ globals
integer array bl_tier_foodlock
real array bl_tier_unitlock
boolean array bl_tier_expansionblock
boolean array bl_tier_lockactive

//==============================================================
// (AMAI) Standard Unit Variables
Expand Down Expand Up @@ -11640,6 +11641,7 @@ function OneBuildLoopAM takes nothing returns nothing
local integer tracedall = 0
local string logtype = ""
local boolean blocktierup = false
local boolean expablocktier = false

call InitLastUpkeep()

Expand Down Expand Up @@ -11689,10 +11691,13 @@ function OneBuildLoopAM takes nothing returns nothing
// call DumpInteger("Prio"+Int2Str(index),build_prio[index])

if qty > mo and qty > 0 then
if tp == BUILD_UNIT and IsRacialHallId(id, 2) and blocktierup then
if tp == BUILD_UNIT and IsRacialHallId(id, 2) and ((blocktierup and bl_tier_lockactive[tier - 1]) or expablocktier) and GetUnitGoldCost2(id) * 4 > total_gold and GetUnitWoodCost2(id) * 4 > total_wood then
call Trace("TIER UP block " + logtype + unitNames[id] + " " + Int2Str(id))
set ret = CANNOT_BUILD // Not ready to tier up
elseif tp == BUILD_UNIT then
if IsRacialHallId(id, 2) then
set bl_tier_lockactive[tier - 1] = false // lock only occurs once per tier, once lock is unlocked for that tier it stays unlocked e.g it doesn't have to start from scratch again if strategy changes or units die within tier 1
endif
set logtype = "unit "
set ret = StartUnitAM(qty,id,build_town[index], build_loc[index], build_prio[index], mo)
elseif tp == BUILD_UPGRADE then
Expand All @@ -11701,8 +11706,8 @@ function OneBuildLoopAM takes nothing returns nothing
elseif tp == BUILD_EXPAND then
set logtype = "expand "
set ret = StartExpansionAM(qty,id)
if ret == BUILT_SOME then // block tier up while actually expanding
set blocktierup = bl_tier_expansionblock[tier - 1]
if ret == BUILT_SOME and GetMinesHarvested() < 3 then // block tier up while actually expanding or enough mines to support this
set expablocktier = bl_tier_expansionblock[tier - 1]
endif
elseif tp == BUILD_ITEM then
set logtype = "item "
Expand Down
6 changes: 6 additions & 0 deletions races.eai
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,12 @@ function build_sequence_all takes nothing returns nothing
local boolean reset_counter = false

call Trace("Starting Build Sequence Loop")
loop
exitwhen new_tier >= tiernum
set bl_tier_lockactive[new_tier] = true
set new_tier = new_tier + 1
endloop
set new_tier = 0
loop
exitwhen player_defeated

Expand Down

0 comments on commit 07d8317

Please sign in to comment.