예제 #1
0
  /** Tests invalid completion of buildable, having enough resources */
  public void testInvalidCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony(2);
    Building carpenterHouse = colony.getBuilding(carpenterHouseType);
    assertEquals(
        "Colony should not have lumber mill", carpenterHouse, colony.getBuilding(lumberMillType));
    assertFalse("Colony should not be able to build lumber mill", colony.canBuild(lumberMillType));
    colony.setCurrentlyBuilding(lumberMillType);
    assertEquals(
        "Colony should be building lumber mill", lumberMillType, colony.getCurrentlyBuilding());
    // Add sufficient units and goods to build lumber mill.
    Unit unit = new ServerUnit(game, colony.getTile(), colony.getOwner(), colonistType);
    unit.setLocation(colony);
    for (AbstractGoods ag : lumberMillType.getRequiredGoods()) {
      GoodsType type = ag.getType();
      int amount = ag.getAmount() + 1;
      colony.addGoods(type, amount);
      assertEquals("Wrong quantity of " + type, amount, colony.getGoodsCount(type));
    }

    // Allow the building to finish
    ServerTestHelper.newTurn();

    assertEquals(
        "Colony should have lumber mill",
        lumberMillType,
        colony.getBuilding(lumberMillType).getType());
    assertFalse(
        "Colony should no longer be building lumber mill",
        colony.getCurrentlyBuilding() == lumberMillType);
  }
예제 #2
0
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      BuildableType item = (BuildableType) value;
      JPanel panel = isSelected ? selectedPanel : itemPanel;
      panel.removeAll();

      ((ImageIcon) imageLabel.getIcon())
          .setImage(ResourceManager.getImage(item.getId() + ".image", buildingDimension));

      nameLabel.setText(Messages.message(item.getNameKey()));
      panel.setToolTipText(lockReasons.get(item));
      panel.add(imageLabel, "span 1 2");
      if (lockReasons.get(item) == null) {
        panel.add(nameLabel, "wrap");
      } else {
        panel.add(nameLabel, "split 2");
        panel.add(lockLabel, "wrap");
      }

      List<AbstractGoods> required = item.getRequiredGoods();
      int size = required.size();
      for (int i = 0; i < size; i++) {
        AbstractGoods goods = required.get(i);
        ImageIcon icon =
            new ImageIcon(ResourceManager.getImage(goods.getType().getId() + ".image", 0.66));
        JLabel goodsLabel =
            new JLabel(Integer.toString(goods.getAmount()), icon, SwingConstants.CENTER);
        if (i == 0 && size > 1) {
          panel.add(goodsLabel, "split " + size);
        } else {
          panel.add(goodsLabel);
        }
      }
      return panel;
    }
예제 #3
0
  private void initialize(BuildableType buildable) {

    removeAll();

    if (buildable == null) {
      String clickToBuild = Messages.message(getDefaultLabel());
      int breakingPoint = Messages.getBreakingPoint(clickToBuild);
      if (breakingPoint > 0) {
        add(new JLabel(clickToBuild.substring(0, breakingPoint)), "span, align center");
        add(new JLabel(clickToBuild.substring(breakingPoint + 1)), "span, align center");
      } else {
        add(new JLabel(clickToBuild), "span, align center");
      }
    } else {
      int turnsToComplete = colony.getTurnsToComplete(buildable);
      String turnsStr = Messages.getTurnsText(turnsToComplete);
      add(
          new JLabel(new ImageIcon(ResourceManager.getImage(buildable.getId() + ".image", 0.75))),
          "spany");
      add(
          new JLabel(
              Messages.message(
                  StringTemplate.template("colonyPanel.currentlyBuilding")
                      .addName("%buildable%", buildable))));

      add(
          new JLabel(
              Messages.message(
                  StringTemplate.template("turnsToComplete.long").addName("%number%", turnsStr))));

      for (AbstractGoods requiredGoods : buildable.getGoodsRequired()) {
        int amountNeeded = requiredGoods.getAmount();
        int amountAvailable = colony.getGoodsCount(requiredGoods.getType());
        int amountProduced = colony.getAdjustedNetProductionOf(requiredGoods.getType());
        add(
            new FreeColProgressBar(
                gui, requiredGoods.getType(), 0, amountNeeded, amountAvailable, amountProduced),
            "height 20:");
      }
    }

    revalidate();
    repaint();
  }
예제 #4
0
  public void testEqualFoodProductionConsumptionCase() {
    Game game = ServerTestHelper.startServerGame(getTestMap(desert));

    // Setting test colony
    Tile colonyTile = game.getMap().getTile(5, 8);
    Colony colony =
        FreeColTestUtils.getColonyBuilder().colonyTile(colonyTile).initialColonists(1).build();

    // Set the food production of the center tile of the colony to 2
    // This will be the only food production of the colony
    List<AbstractGoods> colonyTileProduction = colonyTile.getType().getPossibleProduction(true);
    for (int i = 0; i < colonyTileProduction.size(); i++) {
      AbstractGoods production = colonyTileProduction.get(i);
      if (production.getType() == foodGoodsType) {
        production.setAmount(2);
        break;
      }
    }
    Unit unit = colony.getUnitList().get(0);
    unit.setLocation(colony.getWorkLocationFor(unit, bellsType));

    // Verify that there is enough food stored
    colony.addGoods(foodGoodsType, colony.getFoodConsumption() * 2);

    assertEquals(
        "Production not equal to consumption",
        colony.getFoodConsumption(),
        colony.getFoodProduction());

    int colonists = colony.getUnitCount();
    assertEquals("Unexpected change of colonists in colony", colonists, colony.getUnitCount());

    assertEquals(
        "Unexpected change of production/consumption ratio",
        colony.getFoodProduction(),
        colony.getFoodConsumption());
  }
예제 #5
0
 private boolean equipUnitIfPossible(UnitLabel unitLabel, AbstractGoods goods) {
   Unit unit = unitLabel.getUnit();
   if (unit.hasAbility(Ability.CAN_BE_EQUIPPED)) {
     for (EquipmentType equipment :
         freeColClient.getGame().getSpecification().getEquipmentTypeList()) {
       if (unit.canBeEquippedWith(equipment) && equipment.getGoodsRequired().size() == 1) {
         AbstractGoods requiredGoods = equipment.getGoodsRequired().get(0);
         if (requiredGoods.getType().equals(goods.getType())
             && requiredGoods.getAmount() <= goods.getAmount()) {
           int amount =
               Math.min(
                   goods.getAmount() / requiredGoods.getAmount(), equipment.getMaximumCount());
           freeColClient.getInGameController().equipUnit(unit, equipment, amount);
           unitLabel.updateIcon();
           return true;
         }
       }
     }
   }
   return false;
 }