/// <summary>
        /// Determines the hex that the selected unit will invade from.
        /// </summary>
        /// <param name="selectedUnit"></param>
        public void GetUnitInvasionHex(GameObject selectedUnit, GameObject selectedHex)
        {
            if (selectedHex != null)
            {
                if (selectedHex.GetComponent <HexDatabaseFields>().availableForMovement)
                {
                    GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().LandAlliedUnitFromOffBoard(selectedUnit, selectedHex, false);
                }
                else
                {
                    GlobalDefinitions.GuiDisplayUnitsOnHex(selectedHex);
                    GlobalDefinitions.GuiUpdateStatusMessage("Hex selected is not available for invasion, must select a highlighted hex");
                }
            }
            else
            {
                GlobalDefinitions.GuiUpdateStatusMessage("No hex selected, must select a highlighted hex");
            }

            if (GlobalDefinitions.selectedUnit != null)
            {
                GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
            }
            GlobalDefinitions.selectedUnit = null;

            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                GlobalDefinitions.UnhighlightHex(hex.gameObject);
                hex.GetComponent <HexDatabaseFields>().availableForMovement = false;
            }
        }
        /// <summary>
        /// This routine gets an invading unit from Britain
        /// </summary>
        /// <returns></returns>
        public GameObject GetInvadingUnit(GameObject selectedUnit)
        {
            GlobalDefinitions.WriteToLogFile("getInvadingUnit: executing for unit = " + selectedUnit.name);

            //  Check for valid unit
            if (selectedUnit == null)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("No unit selected; select a unit in Britain that is available to invade this turn");
            }

            // Check if the unit is on a sea hex, this would make it a unit that has already been deployed for an invasion
            // The user may be picking it in order to undo the selection.
            else if ((selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex != null) &&
                     (selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().sea))
            {
                // Hghlight the unit
                GlobalDefinitions.HighlightUnit(selectedUnit);
                return(selectedUnit);
            }

            // If the unit selected isn't in Britain than display the units in the gui
            else if (!selectedUnit.GetComponent <UnitDatabaseFields>().inBritain)
            {
                if (selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
                {
                    GlobalDefinitions.GuiDisplayUnitsOnHex(selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex);
                }
            }
            else if (selectedUnit.GetComponent <UnitDatabaseFields>().HQ)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("HQ units are not allowed to invade");
            }
            else if (selectedUnit.GetComponent <UnitDatabaseFields>().turnAvailable > GlobalDefinitions.turnNumber)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Unit selected is not available until turn " + selectedUnit.GetComponent <UnitDatabaseFields>().turnAvailable);
            }
            else
            {
                // Check if the unit is available for the first invasion area

                if (GlobalDefinitions.turnNumber == 1)
                {
                    if (GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].totalUnitsUsedThisTurn <
                        ReturnMaxTotalUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex]))
                    {
                        if (selectedUnit.GetComponent <UnitDatabaseFields>().armor)
                        {
                            if (GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].armorUnitsUsedThisTurn <
                                ReturnMaxArmorUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex]))
                            {
                                // Valid unit so highlight the hexes available in the invasion area
                                GlobalDefinitions.HighlightUnit(selectedUnit);
                                HighlightAvailableInvasionHexes(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex]);
                                return(selectedUnit);
                            }
                        }
                        else if (selectedUnit.GetComponent <UnitDatabaseFields>().infantry || selectedUnit.GetComponent <UnitDatabaseFields>().airborne)
                        {
                            //GlobalDefinitions.writeToLogFile("getInvadingUnit: infantry units used this turn = " + GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].infantryUnitsUsedThisTurn);
                            //GlobalDefinitions.writeToLogFile("getInvadingUnit: max infantry units this turn = " + returnMaxInfantryUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex]));
                            // Need to check for using infantry against the armor limit
                            if ((GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].infantryUnitsUsedThisTurn <
                                 ReturnMaxInfantryUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex])) ||
                                (GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].armorUnitsUsedThisTurn <
                                 ReturnMaxArmorUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex])))
                            {
                                // Valid unit so highlight the hexes available in the invasion area
                                GlobalDefinitions.HighlightUnit(selectedUnit);
                                HighlightAvailableInvasionHexes(GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex]);
                                return(selectedUnit);
                            }
                        }
                        else
                        {
                            // Don't know why we would ever get here but if we do return a null
                            GlobalDefinitions.GuiUpdateStatusMessage("Internal Error - Selected unit is not recognized as armor, infantry, or airborne");
                        }
                    }
                }
                else
                {
                    // Need to check the second invasion area
                    if (GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].totalUnitsUsedThisTurn <
                        ReturnMaxTotalUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex]))
                    {
                        if (selectedUnit.GetComponent <UnitDatabaseFields>().armor)
                        {
                            if (GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].armorUnitsUsedThisTurn <
                                ReturnMaxArmorUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex]))
                            {
                                // Valid unit so highlight the hexes available in the invasion area
                                GlobalDefinitions.HighlightUnit(selectedUnit);
                                HighlightAvailableInvasionHexes(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex]);
                                return(selectedUnit);
                            }
                        }
                        else if (selectedUnit.GetComponent <UnitDatabaseFields>().infantry || selectedUnit.GetComponent <UnitDatabaseFields>().airborne)
                        {
                            // Need to check for using infantry against the armor limit
                            if ((GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].infantryUnitsUsedThisTurn <
                                 ReturnMaxInfantryUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex])) ||
                                (GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].armorUnitsUsedThisTurn <
                                 ReturnMaxArmorUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex])))
                            {
                                // Valid unit so highlight the hexes available in the invasion area
                                GlobalDefinitions.HighlightUnit(selectedUnit);
                                HighlightAvailableInvasionHexes(GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex]);
                                return(selectedUnit);
                            }
                        }
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// This routine pulls all the defenders and attackers based on the hex passed and then calls the combat selection GUI
        /// </summary>
        /// <param name="defendingNationality"></param>
        public void PrepForCombatDisplay(GameObject hex, GlobalDefinitions.Nationality defendingNationality)
        {
            // First thing we need to do is check that the combat assignment gui isn't already active.  If it is do not load anoether one.
            if (GameObject.Find("CombatGUIInstance") != null)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Resolve current combat assignment before assigning another");
                return;
            }

            GameObject singleCombat = new GameObject("prepForCombatDisplay");

            singleCombat.AddComponent <Combat>();
            // Check if the hex has uncommittted units of the right nationality on it and there are adjacent enemies
            if ((hex != null) &&
                (hex.GetComponent <HexDatabaseFields>().occupyingUnit.Count > 0) &&
                (hex.GetComponent <HexDatabaseFields>().occupyingUnit[0].GetComponent <UnitDatabaseFields>().nationality == defendingNationality) &&
                NonCommittedDefendersAvailable(hex) &&
                (ReturnUncommittedUnits(ReturnAdjacentEnemyUnits(hex, GlobalDefinitions.ReturnOppositeNationality(defendingNationality))).Count > 0))
            {
                // Get all the available defending units
                singleCombat.GetComponent <Combat>().defendingUnits = ReturnUncommittedUnits(hex.GetComponent <HexDatabaseFields>().occupyingUnit);

                singleCombat.GetComponent <Combat>().attackingUnits = ReturnUncommittedUnits(ReturnAdjacentEnemyUnits(hex, GlobalDefinitions.ReturnOppositeNationality(defendingNationality)));

                // Fianlly we have to get all potential defenders that are adjacent to the attackers
                foreach (GameObject defender in ReturnUncommittedUnits(ReturnAdjacentDefenders(hex, singleCombat)))
                {
                    if (!singleCombat.GetComponent <Combat>().defendingUnits.Contains(defender))
                    {
                        singleCombat.GetComponent <Combat>().defendingUnits.Add(defender);
                    }
                }

                CallCombatDisplay(singleCombat);
            }
            else
            {
                if (hex == null)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No valid hex selected for combat; hex selected must contain enemy units");
                }
                else if (hex.GetComponent <HexDatabaseFields>().occupyingUnit.Count == 0)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No units found on hex selected for combat; hex selected must contain enemy units");
                }
                else if (!NonCommittedDefendersAvailable(hex))
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No uncommitted defenders found on hex selected; all units on hex are already assigned to combat.  Cancel attacks and reassign combat to add additional attacking units.");
                }
                else if (ReturnUncommittedUnits(ReturnAdjacentEnemyUnits(hex, GlobalDefinitions.ReturnOppositeNationality(defendingNationality))).Count == 0)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No units are available to attack the hex selected");
                }
                //else if (hex.GetComponent<HexDatabaseFields>().occupyingUnit[0].GetComponent<UnitDatabaseFields>().nationality != defendingNationality)
                else
                {
                    GlobalDefinitions.GuiDisplayUnitsOnHex(hex);
                }

                if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedMovementStateInstance") ||
                    (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanMovementStateInstance"))
                {
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <MovementState>().ExecuteSelectUnit;
                }
                else if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedInvasionStateInstance")
                {
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <AlliedInvasionState>().ExecuteSelectUnit;
                }
                else if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedAirborneStateInstance")
                {
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <AlliedAirborneState>().ExecuteSelectUnit;
                }
                else
                {
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <CombatState>().ExecuteSelectUnit;
                }
            }
        }