
// Copyright (c) 2001 
package uk.co.patrickhaston.mars;


/**
 * A Class class.
 * <P>
 * @author Patrick Haston
 */
public class MarsTechnologies extends MarsArray
{

  /**
   * Constructor
   */
  public MarsTechnologies(MarsModel model)
  {
    super(model);
    this.CollectionName = "[Technologies]";
  }

  public void readData(String line)
  {
    int idx = readIndex(line);
    if (idx>0)
    {
      MarsTechnology t = new MarsTechnology(line);

      this.setElementAt(t, idx);
    }
  }

  /** researchableTechnologies function
   * @return MarsTechnologies list of technologies that can be
   * researched at this point.
   */
  public MarsTechnologies researchableTechnologies()
  {
    // The list of available tech
    MarsTechnologies researchList = new MarsTechnologies(theModel);
    // Pointer to the discoveries already made
    MarsDiscoveries discovered = theModel.Discoveries;
    MarsEnables enablers = theModel.Enables;
    
    // Cycle through each technology
    for(int i=1; i<size(); i++)
    {
      // find out if this has already been discovered
      if(!discovered.isDiscovered(i))
      {
        // Not discovered yet, it could be added to the list
        if(enablers.isTechnologyResearchable(i))
        {
          // it meets all the criteria - we can research it
          researchList.addElement(get(i));
        }
      }
    }
    
    return researchList;
  }
}

 
