• 🏆 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!

Returning a node from a linked list?

Status
Not open for further replies.
Level 3
Joined
Jan 15, 2010
Messages
47
Hello

Is it possible to return a node from a linked list? I am storing all the custom item data for my rpg in a linked list:

JASS:
struct itemDataNode
    //required
    integer itemCode
    string name
    string icon
    string model
    string modelLocation
    integer weight
    
    //stats
    real Armor
    real Life
    real Mana
    real AttackSpeed
    real MovementSpeed
    real PhysicalDamageModifier
    real PhysicalCritBonus
    real PhysicalCritChance
    real MeleeStunChance
    real SpellDamageModifier
    real SpellCritBonus
    real SpellCritChance
    real HealModifier
    real HealCritBonus
    real HealCritChance
    real BlockChance
    real ParryChance
    real DodgeChance
    
    thistype last
endstruct

struct itemData
    itemDataNode last
    
    static method create takes nothing returns thistype
        local thistype this = thistype.allocate()
        set .last = 0
        return this
    endmethod

    //call itemType.add(itemCode, name, icon, model, modelLocation, weight)
    method add takes integer itemCode, string name, string icon, string model, string modelLocation, integer weight  returns nothing
        local itemDataNode k = itemDataNode.create()
        //find the last item
        if .last == 0 then
            set .last = k
            set k.last = 0
        else
            set k.last = this.last
            set .last = k
        endif
        //
        set k.itemCode = itemCode
        set k.name = name
        set k.icon = icon
        set k.model = model
        set k.modelLocation = modelLocation
        set k.weight = weight
    endmethod
    
    //call itemType.addStats(itemCode, firstStat, firstValue, secondStat, secondValue, thirdStat, thirdValue)
    method addStatsToItem takes integer itemCode, string firstStat, real firstValue, string secondStat, real secondValue, string thirdStat, real thirdValue returns nothing
        local itemDataNode k = .last
        loop
            exitwhen (k.last == 0 or k.itemCode == itemCode)
            set k = k.last
        endloop
        if k.itemCode == itemCode then
            //fix item stats
            //! textmacro addStatsToItem takes CASE
            if ($CASE$Stat == "Armor") then
                set k.Armor = $CASE$Value
            elseif ($CASE$Stat == "Life") then
                set k.Life = $CASE$Value
            elseif ($CASE$Stat == "Mana") then
                set k.Mana = $CASE$Value
            elseif ($CASE$Stat == "AttackSpeed") then
                set k.AttackSpeed = $CASE$Value
            elseif ($CASE$Stat == "MovementSpeed") then
                set k.MovementSpeed = $CASE$Value
            elseif ($CASE$Stat == "PhysicalDamageModifier") then
                set k.PhysicalDamageModifier = $CASE$Value
            elseif ($CASE$Stat == "PhysicalCritBonus") then
                set k.PhysicalCritBonus = $CASE$Value
            elseif ($CASE$Stat == "PhysicalCritChance") then
                set k.PhysicalCritChance = $CASE$Value
            elseif ($CASE$Stat == "MeleeStunChance") then
                set k.MeleeStunChance = $CASE$Value
            elseif ($CASE$Stat == "SpellDamageModifier") then
                set k.SpellDamageModifier = $CASE$Value
            elseif ($CASE$Stat == "SpellCritBonus") then
                set k.SpellCritBonus = $CASE$Value
            elseif ($CASE$Stat == "SpellCritChance") then
                set k.SpellCritChance = $CASE$Value
            elseif ($CASE$Stat == "HealModifier") then
                set k.HealModifier = $CASE$Value
            elseif ($CASE$Stat == "HealCritBonus") then
                set k.HealCritBonus = $CASE$Value
            elseif ($CASE$Stat == "HealCritChance") then
                set k.HealCritChance = $CASE$Value
            elseif ($CASE$Stat == "BlockChance") then
                set k.BlockChance = $CASE$Value
            elseif ($CASE$Stat == "ParryChance") then
                set k.ParryChance = $CASE$Value
            elseif ($CASE$Stat == "DodgeChance") then
                set k.DodgeChance = $CASE$Value
            endif
            //! endtextmacro
            //! runtextmacro addStatsToItem("first")
            //! runtextmacro addStatsToItem("second")
            //! runtextmacro addStatsToItem("third")
            call MessageAll("Successfully adding stats!")
        else
            call MessageAll("Error adding stats to "+I2S(itemCode))
        endif
    endmethod

