Exemplo n.º 1
0
    public void onStatus(StatusEvent e) {
      final RobotStatus s = e.getStatus();

      others = peer.getOthers();
      energy = Math.max(1, (int) (s.getEnergy() + 0.5));
      robotX = (int) (s.getX() + 0.5);
      robotY = (int) (s.getY() + 0.5);
      heading = (int) (toDegrees(s.getHeading()) + 0.5);
      gunHeading = (int) (toDegrees(s.getGunHeading()) + 0.5);
      gunBearing =
          (int) (toDegrees(Utils.normalRelativeAngle(s.getGunHeading() - s.getHeading())) + 0.5);
      gunReady = (s.getGunHeat() <= 0);

      currentTurn = e.getTime();

      // Auto fire
      if (juniorFirePower > 0 && gunReady && (peer.getGunTurnRemaining() == 0)) {
        if (peer.setFire(juniorFirePower) != null) {
          gunReady = false;
          juniorFirePower = 0;
        }
      }

      // Reset event data
      scannedDistance = -1;
      scannedAngle = -1;
      scannedBearing = -1;
      scannedVelocity = -99;
      scannedHeading = -1;
      scannedEnergy = -1;
      hitByBulletAngle = -1;
      hitByBulletBearing = -1;
      hitRobotAngle = -1;
      hitRobotBearing = -1;
      hitWallAngle = -1;
      hitWallBearing = -1;
    }
Exemplo n.º 2
0
  void handleStatusEvent(StatusEvent event) {
    AsteriskChannelImpl channel;
    final Extension extension;
    boolean isNew = false;
    Map<String, String> variables = event.getVariables();

    channel = getChannelImplById(event.getUniqueId());
    if (channel == null) {
      Date dateOfCreation;

      if (event.getSeconds() != null) {
        dateOfCreation = new Date(DateUtil.getDate().getTime() - (event.getSeconds() * 1000L));
      } else {
        dateOfCreation = DateUtil.getDate();
      }
      channel =
          new AsteriskChannelImpl(server, event.getChannel(), event.getUniqueId(), dateOfCreation);
      isNew = true;
      if (variables != null) {
        for (String variable : variables.keySet()) {
          channel.updateVariable(variable, variables.get(variable));
        }
      }
    }

    if (event.getContext() == null && event.getExtension() == null && event.getPriority() == null) {
      extension = null;
    } else {
      extension = new Extension(event.getContext(), event.getExtension(), event.getPriority());
    }

    synchronized (channel) {
      channel.setCallerId(new CallerId(event.getCallerIdName(), event.getCallerIdNum()));
      channel.setAccount(event.getAccountCode());
      if (event.getChannelState() != null) {
        channel.stateChanged(
            event.getDateReceived(), ChannelState.valueOf(event.getChannelState()));
      }
      channel.extensionVisited(event.getDateReceived(), extension);

      if (event.getBridgedChannel() != null) {
        final AsteriskChannelImpl linkedChannel = getChannelImplByName(event.getBridgedChannel());
        if (linkedChannel != null) {
          // the date used here is not correct!
          channel.channelLinked(event.getDateReceived(), linkedChannel);
          synchronized (linkedChannel) {
            linkedChannel.channelLinked(event.getDateReceived(), channel);
          }
        }
      }
    }

    if (isNew) {
      logger.info("Adding new channel " + channel.getName());
      addChannel(channel);
      server.fireNewAsteriskChannel(channel);
    }
  }