- Joined
- Jan 9, 2005
- Messages
- 2,129
Is there an efficient way of picking a random unit in range matching certain conditions? I'm trying to create a bouncing attack a la Huntress, using BPower's Missile for projectiles.
Some context:
So I have this code (which doesn't work btw because my loop is nonsense):
As you can see, plenty of red flags. I'm told them Blizzard.j functions are bad, and for my purposes, they are as I need to be able to squeeze out the most amount of performance since this method will happen -A LOT-.
Using the First of Group way, it kinda works, but I have this little problem where it will always pick the same unit, which throws out the randomness of a bounce attack out the window. Can anyone show me another way to enumerate a random unit in range matching conditions?
Some context:
So I have this code (which doesn't work btw because my loop is nonsense):
JASS:
private static method onFinish takes Missile this returns boolean
local unit FoG = null
local unit u = null
local real x = GetUnitX(this.target)
local real y = GetUnitY(this.target)
local integer i
local integer imax
local real h = GetUnitFlyHeight(this.target) + 50
local real angle
local Missile m
set udg_NextDamageType = udg_DamageTypeBounce
call UnitDamageTarget( this.source, this.target, this.damage, true, true, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null )
call ConditionalTriggerExecute( udg_ClearDamageEvent )
if this.data > 0 then
call GroupEnumUnitsInRange(grp,x,y,mAoE[this.data],null)
set imax = CountUnitsInGroup(grp)
loop
set FoG=FirstOfGroup(grp)
exitwhen i>=imax
set i = i + 1
if (not UnitAlive(FoG)) or IsUnitAlly(FoG, GetOwningPlayer(this.source)) or FoG == this.target or (IsUnitOwnedByPlayer(FoG, this.owner)) then
call GroupRemoveUnit(grp,FoG)
endif
endloop
if IsUnitGroupEmptyBJ(grp) == false then
set u = GroupPickRandomUnit(grp)
set angle = Atan2(GetUnitY(FoG)-y,GetUnitX(FoG)-x)
set x = x + Cos(angle)
set y = y + Sin(angle)
set m = Missile.create(x, y, h + 50, angle, 2000, 50)
set m.speed = this.speed
//set m.acceleration = 0
set m.scale = this.scale
set m.model = this.model
set m.arc = this.arc
set m.source = this.source
set m.damage = this.damage * .85
set m.target = FoG
set m.data = this.data - 1
set mAoE[m.data] = mAoE[this.data]
call launch(m)
set u = null
call groupClear(grp)
endif
endif
return true
endmethod
As you can see, plenty of red flags. I'm told them Blizzard.j functions are bad, and for my purposes, they are as I need to be able to squeeze out the most amount of performance since this method will happen -A LOT-.
Using the First of Group way, it kinda works, but I have this little problem where it will always pick the same unit, which throws out the randomness of a bounce attack out the window. Can anyone show me another way to enumerate a random unit in range matching conditions?