Skip to content

Commit

Permalink
Finally fixed harass attacks #444
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Nov 23, 2024
1 parent 9118312 commit 217c106
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Jobs/HARASS.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 13 additions & 22 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 217c106

Please sign in to comment.