/** 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);
  }
Beispiel #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;
    }
 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;
 }
Beispiel #4
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();
  }