Skip to content

Commit

Permalink
Review of Pr 177 (#179)
Browse files Browse the repository at this point in the history
* Update common.eai

* fix

* Update FAST_BUILD.eai

* Update TOWER_RUSH.eai

* Update WISP_CHECK.eai

* Update MILITIA_EXPAND.eai

* Update common.eai

* fix

* Update common.eai

* fix

* fix

* fix

* fix up and down cannot set zoom

* Update ANCIENT_EXPANSION.eai

* Update ITEM_EXPANSION.eai

* Update MICRO_HERO.eai

* Update MICRO_UNITS.eai

* Update MILITIA_CHECK.eai

* Update common.eai

* Update races.eai

* Update Jobs.txt

* Add files via upload

* Delete Jobs/WISP_CHECK.eai

* Add files via upload

* Update RETREAT_CONTROL.eai

* Update RETREAT_CONTROL.eai

* Update RETREAT_CONTROL.eai

* Update RETREAT_CONTROL.eai

* Update MILITIA_CHECK.eai

* Update FOCUSFIRE_CONTROL.eai

* fix Compilation error

* fix Compilation error

* optimized code

* Update README.md

* Update Blizzard.eai

* Optimized

* - Fixed add water_expansion_list no check Resource Amount

* Update common.eai

* optimize

* patrol Order not send UNIT_TYPE_FLYING

* patrol Order not send UNIT_TYPE_FLYING

* fix not buy item

* Update common.eai

* improve ally shop buyitem

* improve zoom tis

* fix Observer Player zoom

* Review PR

Review PR and fix water expansions breaking expansion logic when no zepplins possible.

* Further tweak to zeppelin expansion to not block when zeppelins don't exist

Mainly for maps where zeppelins do not exist, but also far expansions can still be built on even if zeppelin is not available to prevent AI being blocked.

* Update CHANGELOG.md

---------

Co-authored-by: jzy-chitong56 <48715223+jzy-chitong56@users.noreply.github.com>
  • Loading branch information
SMUnlimited and jzy-chitong56 committed Oct 15, 2023
1 parent 0767d38 commit 36eb0ea
Show file tree
Hide file tree
Showing 17 changed files with 989 additions and 731 deletions.
23 changes: 5 additions & 18 deletions Blizzard.eai
Original file line number Diff line number Diff line change
Expand Up @@ -587,24 +587,11 @@ function ZoomUp takes nothing returns nothing
endfunction

function InitZoom takes nothing returns nothing
local integer i = 0
if ZoomSetx == null then
set ZoomSetx = CreateTrigger()
set AdjustZoomUp = CreateTrigger()
set AdjustZoomDown = CreateTrigger()
call TriggerAddAction(ZoomSetx, function ZoomSet)
//call TriggerAddAction(AdjustZoomUp , function ZoomUp)
//call TriggerAddAction(AdjustZoomDown , function ZoomDown)
//loop
// exitwhen i >= GetBJMaxPlayers()
//call SetCameraFieldForPlayer( Player(i), CAMERA_FIELD_TARGET_DISTANCE, 2500, 0 ) // not required in latest war3
if (GetPlayerController(GetLocalPlayer()) != MAP_CONTROL_COMPUTER) or IsPlayerObserver(GetLocalPlayer()) then
call TriggerRegisterPlayerChatEvent( ZoomSetx, GetLocalPlayer(), "-zoom", false )
//call TriggerRegisterPlayerKeyEventBJ( AdjustZoomUp, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP ) // not required in latest war3
//call TriggerRegisterPlayerKeyEventBJ( AdjustZoomDown, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
endif
// set i = i + 1
//endloop
set ZoomSetx = CreateTrigger()
call TriggerAddAction(ZoomSetx, function ZoomSet)
if (GetPlayerController(GetLocalPlayer()) != MAP_CONTROL_COMPUTER) and not IsPlayerObserver(GetLocalPlayer()) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,7,"Set Zoom type: |c00d5f038-zoom1850|r")
call TriggerRegisterPlayerChatEvent( ZoomSetx, GetLocalPlayer(), "-zoom", false )
endif
endfunction

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added opportunities to attempt extreme save behaviour when the AI is struggling e.g Do a militia expansion or ancient expansion (jzy-chitong56)
- Some improvements to handle multiple mines at the same base (jzy-chitong56)
- Use the cloak of shadows ability in micro actions (jzy-chitong56)
- Maps with multiple mines at the starting location can now be handled. (jzy-chitong56)
- Some expansions when far away or impossible to get to will be attempted with a zeppelin. (jzy-chitong56)

