import java.util.*;
import javax.swing.JOptionPane;

/**
 * class Group exists for groups, or so-called "stacks" of units.
 * It is an abstract class; instances will normally be from subclasses.
 */
public class Group {
    protected Orbit orbit;
   protected Vector units;
   protected Environ environ;
   protected Planet planet;
   protected char type, side;
   public Group()
   {
      units = new Vector();
   }
   public Group(Unit u)
   {
      units = new Vector();
      units.addElement(u);
   }
   /**
    * accessor methods
    */
    public Vector getGroup()
    {
	return units;
    }

   public Environ getEnviron()
   {
      return environ;
   }
   public Planet getPlanet()
   {
       return planet;
   }
    public char getType()
    {
	return type;
    }
    public char getSide()
    {
	return side;
    }
    /**
    * getNumMilUnits()
    * returns the number of MilitaryUnits in a vector
    */
    public int getNumMilUnits(){
        int chars = 0;
        Unit u;
	for (int i=0;i<units.size();i++){
	    u = (Unit) units.elementAt(i);
	    if (u.isChar == true)
		chars++;
        }
        return(units.size()-chars);
    }

   /**
    * modifier methods
    */
   public void setEnviron(Environ newEnv)
   {
       environ = newEnv;
   }
   public void setPlanet(Planet newEnv)
   {
       planet = newEnv;
   }
   /**
    * getNumUnits()
    * returns the number (int) of units in the Group
    */
    public int getNumUnits()
    {
	return units.size();
    }
   /**
    * add()
    * adds a Unit to the Group
    */
    public void add(Unit u)
    {
	units.add(u);
	return;
    }
   /**
    * add()
    * adds a MilitaryUnit to the Group
    */
    public void add(MilitaryUnit u)
    {
	units.add(u);
	return;
    }
   /**
    * add()
    * adds a Charactr to the Group
    */
    public void add(Charactr u)
    {
	units.add(u);
	return;
    }
   /**
    * add()
    * adds a Spaceship to the Group
    */
    public void add(Spaceship u)
    {
	units.add(u);
	return;
    }
   /**
    * remove()
    * remove a Unit from the Group
    */
    public void remove(Unit u)
    {
	units.remove(u);
	return;

    }
   /**
    * returns the number of detected characters in the group
    */
    public int getNumDetectedChars(){
	int detectedChars=0;
	for (int i=0;i<units.size();i++){
	    if (((Charactr)units.elementAt(i)).getIsDetected()==true)
		detectedChars++;
	}
	return(detectedChars);
    }
   /**
    * move()
    * This move() method moves a MilitaryGroup from one environ to another.
    * takes a military unit array and destination environ
    * returns true if move successful; false otherwise
    */
    public boolean move(MilitaryUnit[] units, Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	// bug checking
	//	System.out.println("units.length =  "+units.length);
	//	System.out.println("newEnv.getSize() =  "+newEnv.getSize());
	//	System.out.println("newEnv.getRebelMilGroup().getNumMilUnits() = "+newEnv.getRebelMilGroup().getNumMilUnits());
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		JOptionPane.showMessageDialog(null,"ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    JOptionPane.showMessageDialog(null,"ERROR: Trying to move too many Units");
	    return(false);
	}
	// move each MilitaryUnit individually
	for (int i=0;i<units.length;i++) {
	    flag = units[i].moveTo(units[i],newEnv);
	    //if these units had a leader, remove the leader since not moving with the units
	    if (units[i].getLeader() != null){
		units[i].getLeader().getMUnitsLed().remove(units[i]);
		units[i].setLeader(null);
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	return(true);
    }
   /**
    * move()
    * This move() method moves an array of Charactrs from one environ to
    * another on the same planet (no spaceship is involved).  
    * takes an array of charactrs, a destination environ and a
    * destination group.  returns true if move successful; false otherwise
    */
    public boolean move(Charactr[] c, Environ newEnv, Group newGrp)
    {
	//check for null inputs
	if (newEnv == null || c.length == 0 || newGrp == null){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//this is the only case when a character move will fail
// 	for (int i=0;i<c.length;i++){
// 	    if (c[i].getAboardShip() == false && newEnv.getPlanet() != c[i].environ.getPlanet()){
// 		System.out.println("ERROR: Not all Charactr array members are aboard a spaceship");
// 		return(false);
// 	    }
	for (int i=0;i<c.length;i++){
	    if (newEnv.getPlanet() != c[i].environ.getPlanet()){
		JOptionPane.showMessageDialog(null,"ERROR: Need a spaceship to complete this move");
		return(false);
	    }
	}
	// move each Charactr individually
	for (int i=0;i<c.length;i++){
	    flag = c[i].moveTo(c[i],newEnv,newGrp);
	    //if these charactrs led units before the move, remove them from the milUnitsLed
	    //vector since the milUnits did not move with them
	    if (c[i].getMUnitsLed().size()>0){
		for (int j=0;j<c[i].getMUnitsLed().size();j++){
		    ((MilitaryUnit)c[i].getMUnitsLed().elementAt(j)).setLeader(null);
		}
		c[i].getMUnitsLed().removeAllElements();
	    }

	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	
        return(true);
    }
   /**
    * move()
    * This variation of the move() method moves a MilitaryGroup 
    * and any unmanned spaceships being moved with it from environ to another.
    * takes a military unit array, a spaceship array, and destination environ
    * returns true if move successful; false otherwise
    */
    public boolean move(MilitaryUnit[] units, Spaceship[] ships, Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0 || ships==null){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//move is invalid if there are no milUnits being moved
	if (units.length == 0){
	    JOptionPane.showMessageDialog(null,"ERROR: Need military units in order to move the associated ship.");
	    return(false);
	}
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		JOptionPane.showMessageDialog(null,"ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    JOptionPane.showMessageDialog(null,"ERROR: Trying to move too many Units");
	    return(false);
	}
	// move each MilitaryUnit individually
	for (int i=0;i<units.length;i++) {
	    flag = units[i].moveTo(units[i],newEnv);
	    //if these units had a leader, remove the leader since not moving with the units
	    if (units[i].getLeader() != null){
		units[i].getLeader().getMUnitsLed().remove(units[i]);
		units[i].setLeader(null);
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	// move each Spaceship individually
	//check if unit[0] is rebel or imperial & move spaceships to same group
	    // if rebel, move each Spaceship individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.rebelMilGroup.remove(ships[i]);
		newEnv.rebelMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;         
		return(true);
	    }
	}
	    // if imperial, move each spaceship individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.imperialMilGroup.remove(ships[i]);
		newEnv.imperialMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;           
		return(true);
	    }
	}
	return(true);
    }
   /**
    * move()
    * This move() method moves arrays of Military Units and Charactrs from one
    * environ to another.  takes an array of military units, an array of 
    * Charactrs, and a destination environ.  
    * returns true if move successful; false otherwise
    */
    public boolean move(MilitaryUnit[] units, Charactr[] c, Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0 || c.length ==0){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		JOptionPane.showMessageDialog(null,"ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    JOptionPane.showMessageDialog(null,"ERROR: Trying to move too many Units");
	    return(false);
	}
	//move the military units
	move(units,newEnv);
	//move the charactrs

	//since the characters are moving with military units, they don't necessarily need to be aboard a spaceship -- need to put code here to resolve that

	//check if unit[0] is rebel or imperial & move charactrs to same group
	    // if rebel, move each Charactr individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<c.length;i++){
		c[i].environ.rebelMilGroup.remove(c[i]);
		newEnv.rebelMilGroup.add(c[i]);
		c[i].environ = newEnv;
		c[i].moved = true;         
		return(true);
	    }
	}
	    // if imperial, move each Charactr individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<c.length;i++){
		c[i].environ.imperialMilGroup.remove(c[i]);
		newEnv.imperialMilGroup.add(c[i]);
		c[i].environ = newEnv;
		c[i].moved = true;           
		return(true);
	    }

