package engine.gameobject.weapon.upgradetree;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import engine.gameobject.weapon.upgradetree.upgradebundle.BuildableBundle;
import engine.gameobject.weapon.upgradetree.upgradebundle.UpgradeBundle;


/**
 * UpgradeTreeSimple uses a linked list of UpgradeBundles. There is no branching.
 * 
 * @author Nathan Prabhu
 *
 */

public class UpgradeTreeSimple implements UpgradeTree {

    private BuildableBundle first;
    private BuildableBundle current;
    
    public UpgradeTreeSimple() {
        //TODO: Initialize first and current
    }

    public UpgradeTreeSimple (List<BuildableBundle> nodes) {
        first = current = nodes.get(0);
        BuildableBundle last = first;
        // take care of first node's parent
        last.setParent(this);
        
        // iterate from second node onward
        for (BuildableBundle node : nodes.subList(1, nodes.size())) {
            node.setParent(this);
            
            last.addChild(node);
            last = node;
        }
        last.markFinalUpgrade();
    }

    @Override
    public List<UpgradeBundle> getNextUpgrades (){
       // will only return one upgrade
       return new ArrayList<UpgradeBundle>(Arrays.asList(current.getNext()));
    }

    @Override
    public double getValue () {
        return traverseActives(first);
    }
    
    private double traverseActives (BuildableBundle active) {
        if (active.equals(current)){
            return active.getValue();
        }
        return active.getValue() + traverseActives(active.getNext());
    }

    public void updateCurrent (UpgradeTree... toUpdate) {
        // ignores parameter
        current = current.getNext();
    }

}

@@ -112,24 +112,61 @@
 .util.List;%0A
+import engine.fieldsetting.Settable;%0A
 import engin
@@ -224,24 +224,24 @@
 ableBundle;%0A
-
 import engin
@@ -426,16 +426,26 @@
  *%0A */%0A%0A
+@Settable%0A
 public c
@@ -658,38 +658,147 @@
   %7D%0A
+    
 %0A    
-public UpgradeTreeSimple 
+@Settable%0A    void setUpgradeBundles(List%3CBuildableBundle%3E nodes)%7B%0A        buildTree(nodes);%0A    %7D%0A    %0A    private void buildTree
 (Lis

add Settable notation to UpgradeTreeSimple and UpgradeBundleSimple