예제 #1
0
  /**
   * All build options require that appropriate units are built in appropriate places (e.g., armies
   * can't go in the water, fleets can't go in landlocked provinces, fleets must have coasts
   * specified if required, etc.). This method takes care of that.
   *
   * <p>returns false if we cannot build here.
   */
  private boolean checkBuildUnit(
      StateInfo stateInfo, Province province, Location loc, StringBuffer sb) {
    if (srcUnitType == null) {
      sb.append(Utils.getLocalString(NOBUILD_NO_UNIT_SELECTED));
      return false;
    }

    if (srcUnitType.equals(Unit.Type.ARMY)) {
      if (province.isSea()) {
        sb.append(Utils.getLocalString(NOBUILD_NO_ARMY_IN_SEA));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_ARMY_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.FLEET)) {
      if (province.isLandLocked()) {
        sb.append(Utils.getLocalString(NOBUILD_FLEET_LANDLOCKED));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_FLEET_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.WING)) {
      // check borders
      if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
        return false;
      }

      sb.append(Utils.getLocalString(BUILD_WING_OK));
      return true;
    }

    // this should not occur.
    sb.append("** Unknown unit type! **");
    return false;
  } // checkBuildUnit()
예제 #2
0
  @Override
  public boolean testLocation(StateInfo stateInfo, Location location, StringBuffer sb) {
    sb.setLength(0);

    if (isComplete()) {
      sb.append(Utils.getLocalString(GUIOrder.COMPLETE, getFullName()));
      return false;
    }

    Position position = stateInfo.getPosition();
    Province province = location.getProvince();

    if (province.hasSupplyCenter()) {
      Power SCOwner = position.getSupplyCenterOwner(province);

      // general screening, applicable to all build options
      //
      if (SCOwner == null) {
        sb.append(Utils.getLocalString(NOBUILD_UNOWNED_SC));
        return false;
      }

      if (position.hasUnit(province)) {
        sb.append(Utils.getLocalString(NOBUILD_UNIT_PRESENT));
        return false;
      }

      if (!stateInfo.canIssueOrder(SCOwner)) {
        sb.append(Utils.getLocalString(NOBUILD_SC_NOT_CONTROLLED));
        return false;
      }

      // indicate if we have no builds available
      //
      Adjustment.AdjustmentInfo adjInfo = stateInfo.getAdjustmenInfoMap().get(SCOwner);
      if (adjInfo.getAdjustmentAmount() <= 0) {
        sb.append(Utils.getLocalString(NOBUILD_NO_BUILDS_AVAILABLE, SCOwner.getName()));
        return false;
      }

      // build-option-specific, based upon RuleOptions
      //
      RuleOptions ruleOpts = stateInfo.getRuleOptions();
      if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_OWNED) {
        return checkBuildUnit(stateInfo, province, location, sb);
      } else if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_IF_HOME_OWNED) {
        // check if we have ONE owned home supply center before buidling
        // in a non-home supply center.
        //
        if (SCOwner != position.getSupplyCenterHomePower(province)
            && !position.hasAnOwnedHomeSC(SCOwner)) {
          sb.append(Utils.getLocalString(NOBUILD_NEED_ONE_OWNED_SC));
          return false; // failed
        }

        // we (probably) can build here
        return checkBuildUnit(stateInfo, province, location, sb);
      } else {
        // build only in owned HOME supply centers
        //
        if (SCOwner == position.getSupplyCenterHomePower(province)) {
          // we (probably) can build here
          return checkBuildUnit(stateInfo, province, location, sb);
        }

        // build failure.
        sb.append(Utils.getLocalString(NOBUILD_NOT_OWNED_HOME_SC));
        return false;
      }
    } else {
      sb.append(Utils.getLocalString(NOBUILD_MUST_BE_AN_OWNED_SC));
      return false;
    }

    // NO return here: thus we must appropriately exit within an if/else block above.
  } // testLocation()