• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Is this code wise?

Status
Not open for further replies.
Level 3
Joined
Feb 20, 2007
Messages
32
Hello there, just me and my optimization attempts at work. Previously I've been using a loop to determine if something is part of an array, however it recently occured to me that the tag '####' is really an integer id.

That in mind;
JASS:
struct CASTING_EVENT
    integer sid
    trigger use
    boolean override = false
endstruct

globals
    CASTING_EVENT array CASTING_EVENTS
    unit CASTING_EVENT_CASTER
endglobals

constant function MINIMUM_SPELL_HANDLE_ID takes nothing returns integer
    return 'A000'
endfunction

function ENGINE_REGISTER_CASTING_EVENT takes CASTING_EVENT cs returns nothing
   set CASTING_EVENTS[cs.sid - MINIMUM_SPELL_HANDLE_ID] = cs
endfunction

function IsSpellRegistered takes integer sid returns trigger
    local integer I = sid -  MINIMUM_SPELL_HANDLE_ID
    if(CASTING_EVENTS[I] != 0)then
        return CASTING_EVENTS[I].use
    endif
    return null
endfunction

However, I'm not entirely sure if this is an advisible idea. I'm aware the maximum array value is 8190, which I would hope would not be surpassed. This seems almost to good to be true, could anyone confirm/deny if this is a valid way to handle this code?

(If so, does anyone happen to know the minimum possible handle for a trackable?)
 
Status
Not open for further replies.
Top