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:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top