Can this be optimized more?

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
I've made a JASS version of Flare's Frozen Orb ability for my map. I think that this could be optimized a lot more but I'm not sure. Uses ABC and TT for trigger and timer attaching.

Frozen orb is a Diablo II spell.

JASS:

scope FrozenOrb

globals
// ability raw code
    private constant integer ABILITY_RAW = 'A000'
// missile frozen orb unit
    private constant integer MISSILE_RAW = 'h001'
// shards unit
    private constant integer BOLT_RAW = 'h002'
// dummy caster
    private constant integer DUMMY = 'h000'
// frost nova raw
    private constant integer FROST_NOVA = 'A002'
// buff frost
    private constant integer BUFF_RAW = 'Bfro'
// max travel distance for the orb
    private constant real MAX_DIST = 1050.
// travel speed
    private constant real SPEED = 425.
// radius of effect of the orb
    private constant real M_RADIUS = 225.
// radius of effect of the shards
    private constant real S_RADIUS = 100.
endglobals

private struct Data
    unit missile
    integer ticks
    real dx
    real dy
    trigger trig = CreateTrigger()
    
    method onDestroy takes nothing returns nothing
        call RemoveUnit(.missile)
        call ClearTriggerStructA(.trig)
        call DestroyTrigger(.trig)
    endmethod
endstruct

private struct Shard
    unit shard
    trigger trig = CreateTrigger()
    
    method onDestroy takes nothing returns nothing
        call RemoveUnit(.shard)
        call ClearTriggerStructA(.trig)
        call DestroyTrigger(.trig)
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILITY_RAW
endfunction

private function Move takes nothing returns boolean
    local Data d = TT_GetData()
    local real x = GetUnitX(d.missile)
    local real y = GetUnitY(d.missile)
    local real dx = x + d.dx
    local real dy = y + d.dy
    call SetUnitPosition(d.missile, dx, dy) 
    set d.ticks = d.ticks - 1
    if d.ticks <= 0 then
        call d.destroy()
        return true
    endif
    return false
endfunction

