• 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.

Destructible Group?

Status
Not open for further replies.
Not directly but one could try to abstract it a bit.
You can use help libraries like a list or vector and create a struct DestructableGroup.
The struct can have a list as member which will contain all destructables of a DestructableGroup.
You need a function to add to- , and also one for remove a destructable from the list.

Don't have code for you, but that might be the idea. :)

For "index" hashtables you can use the HandleId of destructables.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
You can create collections of destructables ( list, stack, ... )
and iterate over them.

Mmhh you could do something like this here.
I ripped it out of a map of mine, didn't test it properly yet.

It will not compile for you as you don't have Guardian and ItemDrop,
I just posted it to give you an idea.
JASS:
//===================================================================================
// Handles interactable destructables.
//===================================================================================
library Destructable uses List, Guardian, ItemDrop
//**
//*  Settings:
//*  =========
    // Runs on native destructable death event.
    private function OnDeathEvent takes nothing returns nothing
        local real x = GetWidgetX(GetTriggerDestructable())
        local real y = GetWidgetY(GetTriggerDestructable())
        //call destructableItemDrop.dropItems(x, y, null)
    endfunction

//===================================================================================
// System code. Better dont' make any changes!!!!
//===================================================================================    

    globals
        private Table table
        private real damage 
    endglobals

    function DamageDestructable takes destructable d, real amount returns boolean
        if not IsDestructableInvulnerable(d) and (GetWidgetLife(d) > 0.405) and table.has(GetHandleId(d)) then
            call SetWidgetLife(d, RMaxBJ(0., GetWidgetLife(d) - amount))
            return true
        endif
        return false
    endfunction
    
    private function EnumDests takes nothing returns nothing
        call DamageDestructable(GetEnumDestructable(), damage)
    endfunction

    function DamageDestructablesInRange takes real x, real y, real range, real amount returns nothing
        set damage = amount
        call SetRect(GLOBAL_RECT, x - range, y + range, x + range, y - range)
        call EnumDestructablesInRect(GLOBAL_RECT, null, function EnumDests)
    endfunction

    struct Destructable extends array
        implement List
        
        readonly integer      objects
        private  trigger      trig    
        private  integer      wasted
        private  integer      limit
        private  destructable dest
            
        // Clears events. ( In theory )
        private method createTrigger takes code func returns nothing
            local thistype node = first
            local trigger temp = trig
            // Destroy existing trigger.
            if (temp != null) then
                call TriggerClearConditions(temp)
                call DestroyTrigger(temp)
                set trig = null
                set temp = null
            endif
            // Build trigger.
            set temp = CreateTrigger()
            call TriggerAddCondition(temp, Condition(func))
            //
            // Re-register all destructables.
            set objects = 0
            set wasted = 0
            loop
                exitwhen (0 == node)
                call TriggerRegisterDeathEvent(temp, node.dest)
                set objects = objects + 1
                set node = node.next
            endloop
            //
            set trig = temp
            set temp = null
        endmethod
        
        private method checkObjects takes nothing returns nothing
            local thistype node = first
            local thistype temp
            call DisableTrigger(trig)
            loop
                exitwhen (0 == node)
                set temp = node.next
                if (GetWidgetLife(node.dest) <= .405) then
                    call table.remove(GetHandleId(node.dest))
                    call RemoveDestructable(node.dest)
                    call node.remove()
                    set node.dest = null
                    set wasted = wasted + 1
                    set objects = objects - 1
                endif
                set node = temp
            endloop
            call EnableTrigger(trig)
            // Rebuild the trigger.
            if (wasted >= limit or objects == 0) then
                call createTrigger(function OnDeathEvent)
            endif
        endmethod
            
        // Enables render options. Automatically checks all objects added.
        method render takes boolean flag returns nothing
            local thistype node = first
            loop
                exitwhen (0 == node)
                call ShowDestructable(node.dest, flag)
                set node = node.next
            endloop
            //
            // Check for dead objects.
            if (objects > 0) then
                call checkObjects()
            endif
        endmethod
        
        // Enqueues to the collection
        method addDest takes integer id, real x, real y, real face, real scale, integer variation returns destructable
            local thistype node = enqueue()
            set node.dest = CreateDestructable(id, x, y, face, scale, variation)
            call TriggerRegisterDeathEvent(trig, node.dest)
            set table[GetHandleId(node.dest)] = node// Just that this dest can be hit.
            set objects = objects + 1
            return node.dest
        endmethod
        
        method deallocate takes nothing returns integer
            call TriggerClearConditions(trig)
            call DestroyTrigger(trig)
            set trig = null
            call destroy()
            //debug call DebugMsg("Deallocated destructable instance")
            return 0
        endmethod
        
        // Allocates a new collection.
        static method allocate takes integer check returns thistype
            local thistype this = create()
            set limit = check
            set objects = 0
            call createTrigger(function OnDeathEvent)
            return this
        endmethod
        
        private static method init takes nothing returns nothing
            set table = Table.create()
        endmethod
        implement Init
        
    endstruct

endlibrary
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
I once found a destructable indexing system on TheHelper.net, which is used for death events. I dont know, if it helps in your case, because, to be honest, I didnt read the code carefully.

Link The Helper net

For a map I am currently working on, I also use a pretty much customized lumber system. I chose to use units at the moment, maybe this would be an option for you as well to change over to units?

(I am using "Chaos" + "Locust" at map init to loop through all initially planted trees to make them unselectable, while still being targatable)
 
Status
Not open for further replies.
Top