From 217c1063f9201a4440ff64276f95b5e9b6df982a Mon Sep 17 00:00:00 2001 From: SMUnlimited Date: Sat, 23 Nov 2024 15:40:55 +0000 Subject: [PATCH] Finally fixed harass attacks #444 --- Jobs/HARASS.eai | 6 +++--- common.eai | 35 +++++++++++++---------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Jobs/HARASS.eai b/Jobs/HARASS.eai index f6c000073..eb606c750 100644 --- a/Jobs/HARASS.eai +++ b/Jobs/HARASS.eai @@ -147,7 +147,7 @@ function HarassJob takes integer key, unit targ returns nothing endif if town_threatened and (not state_attacking or hero_harass) and state_retreat == 0 then - call TQAddUnitJob(5 * sleep_multiplier, HARASS, ht, target) + call TQAddUnitJob(5 * sleep_multiplier, HARASS, key, target) call GroupRecycleHarrassPositionInstant(CopyGroup(harasser)) call DestroyGroup(harasser) set harasser = null @@ -159,7 +159,7 @@ function HarassJob takes integer key, unit targ returns nothing if DistanceBetweenPoints_dk(GetUnitLoc(hu), home_location) > 1000 then call GroupOrderWindWalkInstant_d(CopyGroup(harasser)) call GroupPointOrder(harasser, "move", GetLocationX(home_location), GetLocationY(home_location)) - call TQAddUnitJob(3 * sleep_multiplier, HARASS, ht, target) + call TQAddUnitJob(3 * sleep_multiplier, HARASS, key, target) //call GroupRemoveUnit(unit_harassing, hu) call DestroyGroup(harasser) set harasser = null @@ -328,7 +328,7 @@ function HarassJob takes integer key, unit targ returns nothing //call GroupRecycleGuardPositionDelay(harasser,GetTimeToReachLoc(u, home_location) + 1) //return endif - call TQAddUnitJob(2, HARASS, ht, target) + call TQAddUnitJob(2, HARASS, key, target) call DestroyGroup(harasser) set harasser = null set target = null diff --git a/common.eai b/common.eai index 5dd527c3c..35769b4b6 100644 --- a/common.eai +++ b/common.eai @@ -1855,7 +1855,7 @@ function LinearInterpolation takes real x1, real x2, real y1, real y2, real p re endfunction // This is just size of hashtable not total number of real units -// If storing other things in hashtable start value can be the +// If storing other things in hashtable start value can be set to start later. function UnitHashtableSize takes hashtable ht, integer key, integer start returns integer return LoadInteger(ht, key, start) endfunction @@ -1872,13 +1872,13 @@ function AddUnitsToHashtable takes hashtable ht, integer key, integer start, gro call SaveUnitHandle(ht, key, i, u) call GroupRemoveUnit(gunits, u) endloop - call SaveInteger(ht, key, 0, i) // First number is the group size + call SaveInteger(ht, key, start, i - start) // First number is the group size return ht endfunction // Only returns valid units, null entries are ignored function ReturnUnitsOfHashtable takes hashtable ht, integer key, integer start, group gunits returns group - local integer size = UnitHashtableSize(ht, key, start) + local integer size = UnitHashtableSize(ht, key, start) + start local integer i = start local unit u = null call GroupClear(gunits) @@ -1898,7 +1898,7 @@ function ReturnUnitsOfHashtable takes hashtable ht, integer key, integer start, endfunction function ReturnLivingUnitsOfHashtable takes hashtable ht, integer key, integer start, group gunits returns group - local integer size = UnitHashtableSize(ht, key, start) + local integer size = UnitHashtableSize(ht, key, start) + start local integer i = start local unit u = null call GroupClear(gunits) @@ -1917,33 +1917,25 @@ function ReturnLivingUnitsOfHashtable takes hashtable ht, integer key, integer s return gunits endfunction -// Remove dead entries to make iteration more optimal +// Remove dead entries to make iteration more optimal in the future function FlushUnitHashtable takes hashtable ht, integer key, integer start returns hashtable local integer size = UnitHashtableSize(ht, key, start) local integer i = 0 local integer j = 0 - local unit u = null - local unit copy = null + local group g = null if size <= 0 then return ht endif + set g = CreateGroup() + set g = ReturnUnitsOfHashtable(ht, key, start, g) loop exitwhen i >= size set i = i + 1 - set u = LoadUnitHandle(ht, key, i) - if u == null then - // TODO Not implemented - loop - exitwhen j >= size - set j = j + 1 - set copy = LoadUnitHandle(ht, key, j) - call SaveUnitHandle(ht, key, i, copy) - endloop - set size = size - 1 - endif + call RemoveSavedHandle(ht, key, i) endloop - call SaveInteger(ht, key, 0, size) - set u = null + set ht = AddUnitsToHashtable(ht, key, start, g) + call DestroyGroup(g) + set g = null return ht endfunction @@ -6837,7 +6829,6 @@ function GetExpFoe takes unit nearunit returns unit local integer c = 0 local unit u = null - if current_expansion_iswater then set g = ReturnLivingUnitsOfHashtable(water_expansion_creeps, current_expansion_creeps, 0, g) else @@ -10002,9 +9993,9 @@ function StartHarass takes integer groupnum, integer harass_target, boolean avoi call SaveReal(additional_info, key, LOCX, lx) call SaveReal(additional_info, key, LOCY, ly) call SaveInteger(additional_info, key, HARASS_TARGET, harass_target) + call DisplayToAll("StartHarass : start harass job " + Int2Str(BlzGroupGetSize(harasser))) call AddUnitsToHashtable(additional_info, key, HARASS_UNITGROUP, harasser) call TQAddUnitJob(0, HARASS, key, null) - call Trace("StartHarass : start harass job" ) call DestroyGroup(harasser) set harasser = null endfunction