Exemplo n.º 1
0
  @Override
  protected final void waitForBattleEndImpl() {
    eventManager.clearAllEvents(false);
    graphicsProxy.setPaintingEnabled(false);
    do {
      // Make sure remaining system events like e.g. are processed this round
      try {
        eventManager.processEvents();

        // The exceptions below are expected to occur, and has already been logged in the robot
        // console,
        // but still exists in the robot's event queue. Hence we just ignore these!
        // Look in the HostingRobotProxy.run() to see which robot errors that are already handled.
      } catch (DeathException ignore) {
      } catch (WinException ignore) { // Bug fix [2952549]
      } catch (AbortedException ignore) {
      } catch (DisabledException ignore) { // Bug fix [2976258]
      }

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

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

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

      // Add remaining events like BattleEndedEvent Otherwise, the robot might never receive those
      // events
      if (execResults.getEvents() != null) {
        for (Event event : execResults.getEvents()) {
          if (event instanceof BattleEndedEvent) {
            eventManager.add(event);
          }
        }
      }
      eventManager.resetCustomEvents();
    } while (!execResults.isHalt() && execResults.isShouldWait());
  }
Exemplo n.º 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();
  }