	    //clean up any leadership issues, i.e. if a character being passed is a leader of all
	    //of the military units in his/her old environ, but only some of those units are 
	    //moving to the new environ
	    boolean flag = false;
	    Vector temp = new Vector();
	    Vector temp1 = new Vector();
	    for (int i=0;i<c.length;i++){
		if (c[i].getMUnitsLed().size()>0){
		    //get any units being passed that are common with the character's units led
		    //and put them into a temp vector
		    for (int j=0;j<units.length;j++){
			if (c[i].getMUnitsLed().contains(units[j]))
			    temp.add(units[j]);
		    }
		    //set the leader of character's units led to null
		    for (int k=0;k<c[i].getMUnitsLed().size();k++){
			((MilitaryUnit)c[i].getMUnitsLed().elementAt(k)).setLeader(null);
		    }
		    //remove all units from character's units led vector
		    c[i].getMUnitsLed().removeAllElements();
		    //set the leader for each unit in the temp vector to the character and
		    //add each member of the temp vector to mUnitsLed vector
		    for (int m=0;m<temp.size();m++){
			((MilitaryUnit)temp.elementAt(m)).setLeader(c[i]);
			c[i].getMUnitsLed().add((MilitaryUnit)temp.elementAt(m));
		    }
		    //done with the temp vector, remove its elements
		    temp.removeAllElements();

		    for  (int j=0;j<temp1.size();j++){
			if (((MilitaryUnit)temp1.elementAt(j)).getLeader()!=null){
			    //check whether the leader of other mUnits is being passed
			    for (int k=0;k<c.length;k++){
				//if they are, break out of this loop, they will be 
				//taken care of in other iteration of main loop
				if (((MilitaryUnit)temp1.elementAt(j)).getLeader()==c[k]){
				    flag = true;
				    break;
				}
			    }
			    //if the characteris not being passed, set links accordingly
			    if (flag==false){
				((MilitaryUnit)temp1.elementAt(j)).getLeader().getMUnitsLed().remove(temp1.elementAt(j));
				((MilitaryUnit)temp1.elementAt(j)).setLeader(null);
			    }
			}
		    }
		}
	    }
	}
        return(true);
    }
   /**
    * move()
    * This move() method moves an array of Charactrs from one environ to
    * another using a spaceship(s).  Takes an array of charactrs,  
    * an array of spaceships, a destination environ and a
    * destination group.  returns true if move successful; false otherwise
    */
    public boolean move(Charactr[] c, Spaceship[] ships,  Environ newEnv, Group newGrp)
    {
	//check for null inputs
	if (newEnv == null || c.length == 0 || ships.length==0 || newGrp==null){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	int totalPassengers=0;
	boolean flag;
	// check to see if number of passengers exceeds capacity of ship(s) and
	// check to make sure each ship has a pilot
	for (int i=0;i<ships.length;i++){
	    totalPassengers += ships[i].getMaxPassengers();
	    if (ships[i].getHasPilot() == false){
	    System.out.println("ERROR: At least one of your ships does not have a pilot.  Please fix and try again.  Move failed.");
	    return(false);
	    }
	}
	if (c.length > totalPassengers){
	    System.out.println("ERROR: Trying to move too many passengers for the ship(s) you have selected. Move failed.");
	    return(false);
	}
	//check to make sure each charactr is a passenger on a ship
	flag = false;
	for (int i=0;i<c.length;i++){
	    flag = false;
	    for (int j=0;j<ships.length;j++){
		if (c[i].getShip()==ships[j])
		    flag=true;
	    }
	    if (flag == false){
		JOptionPane.showMessageDialog(null,"At least one of your passengers is not aboard a ship. Please fix and try again.");
		return(false);
	    }
	}

	// move each Charactr individually
	for (int i=0;i<c.length;i++){
	    flag = c[i].moveTo(c[i],newEnv,newGrp);
	    //if these charactrs led units before the move, remove them from the milUnitsLed
	    //vector since the milUnits did not move with them
	    if (c[i].getMUnitsLed().size()>0){
		for (int j=0;j<c[i].getMUnitsLed().size();j++){
		    ((MilitaryUnit)c[i].getMUnitsLed().elementAt(j)).setLeader(null);
		}
		c[i].getMUnitsLed().removeAllElements();
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug - look at the leadership check in group.java");
		    return(false);
		}
	}
	// move each Spaceship individually
	for (int i=0;i<ships.length;i++){
	    flag = ships[i].moveShip(ships[i],newEnv,newGrp);
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
        return(true);
    }


   /**
    * move()
    * This move() method moves an array of Military Units, an array of 
    * Charactrs, and an array of Spaceships to the military group of the
    * destination environ.  Takes an array of each of the above, plus 
    * the destination environ.  Returns true if sucessful, false otherwise.
    */
    public boolean move(MilitaryUnit[] units, Charactr[] c, Spaceship[] ships,  Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
	    JOptionPane.showMessageDialog(null,"ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		JOptionPane.showMessageDialog(null,"ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		JOptionPane.showMessageDialog(null,"ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    JOptionPane.showMessageDialog(null,"ERROR: Trying to move too many Units");
	    return(false);
	}
	//move the military units
	move(units,newEnv);


	// move the Spaceships
	//check if unit[0] is rebel or imperial & move spaceships to same group
	    // if rebel, move each Spaceship individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.rebelMilGroup.remove(ships[i]);
		newEnv.rebelMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;         
	    }
	}
	    // if imperial, move each spaceship individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.imperialMilGroup.remove(ships[i]);
		newEnv.imperialMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;           
	    }
	}

	//move the charactrs

	//since the characters are moving with military units, they don't necessarily need to be aboard a spaceship -- need to put code here to resolve that

	//check if unit[0] is rebel or imperial & move charactrs to same group
	    // if rebel, move each Charactr individually to rebMilGrp

	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<c.length;i++){
		c[i].moveTo(c[i],newEnv,newEnv.getRebelMilGroup());
// 		c[i].environ.rebelMilGroup.remove(c[i]);
// 		newEnv.rebelMilGroup.add(c[i]);
// 		c[i].environ = newEnv;
// 		c[i].moved = true;         
	    }
	}
