
import javax.swing.JOptionPane;
/**
 * Unit class
 */
public class Unit {
    protected char side,groupType,unitType;
    protected String name;
    protected int combat;
    protected Environ environ;
    protected Orbit orbit;
    protected Group group;
    protected boolean moved, isChar;
    /**
     * Constructor Methods
     */
    public Unit ()
    {
    }
    public Unit(char side, String name, int combat, int nada)
    {
    }

    public Unit(char s, String n, int com, Environ env, Group g)
    {
	side = s;
	name = n;
	combat = com;
	environ = env;
	group = g;
	moved = false;
	orbit = null;
    }
   /**
    * accessor methods
    */
   /**
    * getSide()
    * returns the loyalty (char) of the unit
    */
    public char getSide()
    {
	return side;
    }
   /**
    * getName()
    * returns the name (String) of the unit
    */
    public String getName()
    {
	return name;
    }
   /**
    * getMoved()
    * returns true if the unit has moved; false otherwise
    */
    public boolean getMoved()
    {
	if(Game.getAfterMove()==true)
	    moved=false;
	return moved;
    }
   /**
    * getCombat()
    * returns the combat ability (int) of the unit
    */
    public int getCombat()
    {
	return combat;
    }
   /**
    * getEnviron()
    * returns the current Environ that the unit is located on
    */
    public Environ getEnviron()
    {
	return environ;
    }
   /**
    * getEnviron()
    * returns the current Environ that the unit is located on
    */
    public Orbit getOrbit()
    {
	return orbit;
    }
    public void setEnviron(Environ newEnv)
    {
	environ = newEnv;
    }
    public void setOrbit(Orbit newOrb)
    {
	orbit = newOrb;
    }
    public char getGroupType() { 
        return groupType; 
    } 	
    public char getUnitType() { 
        return unitType; 
    } 
    public void setGroupType(char c) { 
        groupType = c; 
    }
   /**
    * moveShip()
    * The moveShip() method moves a spaceship from one environ to another.
    * takes a spaceship, a destination environ, and a destination group
    * returns true if move successful; false otherwise
    */
    public boolean moveShip(Spaceship ship, Environ newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.environ.getPlanet().PDBdetectionRoutine(ship);
	    ship.environ.rebelCharGroup.remove(ship);
	    newEnv.rebelCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;
	    ship.environ.getPlanet().PDBdetectionRoutine(ship);
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.environ.rebelCharGroup.remove(ship);
	    newEnv.rebelMilGroup.add(ship);
	    ship.environ = newEnv;
	    ship.setGroupType('m');
            ship.moved = true; 
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.environ.rebelMilGroup.remove(ship);
	    newEnv.rebelCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('c');
            ship.moved = true;
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.environ.rebelMilGroup.remove(ship);
	    newEnv.rebelMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;         
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.environ.imperialCharGroup.remove(ship);
	    newEnv.imperialCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;        
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.environ.imperialCharGroup.remove(ship);
	    newEnv.imperialMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('m');
            ship.moved = true;          
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.environ.imperialMilGroup.remove(ship);
	    newEnv.imperialCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('c');
            ship.moved = true;          
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.environ.imperialMilGroup.remove(ship);
	    newEnv.imperialMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;           
	    return(true);
	}
	return(false);
    }

   /**
    * moveTo()
    * This moveTo() method moves a military unit from one environ to another.
    * takes a military unit and destination environ
    * returns true if move successful; false otherwise
    */
    public boolean moveTo(MilitaryUnit m, Environ newEnv)
    {
	//check if moving to an environ on another planet and if 
	//military unit is not mobile
// 	if (newEnv.getPlanet() != (m.getEnviron().getPlanet())){
// 	    if (!m.getIsMobile()) {
// 		System.out.println("ERROR: Unit being moved is not mobile");
// 		return(false);
// 	    }
// 	}
	//check if rebel military units
	if (m.side == 'r' || m.side == 'R'){
	    if ((newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits())>0){
		m.environ.getRebelMilGroup().remove(m);
		newEnv.getRebelMilGroup().add(m);
		m.environ = newEnv;
	  	moved = true;
	    System.out.println(m.getName()+"'s new location: "+m.getEnviron().getStringType()+","+m.getEnviron().getPlanet().getName());
		return(true);
	    }
	    else {
		System.out.println("ERROR: Destination environ full");
		return(false);
	    }
	}
	//check if imperial military units
	if (m.side == 'i' || m.side == 'I')
       	    if (newEnv.getSize() > newEnv.getNumImperialMilUnits()) {
		m.environ.getImperialMilGroup().remove(m);
		newEnv.getImperialMilGroup().add(m);
		m.environ = newEnv;
                moved = true;
	    System.out.println(m.getName()+"'s new location: "+m.getEnviron().getStringType()+","+m.getEnviron().getPlanet().getName());
		return(true);
	    }
	    else {
		System.out.println("ERROR: Destination environ full");
		return(false);
	    }
	System.out.println("This shouldn't happen");
	return(false);
    }
   /**
    * moveTo()
    * This moveTo() method moves a Charactr from one environ to another.
    * takes a Charactr, destination environ, destination Group
    * returns true if move successful; false otherwise
    */
    public boolean moveTo(Charactr c, Environ newEnv, Group dest)
    {
	//this is the only case when a character move will fail
	//bug checking
	//	System.out.println(c.getAboardShip());
	//	System.out.println(newEnv.getPlanet());
	//	System.out.println(c.environ.getPlanet());
// this error case should be handled in the move method of the Group class
// 	if (c.getAboardShip() == false && newEnv.getPlanet() != c.environ.getPlanet()){
// 	    System.out.println("ERROR: Need spaceship");
// 	    return(false);
// 	}
	//case 1: move from rebelCharGroup to rebelCharGroup
        if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;
	    System.out.println(c.getCharName()+"'s new location: "+c.getEnviron().getStringType()+","+c.getEnviron().getPlanet().getName());
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
	    c.setGroupType('m');
            c.moved = true; 
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true;
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;         
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;        
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('m');
            c.moved = true;          
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true;          
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;           
	    return(true);
	}
	System.out.println("ERROR: Illegal move; the group that you are moving from must be on the same side (loyalty) as the group you are moving to");
	return(false);
    }

   /**
    * reactionMove()
    * This method moves a military unit from one environ to another using the rules for
    * reaction moves.  The environ being moved to must be on the same planet as the
    * unit's current environ.  Takes a military unit and an environ.
    * returns true if move successful; false otherwise
    */
    public boolean reactionMove(MilitaryUnit m, Charactr c, Environ newEnv)
    {
	boolean flag = false;
	if (m.getLeader() == c) {
	   flag =  reactionMove(m,newEnv);
	   if (flag == false)
	       return(false);
	   newEnv.setReactionMoveOK(true);
	   if (m.side == 'R' || m.side == 'r')
	       flag = reactionMove(c,newEnv,m.getEnviron().getRebelCharGroup());
	   else
	       flag = reactionMove(c,newEnv,m.getEnviron().getImperialCharGroup());
	}
	return(flag);
    }
   /**
    * reactionMove()
    * This method moves a military unit from one environ to another using the rules for
    * reaction moves.  The environ being moved to must be on the same planet as the
    * unit's current environ.  Takes a military unit and an environ.
    * returns true if move successful; false otherwise
    */
    public boolean reactionMove(MilitaryUnit m, Environ newEnv)
    {
	//check for null inputs
	if (m == null || newEnv == null){
	    JOptionPane.showMessageDialog(null,"ERROR: one or more of your inputs was null; please try again.  Reaction move failed.");
	    return(false);
	}
	//check whether reaction move is allowed for this environ
	if (newEnv.getReactionMoveOK() == false){
	    JOptionPane.showMessageDialog(null,"ERROR: a reaction move for this environ has already been made for this environ.  Reaction move failed.");
	    return(false);
	}
	//check that the planet of the new environ == planet of unit's current environ
	if (newEnv.getPlanet() != m.getEnviron().getPlanet()){
	    JOptionPane.showMessageDialog(null,"ERROR: a reaction move must occur between environs on the same planet.  Reaction move failed.");
	    return(false);
	}
	//if rebel mil unit being moved, check that imperial units are present in newEnv
	if (m.getSide()=='r' || m.getSide()=='R'){
	    if (newEnv.getImperialMilGroup().getNumUnits()==0 && newEnv.getImperialCharGroup().getNumDetectedChars()==0){
		JOptionPane.showMessageDialog(null,"ERROR: the destination environ contains no enemy military units or detected enemy characters.  Reaction move failed.");
		return(false);
	    }
	}
	//if imperial mil unit being moved, check that rebel units are present in newEnv
	if (m.getSide()=='i' || m.getSide()=='I'){
	    if (newEnv.getRebelMilGroup().getNumUnits()==0 && newEnv.getRebelCharGroup().getNumDetectedChars()==0){
		JOptionPane.showMessageDialog(null,"ERROR: the destination environ contains no enemy military units or detected enemy characters.  Reaction move failed.");
		return(false);
	    }
	}

	//if the previous checks have been passed, the move can commence
	if (m.side == 'r' || m.side == 'R'){
	    if ((newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits())>0){
		m.environ.getRebelMilGroup().remove(m);
		newEnv.getRebelMilGroup().add(m);
		m.environ = newEnv;
	  	moved = true;
	//if the military unit has a leader       
	if (m.getLeader() != null){
	    String input = JOptionPane.showInputDialog("Do you want to move the leader of this unit as well?");
	    if (input!=null&&(input.charAt(0)=='y'||input.charAt(0)=='Y')){
		//move the leader with this unit, and separate this leader from any
		//other units he/she might be leading
		for (int i=0;i<m.getLeader().getMUnitsLed().size();i++){
		    //remove all the military units being led except for m
		    if (((MilitaryUnit)m.getLeader().getMUnitsLed().elementAt(i)) != m){
			((MilitaryUnit)m.getLeader().getMUnitsLed().elementAt(i)).setLeader(null);
			m.getLeader().getMUnitsLed().remove(i);
		    }
		}
		//move the leader
		moveTo(m.getLeader(),newEnv,newEnv.getRebelMilGroup());
	    }
	}
	        newEnv.setReactionMoveOK(false);
		return(true);
	    }
	    else {
		JOptionPane.showMessageDialog(null,"ERROR: Destination environ full");
		return(false);
	    }
	}
	//check if imperial military units
	if (m.side == 'i' || m.side == 'I'){
       	    if (newEnv.getSize() > newEnv.getNumImperialMilUnits()) {
		m.environ.getImperialMilGroup().remove(m);
		newEnv.getImperialMilGroup().add(m);
		m.environ = newEnv;
                moved = true;
	        newEnv.setReactionMoveOK(false);
	    System.out.println(m.getName()+"'s new location: "+m.getEnviron().getStringType()+","+m.getEnviron().getPlanet().getName());
		return(true);
	    }
	    else {
		System.out.println("ERROR: Destination environ full");
		return(false);
	    }
	}
	System.out.println("This shouldn't happen");
	return(false);
    }

   /**
    * reactionMove()
    * This method moves a charactr from one environ to another using the rules for
    * reaction moves.  The environ being moved to must be on the same planet as the
    * unit's current environ.  Takes a charactr, an environ, and a Group.
    * returns true if move successful; false otherwise
    */
    public boolean reactionMove(Charactr c, Environ newEnv, Group dest)
    {
	//check for null inputs
	if (c == null || newEnv == null){
	    JOptionPane.showMessageDialog(null, "ERROR: one or more of your inputs was null; please try again.  Reaction move failed.");
	    return(false);
	}
	//check whether reaction move is allowed for this environ
	if (newEnv.getReactionMoveOK() == false){
	    JOptionPane.showMessageDialog(null,"ERROR: a reaction move for this environ has already been made for this environ.  Reaction move failed.");
	    return(false);
	}
	//check that the planet of the new environ == planet of unit's current environ
	if (newEnv.getPlanet() != c.getEnviron().getPlanet()){
	    JOptionPane.showMessageDialog(null, "ERROR: a reaction move must occur between environs on the same planet.  Reaction move failed.");
	    return(false);
	}
	//if rebel charactr being moved, check that imperial units are present in newEnv
	if (c.getSide()=='r' || c.getSide()=='R'){
	    if (newEnv.getImperialMilGroup().getNumUnits()==0 && newEnv.getImperialCharGroup().getNumDetectedChars()==0){
		JOptionPane.showMessageDialog(null,	"ERROR: the destination environ contains no enemy military units or detected enemy characters.  Reaction move failed.");
		return(false);
	    }
	}
	//if imperial charactr being moved, check that rebel units are present in newEnv
	if (c.getSide()=='i' || c.getSide()=='I'){
	    if (newEnv.getRebelMilGroup().getNumUnits()==0 && newEnv.getRebelCharGroup().getNumDetectedChars()==0){
		JOptionPane.showMessageDialog(null,"ERROR: the destination environ contains no enemy military units or detected enemy characters.  Reaction move failed.");
		return(false);
	    }
	}

	//if the previous checks have been passed, the move can commence
	//case 1: move from rebelCharGroup to rebelCharGroup
        if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
	    c.setGroupType('m');
            c.moved = true; 
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true;
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true; 
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true; 
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('m');
            c.moved = true;
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true; 
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true; 
	    newEnv.setReactionMoveOK(false);
	    return(true);
	}
	System.out.println("ERROR: Illegal move; the group that you are moving from must be on the same side (loyalty) as the group you are moving to");
	return(false);
    }

    //************************************************************************
    //The following move methods are used in the province and galactic game

   /**
    * moveFromOrbitBox()
    * This moveTo() method moves a military unit from an orbit box to environ.
    * takes a military unit and destination environ
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(MilitaryUnit m, Environ newEnv)
    {
	//check if rebel military units
	if (m.side == 'r' || m.side == 'R'){
	    if ((newEnv.getSize() - newEnv.getRebelMilGroup().getNumMilUnits())>0){
		m.orbit.getRebelMilGroup().remove(m);
		m.orbit = null;
		newEnv.getRebelMilGroup().add(m);
		m.environ = newEnv;
	  	moved = true;
	    System.out.println(m.getName()+"'s new location: "+m.getEnviron().getStringType()+","+m.getEnviron().getPlanet().getName());
		return(true);
	    }
	    else {
		System.out.println("ERROR: Destination environ full");
		return(false);
	    }
	}
	//check if imperial military units
	if (m.side == 'i' || m.side == 'I'){
       	    if (newEnv.getSize() > newEnv.getNumImperialMilUnits()) {
		m.orbit.getImperialMilGroup().remove(m);
		m.orbit = null;
		newEnv.getImperialMilGroup().add(m);
		m.environ = newEnv;
                moved = true;
	    System.out.println(m.getName()+"'s new location: "+m.getEnviron().getStringType()+","+m.getEnviron().getPlanet().getName());
		return(true);
	    }
	    else {
		System.out.println("ERROR: Destination environ full");
		return(false);
	    }
	}
	System.out.println("This shouldn't happen");
	return(false);
    }

   /**
    * moveFromOrbitBox()
    * This method moves a Charactr from an orbit box to an environ.
    * takes a Charactr, destination environ, destination Group
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(Charactr c, Environ newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.orbit.rebelCharGroup.remove(c);
	    c.orbit = null;
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;
	    System.out.println(c.getCharName()+"'s new location: "+c.getEnviron().getStringType()+","+c.getEnviron().getPlanet().getName());
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.orbit.rebelCharGroup.remove(c);
	    c.orbit = null;
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
	    c.setGroupType('m');
            c.moved = true; 
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.orbit.rebelMilGroup.remove(c);
	    c.orbit = null;
	    newEnv.rebelCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true;
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.orbit.rebelMilGroup.remove(c);
	    c.orbit = null;
	    newEnv.rebelMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;         
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.orbit.imperialCharGroup.remove(c);
	    c.orbit = null;
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;        
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.orbit.imperialCharGroup.remove(c);
	    c.orbit = null;
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('m');
            c.moved = true;          
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.orbit.imperialMilGroup.remove(c);
	    c.orbit = null;
	    newEnv.imperialCharGroup.add(c);
	    c.environ = newEnv;
            c.setGroupType('c');
            c.moved = true;          
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.orbit.imperialMilGroup.remove(c);
	    c.orbit = null;
	    newEnv.imperialMilGroup.add(c);
	    c.environ = newEnv;
            c.moved = true;           
	    return(true);
	}
	System.out.println("ERROR: Illegal move; the group that you are moving from must be on the same side (loyalty) as the group you are moving to");
	return(false);
    }
   /**
    * moveFromOrbitBox()
    * This method moves a spaceship from an orbit box to an environ.
    * takes a spaceship, a destination environ, and a destination group
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(Spaceship ship, Environ newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.orbit.rebelCharGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.rebelCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.orbit.rebelCharGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.rebelMilGroup.add(ship);
	    ship.environ = newEnv;
	    ship.setGroupType('m');
            ship.moved = true; 
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.orbit.rebelMilGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.rebelCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('c');
            ship.moved = true;
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.orbit.rebelMilGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.rebelMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;         
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.orbit.imperialCharGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.imperialCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;        
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.orbit.imperialCharGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.imperialMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('m');
            ship.moved = true;          
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.orbit.imperialMilGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.imperialCharGroup.add(ship);
	    ship.environ = newEnv;
            ship.setGroupType('c');
            ship.moved = true;          
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.orbit.imperialMilGroup.remove(ship);
	    ship.orbit = null;
	    newEnv.imperialMilGroup.add(ship);
	    ship.environ = newEnv;
            ship.moved = true;           
	    return(true);
	}
	return(false);
    }

   /**
    * moveFromOrbitBox()
    * This moveTo() method moves a military unit from an orbit box to another.
    * orbit box.  takes a military unit and destination orbit
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(MilitaryUnit m, Orbit newEnv)
    {
	//check if rebel military units
	if (m.side == 'r' || m.side == 'R'){
	    m.orbit.getRebelMilGroup().remove(m);
	    newEnv.getRebelMilGroup().add(m);
	    m.orbit = newEnv;
	    return(true);
	}
	//check if imperial military units
	if (m.side == 'i' || m.side == 'I'){
		m.orbit.getImperialMilGroup().remove(m);
		newEnv.getImperialMilGroup().add(m);
		m.orbit = newEnv;
 		return(true);
	    }
	System.out.println("This shouldn't happen");
	return(false);
    }


   /**
    * moveFromOrbitBox()
    * This method moves a Charactr from an orbit box to another orbit box.
    * takes a Charactr, destination orbit, destination Group
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(Charactr c, Orbit newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.orbit.rebelCharGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.orbit.rebelCharGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.orbit = newEnv;
	    c.setGroupType('m');
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.orbit.rebelMilGroup.remove(c);
	    newEnv.rebelCharGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('c');
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.orbit.rebelMilGroup.remove(c);
	    newEnv.rebelMilGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.orbit.imperialCharGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.orbit.imperialCharGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('m');
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.orbit.imperialMilGroup.remove(c);
	    newEnv.imperialCharGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('c');
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.orbit.imperialMilGroup.remove(c);
	    newEnv.imperialMilGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	System.out.println("ERROR: Illegal move; the group that you are moving from must be on the same side (loyalty) as the group you are moving to");
	return(false);
    }

   /**
    * moveFromOrbitBox()
    * This method moves a spaceship from an orbit box to another orbit box.
    * takes a spaceship, a destination orbit, and a destination group
    * returns true if move successful; false otherwise
    */
    public boolean moveFromOrbitBox(Spaceship ship, Orbit newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.orbit.rebelCharGroup.remove(ship);
	    newEnv.rebelCharGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.orbit.rebelCharGroup.remove(ship);
	    newEnv.rebelMilGroup.add(ship);
	    ship.orbit = newEnv;
	    ship.setGroupType('m');
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.orbit.rebelMilGroup.remove(ship);
	    newEnv.rebelCharGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('c');
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.orbit.rebelMilGroup.remove(ship);
	    newEnv.rebelMilGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.orbit.imperialCharGroup.remove(ship);
	    newEnv.imperialCharGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.orbit.imperialCharGroup.remove(ship);
	    newEnv.imperialMilGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('m');
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.orbit.imperialMilGroup.remove(ship);
	    newEnv.imperialCharGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('c');
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.orbit.imperialMilGroup.remove(ship);
	    newEnv.imperialMilGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	return(false);
    }
   /**
    * moveToOrbitBox()
    * This method moves a military unit from an environ to an orbit box.
    * orbit box.  takes a military unit and destination orbit
    * returns true if move successful; false otherwise
    */
    public boolean moveToOrbitBox(MilitaryUnit m, Orbit newEnv)
    {
	Environ nullEnv = null;
	//check if rebel military units
	if (m.side == 'r' || m.side == 'R'){
	    m.environ.getRebelMilGroup().remove(m);
	     	System.out.println("TEST");
	    m.environ = null;
	    // 	    newEnv.addToMilGroup(newEnv.getRebelMilGroup(),m);  //.add(m);
 	    m.orbit = newEnv;
	    return(true);
	}
	//check if imperial military units
	if (m.side == 'i' || m.side == 'I'){
	    m.environ.getImperialMilGroup().remove(m);
	    m.environ = null;
	    newEnv.getImperialMilGroup().add(m);
	    m.orbit = newEnv;
	    return(true);
	}
	System.out.println("This shouldn't happen");
	return(false);
    }
   /**
    * moveToOrbitBox()
    * This method moves a Charactr from an environ to an orbit box.
    * takes a Charactr, destination orbit, destination Group
    * returns true if move successful; false otherwise
    */
    public boolean moveToOrbitBox(Charactr c, Orbit newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    c.environ = null;
	    newEnv.rebelCharGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelCharGroup.remove(c);
	    c.environ = null;
	    newEnv.rebelMilGroup.add(c);
	    c.orbit = newEnv;
	    c.setGroupType('m');
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    c.environ = null;
	    newEnv.rebelCharGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('c');
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if (((c.side=='R'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='I'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    c.environ.rebelMilGroup.remove(c);
	    c.environ = null;
	    newEnv.rebelMilGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    c.environ = null;
	    newEnv.imperialCharGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='c')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialCharGroup.remove(c);
	    c.environ = null;
	    newEnv.imperialMilGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('m');
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    c.environ = null;
	    newEnv.imperialCharGroup.add(c);
	    c.orbit = newEnv;
            c.setGroupType('c');
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if (((c.side=='I'&&c.getIsPrisoner()==false&&c.groupType=='m')||(c.side=='R'&&c.getIsPrisoner()==true&&c.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    c.environ.imperialMilGroup.remove(c);
	    c.environ = null;
	    newEnv.imperialMilGroup.add(c);
	    c.orbit = newEnv;
	    return(true);
	}
	System.out.println("ERROR: Illegal move; the group that you are moving from must be on the same side (loyalty) as the group you are moving to");
	return(false);
    }
   /**
    * moveToOrbitBox()
    * This method moves a spaceship from an environ to an orbit box.
    * takes a spaceship, a destination orbit, and a destination group
    * returns true if move successful; false otherwise
    */
    public boolean moveToOrbitBox(Spaceship ship, Orbit newEnv, Group dest)
    {
	//case 1: move from rebelCharGroup to rebelCharGroup
        if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.environ.rebelCharGroup.remove(ship);
	    ship.environ = null;
	    newEnv.rebelCharGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 2: move from rebelCharGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.environ.rebelCharGroup.remove(ship);
	    ship.environ = null;
	    newEnv.rebelMilGroup.add(ship);
	    ship.orbit = newEnv;
	    ship.setGroupType('m');
	    return(true);
	}
	//case 3: move from rebelMilGroup to rebelCharGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='r')){
	    ship.environ.rebelMilGroup.remove(ship);
	    ship.environ = null;
	    newEnv.rebelCharGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('c');
	    return(true);
	}
	//case 4: move from rebelMilGroup to rebelMilGroup
        else if ((((ship.side=='R'||ship.side=='r')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='r')){
	    ship.environ.rebelMilGroup.remove(ship);
	    ship.environ = null;
	    newEnv.rebelMilGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 5: move from imperialCharGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.environ.imperialCharGroup.remove(ship);
	    ship.environ = null;
	    newEnv.imperialCharGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	//case 6: move from imperialCharGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='c'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.environ.imperialCharGroup.remove(ship);
	    ship.environ = null;
	    newEnv.imperialMilGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('m');
	    return(true);
	}
	//case 7: move from imperialMilGroup to imperialCharGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='c'&&dest.getSide()=='i')){
	    ship.environ.imperialMilGroup.remove(ship);
	    ship.environ = null;
	    newEnv.imperialCharGroup.add(ship);
	    ship.orbit = newEnv;
            ship.setGroupType('c');
	    return(true);
	}
	//case 8: move from imperialMilGroup to imperialMilGroup
        else if ((((ship.side=='I'||ship.side=='i')&&ship.groupType=='m'))&&(dest.getType()=='m'&&dest.getSide()=='i')){
	    ship.environ.imperialMilGroup.remove(ship);
	    ship.environ = null;
	    newEnv.imperialMilGroup.add(ship);
	    ship.orbit = newEnv;
	    return(true);
	}
	return(false);
    }
}
