Skip to content

Commit

Permalink
Moved densities function to micro hero job where it is only used
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Dec 16, 2023
1 parent 4d01cc5 commit e3f376e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
73 changes: 73 additions & 0 deletions Jobs/MICRO_HERO.eai
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,79 @@

#ELSE

//==========================================================================
// (AMAI) GetDensities
//==========================================================================
function GetDensities takes location l, player p, real r returns nothing
local group g = CreateGroup()
local unit u = null
local real ur = 0
local real xe = 0
local real ye = 0
local real xa = 0
local real ya = 0
local location ul = null
local location loc = null
local integer i = 0

set enemy_density = 0
set ally_density = 0
call GroupEnumUnitsInRangeOfLoc(g, l, r, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (ModuloInteger(i, 200) == 0) then
call TQSleep(0.1)
endif
if UnitAlive(u) then
set ul = GetUnitLoc(u)
set ur = 1 - (DistanceBetweenPoints(ul, l) / r)
set loc = GetMultipleLoc(ul, ur)
//if ur == 1 then
if IsPlayerEnemy(p, GetOwningPlayer(u)) then
set enemy_density = enemy_density + ur
set xe = xe + GetLocationX(loc) // Prevent loc exceeding map range
set ye = ye + GetLocationY(loc)
//set enemy_density_loc = GetSumLoc_dd(enemy_density_loc, GetMultipleLoc(ul, ur))
elseif IsPlayerAlly(p, GetOwningPlayer(u)) then
set ally_density = ally_density + ur
set xa = xa + GetLocationX(loc)
set ya = ya + GetLocationY(loc)
//set ally_density_loc = GetSumLoc_dd(ally_density_loc, GetMultipleLoc(ul, ur))
endif
call RemoveLocation(loc)
call RemoveLocation(ul)
endif
call GroupRemoveUnit(g, u)
set i = i + 1
endloop

if ally_density > 0 then
set xa = xa / ally_density
set ya = ya / ally_density
//set ally_density_loc = GetDivisionLoc_d(ally_density_loc, ally_density)
else
set xa = 0
set ya = 0
endif
call RemoveLocation(ally_density_loc)
set ally_density_loc = Location(xa,ya)
if enemy_density > 0 then
set xe = xe / enemy_density
set ye = ye / enemy_density
//set enemy_density_loc = GetDivisionLoc_d(enemy_density_loc, enemy_density)
else
set xe = 0
set ye = 0
endif
call RemoveLocation(enemy_density_loc)
set enemy_density_loc = Location(xe,ye)
call DestroyGroup(g)
set g = null
set ul = null
set loc = null
endfunction

function TeleportHome takes integer hn returns nothing
// Team Game improvements Added by Strategy Master 12/03/05
local integer i = 0
Expand Down
73 changes: 0 additions & 73 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -4914,79 +4914,6 @@ function TQSleep takes real time returns nothing
call Sleep(time)
endfunction

//==========================================================================
// (AMAI) GetDensities
//==========================================================================
function GetDensities takes location l, player p, real r returns nothing
local group g = CreateGroup()
local unit u = null
local real ur = 0
local real xe = 0
local real ye = 0
local real xa = 0
local real ya = 0
local location ul = null
local location loc = null
local integer i = 0

set enemy_density = 0
set ally_density = 0
call GroupEnumUnitsInRangeOfLoc(g, l, r, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (ModuloInteger(i, 200) == 0) then
call TQSleep(0.1)
endif
if UnitAlive(u) then
set ul = GetUnitLoc(u)
set ur = 1 - (DistanceBetweenPoints(ul, l) / r)
set loc = GetMultipleLoc(ul, ur)
//if ur == 1 then
if IsPlayerEnemy(p, GetOwningPlayer(u)) then
set enemy_density = enemy_density + ur
set xe = xe + GetLocationX(loc) // Prevent loc exceeding map range
set ye = ye + GetLocationY(loc)
//set enemy_density_loc = GetSumLoc_dd(enemy_density_loc, GetMultipleLoc(ul, ur))
elseif IsPlayerAlly(p, GetOwningPlayer(u)) then
set ally_density = ally_density + ur
set xa = xa + GetLocationX(loc)
set ya = ya + GetLocationY(loc)
//set ally_density_loc = GetSumLoc_dd(ally_density_loc, GetMultipleLoc(ul, ur))
endif
call RemoveLocation(loc)
call RemoveLocation(ul)
endif
call GroupRemoveUnit(g, u)
set i = i + 1
endloop

if ally_density > 0 then
set xa = xa / ally_density
set ya = ya / ally_density
//set ally_density_loc = GetDivisionLoc_d(ally_density_loc, ally_density)
else
set xa = 0
set ya = 0
endif
call RemoveLocation(ally_density_loc)
set ally_density_loc = Location(xa,ya)
if enemy_density > 0 then
set xe = xe / enemy_density
set ye = ye / enemy_density
//set enemy_density_loc = GetDivisionLoc_d(enemy_density_loc, enemy_density)
else
set xe = 0
set ye = 0
endif
call RemoveLocation(enemy_density_loc)
set enemy_density_loc = Location(xe,ye)
call DestroyGroup(g)
set g = null
set ul = null
set loc = null
endfunction

//==========================================================================
// (AMAI) Action List Utility functions
//==========================================================================
Expand Down

0 comments on commit e3f376e

Please sign in to comment.