public PlayerAction getNextAction(long cutOffTime) {
        int count = 0;
        while(moreActions) {
            boolean consistent = true;
            PlayerAction pa = new PlayerAction(base_ru);
            int i = choices.size();
            if (i == 0) {
            	return null;
            }
            //if (i==0) throw new Exception("Move generator created with no units that can execute actions!");
            while(i>0) {
                i--;
                Pair<Unit,List<UnitAction> > unitChoices = choices.get(i);
                int choice = currentChoice[i];
                Unit u = unitChoices.m_a;
                UnitAction ua = unitChoices.m_b.get(choice);
                
                if (pa.consistentResourceUsage(ua)) {
                	pa.mergeResourceUsage(u, ua);
                    pa.addUnitAction(u, ua);
                } else {
                    consistent = false;
                    break;
                }
            }
            
            incrementCurrentChoice(i);
            if (consistent) {
                lastAction = pa;
                generated++;                
                return pa;
            }
            
            // check if we are over time (only check once every 1000 actions, since currenttimeMillis is a slow call):
            if (cutOffTime!=-1 && (count%1000==0) && System.currentTimeMillis()>cutOffTime) {
                lastAction = null;
                return null;
            }
            count++;
        }
        lastAction = null;
        return null;
    }