HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Extending Structs - How to find child struct type

08-19-2008, 02:00 AM#1
Ammorth
Edit: Solved by using an integer in the base struct which I could set to each main parent's id upon parent creation.
08-19-2008, 03:44 AM#2
Vexorian
That's probably a manual solution that wasn't needed. Think typeid, there's a manual...
08-19-2008, 04:36 AM#3
Ammorth
Well, the problem was I was comparing if the struct was a child to another struct. To problem is typeid returns the id for the struct and not any of its parents. Since my item system goes about 7 childs deep, I want to compare if it belonged to say child 3, but it would only give me the last child (great great great great great grandchild).

So, I just added an integer to the base struct that I can set to the depth of children that I need to see if the struct is a relative of that certain type.

Item > Consumable > Potion > Light Healing Potion.

Check that light healing potion was extended from a consumable, set the integer to the consumable id and check that integer in Light healing potion.
08-19-2008, 10:41 AM#4
Anitarf
Hmm, something like this then?
Collapse JASS:
globals
    private constant integer INHERITANCE_DEPTH=2
endglobals

struct origin //item
    integer array inheritance[INHERITANCE_DEPTH]
    static method create takes nothing returns main
        local origin o = origin.allocate()
        set o.inheritance[0]=0
        set c.inheritance[1]=0
        return o
    endmethod
endstruct

struct firstGenChildA extends origin //consumable, artifact,...
    static method create takes nothing returns firstGenChildA
        local firstGenChildA c = firstGenChildA.allocate()
        set c.inheritance[0]=firstGenChildA.typeid
        return c
    endmethod
endstruct

...

struct secondGenChildA extends firstGenChildA //potion
    static method create takes nothing returns secondGenChildA
        local secondGenChildA c = secondGenChildA.allocate()
        set c.inheritance[1]=secondGenChildA.typeid
        return c
    endmethod
endstruct

struct secondGenChildB extends firstGenChildA //ward
    static method create takes nothing returns secondGenChildB
        local secondGenChildB c = secondGenChildB.allocate()
        set c.inheritance[1]=secondGenChildB.typeid
        return c
    endmethod
endstruct

...
Collapse example:
function IsItemPotion takes origin o returns boolean
    return o.inheritance[1]==secondGenChildA.typeid
endfunction
08-19-2008, 11:53 PM#5
Ammorth
Thats virtually what I did, except there is only 1 level right now I'm worried about, so I just kept it as a non-array.