private function Damage takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local unit pick = GetTriggerUnit()
    local unit dummy 
    if IsUnitEnemy(pick, GetOwningPlayer(d.missile)) and GetWidgetLife(pick) > 0.405 and IsUnitType(pick, UNIT_TYPE_STRUCTURE) == false then
        if GetUnitAbilityLevel(pick, BUFF_RAW) > 0 then
        else
            set dummy = CreateUnit(GetOwningPlayer(d.missile), DUMMY, 0., 0., 0.)
            call UnitAddAbility(dummy, FROST_NOVA)
            call IssueTargetOrder(dummy, "frostnova", pick)
            call UnitApplyTimedLife(dummy, 'BTLF', 2.)
        endif
        call UnitDamageTarget(d.missile, pick, 10., false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
    endif
    set dummy = null
    set pick = null
    return false
endfunction

private function RemoveShard takes nothing returns boolean
    local Shard i = TT_GetData()
    if GetWidgetLife(i.shard) < 0.405 then
        call i.destroy()
        return true 
    endif
    return false
endfunction

private function ShardDmg takes nothing returns boolean
    local Shard i = GetTriggerStructA(GetTriggeringTrigger())
    local unit pick = GetTriggerUnit()
    local unit dummy 
    if IsUnitEnemy(pick, GetOwningPlayer(i.shard)) and GetWidgetLife(pick) > 0.405 and IsUnitType(pick, UNIT_TYPE_STRUCTURE) == false then
        if GetUnitAbilityLevel(pick, BUFF_RAW) > 0 then
        else
            set dummy = CreateUnit(GetOwningPlayer(i.shard), DUMMY, 0., 0., 0.)
            call UnitAddAbility(dummy, FROST_NOVA)
            call IssueTargetOrder(dummy, "frostnova", pick)
            call UnitApplyTimedLife(dummy, 'BTLF', 2.)
        endif
        call UnitDamageTarget(i.shard, pick, 10., false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
    endif
    set dummy = null
    set pick = null
    return false
endfunction

private function Shards takes nothing returns boolean
    local Data d = TT_GetData()
    local Shard i = Shard.create()
    local real x 
    local real y 
    local unit shard
    local location loc
    local location move 
    if GetWidgetLife(d.missile) > 0.405 then
        set x = GetUnitX(d.missile)
        set y = GetUnitY(d.missile)
        set i.shard = CreateUnit(GetOwningPlayer(d.missile), BOLT_RAW, x, y, GetRandomReal(1, 360))
        set loc = GetUnitLoc(i.shard)
        set x = GetLocationX(loc) + 850. * Cos(GetUnitFacing(i.shard) * bj_DEGTORAD)
        set y = GetLocationY(loc) + 850. * Sin(GetUnitFacing(i.shard) * bj_DEGTORAD)
        set move = Location(x, y)
        call IssuePointOrderLoc(i.shard, "move", move)
        call RemoveLocation(move)
        call RemoveLocation(loc)
        
        call TriggerRegisterUnitInRange(i.trig, i.shard, S_RADIUS, null)
        call TriggerAddCondition(i.trig, Condition(function ShardDmg))
        call SetTriggerStructA(i.trig, i)
        call TT_Start(function RemoveShard, i)
        call UnitApplyTimedLife(i.shard, 'BTLF', GetRandomReal(0.4, 1.2))
    else
        return true
    endif
    set shard = null
    set loc = null
    set move = null
    return false
endfunction

private function Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local location targ = GetSpellTargetLoc()
    local real x = GetUnitX(cast)
    local real y = GetUnitY(cast)
    local real dx = GetLocationX(targ) - x
    local real dy = GetLocationY(targ) - y
    local real distance = RMinBJ(MAX_DIST, SquareRoot(dx * dx + dy * dy))
    local real angle = Atan2(dy, dx)
    
    local Data d = Data.create()
    set d.missile = CreateUnit(GetOwningPlayer(cast), MISSILE_RAW, x, y, GetUnitFacing(cast))
    set d.ticks = R2I(distance / (SPEED * TT_PERIOD))
    set d.dx = (SPEED * TT_PERIOD) * Cos(angle)
    set d.dy = (SPEED * TT_PERIOD) * Sin(angle)
    call RemoveLocation(targ)
    
    call TT_Start(function Move, d)
    call TT_Start(function Shards, d)

    call TriggerRegisterUnitInRange(d.trig, d.missile, M_RADIUS, null)
    call TriggerAddCondition(d.trig, Condition(function Damage))
    call SetTriggerStructA(d.trig, d)
    set cast = null
    set targ = null
endfunction

function InitTrig_FrozenOrb takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction

endscope


Don't worry, it works fine, I just wanna know if it can be optimized more :D
 

Tom Jones

N/A
Reaction score
437
How about using GetUnitX instead of GetLocationX(Unit loc)? Saves you a bunch of location calls and removals.
 

Cohadar

master of fugue
Reaction score
209
Why are you using ABC timer functions when you already use ABCT?

And if you are going with low periods like 0.03125 better use TT.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
> And if you are going with low periods like 0.03125 better use TT.

Yeah, was thinking of that.

> How about using GetUnitX instead of GetLocationX(Unit loc)? Saves you a bunch of location calls and removals.
Had some problems with that in the past and decided not to use it. I'll try it again anyway.

> Why are you using ABC timer functions when you already use ABCT?

Oh right. Forgot that.. ^^

Ok, made some improvements. Anything else to improve?

JASS:

scope FrozenOrb

globals
    private constant integer ABILITY_RAW = 'A000'
    private constant integer MISSILE_RAW = 'h001'
    private constant integer BOLT_RAW = 'h002'
    private constant integer DUMMY = 'h000'
    private constant integer FROST_NOVA = 'A002'
    private constant real MAX_DIST = 1050.
    private constant real SPEED = 425.
    private constant real M_RADIUS = 225.
    private constant real S_RADIUS = 100.
endglobals

private struct Data
    unit missile
    integer ticks
    real dx
    real dy
    trigger trig = CreateTrigger()
    
    method onDestroy takes nothing returns nothing
        call ClearTriggerStructA(.trig)
        call DestroyTrigger(.trig)
    endmethod
endstruct

private struct Shard
    unit shard
    trigger trig = CreateTrigger()
    
    method onDestroy takes nothing returns nothing
        call ClearTriggerStructA(.trig)
        call DestroyTrigger(.trig)
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILITY_RAW
endfunction

private function Move takes nothing returns boolean
    local Data d = TT_GetData()
    local real x = GetUnitX(d.missile)
    local real y = GetUnitY(d.missile)
    local real dx = x + d.dx
    local real dy = y + d.dy
    call SetUnitPosition(d.missile, dx, dy) 
    set d.ticks = d.ticks - 1
    if d.ticks <= 0 then
        call RemoveUnit(d.missile)
        call d.destroy()
        return true
    endif
    return false
endfunction

private function Damage takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local unit pick = GetTriggerUnit()
    local unit dummy = CreateUnit(GetOwningPlayer(d.missile), DUMMY, 0., 0., 0.)
    if IsUnitEnemy(pick, GetOwningPlayer(d.missile)) and GetWidgetLife(pick) > 0.405 and not IsUnitType(pick, UNIT_TYPE_STRUCTURE) then
        call UnitDamageTarget(d.missile, pick, 75., false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
    endif
    call UnitAddAbility(dummy, FROST_NOVA)
    call IssueTargetOrder(dummy, "frostnova", pick)
    call UnitApplyTimedLife(dummy, 'BTLF', 2.)
    set dummy = null
    set pick = null
    return false
endfunction

private function RemoveShard takes nothing returns boolean
    local Shard i = TT_GetData()
    if GetWidgetLife(i.shard) < 0.405 then
        call RemoveUnit(i.shard)
        call i.destroy()
        return true 
    endif
    return false
endfunction

private function ShardDmg takes nothing returns boolean
    local Shard i = GetTriggerStructA(GetTriggeringTrigger())
    local unit pick = GetTriggerUnit()
    local unit dummy = CreateUnit(GetOwningPlayer(i.shard), DUMMY, 0., 0., 0.)
    if IsUnitEnemy(pick, GetOwningPlayer(i.shard)) and GetWidgetLife(pick) > 0.405 and not IsUnitType(pick, UNIT_TYPE_STRUCTURE) then
        call UnitDamageTarget(i.shard, pick, 75., false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
    endif
    call UnitAddAbility(dummy, FROST_NOVA)
    call IssueTargetOrder(dummy, "frostnova", pick)
    call UnitApplyTimedLife(dummy, 'BTLF', 2.)
    set dummy = null
    set pick = null
    return false
endfunction

private function Shards takes nothing returns boolean
    local Data d = TT_GetData()
    local Shard i = Shard.create()
    local real x 
    local real y 
    local unit shard
    local location loc
    local location move 
    if GetWidgetLife(d.missile) > 0.405 then
        set x = GetUnitX(d.missile)
        set y = GetUnitY(d.missile)
        set i.shard = CreateUnit(GetOwningPlayer(d.missile), BOLT_RAW, x, y, GetRandomReal(1, 360))
        set loc = GetUnitLoc(i.shard)
        set x = GetLocationX(loc) + 850. * Cos(GetUnitFacing(i.shard) * bj_DEGTORAD)
        set y = GetLocationY(loc) + 850. * Sin(GetUnitFacing(i.shard) * bj_DEGTORAD)
        set move = Location(x, y)
        call IssuePointOrderLoc(i.shard, "move", move)
        call RemoveLocation(move)
        call RemoveLocation(loc)
        
        call TriggerRegisterUnitInRange(i.trig, i.shard, S_RADIUS, null)
        call TriggerAddCondition(i.trig, Condition(function ShardDmg))
        call SetTriggerStructA(i.trig, i)
        call TT_Start(function RemoveShard, i)
        call UnitApplyTimedLife(i.shard, 'BTLF', GetRandomReal(0.4, 1.2))
    else
        return true
    endif
    set shard = null
    set loc = null
    set move = null
    return false
endfunction

private function Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local location targ = GetSpellTargetLoc()
    local real x = GetUnitX(cast)
    local real y = GetUnitY(cast)
    local real dx = GetLocationX(targ) - x
    local real dy = GetLocationY(targ) - y
    local real distance = RMinBJ(MAX_DIST, SquareRoot(dx * dx + dy * dy))
    local real angle = Atan2(dy, dx)
    
    local Data d = Data.create()
    set d.missile = CreateUnit(GetOwningPlayer(cast), MISSILE_RAW, x, y, GetUnitFacing(cast))
    set d.ticks = R2I(distance / (SPEED * TT_PERIOD))
    set d.dx = (SPEED * TT_PERIOD) * Cos(angle)
    set d.dy = (SPEED * TT_PERIOD) * Sin(angle)
    call RemoveLocation(targ)
    
    call TT_Start(function Move, d)
    call TT_Start(function Shards, d)

    call TriggerRegisterUnitInRange(d.trig, d.missile, M_RADIUS, null)
    call TriggerAddCondition(d.trig, Condition(function Damage))
    call SetTriggerStructA(d.trig, d)
    set cast = null
    set targ = null
endfunction

function InitTrig_FrozenOrb takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction

endscope

EDIT: Oh wait, forgot to replace getlocationx with getunitx... xD
EDIT2: Done.
 

Cohadar

master of fugue
Reaction score
209
JASS:

call RemoveUnit(d.missile)

Put that inside onDestroy

Also you should not create dummy casters all the time.

You can create one dummy caster put it into struct and than make it cast nova multiple times. (just make sure you set cooldown to zero)
That will save a lot of lag...
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
> That will save a lot of lag...
Thanks. I made it cast frost nova only if the target doesn't have buff slowed. +rep u guys if I can
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top