### Changed
- Chinese Translation improvements. (jzy-chitong56)
Expand All @@ -32,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- ROC BLADE MASTER will no longer use mirror image.
- DEMON HUNTERS will can now sometimes learn Immolation.
- Shredders now replace 10 peons (instead of 8)
- Improvements to worker logic at game start. (jzy-chitong56)

### Removed
- (DevTools) Old non-working installer has now been removed now we have new version in place.
Expand Down
2 changes: 1 addition & 1 deletion Jobs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DETECT_DOUBLE_EXP 10 DetectDoubleExpJob() true 100 120
ZEPPELIN_FOLLOW 20 ZeppelinFollowJob() true 80 100
NEUTRAL_GUARDED 8 NeutralGuardedJob(par) false 0 0
REPAIR_CONTROL 15 RepairControlJob() true 0 10
WISP_CHECK 10 WispCheckJob() race_manual_loading 200 220
HARVEST_CHECK 10 HarvestCheckJob() race_manual_loading or ( not race_manual_loading and not race_uses_mine_expansion and first_town_mine == 3) or (race_uses_mine_expansion and first_town_mine != 0) 200 - Min(first_town_mine,1) * 198 220 - Min(first_town_mine,1) * 208
RETREAT_CONTROL 100 RetreatControlJob() false 0 0
CLEANUP_BLOCKS 4 CleanupBlocksJob() true 60 70
RESET_GUARD_POSITION 20 ResetGuardPositionJob(unit_par) false 0 0
Expand Down
4 changes: 2 additions & 2 deletions Jobs/ANCIENT_EXPANSION.eai
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if GetGold() < GetUnitGoldCost2(racial_expansion) or GetWood() < GetUnitWoodCost
if ancient_exp_wisp == null or not UnitAlive(ancient_exp_wisp) then
set ancient_exp_wisp = GetExpansionPeon()
if ancient_exp_wisp == null then
set ancient_exp_wisp = GetExpansionPeon2()
set ancient_exp_wisp = GetExpansionPeon2(ancient_exp_wisp)
endif
endif
if u != null then
Expand Down Expand Up @@ -122,7 +122,7 @@ elseif ancient_exp_state == 1 then
call IssuePointOrderByIdLoc(ancient_exp_wisp, old_id[racial_expansion], ancient_exp_loc)
call TQAddJob(5, ANCIENT_EXPANSION, 0)
else
set ancient_exp_unit = GetOneOfIdNearLoc(ai_player, old_id[racial_expansion], ancient_exp_loc, 400)
set ancient_exp_unit = GetOneOfIdNearLoc(ancient_exp_unit, ai_player, old_id[racial_expansion], ancient_exp_loc, 400)
if ancient_exp_unit == null and TownCount(race_manual_loading_mine) == 0 then // no mine , check all hall
set ancient_exp_unit = GetOneOfId(ai_player, old_id[racial_expansion])
if ancient_exp_unit == null then
Expand Down
2 changes: 1 addition & 1 deletion Jobs/FOCUSFIRE_CONTROL.eai
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function FocusFireJob takes nothing returns nothing
call DisplayToAllJobDebug("FOCUSFIRE_CONTROL JOB START")

if major_hero == null or not UnitAlive(major_hero) or IsUnitInGroup(major_hero, unit_healing) then
set major_hero = GetMajorHeroReplacement_k(last_major_hero_loc)
set major_hero = GetMajorHeroReplacement_k(major_hero,last_major_hero_loc)
endif
//if retreat_controlled and (attack_running or town_threatened) then

