package uk.co.patrickhaston.mars;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

public class MarsBiotope extends MarsType 
{
  private int resourcesInput;
  // the amount of resources extracted from the atmosphere each day
  private int resourceOutput;
  // the amount of resources output from the atmosphere each day
  private int promotesTo;
  // the next biotope up the scale
  private int demotesTo;
  // the next one down
  private double minTemp;
  // the minimum temperature this biotope can endure before demotion
  private String imageName;
  // The name of the image used to display the background terrain
  private MarsViewImage image = null;
  // the image of the item
  private String description;

  public MarsBiotope(String line, MarsModel model) 
  {
    super(line);
    
    resourcesInput = readInteger(line, 1);
    resourceOutput = readInteger(line, 2);
    promotesTo = readInteger(line, 3);
    demotesTo = readInteger(line, 4);
    minTemp= readDouble(line, 5);
    imageName = readString(line, 6);
    description = readString(line, 7);

    if (imageName.length() > 4)
    {
      // find the image on the directory
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      // get the image from disk
      Image i = toolkit.getImage(
        model.applicationDirectory + "\\" + model.imageDirectory +
        "\\" + imageName + ".gif");
      // add it to this class
      image = new MarsViewImage(i, model.theFrame, model.theFrame);
      // add the image to the media tracker to speed up drawing
      model.mediaTracker.addImage(i, 1);
    }
  }


  public void setResourcesInput(int resourcesInput)
  {
    this.resourcesInput = resourcesInput;
  }

  public int getResourcesInput()
  {
    return resourcesInput;
  }

  public void setResourceOutput(int resourceOutput)
  {
    this.resourceOutput = resourceOutput;
  }

  public int getResourceOutput()
  {
    return resourceOutput;
  }

  public int getPromotesTo()
  {
    return promotesTo;
  }

  public int getDemotesTo()
  {
    return demotesTo;
  }

  public double getMinTemp()
  {
    return minTemp;
  }

  public String getImageName()
  {
    return imageName;
  }

  public MarsViewImage getImage()
  {
    return image;
  }

  public String getDescription()
  {
    return description;
  }

  public void paintAt(Graphics g, int x, int y, int orientation, int cStatus, MarsView view)
  {
    if(image!= null)
    {
      image.paintAt(g, x, y, orientation, view, cStatus, 10);
    }
  }
  
}

