package uk.co.patrickhaston.mars;

public class MarsPlans extends MarsArray 
{

  /**
   * Constructor
   */
  public MarsPlans(MarsModel model)
  {
    super(model);
    this.CollectionName = "[Plans]";
  }

  /**
   * readData function - reads the data from file
   * @param line - the information for a new data item
   */
  public void readData(String line)
  {
    int idx = readIndex(line);
    if (idx>0)
    {
      MarsPlan p = new MarsPlan(line);

      this.setElementAt(p, idx);
    }
  }

  /**
   * getNextInPlan - find out the next construction to make
   * @param planType - the type of settlement
   * @param nextInPlan - the id of the next step
   * @return constructionTypeId or 0 if all done
   */
  public int getNextInPlan(int planType, int nextInPlan)
  {
    if(this.size() < 2) return 0;
    //int c = 0;
    for(int i=0; i<= size(); i++)
    {
      if(elementAt(i) != null)
      {
        if( ((MarsPlan) elementAt(i)).getPlanType() == planType
          && ((MarsPlan) elementAt(i)).getStep() == nextInPlan )
        {
          return i;
        }
      }
    }
    return 0;
  }
}