As you can tell, there are a lot of variables in my systems, and I am looking for a way to extract them and use them in my hero system. I have found a way to do it, but it requires textmacros inside it, for each item type, and i cant nest textmacros, such that i could make it for each stat. So i was wondering if i could just make a function that returns the entire node, and i can access it that way?

Somethin like:

JASS:
    method getItemDataNode takes integer itemCode returns itemDataNode
        local itemDataNode k = .last
        loop
            exitwhen (k.last == 0 or k.itemCode == itemCode)
            set k = k.last
        endloop
        if k.itemCode == itemCode then
            return k
        else
            return null
    endmethod

And then to go through all the item types, just to make it access all items:

JASS:
function getItemNodeAll takes integer itemCode returns itemDataNode
    local itemDataNode result
    //! textmacro itemNodeAll takes ITEMTYPE
    if (result == null) then
        set result = $ITEMTYPE$.getItemDataNode(itemCode)
    else
        return result
    endif
    //! endtextmacro
    //! runtextmacro itemNodeAll("OneHandSlashing")
    //! runtextmacro itemNodeAll("OneHandPiercing")
    //! runtextmacro itemNodeAll("OneHandBlunt")
    //! runtextmacro itemNodeAll("TwoHandSlashing")
    //! runtextmacro itemNodeAll("TwoHandPiercing")
    //! runtextmacro itemNodeAll("TwoHandBlunt")
    //! runtextmacro itemNodeAll("Bow")
    //! runtextmacro itemNodeAll("Staff")
    //! runtextmacro itemNodeAll("OneHandMisc")
    //! runtextmacro itemNodeAll("Shield")
    //! runtextmacro itemNodeAll("ClothHead")
    //! runtextmacro itemNodeAll("ClothChest")
    //! runtextmacro itemNodeAll("ClothLegs")
    //! runtextmacro itemNodeAll("ClothFeet")
    //! runtextmacro itemNodeAll("ClothHands")
    //! runtextmacro itemNodeAll("LeatherHead")
    //! runtextmacro itemNodeAll("LeatherChest")
    //! runtextmacro itemNodeAll("LeatherLegs")
    //! runtextmacro itemNodeAll("LeatherFeet")
    //! runtextmacro itemNodeAll("LeatherHands")
    //! runtextmacro itemNodeAll("ChainHead")
    //! runtextmacro itemNodeAll("ChainChest")
    //! runtextmacro itemNodeAll("ChainLegs")
    //! runtextmacro itemNodeAll("ChainFeet")
    //! runtextmacro itemNodeAll("ChainHands")
    //! runtextmacro itemNodeAll("PlateHead")
    //! runtextmacro itemNodeAll("PlateChest")
    //! runtextmacro itemNodeAll("PlateLegs")
    //! runtextmacro itemNodeAll("PlateFeet")
    //! runtextmacro itemNodeAll("PlateHands")
    //! runtextmacro itemNodeAll("Ring")
    //! runtextmacro itemNodeAll("Amulet")
    return result
endfunction

And then accessing it somehow, like:

JASS:
    //part of my hero data structs
    method equipItem takes integer itemCode returns nothing
        local itemDataNode tempItemData = getItemNodeAll('I00B')
        call MessageAll("Armor of item: "+R2S(tempItemData.Armor))
    endmethod

But now my map wont start. I am afraid that I am doing something "illegal" by JASS or object oriented programming syntax lol
 
Level 3
Joined
Jan 15, 2010
Messages
47
ok thanks ill look into them now :)

Edit: Ok I read through both of them and it appears that what I am attempting it possible, as the both links you gave had a search function that returned the node, but I am not sure how to access it once i save it to a local variable. The way I am attempting has made it so that i cant even test my map lol

Edit2: Could someone who is good with linked lists help me out? I have made a lot of changes to my system, and its hundreds and hundreds of lines of vJass so I will just attach it below. The issue is in the Custom Item System trigger I am sure. I used the Test function under misc folder of triggers to check a function, but it doesn't complete. thanks
 

Attachments

  • RPG1.02.w3x
    1.9 MB · Views: 56
Last edited:
Status
Not open for further replies.
Top