@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() {}
                });
          }
        }
Exemplo 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;
  }