public List<Ability> getClanLevelEffectsList(final MOB mob, final Integer level) {
    if (clanEffectNames == null) return empty;

    if ((clanEffectMap == null)
        && (clanEffectNames != null)
        && (clanEffectLevels != null)
        && (clanEffectParms != null)) clanEffectMap = new Hashtable<Integer, List<Ability>>();

    if (clanEffectMap == null) return empty;

    if (clanEffectMap.containsKey(level)) return clanEffectMap.get(level);
    final CMObjUniqSortSVec<Ability> finalV = new CMObjUniqSortSVec<Ability>();
    for (int v = 0; v < clanEffectLevels.length; v++) {
      if ((clanEffectLevels[v] <= level.intValue())
          && (clanEffectNames.length > v)
          && (clanEffectParms.length > v)) {
        Ability A = CMClass.getAbility(clanEffectNames[v]);
        if (A != null) {
          // mob was set to null here to make the cache map actually relevant .. see caching below
          A.setProficiency(CMLib.ableMapper().getMaxProficiency((MOB) null, true, A.ID()));
          A.setMiscText(clanEffectParms[v]);
          A.makeNonUninvokable();
          A.setSavable(false); // must go AFTER the ablve
          finalV.add(A);
        }
      }
    }
    finalV.trimToSize();
    clanEffectMap.put(level, finalV);
    return finalV;
  }
 public ClanPosition addPosition() {
   Authority[] pows = new Authority[Function.values().length];
   for (int i = 0; i < pows.length; i++) pows[i] = Authority.CAN_NOT_DO;
   Set<Integer> roles = new HashSet<Integer>();
   int highestRank = 0;
   for (ClanPosition pos : positions) {
     roles.add(Integer.valueOf(pos.getRoleID()));
     if (highestRank < pos.getRank()) highestRank = pos.getRank();
   }
   if (positions.length > 0)
     for (int i = 0; i < pows.length; i++) pows[i] = positions[0].getFunctionChart()[i];
   positions = Arrays.copyOf(positions, positions.length + 1);
   ClanPosition P = (ClanPosition) CMClass.getCommon("DefaultClanPosition");
   P.setID(positions.length + "" + Math.random());
   P.setRoleID(0);
   P.setRank(highestRank);
   P.setName("Unnamed");
   P.setPluralName("Unnameds");
   P.setMax(Integer.MAX_VALUE);
   P.setInnerMaskStr("");
   P.setFunctionChart(pows);
   P.setPublic(true);
   positions[positions.length - 1] = P;
   for (int i = 0; i < positions.length; i++)
     if (!roles.contains(Integer.valueOf(i))) {
       P.setRoleID(i);
       break;
     }
   return P;
 }
 public List<Ability> getClanLevelAbilities(Integer level) {
   if ((clanAbilityMap == null)
       && (clanAbilityNames != null)
       && (clanAbilityLevels != null)
       && (clanAbilityProficiencies != null)
       && (clanAbilityQuals != null)) {
     CMLib.ableMapper().delCharMappings(ID()); // necessary for a "clean start"
     clanAbilityMap = new Hashtable<Integer, List<Ability>>();
     for (int i = 0; i < clanAbilityNames.length; i++) {
       CMLib.ableMapper()
           .addDynaAbilityMapping(
               ID(),
               clanAbilityLevels[i],
               clanAbilityNames[i],
               clanAbilityProficiencies[i],
               "",
               !clanAbilityQuals[i],
               false);
     }
   }
   if (clanAbilityMap == null) return empty;
   if (clanAbilityMap.containsKey(level)) return clanAbilityMap.get(level);
   List<AbilityMapper.AbilityMapping> V =
       CMLib.ableMapper().getUpToLevelListings(ID(), level.intValue(), true, true);
   CMObjUniqSortSVec<Ability> finalV = new CMObjUniqSortSVec<Ability>();
   for (AbilityMapper.AbilityMapping able : V) {
     Ability A = CMClass.getAbility(able.abilityID);
     if (A != null) {
       A.setProficiency(CMLib.ableMapper().getDefaultProficiency(ID(), false, A.ID()));
       A.setSavable(false);
       A.setMiscText(CMLib.ableMapper().getDefaultParm(ID(), false, A.ID()));
       finalV.add(A);
     }
   }
   finalV.trimToSize();
   clanAbilityMap.put(level, finalV);
   return finalV;
 }
  public String getHelpStr() {
    if (getLongDesc().length() == 0) return null;
    if (helpStr == null) {
      StringBuilder str = new StringBuilder("\n\rOrganization type: " + getName() + "\n\r\n\r");
      str.append(getLongDesc()).append("\n\r");
      str.append("\n\rAuthority Chart:\n\r\n\r");
      final List<ClanPosition> showablePositions = new Vector<ClanPosition>();
      for (ClanPosition P : getPositions()) {
        boolean showMe = false;
        for (Clan.Authority a : P.getFunctionChart()) if (a == Authority.CAN_DO) showMe = true;
        if (showMe) showablePositions.add(P);
      }
      final List<ClanPosition> sortedPositions = new Vector<ClanPosition>();
      while (sortedPositions.size() < showablePositions.size()) {
        ClanPosition highPos = null;
        for (ClanPosition P : showablePositions)
          if ((!sortedPositions.contains(P))
              && ((highPos == null) || (highPos.getRank() < P.getRank()))) highPos = P;
        sortedPositions.add(highPos);
      }
      final int[] posses = new int[sortedPositions.size()];
      int posTotalLen = 0;
      for (int p = 0; p < sortedPositions.size(); p++) {
        posses[p] = sortedPositions.get(p).getName().length() + 2;
        posTotalLen += posses[p];
      }
      int funcMaxLen = 0;
      int funcTotal = 0;
      String[] functionNames = new String[Clan.Function.values().length];
      for (int f = 0; f < Clan.Function.values().length; f++) {
        Clan.Function func = Clan.Function.values()[f];
        funcTotal += func.name().length() + 1;
        if (func.name().length() > funcMaxLen) funcMaxLen = func.name().length() + 1;
        functionNames[f] = func.name();
      }
      int funcAvg = funcTotal / Clan.Function.values().length;
      int funcMaxAvg = (int) CMath.round((double) funcAvg * 1.3);
      while ((funcMaxLen > funcMaxAvg) && ((funcMaxAvg + posTotalLen) > 78)) funcMaxLen--;
      if (posses.length > 0)
        while ((funcMaxLen + posTotalLen) > 78) {
          int highPos = 0;
          for (int p = 1; p < sortedPositions.size(); p++)
            if (posses[p] > posses[highPos]) highPos = p;
          posTotalLen--;
          posses[highPos]--;
        }

      final int commandColLen = funcMaxLen;
      str.append(CMStrings.padRight("Command", commandColLen - 1)).append("!");
      for (int p = 0; p < posses.length; p++) {
        ClanPosition pos = sortedPositions.get(p);
        String name = CMStrings.capitalizeAndLower(pos.getName().replace('_', ' '));
        str.append(CMStrings.padRight(name, posses[p] - 1));
        if (p < posses.length - 1) str.append("!");
      }
      str.append("\n\r");
      Object lineDraw =
          new Object() {
            private static final String line =
                "----------------------------------------------------------------------------";

            public String toString() {
              StringBuilder s = new StringBuilder("");
              s.append(line.substring(0, commandColLen - 1)).append("+");
              for (int p = 0; p < posses.length; p++) {
                s.append(CMStrings.padRight(line, posses[p] - 1));
                if (p < posses.length - 1) s.append("+");
              }
              return s.toString();
            }
          };
      str.append(lineDraw.toString()).append("\n\r");
      for (Clan.Function func : Clan.Function.values()) {
        String fname = CMStrings.capitalizeAndLower(func.toString().replace('_', ' '));
        str.append(CMStrings.padRight(fname, commandColLen - 1)).append("!");
        for (int p = 0; p < sortedPositions.size(); p++) {
          ClanPosition pos = sortedPositions.get(p);
          Authority auth = pos.getFunctionChart()[func.ordinal()];
          String x = "";
          if (auth == Authority.CAN_DO) x = "X";
          else if (auth == Authority.MUST_VOTE_ON) x = "v";
          str.append(CMStrings.padCenter(x, posses[p] - 1));
          if (p < posses.length - 1) str.append("!");
        }
        str.append("\n\r").append(lineDraw.toString()).append("\n\r");
      }
      /*
      protected String[] 	clanEffectNames			=null;
      protected int[] 	clanEffectLevels		=null;
      protected String[] 	clanEffectParms			=null;
      protected String[] 	clanAbilityNames		=null;
      protected int[] 	clanAbilityLevels		=null;
      protected int[] 	clanAbilityProficiencies=null;
      protected boolean[] clanAbilityQuals		=null;
      */

      if ((clanAbilityLevels != null)
          && (clanEffectLevels != null)
          && (clanAbilityLevels.length > 0)
          && (clanEffectLevels.length > 0)) {
        str.append("\n\rBenefits per Clan Level:\n\r");
        int maxLevel = -1;
        for (int x : clanEffectLevels) if (x > maxLevel) maxLevel = x;
        for (int x : clanAbilityLevels) if (x > maxLevel) maxLevel = x;
        for (int l = 1; l <= maxLevel; l++) {
          final List<String> levelBenefits = new LinkedList<String>();
          for (int x = 0; x < clanEffectLevels.length; x++)
            if (clanEffectLevels[x] == l) {
              final Ability A = CMClass.getAbility(clanEffectNames[x]);
              if (A != null) {
                A.setMiscText(clanEffectParms[x]);
                String desc = A.accountForYourself();
                if ((desc == null) || (desc.length() == 0))
                  desc = "Members gain the following effect: " + A.name();
                levelBenefits.add(desc);
              }
            }
          for (int x = 0; x < clanAbilityLevels.length; x++)
            if (clanAbilityLevels[x] == l) {
              final Ability A = CMClass.getAbility(clanAbilityNames[x]);
              if (A != null) {
                if (clanAbilityQuals[x]) levelBenefits.add("Members qualify for: " + A.name());
                else levelBenefits.add("Members automatically gain: " + A.name());
              }
            }
          for (final String bene : levelBenefits) str.append("Level " + l + ": " + bene + "\n\r");
        }
      }
      helpStr = str.toString();
    }
    return helpStr;
  }
 public int compareTo(CMObject o) {
   return CMClass.classID(this).compareToIgnoreCase(CMClass.classID(o));
 }