/**
   * Initialize this entity for an object.
   *
   * @param base The object.
   * @see #release()
   */
  @Override
  public void initialize(final RPObject base) {
    double speed;

    super.initialize(base);

    if (base.has("dir")) {
      setDirection(Direction.build(base.getInt("dir")));
    }

    if (base.has("speed")) {
      speed = base.getDouble("speed");
    } else {
      speed = 0.0;
    }

    dx = direction.getdx() * speed;
    dy = direction.getdy() * speed;
  }
  /**
   * Process attribute changes that may affect positioning. This is needed because different
   * entities may want to process coordinate changes more gracefully.
   *
   * @param base The previous values.
   * @param diff The changes.
   */
  @Override
  protected void processPositioning(final RPObject base, final RPObject diff) {
    // Real movement case
    final int oldx = base.getInt("x");
    final int oldy = base.getInt("y");

    int newX = oldx;
    int newY = oldy;

    if (diff.has("x")) {
      newX = diff.getInt("x");
    }
    if (diff.has("y")) {
      newY = diff.getInt("y");
    }

    Direction tempDirection;

    if (diff.has("dir")) {
      tempDirection = Direction.build(diff.getInt("dir"));
      setDirection(tempDirection);
    } else if (base.has("dir")) {
      tempDirection = Direction.build(base.getInt("dir"));
      setDirection(tempDirection);
    } else {
      tempDirection = Direction.STOP;
    }

    double speed;

    /*
     * Speed change must be fired only after the new speed has been stored
     * (done in onMove())
     */
    boolean speedChanged = false;

    if (diff.has("speed")) {
      speed = diff.getDouble("speed");
      speedChanged = true;
    } else if (base.has("speed")) {
      speed = base.getDouble("speed");
    } else {
      speed = 0;
    }

    onMove(newX, newY, tempDirection, speed);

    if (speedChanged) {
      fireChange(PROP_SPEED);
    }

    boolean positionChanged = false;
    if ((Direction.STOP.equals(tempDirection)) || (speed == 0)) {
      setSpeed(0.0, 0.0);

      /*
       * Try to ensure relocation in the case the client and server were
       * in disagreement about the position at the moment of stopping.
       */
      if (!(compareDouble(y, newY, EPSILON) && compareDouble(x, newX, EPSILON))) {
        positionChanged = true;
      }

      // Store the new position before signaling it with onPosition().
      x = newX;
      y = newY;
    }

    /*
     * Change in position?
     */
    if (positionChanged || ((oldx != newX) && (oldy != newY))) {
      onPosition(newX, newY);
    }
  }