This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Role
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
####Description All-purpose class for describing every Role a person could have in SimCity201. When entering a structure, the person takes on one or more roles, determining his/her behavior at that location. Every roll will have functions to start a scenario based upon an intent provided by the person.
####Class Signature
public abstract class Role {}
####Data
PersonAgent myPerson; // The PersonAgent that currently has this Role
boolean isActive; // Whether or not this Role's scheduler is being called
####Methods
// Starts an interaction in the Role based upon the PersonAgent's intent
public abstract void startInteraction(PersonAgent.Intention intent);
// Releases the semaphore in PersonAgent so that its scheduler begins to run again
protected void stateChanged() {
if (myPerson != null) {
myPerson.stateChanged();
}
}
// Acquires the semaphore in PersonAgent so that its thread will pause
protected void acquireSemaphore() {
myPerson.animationAcquire();
}
// Scheduler for roles is non-threaded (it is called manually by the PersonAgent's scheduler)
protected abstract boolean pickAndExecuteAnAction();
// Any work-related Role must know when it's time to close
public abstract void msgClosingTime();
// Returns this Role's PersonAgent
public PersonAgent getPerson() {
return myPerson;
}
public void setPerson(PersonAgent newPerson) {
myPerson = newPerson;
}
// Makes this Role active or inactive
public void setActive(boolean newActive) {
isActive = newActive;
}
// Returns whether or not this Role is currently active
public boolean getActive() {
return isActive;
}
// Sets the PersonAgent that currently has this Role
public void setPerson(PersonAgent newPerson) {
myPerson = newPerson;
}
// Returns the name of this Role's PersonAgent if possible
public String getName() {
return (myPerson != null) ? myPerson.getName() : "NULL";
}
// Returns a String representation of this Role
public String toString() {
StringBuffer output = new StringBuffer();
output.append(this.getClass().getSimpleName());
output.append(" ");
output.append((myPerson != null) ? myPerson.getName() : "NULL");
return output.toString();
}
// General-purpose function for printing to the terminal. Format: "RestaurantCustomer Matt: Ordered steak"
@Deprecated
protected void Do(String msg) {
StringBuffer output = new StringBuffer();
output.append("[");
output.append(this.getClass().getSimpleName());
output.append("]");
if (this.myPerson != null) {
output.append(" ");
output.append(this.myPerson.getName());
}
output.append(": ");
output.append(msg);
System.out.println(output.toString());
}