• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

(WIP) GUI->vJass DamageEngine Plugin for Damage Engine 3.2

Status
Not open for further replies.
This is mostly-finished except for documentation and debug testing.

JASS:
//! textmacro DAMAGE_ENGINE_TOP_FUNCTIONS
library DamageEngine //Requires GUI Unit Indexer
    
    globals
        //add custom variables here.
        private trigger modEvTrig = null
        private trigger eventTrig = null
        private trigger afterTrig = null
        private trigger zeroTrig = null
    endglobals
//! endtextmacro

//! textmacro DAMAGE_ENGINE_SPELL_MODIFICATION
    //you have access to udg_DamageEventSource/Target/Amount here
    //you can put a "return" at the end here if you want to ignore the GUI modifiers
//! endtextmacro

//! textmacro DAMAGE_ENGINE_UNIT_FILTER
    //Unit is referenced as "udg_TempUnit"
    //return false if your conditions are not met.
//! endtextmacro

//! textmacro DAMAGE_ENGINE_AFTER_ASSIGNMENT
    //Assign additional variables that can be referenced from damage events here.
    //Same thing as DAMAGE_ENGINE_EVENT_ASSIGNMENT
    /*
        How I use it in DamageEngine GUI:

        set udg_DamageEventSource = udg_LastDamageSource
        set udg_DamageEventTarget = udg_LastDamageTarget
        set udg_DamageEventAmount = udg_LastDamageValue
        set udg_DamageEventType = udg_LastDamageType
        set udg_DamageEventPrevAmt = udg_LastDamagePrevAmount

        ^ You don't have to put anything here if you know for sure that your variables
        were unchanged (ie. you did not use UnitDamageTarget from an event response or
        you only used UnitDamageTargetEx.) I only use those "Last" variables as a pre-
        caution.
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_FIRE_AFTER_EVENT
    //custom event firing goes here.
    call TriggerEvaluate(afterTrig)
//! endtextmacro

//! textmacro DAMAGE_ENGINE_DECLARE_LOCALS
    //assign additional event variables to locals here for safekeeping in case of recursion
    /*
        local real d = udg_DamageEventAmount
        local unit s = udg_DamageEventSource
        local unit t = udg_DamageEventTarget
        local integer ptype = udg_DmgTypPrev
        local boolean spell = udg_IsDamageSpell
        local real prev = udg_DamageEventPrevAmt
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_RESET_LOCALS
    //set your event variables back to their cached local values
    /*
        set udg_DamageEventPrevAmt = prev
        set udg_DmgTypPrev = ptype
        set udg_DamageEventType = ptype
        set udg_DamageEventAmount = d
        set udg_DamageEventSource = s
        set udg_DamageEventTarget = t
        set udg_IsDamageSpell = spell
        set s = null
        set t = null
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_EVENT_ASSIGNMENT
    //Assign additional variables that can be referenced from damage events here.
    //Same thing as DAMAGE_ENGINE_AFTER_ASSIGNMENT but runs after the damage was applied
    /*
        How I use it in DamageEngine GUI:

        set udg_DmgTypPrev = udg_DamageEventType
        set udg_DamageEventAmount = GetEventDamage()
        set udg_DamageEventSource = GetEventDamageSource()
        set udg_DamageEventTarget = GetTriggerUnit()
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_FIRE_MODIFIER
    //custom event firing goes here.
    call TriggerEvaluate(modEvTrig)
//! endtextmacro

//! textmacro DAMAGE_ENGINE_FIRE_EVENT
    //custom event firing goes here.
    call TriggerEvaluate(eventTrig)
//! endtextmacro

//! textmacro DAMAGE_ENGINE_RESET_VARIABLES
    //set your event variables to 0 or null
    /*
        set udg_DamageModifierEvent = 0.00
        set udg_DamageEvent = 0.00
        set udg_DamageEventType = 0
        set udg_DmgTypPrev = 0
        set udg_DmgEvRecursionLevel = 0
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_UNIT_ADDED
    //add stuff to udg_TempUnit here upon allocation if you want. udg_UDex contains the relevant UnitUserData.
    /*
        set udg_UnitDamageRegistered[udg_UDex] = true
        call TriggerRegisterUnitEvent(udg_DamageEventTrigger, udg_TempUnit, EVENT_UNIT_DAMAGED)
        call UnitAddAbility(udg_TempUnit, 'A000')
        call UnitMakeAbilityPermanent(udg_TempUnit, true, udg_SpellDamageAbility)
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_DEALLOCATE
    //if there's anything that needs to be reset when the unit is removed from the engine, do it here.
    /*
        set udg_UnitDamageRegistered[udg_UDex] = false
    */
//! endtextmacro

//! textmacro DAMAGE_ENGINE_BOTTOM_FUNCTIONS

    private function RegisterAndSet takes code c, trigger t returns trigger
        if t == null then
            set t = CreateTrigger()
        endif
        call TriggerAddCondition(afterTrig, Filter(c))
        return t
    endfunction

    //Code passed to the following functions can take return nothing or return
    //boolean - but they cannot have TriggerSleepAction.
    function RegisterAfterDamageEvent takes code c returns nothing
        set afterTrig = RegisterAndSet(c, afterTrig)
    endfunction

    function RegisterDamageEvent takes code c returns nothing
        set eventTrig = RegisterAndSet(c, eventTrig)
    endfunction

    function RegisterDamageModifierEvent takes code c returns nothing
        set modEvTrig = RegisterAndSet(c, modEvTrig)
    endfunction

        function RegisterZeroDamageEvent takes code c returns nothing
        set zeroTrig = RegisterAndSet(c, zeroTrig)
    endfunction

    //In rare circumstances where the max HP of the target unit is disproportionately
    //higher than the damage (10,000 to 1, for example), calling CheckDamagedLifeEvent2
    //after a UnitDamageTarget ensures that no recursive after-damage event is overlooked
    function UnitDamageTargetEx takes unit source, unit target, real amount, boolean b, boolean c, attacktype a, damagetype d, weapontype w returns boolean
        local boolean b = UnitDamageTarget(source, target, amount, b, c, a, d, w)
        call CheckDamagedLifeEvent2()
        return b
    endfunction

    function DamageEngine__Init takes nothing returns nothing
        //Initialize stuff here.
    endfunction
endlibrary
//! endtextmacro

//! textmacro DAMAGE_ENGINE_INIT
        //this is an out-of-scope function calling to an in-scope library function.
        //You have access to the variable "udg_TempUnit" for preloading abilities on it
        call DamageEngine__Init()
//! endtextmacro
 
Last edited:
Ok, it is just about ready. I still need to add documentation, though.

Some things I want to point out about this:

- Damage Engine GUI will compile without JassHelper no problem since textmacros are comments.

- Damage Engine GUI will compile WITH JassHelper, also with no problem, since all the textmacros are optional.

- GUI doesn't guarantee the placement of UnitDamageTargetEx will take precedence over functions that call it. By placing it into a library, the problem is solved.

- Events will run a little faster than TriggerRegisterVariableEvent but cannot be unregistered for simplicity's sake. Just use TriggerRegisterVariableEvent if you want to do things like turn the containing trigger off.

- Is much more extensible as I have had a couple of requests to improve this feature set of DamageEngine.

- I can add more textmacros to different parts of the GUI script if people need it.
 
Status
Not open for further replies.
Top