Expand Down
162 changes: 162 additions & 0 deletions Jobs/HARVEST_CHECK.eai
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#IFDEF GLOBAL
unit secondmine = null
#ELSE
function PeonMineCheck takes unit mine returns boolean
local group g = CreateGroup()
local group tempg = null
local location unitloc = GetUnitLoc(mine)
local unit u = null
local unit savewisp = null
local integer i = 0
local integer peon = TownCount(racial_peon)
local integer peond = TownCountDone(racial_peon)
local integer delaywisps = ver_optimal_gold - 1
call DisplayToAllJobDebug("HARVEST CHECK Job Start")
if peond > 6 then
set delaywisps = ver_optimal_gold
endif
if race_manual_loading then
call GroupEnumUnitsOfPlayer(g, ai_player, null)
set g = SelectById(g, old_id[race_manual_loading_wisp], true)
set g = SelectByAlive(g, true)
set tempg = CreateGroup()
loop
set u = FirstOfGroup(g)
exitwhen u == null
if IsUnitInTransport(u, mine) then
set savewisp = u
set i = i + 1
elseif not IsUnitHidden(u) then
call GroupAddUnit(tempg, u)
endif
call GroupRemoveUnit(g, u)
endloop
if FoodSpace() <= 0 and i >= 3 then // no foodspace , no peon(at least keep 2 harvest mine) , need one harvest mine peon build Farms
if peon == peond and peon <= 4 then
set delaywisps = 2
call IssueTargetOrder(mine, "unload", savewisp)
endif
elseif peond < 7 and not hero_built[1] then
set delaywisps = ver_optimal_gold - 2
endif
if i < delaywisps then
set tempg = SelectByLoaded(tempg, false)
set tempg = SelectUnittype(tempg, UNIT_TYPE_STRUCTURE, false) // Preventing Tree Transformation
set tempg = GetNearestSubGroupOfGroup(tempg, unitloc, delaywisps - i)
//call GroupRemoveGuardPositionInstant(g) // this gets wisps to come off the trees.
//call GroupTargetOrder(g, "harvest", mine)
loop //use accurate quantity control , prevent any wips harvestmine , but mine no vacancies
set u = FirstOfGroup(tempg)
exitwhen u == null or i == delaywisps
call IssueTargetOrder(u, "harvest", mine)
set i = i + 1
call GroupRemoveUnit(tempg, u)
endloop
endif
call DestroyGroup(tempg)
set tempg = null
set savewisp = null
elseif race_uses_mine_expansion then
set delaywisps = Min(ver_optimal_gold,peond)
call GroupEnumUnitsOfPlayer(g, ai_player, null)
set g = SelectUnittype(g, UNIT_TYPE_PEON, true)
set g = SelectByAlive(g, true)
set g = SelectByHidden(g, false)
set tempg = CreateGroup()
loop
set u = FirstOfGroup(g)
exitwhen u == null or i == delaywisps
if GetUnitCurrentOrder(u) == OrderId("harvest") and DistanceBetweenUnits(u,mine) < 225 then // UD harvest gold max Distance is 221
set i = i + 1
elseif GetUnitCurrentOrder(u) == 0 and not IsUnitBuying(u) and not IsUnitInGroup(u, unit_zepplin_move) then
call GroupAddUnit(tempg,u) // prevent the mine harvest peon more than 5
endif
call GroupRemoveUnit(g, u)
endloop
if i < delaywisps then
loop
set u = FirstOfGroup(tempg)
exitwhen u == null or i == delaywisps
call IssueTargetOrder(u, "harvest", mine)
set i = i + 1
call GroupRemoveUnit(tempg, u)
endloop
endif
call DestroyGroup(tempg)
set tempg = null
else //human and orc
call GroupEnumUnitsOfPlayer(g, ai_player, null)
set g = SelectUnittype(g, UNIT_TYPE_PEON, true)
set g = SelectByAlive(g, true)
set g = SelectByHidden(g, false)
set g = GetNearestSubGroupOfGroup(g, home_location, 10)
loop
set u = FirstOfGroup(g)
exitwhen u == null or i == delaywisps
if (GetUnitCurrentOrder(u) == 0 or GetUnitCurrentOrder(u) == OrderId("harvest")) and not IsUnitBuying(u) and not IsUnitInGroup(u, unit_zepplin_move) then // no get other order peon , maybe the peon go buy unit or build some
call IssueTargetOrder(u, "harvest", mine)
endif
call GroupRemoveUnit(g, u)
set i = i + 1
endloop
set i = delaywisps //human and orc no need full
endif
call RemoveLocation(unitloc)
set unitloc = null
call DestroyGroup(g)
set g = null
set u = null
return i < delaywisps
endfunction

