package agent;

import utilities.StringUtil;
import city.PersonAgent;
import city.Place;

public abstract class Role
{
	// ----------------------------- DATA ------------------------------------
	protected PersonAgent _person;
	public boolean active = false;
	
	// ----------------------------- CONSTRUCTOR & PROPERTIES ------------------------------------
	public Role(PersonAgent person) { _person = person; }
	public void setPersonAgent(PersonAgent person) { _person = person; }
	public abstract Place place();
	public String toString() { return StringUtil.shortName(getClass()); }
	
	// ----------------------------- METHODS ------------------------------------
	protected void stateChanged()
	{
		_person.stateChanged(); // it should be okay to perform extra scheduler calls in the person (since they all take place in one thread anyway)
		//if(active) _person.stateChanged();
	}
	
	// --------- ABSTRACT ---------
	public abstract boolean pickAndExecuteAnAction();
	public abstract void cmdFinishAndLeave(); // from PersonAgent
	
	// --------- UTILITIES ---------
    /**
     * Print message with this agent's name and exception stack trace
     */
    protected void print(String msg, Throwable e)
    {
        StringBuffer sb = new StringBuffer();
        sb.append(_person.getName());
        sb.append(": ");
        sb.append(msg);
        sb.append("\n");
        if (e != null) sb.append(StringUtil.stackTraceString(e));
        System.out.print(sb.toString());
    }
    protected void print(String msg)
    {
    	print(msg, null);
    }
}

@@ -9,16 +9,43 @@
 agent;%0A%0A
+import utilities.EventLog;%0A
 import u
@@ -279,16 +279,55 @@
  false;%0A
+%09public EventLog log = new EventLog();%0A
 %09%0A%09// --

add event log in role