robocode
Class CustomEvent

java.lang.Object
  extended by robocode.Event
      extended by robocode.CustomEvent
All Implemented Interfaces:
Serializable, Comparable<Event>

public class CustomEvent
extends Event

This event is sent to onCustomEvent() when a custom condition is met. Be sure to reset or remove the custom condition to avoid having it recurring repeatedly (see the example for the getCondition() method.

Author:
Mathew A. Nelson (original), Flemming N. Larsen (contributor)
See Also:
getCondition(), Serialized Form

Constructor Summary
CustomEvent(Condition condition)
          Called by the game to create a new CustomEvent when a condition is met.
CustomEvent(Condition condition, int priority)
          Called by the game to create a new CustomEvent when a condition is met.
 
Method Summary
 int compareTo(Event event)
          Compares this event to another event regarding precedence.
 Condition getCondition()
          Returns the condition that fired, causing this event to be generated.
 int getPriority()
          Returns the priority of this event.
 
Methods inherited from class robocode.Event
getTime, setPriority, setTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomEvent

public CustomEvent(Condition condition)
Called by the game to create a new CustomEvent when a condition is met.

Parameters:
condition - the condition that must be met

CustomEvent

public CustomEvent(Condition condition,
                   int priority)
Called by the game to create a new CustomEvent when a condition is met. The event will have the given priority. An event priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.

This is equivalent to calling Condition.setPriority(int) on the Condition.

Parameters:
condition - the condition that must be met
priority - the priority of the condition
Method Detail

getCondition

public Condition getCondition()
Returns the condition that fired, causing this event to be generated. Use this to determine which condition fired, and to remove the custom event.
   public void onCustomEvent(CustomEvent event) {
       if (event.getCondition().getName().equals("mycondition")) {
           removeCustomEvent(event.getCondition());
           // do something else
       }
   }
 

Returns:
the condition that fired, causing this event to be generated

compareTo

public final int compareTo(Event event)
Compares this event to another event regarding precedence. The event precedence is first and foremost determined by the event time, secondly the event priority, and lastly specific event information.

This method will first compare the time of each event. If the event time is the same for both events, then this method compared the priority of each event. If the event priorities are equals, then this method will compare the two event based on specific event information.

This method is called by the game in order to sort the event queue of a robot to make sure the events are listed in chronological order.

Specified by:
compareTo in interface Comparable<Event>
Overrides:
compareTo in class Event
Parameters:
event - the event to compare to this event.
Returns:
a negative value if this event has higher precedence, i.e. must be listed before the specified event. A positive value if this event has a lower precedence, i.e. must be listed after the specified event. 0 means that the precedence of the two events are equal.

getPriority

public final int getPriority()
Returns the priority of this event.

An event priority is a value from 0 - 99. The higher value, the higher priority.

The default priority is 80, but varies depending on the type of event.

Overrides:
getPriority in class Event
Returns:
the priority of this event.


Copyright © 2013 Robocode. All Rights Reserved.