// 	    // if imperial, move each Charactr individually to impMilGrp
// 	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
// 	    for (int i=0;i<c.length;i++){
// 		c[i].environ.imperialMilGroup.remove(c[i]);
// 		newEnv.imperialMilGroup.add(c[i]);
// 		c[i].environ = newEnv;
// 		c[i].moved = true;           
// 	    }
// 	}

	    //clean up any leadership issues, i.e. if a character being passed is a leader of all
	    //of the military units in his/her old environ, but only some of those units are 
	    //moving to the new environ
	    flag = false;
	    Vector temp = new Vector();
	    Vector temp1 = new Vector();
	    for (int i=0;i<c.length;i++){
		if (c[i].getMUnitsLed().size()>0){
		    for (int j=0;j<units.length;j++){
			//get any units being passed that are common with the character's units led
			//and put them into a temp vector
			if (c[i].getMUnitsLed().contains(units[j]))
			    temp.add(units[j]);
			else 
			    temp1.add(units[j]);
		    }
		    //set the leader of character's units led to null
		    for (int k=0;k<c[i].getMUnitsLed().size();k++){
			((MilitaryUnit)c[i].getMUnitsLed().elementAt(k)).setLeader(null);
		    }
		    //remove all units from character's units led vector
		    c[i].getMUnitsLed().removeAllElements();
		    //set the leader for each unit in the temp vector to the character and
		    //add each member of the temp vector to mUnitsLed vector
		    for (int m=0;m<temp.size();m++){
			((MilitaryUnit)temp.elementAt(m)).setLeader(c[i]);
			c[i].getMUnitsLed().add((MilitaryUnit)temp.elementAt(m));
		    }
		    //done with the temp vector, remove its elements
		    temp.removeAllElements();

		    for  (int j=0;j<temp1.size();j++){
			if (((MilitaryUnit)temp1.elementAt(j)).getLeader()!=null){
			    //check whether the leader of other mUnits is being passed
			    for (int k=0;k<c.length;k++){
				//if they are, break out of this loop, they will be 
				//taken care of in other iteration of main loop
				if (((MilitaryUnit)temp1.elementAt(j)).getLeader()==c[k]){
				    flag = true;
				    break;
				}
			    }
			    //if the characteris not being passed, set links accordingly
			    if (flag==false){
				((MilitaryUnit)temp1.elementAt(j)).getLeader().getMUnitsLed().remove(temp1.elementAt(j));
				((MilitaryUnit)temp1.elementAt(j)).setLeader(null);
			    }
			}
		    }
		}
	    }

	    return(true);
    
    }
    //********************************************************************
    //These move methods are implemented in the province and galactic game

   /**
    * moveGroupFromOrbitToEnviron()
    * This method moves a MilitaryGroup from an orbit box to an environ.
    * takes a military unit array and destination environ
    * returns true if move successful; false otherwise
    */
    public boolean moveGroupFromOrbitToEnviron(MilitaryUnit[] units, Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	//check if nonmobile units outnumber mobile units
	boolean flag;
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].orbit.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    System.out.println("ERROR: Trying to move too many Units");
	    return(false);
	}
	// move each MilitaryUnit individually
	for (int i=0;i<units.length;i++) {
	    flag = units[i].moveFromOrbitBox(units[i],newEnv);
	    //if these units had a leader, remove the leader since not moving with the units
	    if (units[i].getLeader() != null){
		units[i].getLeader().getMUnitsLed().remove(units[i]);
		units[i].setLeader(null);
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	return(true);
    }

   /**
    * moveGroupFromOrbitToEnviron
    * This method moves an array of Charactrs from an orbit box to
    * an environ using a spaceship(s).  Takes an array of charactrs,  
    * an array of spaceships, a destination environ and a
    * destination group.  returns true if move successful; false otherwise
    */
    public boolean moveGroupFromOrbitToEnviron(Charactr[] c, Spaceship[] ships,  Environ newEnv, Group newGrp)
    {
	//check for null inputs
	if (newEnv == null || c.length == 0 || ships.length==0 || newGrp==null){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	int totalPassengers=0;
	boolean flag;
	// check to see if number of passengers exceeds capacity of ship(s) and
	// check to make sure each ship has a pilot
	for (int i=0;i<ships.length;i++){
	    totalPassengers += ships[i].getMaxPassengers();
	    if (ships[i].getHasPilot() == false){
	    System.out.println("ERROR: At least one of your ships does not have a pilot.  Please fix and try again.  Move failed.");
	    return(false);
	    }
	}
	if (c.length > totalPassengers){
	    System.out.println("ERROR: Trying to move too many passengers for the ship(s) you have selected. Move failed.");
	    return(false);
	}
	// move each Charactr individually
	for (int i=0;i<c.length;i++){
	    flag = c[i].moveFromOrbitBox(c[i],newEnv,newGrp);
	    //if these charactrs led units before the move, remove them from the milUnitsLed
	    //vector since the milUnits did not move with them
	    if (c[i].getMUnitsLed().size()>0){
		for (int j=0;j<c[i].getMUnitsLed().size();j++){
		    ((MilitaryUnit)c[i].getMUnitsLed().elementAt(j)).setLeader(null);
		}
		c[i].getMUnitsLed().removeAllElements();
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	// move each Spaceship individually
	for (int i=0;i<ships.length;i++){
	    flag = ships[i].moveFromOrbitBox(ships[i],newEnv,newGrp);
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
        return(true);
    }
   /**
    * moveGroupFromOrbitToEnviron()
    * This method moves an array of Military Units, an array of 
    * Charactrs, and an array of Spaceships to the military group of the
    * destination environ.  Takes an array of each of the above, plus 
    * the destination environ.  Returns true if sucessful, false otherwise.
    */
    public boolean moveGroupFromOrbitToEnviron(MilitaryUnit[] units, Charactr[] c, Spaceship[] ships,  Environ newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].orbit.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//check to make sure we have enough space in the environ
	if (!(units.length <= (newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits()))){
	    System.out.println("ERROR: Trying to move too many Units");
	    return(false);
	}
	//move the military units
	moveGroupFromOrbitToEnviron(units,newEnv);


	// move the Spaceships
	//check if unit[0] is rebel or imperial & move spaceships to same group
	    // if rebel, move each Spaceship individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<ships.length;i++){
		ships[i].orbit.rebelMilGroup.remove(ships[i]);
		ships[i].orbit = null;
		newEnv.rebelMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;         
	    }
	}
	    // if imperial, move each spaceship individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<ships.length;i++){
		ships[i].orbit.imperialMilGroup.remove(ships[i]);
		ships[i].orbit = null;
		newEnv.imperialMilGroup.add(ships[i]);
		ships[i].environ = newEnv;
		ships[i].moved = true;           
	    }
	}

	//move the charactrs

	//since the characters are moving with military units, they don't necessarily need to be aboard a spaceship -- need to put code here to resolve that

	//check if unit[0] is rebel or imperial & move charactrs to same group
	    // if rebel, move each Charactr individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<c.length;i++){
		c[i].orbit.rebelMilGroup.remove(c[i]);
		c[i].orbit = null;
		newEnv.rebelMilGroup.add(c[i]);
		c[i].environ = newEnv;
		c[i].moved = true;         
	    }
	}
	    // if imperial, move each Charactr individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<c.length;i++){
		c[i].orbit.imperialMilGroup.remove(c[i]);
		c[i].orbit = null;
		newEnv.imperialMilGroup.add(c[i]);
		c[i].environ = newEnv;
		c[i].moved = true;           
	    }
	}

	    //clean up any leadership issues, i.e. if a character being passed is a leader of all
	    //of the military units in his/her old environ, but only some of those units are 
	    //moving to the new environ
	    flag = false;
	    Vector temp = new Vector();
	    Vector temp1 = new Vector();
	    for (int i=0;i<c.length;i++){
		if (c[i].getMUnitsLed().size()>0){
		    for (int j=0;j<units.length;j++){
			//get any units being passed that are common with the character's units led
			//and put them into a temp vector
			if (c[i].getMUnitsLed().contains(units[j]))
			    temp.add(units[j]);
			else 
			    temp1.add(units[j]);
		    }
		    //set the leader of character's units led to null
		    for (int k=0;k<c[i].getMUnitsLed().size();k++){
			((MilitaryUnit)c[i].getMUnitsLed().elementAt(k)).setLeader(null);
		    }
		    //remove all units from character's units led vector
		    c[i].getMUnitsLed().removeAllElements();
		    //set the leader for each unit in the temp vector to the character and
		    //add each member of the temp vector to mUnitsLed vector
		    for (int m=0;m<temp.size();m++){
			((MilitaryUnit)temp.elementAt(m)).setLeader(c[i]);
			c[i].getMUnitsLed().add((MilitaryUnit)temp.elementAt(m));
		    }
		    //done with the temp vector, remove its elements
		    temp.removeAllElements();

		    for  (int j=0;j<temp1.size();j++){
			if (((MilitaryUnit)temp1.elementAt(j)).getLeader()!=null){
			    //check whether the leader of other mUnits is being passed
			    for (int k=0;k<c.length;k++){
				//if they are, break out of this loop, they will be 
				//taken care of in other iteration of main loop
				if (((MilitaryUnit)temp1.elementAt(j)).getLeader()==c[k]){
				    flag = true;
				    break;
				}
			    }
			    //if the characteris not being passed, set links accordingly
			    if (flag==false){
				((MilitaryUnit)temp1.elementAt(j)).getLeader().getMUnitsLed().remove(temp1.elementAt(j));
				((MilitaryUnit)temp1.elementAt(j)).setLeader(null);
			    }
			}
		    }
		}
	    }
	    return(true);
    }
   /**
    * moveGroupFromOrbitToOrbit()
    * This method moves a MilitaryGroup from an orbit box to an orbit box.
    * takes a military unit array and destination orbit
    * returns true if move successful; false otherwise
    */
    public boolean moveGroupFromOrbitToOrbit(MilitaryUnit[] units, Orbit newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	//check if nonmobile units outnumber mobile units
	boolean flag;
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].orbit.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	// move each MilitaryUnit individually
	for (int i=0;i<units.length;i++) {
	    flag = units[i].moveFromOrbitBox(units[i],newEnv);
	    //if these units had a leader, remove the leader since not moving with the units
	    if (units[i].getLeader() != null){
		units[i].getLeader().getMUnitsLed().remove(units[i]);
		units[i].setLeader(null);
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	return(true);
    }
   /**
    * moveGroupFromOrbitToOrbit()
    * This method moves an array of Charactrs from an orbit box to
    * an orbit box using a spaceship(s).  Takes an array of charactrs,  
    * an array of spaceships, a destination orbit and a
    * destination group.  returns true if move successful; false otherwise
    */
    public boolean moveGroupFromOrbitToOrbit(Charactr[] c, Spaceship[] ships, Orbit newEnv, Group newGrp)
    {
	//check for null inputs
	if (newEnv == null || c.length == 0 || ships.length==0 || newGrp==null){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	int totalPassengers=0;
	boolean flag;
	// check to see if number of passengers exceeds capacity of ship(s) and
	// check to make sure each ship has a pilot
	for (int i=0;i<ships.length;i++){
	    totalPassengers += ships[i].getMaxPassengers();
	    if (ships[i].getHasPilot() == false){
	    System.out.println("ERROR: At least one of your ships does not have a pilot.  Please fix and try again.  Move failed.");
	    return(false);
	    }
	}
	if (c.length > totalPassengers){
	    System.out.println("ERROR: Trying to move too many passengers for the ship(s) you have selected. Move failed.");
	    return(false);
	}
	// move each Charactr individually
	for (int i=0;i<c.length;i++){
	    flag = c[i].moveFromOrbitBox(c[i],newEnv,newGrp);
	    //if these charactrs led units before the move, remove them from the milUnitsLed
	    //vector since the milUnits did not move with them
	    if (c[i].getMUnitsLed().size()>0){
		for (int j=0;j<c[i].getMUnitsLed().size();j++){
		    ((MilitaryUnit)c[i].getMUnitsLed().elementAt(j)).setLeader(null);
		}
		c[i].getMUnitsLed().removeAllElements();
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	// move each Spaceship individually
	for (int i=0;i<ships.length;i++){
	    flag = ships[i].moveFromOrbitBox(ships[i],newEnv,newGrp);
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
        return(true);
    }
   /**
    * moveGroupFromOrbitToOrbit()
    * This method moves an array of Military Units, an array of 
    * Charactrs, and an array of Spaceships to the military group of the
    * destination orbit box.  Takes an array of each of the above, plus 
    * the destination orbit.  Returns true if sucessful, false otherwise.
    */
    public boolean moveGroupFromOrbitToOrbit(MilitaryUnit[] units, Charactr[] c, Spaceship[] ships, Orbit newEnv)
    {
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].orbit.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//move the military units
	moveGroupFromOrbitToOrbit(units,newEnv);

	// move the Spaceships
	//check if unit[0] is rebel or imperial & move spaceships to same group
	    // if rebel, move each Spaceship individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<ships.length;i++){
		ships[i].orbit.rebelMilGroup.remove(ships[i]);
		newEnv.rebelMilGroup.add(ships[i]);
		ships[i].orbit = newEnv;
	    }
	}
	    // if imperial, move each spaceship individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<ships.length;i++){
		ships[i].orbit.imperialMilGroup.remove(ships[i]);
		newEnv.imperialMilGroup.add(ships[i]);
		ships[i].orbit = newEnv;
	    }
	}

	//move the charactrs

	//since the characters are moving with military units, they don't necessarily need to be aboard a spaceship -- need to put code here to resolve that

	//check if unit[0] is rebel or imperial & move charactrs to same group
	    // if rebel, move each Charactr individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<c.length;i++){
		c[i].orbit.rebelMilGroup.remove(c[i]);
		newEnv.rebelMilGroup.add(c[i]);
		c[i].orbit = newEnv;
	    }
	}
	    // if imperial, move each Charactr individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<c.length;i++){
		c[i].orbit.imperialMilGroup.remove(c[i]);
		newEnv.imperialMilGroup.add(c[i]);
		c[i].orbit = newEnv;
	    }
	}

	    //clean up any leadership issues, i.e. if a character being passed is a leader of all
	    //of the military units in his/her old environ, but only some of those units are 
	    //moving to the new environ
	    flag = false;
	    Vector temp = new Vector();
	    Vector temp1 = new Vector();
	    for (int i=0;i<c.length;i++){
		if (c[i].getMUnitsLed().size()>0){
		    for (int j=0;j<units.length;j++){
			//get any units being passed that are common with the character's units led
			//and put them into a temp vector
			if (c[i].getMUnitsLed().contains(units[j]))
			    temp.add(units[j]);
			else 
			    temp1.add(units[j]);
		    }
		    //set the leader of character's units led to null
		    for (int k=0;k<c[i].getMUnitsLed().size();k++){
			((MilitaryUnit)c[i].getMUnitsLed().elementAt(k)).setLeader(null);
		    }
		    //remove all units from character's units led vector
		    c[i].getMUnitsLed().removeAllElements();
		    //set the leader for each unit in the temp vector to the character and
		    //add each member of the temp vector to mUnitsLed vector
		    for (int m=0;m<temp.size();m++){
			((MilitaryUnit)temp.elementAt(m)).setLeader(c[i]);
			c[i].getMUnitsLed().add((MilitaryUnit)temp.elementAt(m));
		    }
		    //done with the temp vector, remove its elements
		    temp.removeAllElements();

		    for  (int j=0;j<temp1.size();j++){
			if (((MilitaryUnit)temp1.elementAt(j)).getLeader()!=null){
			    //check whether the leader of other mUnits is being passed
			    for (int k=0;k<c.length;k++){
				//if they are, break out of this loop, they will be 
				//taken care of in other iteration of main loop
				if (((MilitaryUnit)temp1.elementAt(j)).getLeader()==c[k]){
				    flag = true;
				    break;
				}
			    }
			    //if the characteris not being passed, set links accordingly
			    if (flag==false){
				((MilitaryUnit)temp1.elementAt(j)).getLeader().getMUnitsLed().remove(temp1.elementAt(j));
				((MilitaryUnit)temp1.elementAt(j)).setLeader(null);
			    }
			}
		    }
		}
	    }
	    return(true);
    }
   /**
    * moveGroupFromEnvironToOrbit()
    * This method moves a MilitaryGroup from an environ to an orbit box.
    * takes a military unit array and destination orbit
    * returns true if move successful; false otherwise
    */
    public boolean moveGroupFromEnvironToOrbit(MilitaryUnit[] units, Orbit newEnv)
    {
	//	System.out.println("TEST");
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	//check if nonmobile units outnumber mobile units
	boolean flag;
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	// move each MilitaryUnit individually
	for (int i=0;i<units.length;i++) {
	    flag = units[i].moveToOrbitBox(units[i],newEnv);
	    //if these units had a leader, remove the leader since not moving with the units
	    if (units[i].getLeader() != null){
		units[i].getLeader().getMUnitsLed().remove(units[i]);
		units[i].setLeader(null);
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	return(true);
    }
   /**
    * moveGroupFromEnvironToOrbit()
    * This method moves an array of Charactrs from an orbit box to
    * an orbit box using a spaceship(s).  Takes an array of charactrs,  
    * an array of spaceships, a destination orbit and a
    * destination group.  returns true if move successful; false otherwise
    */
    public boolean moveGroupFromEnvironToOrbit(Charactr[] c, Spaceship[] ships, Orbit newEnv, Group newGrp)
    {
	//check for null inputs
	if (newEnv == null || c.length == 0 || ships.length==0 || newGrp==null){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	int totalPassengers=0;
	boolean flag;
	// check to see if number of passengers exceeds capacity of ship(s) and
	// check to make sure each ship has a pilot
	for (int i=0;i<ships.length;i++){
	    totalPassengers += ships[i].getMaxPassengers();
	    if (ships[i].getHasPilot() == false){
	    System.out.println("ERROR: At least one of your ships does not have a pilot.  Please fix and try again.  Move failed.");
	    return(false);
	    }
	}
	if (c.length > totalPassengers){
	    System.out.println("ERROR: Trying to move too many passengers for the ship(s) you have selected. Move failed.");
	    return(false);
	}
	// move each Charactr individually
	for (int i=0;i<c.length;i++){
	    flag = c[i].moveToOrbitBox(c[i],newEnv,newGrp);
	    //if these charactrs led units before the move, remove them from the milUnitsLed
	    //vector since the milUnits did not move with them
	    if (c[i].getMUnitsLed().size()>0){
		for (int j=0;j<c[i].getMUnitsLed().size();j++){
		    ((MilitaryUnit)c[i].getMUnitsLed().elementAt(j)).setLeader(null);
		}
		c[i].getMUnitsLed().removeAllElements();
	    }
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
	// move each Spaceship individually
	for (int i=0;i<ships.length;i++){
	    flag = ships[i].moveToOrbitBox(ships[i],newEnv,newGrp);
	    if (flag == false)
		{
		    System.out.println("An ERROR occurred during the move - probably a bug");
		    return(false);
		}
	}
        return(true);
    }
   /**
    * moveGroupFromEnvironToOrbit()
    * This method moves an array of Military Units, an array of 
    * Charactrs, and an array of Spaceships to the military group of the
    * destination orbit box.  Takes an array of each of the above, plus 
    * the destination orbit.  Returns true if sucessful, false otherwise.
    */
    public boolean moveGroupFromEnvironToOrbit(MilitaryUnit[] units, Charactr[] c, Spaceship[] ships, Orbit newEnv)
    {
	System.out.println("TEST");
	//check for null inputs
	if (newEnv == null || units.length == 0){
		System.out.println("ERROR: One or more inputs NULL; please check and try again.");
		return(false);
	}
	//check if any of the units have been moved previously this turn
	for (int i=0;i<units.length;i++){
	    if (units[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<c.length;i++){
	    if (c[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}
	for (int i=0;i<ships.length;i++){
	    if (ships[i].getMoved()==true){
		System.out.println("ERROR: One or more of your units has already moved; please check and try again.");
		return(false);
	    }
	}

	boolean flag;
	//check if moving to another planet that mobile units >= nonmobile units
	int mobile=0,nonmobile=0;
	if (newEnv.getPlanet() != units[0].environ.getPlanet()){
	    for (int i=0;i<units.length;i++){
		if (units[i].getIsMobile() == false)
		    nonmobile++;
		else
		    mobile++;
	    }
	    if (mobile<nonmobile){
		System.out.println("ERROR: Illegal move; for this move, make sure the nonmobile military units don't exceed the mobile military units.");
		return(false);
	    }    
	}
	//move the military units
	moveGroupFromEnvironToOrbit(units,newEnv);

	// move the Spaceships
	//check if unit[0] is rebel or imperial & move spaceships to same group
	    // if rebel, move each Spaceship individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.rebelMilGroup.remove(ships[i]);
		ships[i].environ = null;
		newEnv.rebelMilGroup.add(ships[i]);
		ships[i].orbit = newEnv;
	    }
	}
	    // if imperial, move each spaceship individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<ships.length;i++){
		ships[i].environ.imperialMilGroup.remove(ships[i]);
		ships[i].environ = null;
		newEnv.imperialMilGroup.add(ships[i]);
		ships[i].orbit = newEnv;
	    }
	}

	//move the charactrs

	//since the characters are moving with military units, they don't necessarily need to be aboard a spaceship -- need to put code here to resolve that

	//check if unit[0] is rebel or imperial & move charactrs to same group
	    // if rebel, move each Charactr individually to rebMilGrp
	if (units[0].getSide() == 'R' || units[0].getSide() == 'r'){
	    for (int i=0;i<c.length;i++){
		c[i].environ.rebelMilGroup.remove(c[i]);
		ships[i].environ = null;
		newEnv.rebelMilGroup.add(c[i]);
		c[i].orbit = newEnv;
	    }
	}
	    // if imperial, move each Charactr individually to impMilGrp
	else if (units[0].getSide() == 'I' || units[0].getSide() == 'i'){
	    for (int i=0;i<c.length;i++){
		c[i].environ.imperialMilGroup.remove(c[i]);
		ships[i].environ = null;
		newEnv.imperialMilGroup.add(c[i]);
		c[i].orbit = newEnv;
	    }
	}

	    //clean up any leadership issues, i.e. if a character being passed is a leader of all
	    //of the military units in his/her old environ, but only some of those units are 
	    //moving to the new environ
	    flag = false;
	    Vector temp = new Vector();
	    Vector temp1 = new Vector();
	    for (int i=0;i<c.length;i++){
		if (c[i].getMUnitsLed().size()>0){
		    for (int j=0;j<units.length;j++){
			//get any units being passed that are common with the character's units led
			//and put them into a temp vector
			if (c[i].getMUnitsLed().contains(units[j]))
			    temp.add(units[j]);
			else 
			    temp1.add(units[j]);
		    }
		    //set the leader of character's units led to null
		    for (int k=0;k<c[i].getMUnitsLed().size();k++){
			((MilitaryUnit)c[i].getMUnitsLed().elementAt(k)).setLeader(null);
		    }
		    //remove all units from character's units led vector
		    c[i].getMUnitsLed().removeAllElements();
		    //set the leader for each unit in the temp vector to the character and
		    //add each member of the temp vector to mUnitsLed vector
		    for (int m=0;m<temp.size();m++){
			((MilitaryUnit)temp.elementAt(m)).setLeader(c[i]);
			c[i].getMUnitsLed().add((MilitaryUnit)temp.elementAt(m));
		    }
		    //done with the temp vector, remove its elements
		    temp.removeAllElements();

		    for  (int j=0;j<temp1.size();j++){
			if (((MilitaryUnit)temp1.elementAt(j)).getLeader()!=null){
			    //check whether the leader of other mUnits is being passed
			    for (int k=0;k<c.length;k++){
				//if they are, break out of this loop, they will be 
				//taken care of in other iteration of main loop
				if (((MilitaryUnit)temp1.elementAt(j)).getLeader()==c[k]){
				    flag = true;
				    break;
				}
			    }
			    //if the characteris not being passed, set links accordingly
			    if (flag==false){
				((MilitaryUnit)temp1.elementAt(j)).getLeader().getMUnitsLed().remove(temp1.elementAt(j));
				((MilitaryUnit)temp1.elementAt(j)).setLeader(null);
			    }
			}
		    }
		}
	    }
	    return(true);
    }
    public void foo(){
	System.out.println("TEST");
    }
    /** Test whether Group is empty */
    public boolean CheckEmpty() {
	if (units.isEmpty())
	    return(true);

	return(false);
    }

   
    /** Assigns wounds randomly to active Characters in combat */
    protected void assignWounds(int woundsToBeDealt) 
    {
	Unit curUnit;
	Charactr curChar;
	
	int randomIndex;
	Random randomCast = new Random();
	
	Vector activeVector = new Vector();
	
	int a = woundsToBeDealt;
	
	while(units.size() != 0 && a > 0) {
	    randomIndex = randomCast.nextInt(units.size());
	    curChar = (Charactr)units.elementAt(randomIndex);
	    //curUnit = (Unit)activeVector.elementAt(randomIndex);
	    
	    if (!(curChar.getIsPrisoner())) {
		curChar.changeLife(-1);
		units.remove(randomIndex);
		if (curChar.getLife() > 0)
		    units.add(curChar);
		a--;
	    }
	}
	
	return;
    }
}
