
// Copyright (c) 2004
package uk.co.patrickhaston.mars;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

/**
 * A Class class.
 * <P>
 * @author Patrick Haston
 */
public class MarsConstructionType extends MarsType 
{
  // Contents
  public long components;
  // The number of components required to make this item
  public int resourcesMaxStore;
  // The amount of resources this construction can store
  public int resourceUse;
  // The amount of resouces used by this item
  public long maxOccupants;
  // The number of people this can hold
  public long workers;
  // The number of workers required to operate this item
  public double movement;
  // The distance this item can travel in one day
  protected String description;
  // A description of this type of construction
  protected int length;
  // how long this item is in metres
  protected int width;
  // the width of this item in metres
  protected String imageName;
  // the filename of the image of this item
  protected MarsViewImage image = null;
  // the image of the item
  protected int type;
  // the type of construction
  public static int BUILDING = 1;
  public static int VEHICLE = 2;
  public static int OTHER = 3;

  /**
   * Constructor
   */
  public MarsConstructionType(int id) 
  {
    super(id);
    components = 0;
    resourcesMaxStore = 0;
    resourceUse = 0;
    maxOccupants = 0;
    workers = 0;
    movement = 0;
    description = "";
    length =0;
    width = 0;
    imageName = "";
  }

  public MarsConstructionType(MarsConstructionType t) 
  {
    super((MarsType) t);
    if (t == null)
    {
      components = 0;
      resourcesMaxStore = 0;
      resourceUse = 0;
      maxOccupants = 0;
      workers = 0;
      movement = 0;
      description = "";
      length =0;
      width = 0;
      imageName = "";
    }
    else
    {
      components = t.components;
      resourcesMaxStore = t.resourcesMaxStore;
      resourceUse = t.resourceUse;
      maxOccupants = t.maxOccupants;
      workers = t.workers;
      movement = t.movement;
      description = t.description;
      length =t.length;
      width = t.width;
      imageName = t.imageName;
      image = null;
    }
  }

  public MarsConstructionType(String line, MarsModel model)
  {
    super(line);
    components = readLong(line, 1);
    resourcesMaxStore = readInteger(line, 2);
    resourceUse = readInteger(line, 3);
    maxOccupants = readLong(line, 4);
    workers = readLong(line, 5);
    movement = readDouble(line, 7);
    description = readString(line, 8);
    length = readInteger(line, 9);
    width = readInteger(line, 10);
    imageName = readString(line, 11);
    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);
    }
    type = readInteger(line, 12);
    
  }

  public String toString()
  {
    String s = super.toString();

    s = s + new Long(components).toString() + ",";
    s = s + new Integer(resourcesMaxStore).toString() + ",";
    s = s + new Integer(resourceUse).toString() + ",";
    s = s + new Long(maxOccupants).toString() + ",";
    s = s + new Long(workers).toString() + ",";
    s = s + " Movement:" + movement ;
    s = s + " Length:" + length + " Width:"+ width + " Image File:" + imageName;
    if(isBuilding()) s = s + " building";
    if(isVehicle()) s = s+ " vehicle";
    return s;
  }
  
  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, length);
    }
  }
  
  public int getType()
  {
    return type;
  }
  
  public boolean isBuilding()
  {
    return (type == BUILDING);
  }
  
  public boolean isVehicle()
  {
    return (type == VEHICLE);
  }
}

 