function HarvestCheckJob takes nothing returns nothing
local group g = null
local unit u = null
local integer i = 0
local boolean mines_not_full = true
// call DisplayToAll("Harvest Start")
if first_town_mine == -1 then
return // home_location no more mine , ORC and HUMAN no need run
endif
set g = CreateGroup()
if race_manual_loading then
call GroupEnumUnitsOfPlayer(g, ai_player, null)
set g = SelectNumberOfId(g, 100, old_id[race_manual_loading_mine])
elseif not TownThreatened() then
if race_uses_mine_expansion then
call GroupEnumUnitsInRangeOfLoc(g, home_location, 1500, null)
set g = SelectByPlayer(g, ai_player, true)
set g = SelectById(g, old_id[racial_expansion], true)
elseif GetResourceAmount(secondmine) <= 0 and TownCountDone(racial_peon) > 10 then //human and orc
call GroupEnumUnitsInRangeOfLoc(g, home_location, 1500, null)
call GroupRemoveUnit(g,own_town_mine[0])
set g = SelectById(g, old_id[GOLD_MINE], true)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetResourceAmount(u) > i then // find Resource max mine
set i = GetResourceAmount(u)
set secondmine = u
endif
call GroupRemoveUnit(g, u)
endloop
call GroupAddUnit(g, secondmine) // only first take secondmine run PeonMineCheck , Prevention have more peon harvest
endif
endif
loop
set u = FirstOfGroup(g)
exitwhen u == null
if UnitAlive(u) then
set mines_not_full = PeonMineCheck(u) and mines_not_full
endif
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
set g = null
if mines_not_full then
call TQAddJob(4, HARVEST_CHECK, 0)
else
call TQAddJob(40, HARVEST_CHECK, 0)
endif
endfunction
#ENDIF
12 changes: 4 additions & 8 deletions Jobs/HEALTH_FOUNTAIN.eai
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,15 @@ local boolean creepsawake = false
if distance >= buy_distance then
if GetUnitAbilityLevel(u, 'AIhm') > 0 or (GetUnitAbilityLevel(u, 'Ashm') > 0 and GetLocationNonCreepStrength(GetUnitX(u), GetUnitY(u), 800) > 0 and (GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18 or GetFloatGameState(GAME_STATE_TIME_OF_DAY) <= 6)) then
call IssueImmediateOrder(u, "ambush")
else
if GetUnitCurrentOrder(u) != OrderId("move") then
call IssuePointOrder(u, "move", x, y)
endif
elseif GetUnitCurrentOrder(u) != OrderId("move") then
call IssuePointOrder(u, "move", x, y)
endif
else
if IsUnitInvisible(u, Player(PLAYER_NEUTRAL_AGGRESSIVE)) then //no need do anything
elseif GetUnitAbilityLevel(u, 'AIhm') > 0 or (GetUnitAbilityLevel(u, 'Ashm') > 0 and (GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18 or GetFloatGameState(GAME_STATE_TIME_OF_DAY) <= 6)) then
call IssueImmediateOrder(u, "ambush")
else
if GetUnitCurrentOrder(u) != OrderId("patrol") then
call IssuePointOrder( u, "patrol", x + GetRandomReal(-100,100), y + GetRandomReal(-100,100)) //Prevent units from being blocked by other units coming from behind when leaving
endif
elseif not IsUnitType(u, UNIT_TYPE_FLYING) and GetUnitCurrentOrder(u) != OrderId("patrol") then
call IssuePointOrder( u, "patrol", x + GetRandomReal(-100,100), y + GetRandomReal(-100,100)) //Prevent units from being blocked by other units coming from behind when leaving
endif
endif
call TQAddUnitJob(8, HEALTH_FOUNTAIN, p, u)
Expand Down
4 changes: 2 additions & 2 deletions Jobs/ITEM_EXPANSION.eai
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ItemExpansionJob takes nothing returns nothing
call Trace("Expansion Distance: " + Int2Str(R2I(GetExpansionDistance())))
call Trace("Expansion state 0: Check Expansion Hero and Location")
if itemhero == null then
set exp_item = GetItemOfType(race_item_expansion_item_id)
set exp_item = GetItemOfType(exp_item,race_item_expansion_item_id)
if exp_item != null then
set itemhero = GetItemHero(exp_item)
endif
Expand Down Expand Up @@ -110,4 +110,4 @@ function ItemExpansionJob takes nothing returns nothing
set u = null
call TQAddJob(time_next_try, ITEM_EXPANSION, 0)
endfunction
#ENDIF
#ENDIF
14 changes: 5 additions & 9 deletions Jobs/MANA_FOUNTAIN.eai
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,19 @@ local boolean creepsawake = false
if distance >= buy_distance then
if GetUnitAbilityLevel(u, 'AIhm') > 0 or (GetUnitAbilityLevel(u, 'Ashm') > 0 and GetLocationNonCreepStrength(GetUnitX(u), GetUnitY(u), 800) > 0 and (GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18 or GetFloatGameState(GAME_STATE_TIME_OF_DAY) <= 6)) then
call IssueImmediateOrder(u, "ambush")
else
if GetUnitCurrentOrder(u) != OrderId("move") then
call IssuePointOrder(u, "move", x, y)
endif
elseif GetUnitCurrentOrder(u) != OrderId("move") then
call IssuePointOrder(u, "move", x, y)
endif
else
if IsUnitInvisible(u, Player(PLAYER_NEUTRAL_AGGRESSIVE)) then //no need do anything
elseif GetUnitAbilityLevel(u, 'AIhm') > 0 or (GetUnitAbilityLevel(u, 'Ashm') > 0 and (GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18 or GetFloatGameState(GAME_STATE_TIME_OF_DAY) <= 6)) then
call IssueImmediateOrder(u, "ambush")
else
if GetUnitCurrentOrder(u) != OrderId("patrol") then
call IssuePointOrder( u, "patrol", x + GetRandomReal(-100,100), y + GetRandomReal(-100,100)) //Prevent units from being blocked by other units coming from behind when leaving
endif
elseif not IsUnitType(u, UNIT_TYPE_FLYING) and GetUnitCurrentOrder(u) != OrderId("patrol") then
call IssuePointOrder( u, "patrol", x + GetRandomReal(-100,100), y + GetRandomReal(-100,100)) //Prevent units from being blocked by other units coming from behind when leaving
endif
endif
call TQAddUnitJob(8, MANA_FOUNTAIN, p, u)
endif
set fountain = null
endfunction
#ENDIF
#ENDIF
8 changes: 3 additions & 5 deletions Jobs/MICRO_HERO.eai
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function SaveHero takes integer hn , integer armyOfHero returns nothing
local integer hFountainID = GetHealthFountainID()
local integer mFountainID = GetManaFountainID()
local location l = GetUnitLoc(hero_unit[hn])
set healer = GetHealer()
set healer = GetHealer(healer)
call ActionListInit(9)
#INCLUDE <HeroFleeRules.ai>
call ExecuteSaveHero(hn, ActionListEval(), healer)
Expand Down Expand Up @@ -222,11 +222,9 @@ function MicroHeroJob takes integer hn returns nothing
set hero_hp[hn] = new_hp
call GetDensities(hero_loc[hn], ai_player, hero_radius)
set hero_enemy_density[hn] = enemy_density
call RemoveLocation(hero_enemy_loc[hn])
set hero_enemy_loc[hn] = Location(GetLocationX(enemy_density_loc), GetLocationY(enemy_density_loc))
call MoveLocation(hero_enemy_loc[hn], GetLocationX(enemy_density_loc), GetLocationY(enemy_density_loc))
set hero_ally_density[hn] = ally_density
call RemoveLocation(hero_ally_loc[hn])
set hero_ally_loc[hn] = Location(GetLocationX(ally_density_loc), GetLocationY(ally_density_loc))
call MoveLocation(hero_ally_loc[hn], GetLocationX(ally_density_loc), GetLocationY(ally_density_loc))

