HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Ability tree and information storage

08-28-2008, 02:47 AM#1
Zandose
I'm sure I'll figure something out, but I wanted to know if anyone had any ideas first.

Basically, I'm trying to make a ability tree and I'm looking for methods to organize this.

First, I thought of using structs. One struct for each ability which would store its parent and sub-abilities.

Second, I thought of making a matrix (an array of arrays), but I might be a little messy.
08-28-2008, 03:37 AM#2
Ammorth
A matrix would be your best best. You can store each "spell level" as a row and then add the spells in the row to the columns. Give each spell a requirement spell, and then to check, just loop down the requirements until all are met.
08-28-2008, 04:14 AM#3
DioD
Use game cache and dont care about leaks, cos this data is static.
08-28-2008, 10:23 AM#4
TheDamien
Quote:
Originally Posted by Zandose
Second, I thought of making a matrix (an array of arrays), but I might be a little messy.

Not necessarily:

Collapse JASS:
//! textmacro Matrix takes NAME, TYPE, SCOPE, WIDTH
$SCOPE$ struct $NAME$
    private static $TYPE$ array a
        
    method operator [] takes integer i returns $TYPE$
        return .a[this+i]
    endmethod
        
    method operator []= takes integer i, $TYPE$ t returns nothing
        set .a[this+i] = t
    endmethod
        
    static method operator [] takes integer i returns $NAME$
        return i*$WIDTH$
    endmethod
endstruct
//! endtextmacro

I do not think a matrix is the best way of representing a tree structure in this case. I'd probably go with structs and lists.