/** * Checks if the user's condition for a custom event is satisfied. * * @param condition is the condition to check. * @return {@code true} if the condition is satisfied; {@code false} otherwise. */ private boolean callUserCode(Condition condition) { boolean conditionSatisfied; robotProxy.setTestingCondition(true); try { conditionSatisfied = condition.test(); } finally { robotProxy.setTestingCondition(false); } return conditionSatisfied; }
/** * Sets the event priority of events belonging to a specific class. * * @param eventClass is a string with the full class name of the event type to set the priority * for. * @param priority is the new priority */ public void setEventPriority(String eventClass, int priority) { if (eventClass == null) { return; } final Event event = eventNames.get(eventClass); if (event == null) { robotProxy.println("SYSTEM: Unknown event class: " + eventClass); return; } if (HiddenAccess.isCriticalEvent(event)) { robotProxy.println("SYSTEM: You may not change the priority of a system event."); } HiddenAccess.setEventPriority(event, priority); }
/** * Internal method for adding an event to the event queue. * * @param event is the event to add to the event queue. */ private void addImpl(Event event) { if (eventQueue != null) { if (eventQueue.size() > MAX_QUEUE_SIZE) { robotProxy.println( "Not adding to " + robotProxy.getStatics().getName() + "'s queue, exceeded " + MAX_QUEUE_SIZE + " events in queue."); } else { HiddenAccess.setEventTime(event, getTime()); eventQueue.add(event); } } }
/** * Dispatches an event for a robot. * * <p>Too old events will not be dispatched and a critical event is always dispatched. * * @param event the event to dispatch to the robot. */ private void dispatch(Event event) { if (robot != null && event != null) { try { // skip too old events if ((event.getTime() > getTime() - MAX_EVENT_STACK) || HiddenAccess.isCriticalEvent(event)) { HiddenAccess.dispatch( event, robot, robotProxy.getStatics(), robotProxy.getGraphicsImpl()); } } catch (Exception ex) { robotProxy.println("SYSTEM: Exception occurred on " + event.getClass().getName()); ex.printStackTrace(robotProxy.getOut()); } } }
@Override protected void initializeRound(ExecCommands commands, RobotStatus status) { super.initializeRound(commands, status); isStopped = true; }
/** Returns the current time/turn of the battle round. */ public long getTime() { return robotProxy.getTimeImpl(); }