if not teleporting and current_order >= 852008 and current_order <= 852013 then
if GetItemTypeId(UnitItemInSlot(hero_unit[hn], current_order - 852008)) == old_id[tp_item] then
Expand Down
10 changes: 5 additions & 5 deletions Jobs/MICRO_UNITS.eai
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
group unit_rescueing = CreateGroup()
group unit_harassing = CreateGroup()
group unit_zepplin_move = CreateGroup()
group unit_buying_item = CreateGroup()
group unit_buying_merc = CreateGroup()
group unit_buying_tavern = CreateGroup()
group unit_buying_item = CreateGroup()
group unit_buying_merc = CreateGroup()
group unit_buying_tavern = CreateGroup()

#ELSE

Expand All @@ -16,7 +16,7 @@


//function MakeUnitHeal takes unit u returns nothing
// local unit healer = GetHealer()
// local unit healer = GetHealer(healer)
// local location unitloc = GetUnitLoc(healer)
// local real daytime = GetFloatGameState(GAME_STATE_TIME_OF_DAY)

Expand Down Expand Up @@ -84,7 +84,7 @@ function SaveUnit takes unit u , integer id returns nothing
call IssueImmediateOrder(u, "windwalk")
endif
endif
set healer = GetHealer()
set healer = GetHealer(healer)
// call SetUnitUserData(u, UNIT_GOING_HOME)
if healer != null then //and not IsUnitType(u, UNIT_TYPE_MECHANICAL) then //Repetitive judgment
set healertepy = healer_type[GetHealerId(GetUnitTypeId(healer))]
Expand Down
Loading

0 comments on commit 36eb0ea

Please sign in to comment.