Exemple #1
0
  /**
   * Create a <use> element with a SYMBOL_FAILEDORDER at the given coordinates, sized
   * appropriately.
   */
  public static SVGUseElement createFailedOrderSymbol(MapInfo mapInfo, float x, float y) {
    MapMetadata.SymbolSize symbolSize =
        mapInfo.getMapMetadata().getSymbolSize(DefaultMapRenderer2.SYMBOL_FAILEDORDER);

    return SVGUtils.createUseElement(
        mapInfo.getDocument(),
        "#" + DefaultMapRenderer2.SYMBOL_FAILEDORDER,
        null, // no id
        null, // no special style
        x,
        y,
        symbolSize);
  } // createFailedOrderSymbol()
Exemple #2
0
  /**
   * Returns true if the given power is a member of the displayble powers group, <b>or</b> the
   * TurnState is resolved (and orders for all powers can be shown)
   */
  public static boolean isDisplayable(final Power power, final MapInfo mapInfo) {
    if (mapInfo.getTurnState().isResolved()) {
      return true;
    }

    final Power[] displayedPowers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < displayedPowers.length; i++) {
      if (displayedPowers[i] == power) {
        return true;
      }
    }

    return false;
  } // isDisplayable()
Exemple #3
0
  /**
   * Given a TurnState, determines if any order exists that matches the given Hold order. Returns
   * null if no matching Hold order found.
   */
  public static Hold findMatchingHold(MapInfo mapInfo, Province src) {
    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Hold && o.getSource().isProvinceEqual(src)) {
          return (Hold) o;
        }
      }
    }

    return null;
  } // findMatchingHold()
Exemple #4
0
  /**
   * Given a TurnState, determines if any order exists that matches the given Move order. Returns
   * null if no matching Move order found.
   */
  public static Move findMatchingMove(MapInfo mapInfo, Province src, Province dest) {
    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Move) {
          Move mv = (Move) o;
          if (mv.getSource().isProvinceEqual(src) && mv.getDest().isProvinceEqual(dest)) {
            return mv;
          }
        }
      }
    }

    return null;
  } // findMatchingMove()
Exemple #5
0
  /**
   * Given a TurnState, determines if the number (if any) of . Support orders that match the given
   * Move or Hold order. (use src == dest for Hold orders)
   *
   * <p>Note that only the displayable powers are used to check the support.
   */
  public static int getMatchingSupportCount(MapInfo mapInfo, Province supSrc, Province supDest) {
    int count = 0;

    Power[] powers = mapInfo.getDisplayablePowers();
    for (int i = 0; i < powers.length; i++) {
      List<Orderable> orders = mapInfo.getTurnState().getOrders(powers[i]);
      Iterator<Orderable> iter = orders.iterator();
      while (iter.hasNext()) {
        Orderable o = iter.next();
        if (o instanceof Support) {
          Support sup = (Support) o;
          if (sup.getSupportedSrc().isProvinceEqual(supSrc)
              && sup.getSupportedDest().isProvinceEqual(supDest)) {
            count++;
          }
        }
      }
    }

    return count;
  } // findMatchingSupports()
Exemple #6
0
  /**
   * Checks that support width is in-bounds. Note that negative widths are possible (see the base
   * move modifier; e.g., Loeb9). If the support is out-of-bounds (max), the largest width is
   * returned.
   *
   * <p>All negative widths are treated alike; DPB_LINE_WIDTH times the value of the smallest width
   * in the line-width list (index 0).
   */
  public static float getLineWidth(
      MapInfo mapInfo, String mmdElementName, String mmdElementType, int support) {
    int idx = support;
    if (support < 0) {
      idx = 0;
    }

    final float[] widths =
        mapInfo.getMapMetadata().getOrderParamFloatArray(mmdElementName, mmdElementType);
    if (support >= widths.length) {
      return widths[widths.length - 1];
    }

    return (support >= 0) ? widths[idx] : (widths[idx] * DPB_LINE_WIDTH);
  } // getLineWidth()