| 11-08-2007, 02:42 PM | #1 | |
Quote:
I meant overkill in the sense of writing the code not in the sense of memory used. Lets let people judge this by themselves, here are 2 spells that do exactly the same thing: (with differences highlighted in the code) JASS://=========================================================================== // Example spell for using ABC //=========================================================================== scope Slide globals constant integer SID_SLIDE = 'A000' endglobals globals private constant real SLIDE_MAX_DISTANCE = 1200. private constant real SLIDE_SPEED = 500. private constant real PERIOD = 0.04 endglobals private struct SpellData unit hero real dx real dy integer ticks endstruct private function Timer_Actions takes nothing returns nothing local integer i = 1 local SpellData data local real x local real y local timer t = GetExpiredTimer() set data = GetTimerStructA(t) set x = GetUnitX(data.hero)+data.dx set y = GetUnitY(data.hero)+data.dy call SetUnitPosition(data.hero,x,y) set data.ticks = data.ticks - 1 if data.ticks <= 0 then call SetUnitPathing( data.hero, true ) call PauseUnit( data.hero, false ) call data.destroy() call ClearTimerStructA(t) // We must clear attachments before destroying timer call DestroyTimer(t) endif endfunction private function Actions takes nothing returns nothing local SpellData data = SpellData.create() local location target = GetSpellTargetLoc() local timer t = CreateTimer() local real Dx local real Dy local real distance local real angle set data.hero = GetTriggerUnit() set Dx = GetLocationX(target) - GetUnitX(data.hero) set Dy = GetLocationY(target) - GetUnitY(data.hero) call RemoveLocation(target) set distance = RMinBJ(SLIDE_MAX_DISTANCE, SquareRoot(Dx * Dx + Dy * Dy)) set data.ticks = R2I(distance / (SLIDE_SPEED*PERIOD)) set angle = Atan2(Dy, Dx) set data.dx = (SLIDE_SPEED*PERIOD) * Cos(angle) set data.dy = (SLIDE_SPEED*PERIOD) * Sin(angle) call SetUnitPathing( data.hero, false ) call PauseUnit( data.hero, true ) // attaching a struct to a timer call SetTimerStructA(t, data) call TimerStart(t,PERIOD,true,function Timer_Actions) endfunction private function SpellComparision takes nothing returns boolean return GetSpellAbilityId() == SID_SLIDE endfunction //=========================================================================== public function InitTrig takes nothing returns nothing local trigger trig = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( trig, Condition( function SpellComparision ) ) call TriggerAddAction( trig, function Actions) endfunction endscope JASS://=========================================================================== // Example spell for using global arrays //=========================================================================== globals constant integer SID_GLIDE = 'A000' endglobals scope Glide globals private constant real GLIDE_MAX_DISTANCE = 1200. private constant real GLIDE_SPEED = 500. private constant real PERIOD = 0.04 private timer SpellTimer = CreateTimer() // This timer is never destroyed endglobals private struct SpellData unit hero real dx real dy integer ticks static SpellData array A static integer counter = 0 endstruct private function Timer_Actions takes nothing returns nothing local SpellData data local real x local real y local integer i = 0 loop exitwhen i >= SpellData.counter set data = SpellData.A[i] set x = GetUnitX(data.hero)+data.dx set y = GetUnitY(data.hero)+data.dy call SetUnitPosition(data.hero,x,y) set data.ticks = data.ticks - 1 if data.ticks <= 0 then call SetUnitPathing( data.hero, true ) call PauseUnit( data.hero, false ) call data.destroy() set SpellData.counter = SpellData.counter - 1 set SpellData.A[i] = SpellData.A[SpellData.counter] endif set i = i + 1 endloop // Noone is using our spell right now so we can pause the timer if SpellData.counter == 0 then call PauseTimer(SpellTimer) endif endfunction private function Actions takes nothing returns nothing local SpellData data = SpellData.create() local location target = GetSpellTargetLoc() local timer t = CreateTimer() local real Dx local real Dy local real distance local real angle set data.hero = GetTriggerUnit() set Dx = GetLocationX(target) - GetUnitX(data.hero) set Dy = GetLocationY(target) - GetUnitY(data.hero) call RemoveLocation(target) set distance = RMinBJ(GLIDE_MAX_DISTANCE, SquareRoot(Dx * Dx + Dy * Dy)) set data.ticks = R2I(distance / (GLIDE_SPEED*PERIOD)) set angle = Atan2(Dy, Dx) set data.dx = (GLIDE_SPEED*PERIOD) * Cos(angle) set data.dy = (GLIDE_SPEED*PERIOD) * Sin(angle) call SetUnitPathing( data.hero, false ) call PauseUnit( data.hero, true ) set SpellData.A[SpellData.counter] = data set SpellData.counter = SpellData.counter + 1 call TimerStart(SpellTimer,PERIOD,true,function Timer_Actions) endfunction function SpellComparision takes nothing returns boolean return GetSpellAbilityId() == SID_GLIDE endfunction //=========================================================================== public function InitTrig takes nothing returns nothing local trigger trig = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( trig, Condition( function SpellComparision ) ) call TriggerAddAction( trig, function Actions) endfunction endscope |
| 11-08-2007, 10:14 PM | #2 | |
omg... =) are "through ass solution"... you could also compare GUI triggers and you ABC... i mean a skilled coder can realiese it very well with out many fucking awesome systems which will save the universe. ^^ (imho idk) btw use my XAT it's much better than ABC xD rofl lolzor =) (cause it doesnt have any loops and have the minimal chance of overlaping) but it's also a question of taste =) wow sorry ^^ (+ no personal offense or something, just lol) by Vexorian Quote:
|
| 11-08-2007, 10:27 PM | #3 | ||
Quote:
Thats exactly my point, you don't have be a skilled coder to use ABC :P And results are absolutely the same. XAT indeed has minimal chance of overlapping, who ever invented that hashing code inside XAT must be some form of genius. roflmao :D Quote:
|
