plist.add(player);
player.resetTankCount(); player.resetInfantryCount(); player.resetMechCount();
    private void determineTurnOrder() {        // sort players        com.sun.java.util.collections.ArrayList plist = new com.sun.java.util.collections.ArrayList(game.getNoOfPlayers());        for (Enumeration i = game.getPlayers(); i.hasMoreElements();) {            final Player player = (Player)i.nextElement();            plist.add(player);        }        com.sun.java.util.collections.Collections.sort(plist, new com.sun.java.util.collections.Comparator() {            public int compare(Object o1, Object o2) {                return ((Player)o1).getInitiative().compareTo(((Player)o2).getInitiative());            }        });                // determine turn order        int[] order = new int[game.getNoOfPlayers()];        int oi = 0;        for (com.sun.java.util.collections.Iterator i = plist.iterator(); i.hasNext();) {            final Player player = (Player)i.next();            order[oi++] = player.getId();        }                // count how many entities each player controls, and how many turns we have to assign        int MAX_PLAYERS = 255; //XXX HACK HACK HACK!        int[] noe = new int[MAX_PLAYERS];        int playerId = 0;        int noOfTurns = 0;        int[] noi = new int[MAX_PLAYERS]; // The number of Infantry for player.        int noOfInfTurns = 0;        boolean infMulti = game.getOptions().booleanOption("inf_move_multi");        boolean infLast = game.getOptions().booleanOption("inf_move_last");        for (Enumeration e = game.getEntities(); e.hasMoreElements();) {            final Entity entity = (Entity)e.nextElement();            if (entity.isSelectable()) {                playerId = entity.getOwner().getId();                // Special handling for infantry for certain game options.                if ( entity instanceof Infantry ) {                    noi[playerId]++;                    // If multiple Infantry move per Mek and Vehicle and this                    // is NOT the start of a new block of infantry for the                    // player do NOT add a turn.                    if ( infMulti &&                         1 != (noi[playerId] % Game.INF_MOVE_MULTI) ) {                        continue;                    }                    // If Infantry move after Meks and Vehicles, we'll                    // delay calculating the infantry turns.                    else if ( infLast ) {                        noOfInfTurns++;                        continue;                    }                }                noe[playerId]++;                noOfTurns++;            }        }                // generate turn list        Vector turns = new Vector(noOfTurns + noOfInfTurns);        int turnIndex = 0;        // Handle all "mainline entities".  I.E. Meks, Vehicles, and        // (unless overrided by the "inf_move_last" option) Infantry.        while (turnIndex < noOfTurns) {            // get lowest number of entities, minimum 1.            int hnoe = 1;            int lnoe = Integer.MAX_VALUE;            for (int i = 0; i < MAX_PLAYERS; i++) {                if (noe[i] > 0 && noe[i] < lnoe) {                    lnoe = noe[i];                }                if (noe[i] > hnoe) {                    hnoe = noe[i];                }            }            // cycle through order list            for (int i = 0; i < order.length; i++) {                if (noe[order[i]] <= 0) {                    continue;                }                /* if you have less than twice the next lowest,                 * move 1, otherwise, move more.                 * if you have less than half the maximum,                 * move none                 */                int ntm = Math.max(1, (int)Math.floor(noe[order[i]] / lnoe));                for (int j = 0; j < ntm; j++) {                    GameTurn turn;                    if (infLast) {                        turn = new GameTurn.NotInfantryTurn(order[i]);                    } else {                        turn = new GameTurn(order[i]);                    }                    turns.addElement(turn);                    turnIndex++;                    noe[order[i]]--;                }            }        } // Handle the next "mainline entity"        // Now handle all Infantry (the "inf_move_last" option must be on).        while (turnIndex < turns.size()) {            // get lowest number of entities, minimum 1.            int hnoi = 1;            int lnoi = Integer.MAX_VALUE;            for (int i = 0; i < MAX_PLAYERS; i++) {                if (noi[i] > 0 && noi[i] < lnoi) {                    lnoi = noi[i];                }                if (noi[i] > hnoi) {                    hnoi = noi[i];                }            }            // cycle through order list            for (int i = 0; i < order.length; i++) {                if (noi[order[i]] <= 0) {                    continue;                }                /* if you have less than twice the next lowest,                 * move 1, otherwise, move more.                 * if you have less than half the maximum,                 * move none                 */                int ntm = Math.max(1, (int)Math.floor(noi[order[i]] / lnoi));                for (int j = 0; j < ntm; j++) {                    turns.addElement(new GameTurn.OnlyInfantryTurn(order[i]));                    turnIndex++;                    noi[order[i]]--;                }            }        } // Handle the next infantry platoon                // set fields in game        game.setTurnVector(turns);        game.resetTurnIndex();                // send turns to all players        send(createTurnVectorPacket());    }