Skip to content

Commit

Permalink
Various fixes from #214
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Jan 27, 2024
1 parent 3285405 commit d5b6832
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Units sent home for healing from a water expansion can now be picked up by zeppelins.
- Fixed issue where undead gold mines were never fully detected as mines correctly for various logic.
- Hardened the town checks to ensure more likely to match the internal blizzard AI town.
- Fixed picked healer was not alive. (jzy-chitong56)
- Some mining irregularity fixes.
- (Classic) Fixed game start crash with AMAI vs AI. (jzy-chitong56)
- (Classic) Fixed some TFT settings not in sync with REFORGED.
- (DevTools) Fixed the optimize all script and the makeAll and optimizeAll scripts will pause between versions.
Expand Down
67 changes: 29 additions & 38 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -4121,15 +4121,9 @@ endfunction
// (AMAI) GetMineNearLoc
//==========================================================================
function GetMineNearLoc takes unit u, location l, real dist returns unit
local group g = null
local group g = CreateGroup()
local integer i = 0
local real distance = 1500
if DistanceBetweenPoints(l , home_location) < 500 then
if own_town_mine[0] != null and GetResourceAmount(own_town_mine[0]) > 0 then
return own_town_mine[0]
endif
endif
set g = CreateGroup()
call GroupEnumUnitsInRangeOfLoc(g, l, dist, null)
//set g = SelectByAlive(g, true)
loop
Expand Down Expand Up @@ -6009,7 +6003,7 @@ function AddExpansion takes unit u, real d returns nothing
set expansion_dist[expansion_list_length] = d
set expansion_creeps[expansion_list_length] = GetExpFoeGroup(expansion_creeps[expansion_list_length],u) // group of the the creeps that guard this mine
if first_expansion_chosen == false then
set first_expansion_chosen = (expansion_creeps[expansion_list_length] != null) or (CheckExpansionTaken(u) == false)
set first_expansion_chosen = not CheckExpansionTaken(u)
endif
set expansion_list_length = expansion_list_length + 1
endfunction
Expand Down Expand Up @@ -6345,7 +6339,7 @@ if c_enemy_user_total == 1 then
set builder[10] = temphumanu
set rushedplayer = nearhumanplayer
set mindistance = humandistance
else
elseif c_enemy_user_total != 0 then
set builder[10] = tempu
set rushedplayer = nearplayer
endif
Expand Down Expand Up @@ -6618,7 +6612,7 @@ function CanCreepGuardsSleep takes integer nn returns boolean
return b
endif
if FirstOfGroup(neutral_guards[nn]) == null then
return true
return b
endif
set g = CopyGroup(neutral_guards[nn])
loop
Expand Down Expand Up @@ -7040,7 +7034,7 @@ function GetHealer takes unit u returns unit
set u = FirstOfGroup(healer_group)
exitwhen u == null
set id = GetHealerId(GetUnitTypeId(u))
if id != -1 and not IsUnitLoaded(u) and GetUnitState(u, UNIT_STATE_MANA) >= healer_mana_cost[id] and ((healer_upg_id[id] == 0) or (GetUpgradeLevel(healer_upg_id[id]) >= healer_upg_level[id])) then
if id != -1 and not IsUnitLoaded(u) and UnitAlive(u) and GetUnitState(u, UNIT_STATE_MANA) >= healer_mana_cost[id] and ((healer_upg_id[id] == 0) or (GetUpgradeLevel(healer_upg_id[id]) >= healer_upg_level[id])) then
return u
endif
call GroupRemoveUnit(healer_group, u)
Expand Down Expand Up @@ -7947,6 +7941,7 @@ function InitCheckHarvest takes nothing returns nothing
set g = null
call HarvestGold(0,3)
call HarvestWood(0,2) // Early triggering Harvest , convenient HARVEST_CHECK job check peon
call Trace("first town mine mode :" + Int2Str(first_town_mine))
endfunction

//===========================================================================
Expand All @@ -7955,6 +7950,7 @@ function InitTownBuilt takes nothing returns nothing
loop
exitwhen i >= max_towns
set town_built[i] = false
set own_town_loc[i] = null
set i = i + 1
endloop
set town_built[0] = true
Expand Down Expand Up @@ -10646,9 +10642,9 @@ function ShredderBuilder takes nothing returns nothing
local real gdivw = g / w
if neutral_available[NEUTRAL_OBSERVATORY] and gdivw > 4 and g - w > 500 and w < 550 and g > GetUnitGoldCost2(neutral_shredder) and w > GetUnitWoodCost2(neutral_shredder) and ai_time - available_time[neutral_shredder] >= -1 then
if (race_has_ghouls) then
call BuildUnit(1, neutral_shredder, ghoul_prio - 4)
call BuildUnit(1, neutral_shredder, Max(ghoul_prio - 4,1))
else
call BuildUnit(1, neutral_shredder, peon_prio - 10)
call BuildUnit(1, neutral_shredder, Max(peon_prio - 10,1))
endif
endif
endfunction
Expand All @@ -10670,12 +10666,11 @@ endfunction
//============================================================================
function PeonBuilder takes nothing returns nothing
local integer mo = GetMinesHarvested()
local integer sc = TownCount(neutral_shredder)
local integer sc = 0
local real w = GetWood()
if race_uses_shredder then
if race_uses_shredder and neutral_shredder != 0 then
set sc = TownCount(neutral_shredder)
call ShredderBuilder()
else
set sc = 0
endif
//if w <= maximum_peon_wood then
// call BuildPeons( peon_1_mine_number * mo + Max(max_lumber_peons - shredder_peon_count*sc, 1 ) ) // number of peons per mine + wood peons
Expand All @@ -10684,8 +10679,12 @@ function PeonBuilder takes nothing returns nothing
//else
// call BuildPeons( peon_1_mine_number * mo + Max(Max(min_lumber_peons, R2I(I2R(max_lumber_peons) / 2)) - shredder_peon_count*sc, 1 ) )
//endif

