/**
   * Split off creatures into a new legion using legion marker markerId. (Or the first available
   * marker, if markerId is null.) Return the new legion, or null if there's an error.
   */
  LegionServerSide split(List<CreatureType> creatures, String newMarkerId) {
    assert newMarkerId != null : "We need a marker to split";
    PlayerServerSide player = getPlayer();

    player.selectMarkerId(newMarkerId);
    LegionServerSide newLegion =
        new LegionServerSide(
            newMarkerId, this, getCurrentHex(), getCurrentHex(), getPlayer(), game);

    Iterator<CreatureType> it = creatures.iterator();
    while (it.hasNext()) {
      CreatureType creature = it.next();
      creature = removeCreature(creature, false, false);
      if (creature == null) {
        // Abort the split.
        LOGGER.warning("Split aborted since removeCreature(..) returned null");
        newLegion.recombine(this, true);
        return null;
      }
      newLegion.addCreature(creature, false);
    }

    player.addLegion(newLegion);

    game.getServer().allUpdatePlayerInfo("Split");
    LOGGER.log(
        Level.INFO,
        newLegion.getHeight()
            + " creatures are split off from legion "
            + this
            + " into new legion "
            + newLegion);

    sortCritters();
    newLegion.sortCritters();

    // game.getServer().allTellLegionLocation(newMarkerId);

    return newLegion;
  }
  /**
   * Recombine this legion into another legion. Only remove this legion from the Player if remove is
   * true. If it's false, the caller is responsible for removing this legion, which can avoid
   * concurrent access problems. Someone needs to call MasterBoard.alignLegions() on the remaining
   * legion's hexLabel after the recombined legion is actually removed.
   */
  void recombine(Legion legion, boolean remove) {
    // Sanity check
    if (legion == this) {
      LOGGER.log(Level.WARNING, "Tried to recombine a legion with itself!");
      return;
    }
    for (Creature critter : getCreatures()) {
      ((LegionServerSide) legion).addCreature(critter.getType(), false);
    }

    if (remove) {
      remove(false, false);
    } else {
      prepareToRemove(false, false);
    }

    LOGGER.log(Level.INFO, "Legion " + this + " recombined into legion " + legion);

    sortCritters();

    // Let the clients know that the legions have recombined.
    game.getServer().undidSplit(this, legion, true, game.getTurnNumber());
  }
 @Override
 public void addCreature(CreatureType type) {
   addCreature(type, true);
 }