HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Can this be optimized in anyway?

07-18-2007, 09:58 PM#1
Beardo
Collapse JASS:
//******************************************************
//*Holy Concentration (Clearcasting)
//******************************************************
function HolyConcentrationRemoval takes nothing returns nothing
local timer t = GetExpiredTimer()
local string d = GetAttachmentTable(t)
local unit u = GetTableUnit(d, "unit")
local integer abilityid = GetTableInt(d, "abilityid")

if GetUnitAbilityLevel(u, 'A05P') > 0 then
call SetUnitAbilityLevel(u, abilityid, GetUnitAbilityLevel(u, abilityid) - 1)
call UnitRemoveAbility(u, 'A05P')
debug call BJDebugMsg("Removed")
endif

set u = null
set t = null
call ClearTable(d)
call DestroyTimer(t)
endfunction

function HolyConcentrationApply takes unit u, integer abilityid, integer manacost returns nothing
local timer t = CreateTimer()
local string d = GetAttachmentTable(t)

call SetUnitAbilityLevel(u, 'A05N', GetUnitAbilityLevel(u, 'A05N') + 1)
call SetUnitAbilityLevel(u, 'A04E', GetUnitAbilityLevel(u, 'A04E') + 1)
call SetUnitState (u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA) - manacost)

debug call BJDebugMsg("HIT2")
call UnitAddAbility(u, 'A05P')
call SCTDisplayTextGen(u, u, "Clearcasting", true)

call SetTableObject(d, "unit", u)      
call SetTableInt(d, "abilityid", abilityid)
call TimerStart(t, 15, false, function HolyConcentrationRemoval)             
set t = null
set d = null  
endfunction


Collapse JASS:
//******************************************************      
//*Inspiration
//******************************************************
function InspirationRemoval takes nothing returns nothing
local timer t = GetExpiredTimer()
local string d = GetAttachmentTable(t)
local inspirationdata insdata = GetTableInt(d, "inspirationdata")
local string targettable = GetAttachmentTable(insdata.target)
local herodata targethd = GetTableInt(targettable, "herodata")

debug call BJDebugMsg("Removed")

set targethd.armor = targethd.armor - insdata.added

call SetTableInt(targettable, "herodata", targethd)

call insdata.destroy()
call ClearTable(d)
call DestroyTimer(t)
set t = null
set targettable = null
endfunction

function InspirationApply takes unit u, unit target returns nothing
local inspirationdata insdata = inspirationdata.create()
local timer t = CreateTimer()
local string castertable = GetAttachmentTable(u)
local string targettable = GetAttachmentTable(target)
local string d = GetAttachmentTable(t)
local real added
local herodata hd = GetTableInt(castertable, "herodata")
local herodata targethd = GetTableInt(targettable, "herodata")
local player p = GetOwningPlayer(u)

debug call BJDebugMsg("HIT2")

call CasterCastAbility(p, 'A057', "innerfire", target, true)

set added =  ( targethd.armor * hd.t11actual ) - targethd.armor
set insdata.added = added
set targethd.armor = targethd.armor + (added)

call SetTableInt(d, "inspirationdata", insdata)      
call TimerStart(t, 15, false, function InspirationRemoval)             

set castertable = null
set targettable = null
set d = null
set t = null 
set p = null   
endfunction

They're two simple buff adders with removal functions

Just want to make sure its efficent,as I'm going to base alot of stuff off those functions
07-18-2007, 10:46 PM#2
Anitarf
It's not very clear what you're trying to do since there's no description of what the spells are supposed to do, so I can't tell you if this is the best way to get that effect.

You could always optimize it by using vJass, though.
07-18-2007, 11:11 PM#3
Vexorian
The first one should attach a pointer to a single struct instead of attaching multiple fields, specially since right now your are using I2U which is not "ideally safe".
07-18-2007, 11:23 PM#4
Beardo
They're both triggered spell effects

The first one adds a Slow Tornado aura to the target, second one uses a dummy caster to apply an inner fire-based buff on the target


vex, Where is I2U being used? SetTableInt ?

Updated to:
Hidden information:

Collapse JASS:
//******************************************************
//*Holy Concentration (Clearcasting)
//******************************************************
function HolyConcentrationRemoval takes nothing returns nothing
local timer t = GetExpiredTimer()
local string d = GetAttachmentTable(t)
local holycondata hcd = GetTableInt(d, "hcd")

if GetUnitAbilityLevel(hcd.target, 'A05P') > 0 then
call SetUnitAbilityLevel(hcd.target, hcd.abilityid, GetUnitAbilityLevel(hcd.target, hcd.abilityid) - 1)
call UnitRemoveAbility(hcd.target, 'A05P')
debug call BJDebugMsg("Removed")
endif

set t = null
call ClearTable(d)
call DestroyTimer(t)
endfunction

function HolyConcentrationApply takes unit u, integer abilityid, integer manacost returns nothing
local timer t = CreateTimer()
local string d = GetAttachmentTable(t)
local holycondata hcd = holycondata.create()

call SetUnitAbilityLevel(u, 'A05N', GetUnitAbilityLevel(u, 'A05N') + 1)
call SetUnitAbilityLevel(u, 'A04E', GetUnitAbilityLevel(u, 'A04E') + 1)
call SetUnitState (u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA) - manacost)

debug call BJDebugMsg("HIT2")

call UnitAddAbility(u, 'A05P')
call SCTDisplayTextGen(u, u, "Clearcasting", true)

set hcd.target = u
set hcd.abilityid = abilityid

call SetTableInt(d, "hcd", hcd)
call TimerStart(t, 15, false, function HolyConcentrationRemoval)             
set t = null
set d = null  
endfunction
07-19-2007, 06:34 AM#5
Pyrogasm
Quote:
Originally Posted by Beardo
vex, Where is I2U being used?
callGetTable<Anything that's not Integer, Boolean, Real, or String>(...) uses an I2_ function that is apparently inherently bad.
07-19-2007, 06:36 AM#6
Beardo
Ah, so using structs avoids that...
07-19-2007, 06:42 AM#7
Pyrogasm
Yes.
07-19-2007, 10:02 AM#8
Anitarf
If you plan on using buffs a lot, then perhaps I may interest you in my ABuff system? It's not released yet, but it's nearly finished and now that I have my computer back I should have it out in a couple of days.
07-19-2007, 10:09 AM#9
Pyrogasm
What exactly does your ABuff system do, Anitarf? I'm curious...
07-19-2007, 05:11 PM#10
Anitarf
Take a look.