Esempio n. 1
0
 /**
  * Adds an event to the event queue.
  *
  * @param event is the event to add to the event queue.
  */
 public void add(Event event) {
   if (!HiddenAccess.isCriticalEvent(event)) {
     final int priority = getEventPriority(event.getClass().getName());
     HiddenAccess.setEventPriority(event, priority);
   }
   addImpl(event);
 }
Esempio n. 2
0
 /**
  * Registers the full and simple class name of the specified event and sets the default priority
  * of the event class.
  *
  * @param event an event belonging to the event class to register the class name for etc.
  */
 private void registerEventNames(Event event) {
   if (!HiddenAccess.isCriticalEvent(event)) {
     HiddenAccess.setDefaultPriority(event);
   }
   final Class<?> type = event.getClass();
   eventNames.put(type.getName(), event); // full name with package name
   eventNames.put(type.getSimpleName(), event); // only the class name
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
0
 /**
  * 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());
     }
   }
 }
Esempio n. 5
0
 /**
  * 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);
     }
   }
 }
Esempio n. 6
0
  @Override
  protected final void executeImpl() {
    if (execResults == null) {
      // this is to slow down undead robot after cleanup, from fast exception-loop
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ignore) {
      }
    }

    // Entering tick
    robotThreadManager.checkRunThread();
    if (testingCondition) {
      throw new RobotException(
          "You cannot take action inside Condition.test().  You should handle onCustomEvent instead.");
    }

    setSetCallCount(0);
    setGetCallCount(0);

    // This stops autoscan from scanning...
    if (waitCondition != null && waitCondition.test()) {
      waitCondition = null;
      commands.setScan(true);
    }

    commands.setOutputText(out.readAndReset());
    commands.setGraphicsCalls(graphicsProxy.readoutQueuedCalls());

    // Call server
    execResults = peer.executeImpl(commands);

    updateStatus(execResults.getCommands(), execResults.getStatus());

    graphicsProxy.setPaintingEnabled(execResults.isPaintEnabled());
    firedEnergy = 0;
    firedHeat = 0;

    // add new events
    eventManager.add(new StatusEvent(execResults.getStatus()));
    if (statics.isPaintRobot() && execResults.isPaintEnabled()) {
      // Add paint event, if robot is a paint robot and its painting is enabled
      eventManager.add(new PaintEvent());
    }

    // add other events
    if (execResults.getEvents() != null) {
      for (Event event : execResults.getEvents()) {
        eventManager.add(event);
      }
    }

    if (execResults.getBulletUpdates() != null) {
      for (BulletStatus bulletStatus : execResults.getBulletUpdates()) {
        final Bullet bullet = bullets.get(bulletStatus.bulletId);

        if (bullet != null) {
          HiddenAccess.update(
              bullet,
              bulletStatus.x,
              bulletStatus.y,
              bulletStatus.victimName,
              bulletStatus.isActive);
          if (!bulletStatus.isActive) {
            bullets.remove(bulletStatus.bulletId);
          }
        }
      }
    }

    // add new team messages
    loadTeamMessages(execResults.getTeamMessages());

    eventManager.processEvents();
  }
Esempio n. 7
0
 public static void main(final String[] args) {
   HiddenAccess.robocodeMain(args);
 }