예제 #1
0
 protected final void setMoveImpl(double distance) {
   if (getEnergyImpl() == 0) {
     return;
   }
   commands.setDistanceRemaining(distance);
   commands.setMoved(true);
 }
예제 #2
0
  private final Bullet setFireImpl(double power) {
    if (Double.isNaN(power)) {
      println("SYSTEM: You cannot call fire(NaN)");
      return null;
    }
    if (getGunHeatImpl() > 0 || getEnergyImpl() == 0) {
      return null;
    }

    power = min(getEnergyImpl(), min(max(power, Rules.MIN_BULLET_POWER), Rules.MAX_BULLET_POWER));

    Bullet bullet;
    BulletCommand wrapper;
    Event currentTopEvent = eventManager.getCurrentTopEvent();

    nextBulletId++;

    if (currentTopEvent != null
        && currentTopEvent.getTime() == status.getTime()
        && !statics.isAdvancedRobot()
        && status.getGunHeadingRadians() == status.getRadarHeadingRadians()
        && ScannedRobotEvent.class.isAssignableFrom(currentTopEvent.getClass())) {
      // this is angle assisted bullet
      ScannedRobotEvent e = (ScannedRobotEvent) currentTopEvent;
      double fireAssistAngle =
          Utils.normalAbsoluteAngle(status.getHeadingRadians() + e.getBearingRadians());

      bullet =
          new Bullet(
              fireAssistAngle, getX(), getY(), power, statics.getName(), null, true, nextBulletId);
      wrapper = new BulletCommand(power, true, fireAssistAngle, nextBulletId);
    } else {
      // this is normal bullet
      bullet =
          new Bullet(
              status.getGunHeadingRadians(),
              getX(),
              getY(),
              power,
              statics.getName(),
              null,
              true,
              nextBulletId);
      wrapper = new BulletCommand(power, false, 0, nextBulletId);
    }

    firedEnergy += power;
    firedHeat += Rules.getGunHeat(power);

    commands.getBullets().add(wrapper);

    bullets.put(nextBulletId, bullet);

    return bullet;
  }
예제 #3
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());
  }
예제 #4
0
  public void rescan() {
    boolean reset = false;
    boolean origInterruptableValue = false;

    if (eventManager.getCurrentTopEventPriority() == eventManager.getScannedRobotEventPriority()) {
      reset = true;
      origInterruptableValue =
          eventManager.isInterruptible(eventManager.getScannedRobotEventPriority());
      eventManager.setInterruptible(eventManager.getScannedRobotEventPriority(), true);
    }

    commands.setScan(true);
    executeImpl();

    if (reset) {
      eventManager.setInterruptible(
          eventManager.getScannedRobotEventPriority(), origInterruptableValue);
    }
  }
예제 #5
0
 protected final void setTurnRadarImpl(double radians) {
   commands.setRadarTurnRemaining(radians);
 }
예제 #6
0
 protected final void setTurnBodyImpl(double radians) {
   if (getEnergyImpl() > 0) {
     commands.setBodyTurnRemaining(radians);
   }
 }
예제 #7
0
 protected final void setTurnGunImpl(double radians) {
   commands.setGunTurnRemaining(radians);
 }
예제 #8
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();
  }
예제 #9
0
 public void setDebugProperty(String key, String value) {
   setCall();
   commands.setDebugProperty(key, value);
 }
예제 #10
0
 public Graphics2D getGraphics() {
   getCall();
   commands.setTryingToPaint(true);
   return getGraphicsImpl();
 }
예제 #11
0
 public double getGunTurnRemaining() {
   getCall();
   return commands.getGunTurnRemaining();
 }
예제 #12
0
 public double getDistanceRemaining() {
   getCall();
   return commands.getDistanceRemaining();
 }
예제 #13
0
 public void setScanColor(Color color) {
   setCall();
   commands.setScanColor(color != null ? color.getRGB() : ExecCommands.defaultScanColor);
 }