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; }
protected boolean doIExchangeThisCurrency(final Environmental affecting, final String currency) { final Map<String, Double> rates = getRatesFor(affecting, currency); return ((rates.size() == 0) || (rates.containsKey(currency.toUpperCase()))); }
protected double getMyCut(final Environmental affecting, final String currency) { final Map<String, Double> rates = getRatesFor(affecting, currency); if ((rates.size() > 0) && (rates.containsKey(currency.toUpperCase()))) return rates.get(currency.toUpperCase()).doubleValue(); return cut; }
protected String getDeviation(int val, Map<String, String> vals, String key) { if (!vals.containsKey(key)) return " - "; final int val2 = CMath.s_int(vals.get(key)); return getDeviation(val, val2); }