예제 #1
0
  @Override
  public void cleanup() {
    super.cleanup();

    // Cleanup and remove current wait condition
    if (waitCondition != null) {
      waitCondition.cleanup();
      waitCondition = null;
    }

    // Cleanup and remove the event manager
    if (eventManager != null) {
      eventManager.cleanup();
      eventManager = null;
    }

    // Cleanup graphics proxy
    graphicsProxy = null;
    execResults = null;
    status = null;
    commands = null;
  }
예제 #2
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();
  }