@Override
        public void addJobless(IManageableBearer bearer) {
          if (!materials.isEmpty()) {
            ShortPoint2D source = materials.pop();
            final ShortPoint2D targetPos =
                new ShortPoint2D(
                    MatchConstants.random().nextInt(width),
                    MatchConstants.random().nextInt(height));
            bearer.deliver(
                materialTypeMap[source.x][source.y],
                source,
                new IMaterialRequest() {

                  @Override
                  public ShortPoint2D getPos() {
                    return targetPos;
                  }

                  @Override
                  public boolean isActive() {
                    return true;
                  }

                  @Override
                  public void deliveryFulfilled() {}

                  @Override
                  public void deliveryAccepted() {}

                  @Override
                  public void deliveryAborted() {}
                });
          }
        }
Esempio n. 2
0
  public static void compareMapFiles(MapLoader expectedSavegame, MapLoader actualSavegame)
      throws IOException, MapLoadException, ClassNotFoundException {
    System.out.println(
        "Comparing expected '"
            + expectedSavegame
            + "' with actual '"
            + actualSavegame
            + "' (uncompressed!)");

    try (InputStream expectedStream =
            RemakeMapLoader.getMapInputStream(expectedSavegame.getListedMap());
        CountingInputStream actualStream =
            new CountingInputStream(
                RemakeMapLoader.getMapInputStream(actualSavegame.getListedMap()))) {
      MapFileHeader expectedHeader = MapFileHeader.readFromStream(expectedStream);
      MatchConstants.init(new NetworkTimer(true), 0L);
      MatchConstants.deserialize(new ObjectInputStream(expectedStream));
      int expectedTime = MatchConstants.clock().getTime();
      ExtendedRandom expectedRandom = MatchConstants.random();
      MatchConstants.clearState();

      MapFileHeader actualHeader = MapFileHeader.readFromStream(actualStream);
      MatchConstants.init(new NetworkTimer(true), 1L);
      MatchConstants.deserialize(new ObjectInputStream(actualStream));
      int actualTime = MatchConstants.clock().getTime();
      ExtendedRandom actualRandom = MatchConstants.random();
      MatchConstants.clearState();

      assertEquals(expectedHeader.getBaseMapId(), actualHeader.getBaseMapId());
      assertEquals(expectedTime, actualTime);
      // Test the random behavior a bit to have a high probability of equality. An equals method
      // does not exist for Random.
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());

      int e, a;
      while (((e = expectedStream.read()) != -1) & ((a = actualStream.read()) != -1)) {
        assertEquals("difference at (uncompressed) byte " + actualStream.getByteCounter(), e, a);
      }
      assertEquals("files have different lengths (uncompressed)", e, a);
    }
  }
  private ShortPoint2D getDiggablePosition() {
    RelativePoint[] blockedTiles = requester.getBuildingType().getProtectedTiles();
    ShortPoint2D buildingPos = requester.getPos();
    int offset = MatchConstants.random().nextInt(blockedTiles.length);

    for (int i = 0; i < blockedTiles.length; i++) {
      ShortPoint2D pos =
          blockedTiles[(i + offset) % blockedTiles.length].calculatePoint(buildingPos);
      if (!super.getGrid().isMarked(pos) && needsToBeWorkedOn(pos)) {
        return pos;
      }
    }
    return null;
  }
  private MovableTestWindow() throws InterruptedException {
    MatchConstants.init(new NetworkTimer(true), 1000);
    MatchConstants.clock().startExecution();

    MovableTestsMap grid = new MovableTestsMap(100, 100, PLAYER_0);
    MapInterfaceConnector connector = TestUtils.openTestWindow(grid);

    movable =
        new Movable(
            grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(49, 50), PLAYER_0);
    movable.setSelected(true);

    connector.setSelection(new SelectionSet(movable));

    connector.addListener(
        new IMapInterfaceListener() {
          @Override
          public void action(Action action) {
            switch (action.getActionType()) {
              case MOVE_TO:
                movable.moveTo(((PointAction) action).getPosition());
                break;
              case SPEED_FASTER:
                MatchConstants.clock().multiplyGameSpeed(1.2f);
                break;
              case SPEED_SLOWER:
                MatchConstants.clock().multiplyGameSpeed(1 / 1.2f);
                break;
              case FAST_FORWARD:
                MatchConstants.clock().fastForward();
                break;
              default:
                break;
            }
          }
        });

    grid.getMovableGrid().dropMaterial(new ShortPoint2D(40, 40), EMaterialType.PLANK, true);
    grid.getMovableGrid().dropMaterial(new ShortPoint2D(60, 60), EMaterialType.STONE, true);

    new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(30, 30), PLAYER_0);
    new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(31, 31), PLAYER_0);
    new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(32, 32), PLAYER_0);
    new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(33, 33), PLAYER_0);

    new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(50, 50), PLAYER_0);

    { // test automatic distribution of many movables next to each other
      for (int x = 30; x < 40; x++) {
        for (int y = 80; y < 90; y++) {
          new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(x, y), PLAYER_0);
        }
      }
    }

    {
      Thread.sleep(3000);
      // circle of three movables blocking each others path
      Movable m1 =
          new Movable(
              grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(50, 65), PLAYER_0);
      Movable m2 =
          new Movable(
              grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(51, 65), PLAYER_0);
      Movable m3 =
          new Movable(
              grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(50, 64), PLAYER_0);

      m1.moveTo(new ShortPoint2D(52, 65));
      m2.moveTo(new ShortPoint2D(49, 63));
      m3.moveTo(new ShortPoint2D(50, 66));
    }
  }