Ejemplo n.º 1
0
 // update the input-link appropriately
 @Override
 public synchronized void updateInputLink(Identifier parentIdentifier) {
   if (poseID == null) {
     // Create the pose on the input link
     poseID = parentIdentifier.CreateIdWME("pose");
     wmes = new FloatElement[6];
     for (int i = 0; i < 6; i++) {
       wmes[i] = poseID.CreateFloatWME(poseStrings[i], pose[i]);
     }
   } else {
     // Update the pose on the input link
     for (int i = 0; i < 6; i++) {
       if (wmes[i].GetValue() != pose[i]) {
         wmes[i].Update(pose[i]);
       }
     }
   }
 }
Ejemplo n.º 2
0
  // remove the object from the input-link
  @Override
  public synchronized void destroy() {
    if (wmes != null) {
      for (int i = 0; i < 6; i++) {
        wmes[i].DestroyWME();
      }
      wmes = null;

      poseID.DestroyWME();
      poseID = null;
    }
  }
  public CommandInfo nextCommand() {
    // if there was no command issued, that is kind of strange
    if (agent.GetNumberCommands() == 0) {
      if (logger.isDebugEnabled()) {
        logger.debug(player.getName() + " issued no command.");
      }
      return new CommandInfo();
    }

    // go through the commands
    // see move info for details
    CommandInfo move = new CommandInfo();
    boolean moveWait = false;
    if (agent.GetNumberCommands() > 1) {
      logger.debug(
          player.getName()
              + ": "
              + agent.GetNumberCommands()
              + " commands detected, all but the first will be ignored");
    }
    for (int i = 0; i < agent.GetNumberCommands(); ++i) {
      Identifier commandId = agent.GetCommand(i);
      String commandName = commandId.GetAttribute();

      if (commandName.equalsIgnoreCase(Names.kMoveID)) {
        if (move.move || moveWait) {
          logger.debug(player.getName() + ": multiple move commands detected");
          commandId.AddStatusError();
          continue;
        }
        move.move = true;

        String direction = commandId.GetParameterValue(Names.kDirectionID);
        if (direction != null) {
          if (direction.equals(Names.kNone)) {
            // legal wait
            move.move = false;
            moveWait = true;
            commandId.AddStatusComplete();
            continue;
          } else {
            move.moveDirection = Direction.parse(direction);
            commandId.AddStatusComplete();
            continue;
          }
        }

      } else if (commandName.equalsIgnoreCase(Names.kStopSimID)) {
        if (move.stopSim) {
          logger.debug(player.getName() + ": multiple stop commands detected, ignoring");
          commandId.AddStatusError();
          continue;
        }
        move.stopSim = true;
        commandId.AddStatusComplete();
        continue;

      } else if (commandName.equalsIgnoreCase(Names.kPickUpID)) {
        if (move.pickup) {
          logger.debug(
              player.getName() + ": multiple " + Names.kPickUpID + " commands detected, ignoring");
          commandId.AddStatusError();
          continue;
        }
        move.pickup = true;
        commandId.AddStatusComplete();
        continue;

      } else if (commandName.equalsIgnoreCase(Names.kPutDownID)) {
        if (move.putdown) {
          logger.debug(
              player.getName() + ": multiple " + Names.kPutDownID + " commands detected, ignoring");
          commandId.AddStatusError();
          continue;
        }
        move.putdown = true;
        commandId.AddStatusComplete();
        continue;

      } else if (commandName.equalsIgnoreCase(Names.kFillUpID)) {
        if (move.fillup) {
          logger.debug(
              player.getName() + ": multiple " + Names.kFillUpID + " commands detected, ignoring");
          commandId.AddStatusError();
          continue;
        }
        move.fillup = true;
        commandId.AddStatusComplete();
        continue;

      } else {
        logger.warn("Unknown command: " + commandName);
        commandId.AddStatusError();
        continue;
      }

      logger.warn("Improperly formatted command: " + commandName);
      commandId.AddStatusError();
    }
    agent.ClearOutputLinkChanges();

    if (!agent.Commit()) {
      Gridmap2D.control.errorPopUp(Names.Errors.commitFail + player.getName());
      Gridmap2D.control.stopSimulation();
    }

    return move;
  }