Ejemplo n.º 1
0
  protected final Map<String, Double> getRatesFor(final Environmental affecting, String currency) {
    if (spaceMaxCut <= 0.0) return rates;
    currency = currency.toUpperCase();
    if (rates.containsKey(currency)) return rates;
    String myCurrency = CMLib.beanCounter().getCurrency(affecting);
    if (myCurrency.equalsIgnoreCase(currency)) {
      rates.put(currency, Double.valueOf(cut));
      return rates;
    }
    SpaceObject homeO = CMLib.map().getSpaceObject(affecting, false);
    if (homeO != null) {
      myCurrency = CMLib.beanCounter().getCurrency(homeO);
      if (myCurrency.equalsIgnoreCase(currency)) {
        rates.put(currency, Double.valueOf(cut));
        return rates;
      }
    } else {
      // no space object, wtf? this SHOULD fail
      if (!complainedAboutSpaceError) {
        complainedAboutSpaceError = true;
        Log.errOut(
            "MoneyChanger", affecting.Name() + " is not on a planet, so space rates cannot apply!");
      }
      return rates;
    }
    for (Enumeration<Area> a = CMLib.map().spaceAreas(); a.hasMoreElements(); ) {
      Area A = a.nextElement();
      if ((A != null) && (A != homeO)) {
        myCurrency = CMLib.beanCounter().getCurrency(A);
        if (myCurrency.equalsIgnoreCase(currency)) {
          SpaceObject oA = (SpaceObject) A;
          long distance = CMLib.map().getDistanceFrom(homeO, oA);
          if ((distance < 0) || (distance > spaceMaxDistance)) {
            rates.put(currency, Double.valueOf(spaceMaxCut));
          } else {
            double pct = CMath.div(distance, spaceMaxDistance);
            double amt = spaceMaxCut * pct;
            if (amt < cut) amt = cut;
            rates.put(currency, Double.valueOf(cut));
          }
          return rates;
        }
      }
    }

    return rates;
  }