if race_uses_mine_expansion then
set mo = TownCount(racial_expansion)
endif

if race_has_ghouls then
if race_has_ghouls then // Ignore shredders
if mo <= 1 then
call BuildPeons(min_peon_number_single_mine)
elseif mo <= 2 then
Expand Down Expand Up @@ -12940,10 +12939,10 @@ function HealArmy takes nothing returns nothing
local integer sleepFrequency = 0
loop
set hs = GetArmyHealthState()
set mass_healed = false
exitwhen (sleepFrequency >= 3 and hs > healthTrigger) // Tried to heal but overall still strong so exit loop
exitwhen (urgent_healing_count + medium_healing_count <= 3 and hs > healthTrigger)
exitwhen player_defeated or town_threatened or ver_heroes == false
set mass_healed = false
call Trace("function HealArmy: Army is badly damaged and needs healing " + Real2Str(hs))
set build_emergency_healing_item = 0
set mh_item = GetMassHealingItem()
Expand Down Expand Up @@ -13133,26 +13132,18 @@ function universal_peon_assignment takes nothing returns nothing
call HarvestWood(0,swh)

set T = Max(T + 3,TownCountDone(racial_expansion))
if FoodUsed() <= 20 and FoodCap() >= 90 then // later stages of the game, AI may not be harvest
loop
exitwhen i > T
call HarvestGold(i,ver_optimal_gold)
set i = i + 1
endloop
else
loop
//set i = i + 1
exitwhen i > T
if T != i and TownHasMine(i) and TownCountEx(racial_expansion,true,i) > 0 then
if gdivw < 3.0 or g < 300 then
call HarvestGold(i,ver_optimal_gold)
else
call HarvestGold(i,ver_optimal_gold - 2)
endif
call CreateDebugTagLoc("MINES:" + Int2Str(GetMinesOwned()), 10, GetLocationX(home_location), GetLocationY(home_location), 1.00, 0.80)
loop
exitwhen i > T
if T != i and TownHasMine(i) and TownCountEx(racial_expansion,true,i) > 0 then
if gdivw < 3.0 or g < 300 or ((FoodUsed() <= 20 or GetMinesOwned() < 1 or g <= 2500) and hero_built[3]) then
call HarvestGold(i,ver_optimal_gold)
else
call HarvestGold(i,ver_optimal_gold - 2)
endif
set i = i + 1
endloop
endif
endif
set i = i + 1
endloop

call HarvestWood(0,20)
endfunction
Expand Down

2 comments on commit d5b6832

@jzy-chitong56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CanCreepGuardsSleep return ( u == null ) , so b first should is true

PeonBuilder -- GetMinesHarvested check race_manual_loading and race_uses_mine_expansion done , so no need check on PeonBuilder

@jzy-chitong56
Copy link
Contributor

@jzy-chitong56 jzy-chitong56 commented on d5b6832 Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Forced Harvest mine code

 if (FoodUsed() <= 20 or GetMinesOwned() < 1 or g <= 2500) and hero_built[3] then  // later stages of the game, AI may not be harvest
    set i = 0
    set T = 0
    loop
      exitwhen i > max_towns or T > 2
      if exist_mine[i] != null and not CheckExpansionTaken(exist_mine[i]) then
        call PeonMineCheck(exist_mine[i])
        set T = T + 1
        call CreateDebugTag("Forced Harvest mine " + Int2Str(i), 10, exist_mine[i], 3.00, 1.50)
      endif
      set i = i + 1
    endloop
  else
    loop
      //set i = i + 1
      exitwhen i > T
      if T != i and TownHasMine(i) and TownCountEx(racial_expansion,true,i) > 0 then
        if gdivw < 3.0 or g < 300 then
          call HarvestGold(i,ver_optimal_gold)
        else
          call HarvestGold(i,ver_optimal_gold - 2)
        endif
      endif
      set i = i + 1
    endloop
  endif
function LocalizeNewMine takes integer num returns nothing
  local group g = CreateGroup()
  local unit u = null
  local location l = null
  call GroupEnumUnitsOfPlayer(g, ai_player, null)
  set g = SelectById(g, old_id[racial_expansion], true)
  set g = SelectByHidden(g,false)
  set g = SelectByAlive(g,true)
  loop
    set u = FirstOfGroup(g)
    exitwhen u == null
    exitwhen CheckUnitNewTown(u, num)
    call GroupRemoveUnit(g,u)
  endloop
  call DestroyGroup(g)
  set g = null
  if u != null then
    set l = GetUnitLoc(u)
    set exist_mine[num] = GetMineNearLoc(exist_mine[num], l, 1500)
    if debugging and exist_mine[num] != null then
      call PingMinimap(GetUnitX(exist_mine[num]), GetUnitY(exist_mine[num]), 20)
    endif
    call RemoveLocation(l)
    set l = null
    set u = null
  endif
endfunction

----------------------------------------------

function CheckTownBuilt takes nothing returns nothing

.....

  set i = 0
  loop
    exitwhen i >= max_towns
    if own_town_loc[i] != null then
      set exist_town[c] = own_town_loc[i]
      set c = c + 1
    endif
    if exist_mine[i] == null or GetResourceAmount(exist_mine[i]) <= 0 then
     call LocalizeNewMine(i)
    endif
    set i = i + 1
  endloop
  set exist_town_num = c
  loop
    exitwhen c >= max_towns
    set exist_town[c] = home_location
    set c = c + 1
  endloop
endfunction

Please sign in to comment.