package alive;

/**
 * <ALIVE Project>
 * Testing Environment class
 * By Rogerio Neves
 * LSI - POLI - USP
 */

import javax.vecmath.*;
import javax.media.j3d.*;

public class XP_Test_Env  extends Environment {

  public XP_Test_Env(EnvConfig cfg) { // Object Constructor (class name)
    configureEnvironment(cfg);
    param = new double[3];
    paramName = new String[3];
    set(0,"temperature",20);
    set(1,"ph",4);
    set(2,"friction",.05);
    message("\nTemplate started...");
    super.start();
  }

  public void createContent() {
    for (int i=0; i<config.POP_LIMIT/80;i++) addAgent(new XP_Test_Obj(this));
    for (int i=0; i<config.POP_LIMIT/80;i++) addAgent(new XP_Test_Lws(this));
    rest(1000);  // Give time to agents to startup
  }

  public void createCustomUI() {
    control.ui.add(new java.awt.Label("Experiment_Template Interface"));
    java.awt.Button b = new java.awt.Button("Custom buttom");
    b.addActionListener(new java.awt.event.ActionListener() {
       public void actionPerformed(java.awt.event.ActionEvent e) {b_actionPerformed();}});
    control.ui.add(b);
  }

  public void b_actionPerformed() {
    message("\nThe button was pressed\n");
  }

  public void update() { // Put environmental computations here
    for (int i=0; i<agents.size();i++) {
      if (agents.get(i)!=null) getAgent(i).speed.scale(1-get("friction"));
    }
  }

  // *** Main method: Just makes experiment executable
  public static void main(String[] args) {
    EnvConfig cfg = new EnvConfig();
    new  XP_Test_Env(cfg);
  }
}
