package biosim; /** * EcoEvents are the messages that facilitate communication * between the Ecosystem and its Organisms. Organisms also use this * mechanism to communicate to each other, indirectly through * the Ecosystem. Organisms are not directly aware of one another; * the only awareness that an Organism has of other Organisms is * through EcoEvents. When an Organism initiates an EcoEvent, it * places a handle to itself in the from field. When the Ecosystem * sends an EcoEvent to an Organism, if that event involves some * other Organism, the EcoSystem passes a handle to the other * Organism in this field. The attachment field is open-ended, and allows * specific kinds of EcoEvents to contain arbitrary information, * including Objects that are aggregates of other Objects. */ public class EcoEvent { /** * What kind of event? */ public int id; /** * At what time step should this event occur? */ public int time; /** * Events to occur as soon as possible can be scheduled * to happen NOW. (Actually they occur on the next cycle, * but that's close to now as we'll allow.) */ public static final int NOW = -1; /** * To what Organism should this event be delivered? * For events sent to the Ecosystem, this field should * be null. */ public Organism to; /** * What Organism (if any, other than the receiver) * is involved in this event? In the case of events * directed to the Ecosystem, this contains a handle * to the Organism that originated the event. */ public Organism from; /** * The contents of this field depend upon the kind * of event, as reflected in the id field. */ public Object attachment; /** * An Organism posts a BIRTH event when it gives birth to a * new organism. The from field contains a handle to the * "parent" organism. The attachment field contains a handle * to the offspring; either a single Organism or a Vector * containing multiple Organisms. The Ecosystem should * respond to this event by adding any new offspring to * its Organism list. */ public static final int BIRTH = 0; /** * An Organism posts a DEATH event when it must die for any * reason. The from field contains a handle to the Organism that died. * The Ecosystem should respond by removing the dead Organism from * its list of Organisms. */ public static final int DEATH = 1; /** * The Ecosystem sends a COLLISION event to two organisms * when they collide. The Organisms should each handle this * in their own way. One might attack the other, or they * might initiate a reproductive ritual, or simply bounce * off of one another. Each Organism receives a handle to * the other in the from field of the event. * NOTE: How to handle multiple collisions? Perhaps use the * what field to pass a list of other Organisms? Tricky... */ public static final int COLLISION = 2; /** * An Organism sends an ATTACK event when it wishes to attack * another Organism. The Organism responds to the ATTACK event * as appropriate. Perhaps it dies; perhaps it tries to escape; * perhaps it attacks back. */ public static final int ATTACK = 3; /** * An Organism that successfully resists attack sends a RESIST * event to the attacker, so that the attacker knows it has failed. */ public static final int RESIST = 4; // CONSTRUCTORS /** * Construct an EcoEvent with the specified fields. */ public EcoEvent(int id, int time, Organism to, Organism from, Object attachment) { this.id = id; this.time = time; this.to = to; this.from = from; this.attachment = attachment; } /** * Construct an EcoEvent without an attachment */ public EcoEvent(int id, int time, Organism to, Organism from) { this(id, time, to, from, null); } }