Skip to content

Commit

Permalink
Optimizations to prevent cases of 0 ghouls on wood at the wrong time #…
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Dec 19, 2024
1 parent 0193fb9 commit ff135ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- 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.
- Fixed an issue where as ghouls die in an attack, harvesting ghouls are being pulled off to fill dead/fleeing units.
- (DevTools) Removed use of hardcoded ids in expansion tracking for custom mod support.

## [3.4.1] - 2024-12-07
Expand Down
22 changes: 22 additions & 0 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -11915,6 +11915,8 @@ function FormGroupAM takes integer seconds returns nothing
local integer count = 0
local integer unitid = 0
local integer desire = 0
local group g = null
local unit u = null

call InitAssault()

Expand All @@ -11933,7 +11935,27 @@ function FormGroupAM takes integer seconds returns nothing
set desire = attack_max[index]
set count = TownCountDone(unitid)

if wood > minimum_peon_wood then
set take_all_ghouls_along = true
elseif wood < minimum_peon_wood then
set take_all_ghouls_along = false
endif

if unitid == racial_ghoul and not take_all_ghouls_along then
// Ghoul count needs to exclude units sent back to heal otherwise harvesting ghouls will be pulled off.
set count = 0
set g = CreateGroup()
call GroupEnumUnitsOfPlayer(g, ai_player, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetUnitTypeId(u) == old_id[racial_ghoul] and UnitAlive(u) and IsStandardUnit(u) and not IsUnitBuying(u) then
set count = count + 1
endif
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
set g = null
set desire = (count - harvesting_ghouls) // all spare ghouls should attack and join attack as built
if towerrush then
set desire = Min(Max(count - 2 , 0),desire) // reserve
Expand Down
14 changes: 4 additions & 10 deletions races.eai
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,7 @@ function setup_ghouls takes nothing returns nothing
local integer gn = TownCountDone(racial_ghoul)
local integer wood = GetWood()

if wood > minimum_peon_wood then
set take_all_ghouls_along = true
elseif wood < minimum_peon_wood then
set take_all_ghouls_along = false
endif
if take_all_ghouls_along then
set harvesting_ghouls = 0
elseif wave <= 4 then
if wave <= 2 then
set harvesting_ghouls = 1
//elseif wave==2 then
//set attacking_ghouls = Max(6, gn - 2)
Expand All @@ -536,9 +529,10 @@ function setup_ghouls takes nothing returns nothing
//set attacking_ghouls = gn - (havesting_ghouls - (4 * TownCountDone(neutral_shredder))
//elseif wood > maximum_peon_wood and wood < minimum_peon_wood / 2 then
//set attacking_ghouls = gn - Max(2 - (4 * TownCountDone(neutral_shredder)), 0)
elseif wave <= 4 then
set harvesting_ghouls = Max(1,Min(R2I(race_min_ghouls*LinearInterpolation(maximum_peon_wood, minimum_peon_wood, 1, 0, wood) + 0.5),gn) - (R2I(shredder_peon_count/2) * TownCountDone(neutral_shredder)))
else
//set harvesting_ghouls = Max(0,Min(5 - wood / R2I(maximum_peon_wood*1),gn) - (R2I(shredder_peon_count/2) * TownCountDone(neutral_shredder)))
set harvesting_ghouls = Max(1,Min(5 - wood / R2I(maximum_peon_wood*1),gn) - (R2I(shredder_peon_count/2) * TownCountDone(neutral_shredder)))
set harvesting_ghouls = Max(1,Min(R2I(race_max_ghouls*LinearInterpolation(maximum_peon_wood, minimum_peon_wood, 1, 0, wood) + 0.5),gn) - (R2I(shredder_peon_count/2) * TownCountDone(neutral_shredder)))
endif
set attacking_ghouls = gn - harvesting_ghouls
set attacking_ghouls = Min(Max(attacking_ghouls, 0), gn)
Expand Down

0 comments on commit ff135ec

Please sign in to comment.