Esempio n. 1
0
 /**
  * Loads orders for a particular power into the most recent turn state. Overwrites any existing
  * orders for the given power.
  *
  * @param orderStrings the orders to load
  * @param powerToSet the power to load against
  * @throws PowerNotFoundException
  * @throws JdipException
  */
 public void setOrders(String[] orderStrings, JdipPower powerToSet)
     throws PowerNotFoundException, JdipException {
   // fetch the power
   Power power = powerToSet.getPower();
   if (power == null) {
     throw new PowerNotFoundException();
   }
   // parse the orders
   ArrayList orders = new ArrayList();
   OrderParser parser = OrderParser.getInstance();
   OrderFactory of = strategy.getOrderFactory();
   try {
     for (int i = 0; i < orderStrings.length; i++) {
       Order o =
           parser.parse(
               of,
               power.getName() + " " + orderStrings[i],
               power,
               world.getLastTurnState(),
               true,
               false);
       orders.add(o);
     }
   } catch (OrderException e) {
     throw new JdipException(e.getMessage() + " <" + e.getOrder() + ">", e);
   }
   // set the orders
   world.getLastTurnState().setOrders(power, orders);
 }
Esempio n. 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()