Exemple #1
0
        /// <summary>
        /// Write out the current configuration settings to the configuration file
        /// </summary>
        /// <param name="difficultySetting"></param>
        /// <param name="aggresivenessSetting"></param>
        public void WriteSettingsFile(int difficultySetting, int aggressiveSetting)
        {
            if (File.Exists(GlobalGameFields.settingsFile))
            {
                File.Delete(GlobalGameFields.settingsFile);
            }
            StreamWriter fileWriter = new StreamWriter(GlobalGameFields.settingsFile);

            GlobalDefinitions.WriteToLogFile("writeSettingsFile: creating file = " + GlobalGameFields.settingsFile);
            if (fileWriter == null)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Unable to create the settings file " + GameControl.path + "TGCSettingsFile.txt");
            }
            else
            {
                GlobalDefinitions.difficultySetting = Convert.ToInt32(difficultySetting);
                GlobalDefinitions.aggressiveSetting = Convert.ToInt32(aggressiveSetting);

                fileWriter.WriteLine("Difficulty " + difficultySetting);
                GlobalDefinitions.WriteToLogFile("writeSettingsFile: Difficulty = " + difficultySetting);
                fileWriter.WriteLine("Aggressive " + aggressiveSetting);
                GlobalDefinitions.WriteToLogFile("writeSettingsFile: Aggressive = " + aggressiveSetting);
                fileWriter.Close();
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads the configuration settings from the configuration file
        /// </summary>
        public void ReadSettingsFile()
        {
            char[] delimiterChars = { ' ' };
            string line;

            string[] switchEntries;

            StreamReader theReader = new StreamReader(GlobalGameFields.settingsFile);

            using (theReader)
            {
                do
                {
                    line = theReader.ReadLine();
                    if (line != null)
                    {
                        switchEntries = line.Split(delimiterChars);
                        switch (switchEntries[0])
                        {
                        case "Difficulty":
                            GlobalDefinitions.WriteToLogFile("readSettingsFile: " + line);
                            GlobalDefinitions.difficultySetting = Convert.ToInt32(switchEntries[1]);
                            break;

                        case "Aggressive":
                            GlobalDefinitions.WriteToLogFile("readSettingsFile: " + line);
                            GlobalDefinitions.aggressiveSetting = Convert.ToInt32(switchEntries[1]);
                            break;
                        }
                    }
                }while (line != null);
                theReader.Close();
            }
        }
        /// <summary>
        /// Used to toggle the air support option on the combat gui in network games
        /// </summary>
        public void ToggleAirSupport()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.TOGGLEAIRSUPPORTCOMBATTOGGLE + " " + name);

            if (this.GetComponent <Toggle>().isOn)
            {
                if (GlobalDefinitions.tacticalAirMissionsThisTurn < GlobalDefinitions.maxNumberOfTacticalAirMissions)
                {
                    currentCombat.GetComponent <Combat>().attackAirSupport = true;
                    GlobalDefinitions.WriteToLogFile("toggleAirSupport: incrementing GlobalDefinitions.tacticalAirMissionsThisTurn");
                    GlobalDefinitions.tacticalAirMissionsThisTurn++;
                }
                else
                {
                    GlobalDefinitions.WriteToLogFile("No more air missions available");
                    this.GetComponent <Toggle>().isOn = false;
                }
            }
            else
            {
                currentCombat.GetComponent <Combat>().attackAirSupport = false;
                GlobalDefinitions.tacticalAirMissionsThisTurn--;
            }
            UpdateOddsText();
        }
Exemple #4
0
        public void NewSavedGameOK()
        {
            if (GlobalDefinitions.newGameToggle.GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToLogFile("newSavedGameOK: Starting new game");

                GUIRoutines.RemoveGUI(transform.parent.gameObject);
                GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteNewGame();
            }
            else if (GlobalDefinitions.savedGameToggle.GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToLogFile("newSavedGameOK: Starting saved game");

                // Since at this point we know we are starting a new game and not running the command file, remove the command file
                if (!GlobalDefinitions.commandFileBeingRead)
                {
                    GlobalDefinitions.DeleteCommandFile();
                }

                GUIRoutines.RemoveGUI(transform.parent.gameObject);
                GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteSavedGame();
            }
            else if (GlobalDefinitions.commandFileToggle.GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToLogFile("newSavedGameOK: Executing command file");

                GUIRoutines.RemoveGUI(transform.parent.gameObject);
                GameControl.setUpStateInstance.GetComponent <SetUpState>().ReadCommandFile();
            }
        }
Exemple #5
0
        /// <summary>
        /// Draws a line between the two points passed
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        public static void DrawLineBetweenTwoPoints(Vector3 point1, Vector3 point2, float width, UnityEngine.Color color)
        {
            Material   lineMaterial = Resources.Load("LineMaterial", typeof(Material)) as Material;
            GameObject line         = new GameObject("DrawLineBetweenTwoPoints");

            if (lineMaterial == null)
            {
                GlobalDefinitions.WriteToLogFile("DrawLineBetweenTwoPoints: ERROR - Material returned null from Resources");
            }

            line.layer = LayerMask.NameToLayer("Lines");
            line.transform.SetParent(GameObject.Find("Lines").transform);

            Vector3[] linePositions = new Vector3[2];
            linePositions[0] = point1;
            linePositions[1] = point2;

            line.AddComponent <LineRenderer>();
            line.GetComponent <LineRenderer>().useWorldSpace  = true;
            line.GetComponent <LineRenderer>().startColor     = color;
            line.GetComponent <LineRenderer>().endColor       = color;
            line.GetComponent <LineRenderer>().positionCount  = 2;
            line.GetComponent <LineRenderer>().startWidth     = 0.5f;
            line.GetComponent <LineRenderer>().endWidth       = 0.5f;
            line.GetComponent <LineRenderer>().numCapVertices = 10;
            line.GetComponent <LineRenderer>().material       = lineMaterial;
            line.GetComponent <LineRenderer>().SetPositions(linePositions);
            line.GetComponent <LineRenderer>().sortingLayerName = "Lines";
            line.GetComponent <LineRenderer>().startWidth       = width;
            line.GetComponent <LineRenderer>().endWidth         = width;
        }
 /// <summary>
 /// This routine is called when a unit decides to attack from a fortress.   It toggles all units that would be in the unit's ZOC if it wasn't in a fortress.
 /// </summary>
 /// <param name="fortressHex"></param>
 public void AddDefendersOfFortressAttack(GameObject fortressHex)
 {
     foreach (HexDefinitions.HexSides hexSide in Enum.GetValues(typeof(HexDefinitions.HexSides)))
     {
         if (fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide] != null)
         {
             if (!fortressHex.GetComponent <BooleanArrayData>().riverSides[(int)hexSide] &&
                 !fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().fortress)
             {
                 if ((fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit.Count > 0) &&
                     (fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit[0].GetComponent <UnitDatabaseFields>().nationality !=
                      fortressHex.GetComponent <HexDatabaseFields>().occupyingUnit[0].GetComponent <UnitDatabaseFields>().nationality))
                 {
                     // If we get here then the unit should be highlighted since it is adjacent and isn't separated by a river or it isn't a fortress
                     foreach (GameObject unit in fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit)
                     {
                         GlobalDefinitions.HighlightUnit(unit);
                         foreach (Transform childTransform in transform.parent.transform)
                         {
                             if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == unit))
                             {
                                 // Turn on the defenders toggle to show that the unit must be attacked
                                 GlobalDefinitions.WriteToLogFile("addDefendersOfFortressAttack: adding unit " + unit.name + " as defender of attack from fortress");
                                 childTransform.GetComponent <Toggle>().isOn = true;
                                 // The only way to turn the toggle off will be to click off the attacking unit
                                 childTransform.GetComponent <Toggle>().interactable = false;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #7
0
        /// <summary>
        /// Creates the state instances and sets up the state transitions for network or hotseat games
        /// </summary>
        public static void CreateStatesForHotSeatOrNetwork()
        {
            GlobalDefinitions.WriteToLogFile("createStatesForHotSeatOrNetwork: executing");

            setUpStateInstance = new GameObject("setUpStateInstance");
            turnInitializationStateInstance = new GameObject("turnInitializationStateInstance");
            alliedReplacementStateInstance  = new GameObject("alliedReplacementStateInstance");
            alliedSupplyStateInstance       = new GameObject("alliedSupplyStateInstance");
            alliedInvasionStateInstance     = new GameObject("alliedInvasionStateInstance");
            alliedAirborneStateInstance     = new GameObject("alliedAirborneStateInstance");
            alliedMovementStateInstance     = new GameObject("alliedMovementStateInstance");
            alliedCombatStateInstance       = new GameObject("alliedCombatStateInstance");
            alliedTacticalAirStateInstance  = new GameObject("alliedTacticalAirStateInstance");
            germanIsolationStateInstance    = new GameObject("germanIsolationStateInstance");
            germanReplacementStateInstance  = new GameObject("germanReplacementStateInstance");
            germanMovementStateInstance     = new GameObject("germanMovementStateInstance");
            germanCombatStateInstance       = new GameObject("germanCombatStateInstance");

            setUpStateInstance.AddComponent <SetUpState>();
            turnInitializationStateInstance.AddComponent <TurnInitializationState>();
            alliedReplacementStateInstance.AddComponent <AlliedReplacementState>();
            alliedSupplyStateInstance.AddComponent <SupplyState>();
            alliedInvasionStateInstance.AddComponent <AlliedInvasionState>();
            alliedAirborneStateInstance.AddComponent <AlliedAirborneState>();
            alliedMovementStateInstance.AddComponent <MovementState>();
            alliedCombatStateInstance.AddComponent <CombatState>();
            alliedTacticalAirStateInstance.AddComponent <AlliedTacticalAirState>();
            germanIsolationStateInstance.AddComponent <GermanIsolationState>();
            germanReplacementStateInstance.AddComponent <GermanReplacementState>();
            germanMovementStateInstance.AddComponent <MovementState>();
            germanCombatStateInstance.AddComponent <CombatState>();

            // Set up the state transitions
            setUpStateInstance.GetComponent <SetUpState>().nextGameState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
            turnInitializationStateInstance.GetComponent <TurnInitializationState>().nextGameState = alliedReplacementStateInstance.GetComponent <AlliedReplacementState>();
            alliedReplacementStateInstance.GetComponent <AlliedReplacementState>().nextGameState   = alliedSupplyStateInstance.GetComponent <SupplyState>();
            alliedSupplyStateInstance.GetComponent <SupplyState>().nextGameState                 = alliedInvasionStateInstance.GetComponent <AlliedInvasionState>();
            alliedInvasionStateInstance.GetComponent <AlliedInvasionState>().nextGameState       = alliedAirborneStateInstance.GetComponent <AlliedAirborneState>();
            alliedAirborneStateInstance.GetComponent <AlliedAirborneState>().nextGameState       = alliedMovementStateInstance.GetComponent <MovementState>();
            alliedMovementStateInstance.GetComponent <MovementState>().nextGameState             = alliedCombatStateInstance.GetComponent <CombatState>();
            alliedCombatStateInstance.GetComponent <CombatState>().nextGameState                 = alliedTacticalAirStateInstance.GetComponent <AlliedTacticalAirState>();
            alliedTacticalAirStateInstance.GetComponent <AlliedTacticalAirState>().nextGameState = germanIsolationStateInstance.GetComponent <GermanIsolationState>();
            germanIsolationStateInstance.GetComponent <GermanIsolationState>().nextGameState     = germanReplacementStateInstance.GetComponent <GermanReplacementState>();
            germanReplacementStateInstance.GetComponent <GermanReplacementState>().nextGameState = germanMovementStateInstance.GetComponent <MovementState>();
            germanMovementStateInstance.GetComponent <MovementState>().nextGameState             = germanCombatStateInstance.GetComponent <CombatState>();
            germanCombatStateInstance.GetComponent <CombatState>().nextGameState                 = turnInitializationStateInstance.GetComponent <TurnInitializationState>();

            // Set up the correct nationality for the game states that share
            turnInitializationStateInstance.GetComponent <TurnInitializationState>().currentNationality = GlobalDefinitions.Nationality.Allied;
            germanIsolationStateInstance.GetComponent <GermanIsolationState>().currentNationality       = GlobalDefinitions.Nationality.German;
            alliedMovementStateInstance.GetComponent <MovementState>().currentNationality = GlobalDefinitions.Nationality.Allied;
            alliedCombatStateInstance.GetComponent <CombatState>().currentNationality     = GlobalDefinitions.Nationality.Allied;
            germanMovementStateInstance.GetComponent <MovementState>().currentNationality = GlobalDefinitions.Nationality.German;
            germanCombatStateInstance.GetComponent <CombatState>().currentNationality     = GlobalDefinitions.Nationality.German;
        }
        /// <summary>
        /// This routine is used to adjust the unit limits when a unit is landed from Britain
        /// </summary>
        /// <param name="unit"></param>
        public void IncrementInvasionUnitLimits(GameObject unit)
        {
            int invasionAreaIndex = unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().invasionAreaIndex;

            if ((GlobalDefinitions.invasionAreas[invasionAreaIndex].invaded) &&
                ((GlobalDefinitions.invasionAreas[invasionAreaIndex].turn == 1) || (GlobalDefinitions.invasionAreas[invasionAreaIndex].turn == 2)))
            {
                if (unit.GetComponent <UnitDatabaseFields>().armor)
                {
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].armorUnitsUsedThisTurn++;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn++;
                    GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn++;
                }
                else if (unit.GetComponent <UnitDatabaseFields>().infantry)
                {
                    //  First check if infantry should be used against the armor limits
                    if (GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUnitsUsedThisTurn ==
                        ReturnMaxInfantryUnitsForInvasionAreaThisTurn(GlobalDefinitions.invasionAreas[invasionAreaIndex]))
                    {
                        // If so then increment the armor and the decrement the infantry used as armor
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].armorUnitsUsedThisTurn++;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUsedAsArmorThisTurn++;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn++;
                        GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn++;
                    }
                    else
                    {
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUnitsUsedThisTurn++;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn++;
                        GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn++;
                    }
                }
                else if (unit.GetComponent <UnitDatabaseFields>().airborne)
                {
                    //  Airborne landed over a beach counts against the infantry limits
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUnitsUsedThisTurn++;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].airborneUsedAsInfantryThisTurn++;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn++;
                    GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn++;
                }
                else
                {
                    GlobalDefinitions.WriteToLogFile("incrementInvasionLimits: ERROR - unit = " + unit.name + " Most likely due to an HQ being landed during the first two turns.. This should never be executed");
                }
            }
            else
            {
                // Note that a unit being landed in a non-invasion area so use the turn three limits
                GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn++;
                GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn++;
            }
        }
 /// <summary>
 /// Sets the global variables related to an invasion site
 /// </summary>
 /// <param name="invadedAreaSectionIndex"></param>
 public void SetInvasionArea(int invadedAreaSectionIndex)
 {
     GlobalDefinitions.WriteToLogFile("setInvasionArea: executing with index " + invadedAreaSectionIndex);
     GlobalDefinitions.numberInvasionsExecuted++;
     if (GlobalDefinitions.turnNumber == 1)
     {
         GlobalDefinitions.firstInvasionAreaIndex = invadedAreaSectionIndex;
         GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].invaded = true;
         GlobalDefinitions.invasionAreas[GlobalDefinitions.firstInvasionAreaIndex].turn    = 1;
     }
     else
     {
         GlobalDefinitions.secondInvasionAreaIndex = invadedAreaSectionIndex;
         GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].invaded = true;
         GlobalDefinitions.invasionAreas[GlobalDefinitions.secondInvasionAreaIndex].turn    = 1;
     }
 }
        // Called when the user select to change the status of air support on the combat resolution gui
        public void AddAttackAirSupport()
        {
            if (GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.ADDCOMBATAIRSUPPORTKEYWORD + " " + name);

                if (GlobalDefinitions.tacticalAirMissionsThisTurn < GlobalDefinitions.maxNumberOfTacticalAirMissions)
                {
                    curentCombat.GetComponent <Combat>().attackAirSupport = true;
                    GlobalDefinitions.WriteToLogFile("addAttackAirSupport: incrementing GlobalDefinitions.tacticalAirMissionsThisTurn");
                    GlobalDefinitions.tacticalAirMissionsThisTurn++;
                    attackFactorTextGameObject.GetComponent <TextMeshProUGUI>().text =
                        CalculateBattleOddsRoutines.CalculateAttackFactor(
                            curentCombat.GetComponent <Combat>().attackingUnits,
                            curentCombat.GetComponent <Combat>().attackAirSupport).ToString();
                    oddsTextGameObject.GetComponent <TextMeshProUGUI>().text =
                        GlobalDefinitions.ConvertOddsToString(
                            CalculateBattleOddsRoutines.ReturnCombatOdds(curentCombat.GetComponent <Combat>().defendingUnits,
                                                                         curentCombat.GetComponent <Combat>().attackingUnits,
                                                                         curentCombat.GetComponent <Combat>().attackAirSupport));
                }
                else
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No more air support missions left to assign");
                    GetComponent <Toggle>().isOn = false;
                }
            }
            else
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.REMOVECOMBATAIRSUPPORTKEYWORD + " " + name);

                curentCombat.GetComponent <Combat>().attackAirSupport = false;
                GlobalDefinitions.tacticalAirMissionsThisTurn--;
                attackFactorTextGameObject.GetComponent <TextMeshProUGUI>().text =
                    CalculateBattleOddsRoutines.CalculateAttackFactor(
                        curentCombat.GetComponent <Combat>().attackingUnits,
                        curentCombat.GetComponent <Combat>().attackAirSupport).ToString();
                oddsTextGameObject.GetComponent <TextMeshProUGUI>().text =
                    GlobalDefinitions.ConvertOddsToString(
                        CalculateBattleOddsRoutines.ReturnCombatOdds(
                            curentCombat.GetComponent <Combat>().defendingUnits,
                            curentCombat.GetComponent <Combat>().attackingUnits,
                            curentCombat.GetComponent <Combat>().attackAirSupport));
            }
        }
 private int ReturnMaxInfantryUnitsForInvasionAreaThisTurn(InvasionArea targetArea)
 {
     if (targetArea.turn == 0)
     {
         GlobalDefinitions.WriteToLogFile("returnMaxInfantryUnitsForInvasionAreaThisTurn: Something is wrong - invasion area with turn set to 0");
         return(0);
     }
     else if (targetArea.turn == 1)
     {
         return(targetArea.firstTurnInfantry);
     }
     else if (targetArea.turn == 2)
     {
         return(targetArea.secondTurnInfantry);
     }
     else
     {
         return(targetArea.divisionsPerTurn);
     }
 }
        /// <summary>
        /// Routine pulls up a list of the invasion areas for the user to select from.
        /// </summary>
        /// <returns></returns>
        public void SelectInvasionArea()
        {
            GlobalDefinitions.WriteToLogFile("selectInvasionArea: executing");
            Canvas invasionAreaSelectionCanvasInstance = new Canvas();

            float panelWidth  = 3 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = 9 * GlobalDefinitions.GUIUNITIMAGESIZE;

            GlobalDefinitions.invasionAreaSelectionGUIInstance = GUIRoutines.CreateGUICanvas("InvasionAreaSelectionGUIInstance",
                                                                                             panelWidth,
                                                                                             panelHeight,
                                                                                             ref invasionAreaSelectionCanvasInstance, 0.16f, 0.16f);
            GlobalDefinitions.invasionAreaSelectionGUIInstance.GetComponent <RectTransform>().anchorMin = new Vector2(0.16f, 0.5f);

            GUIRoutines.CreateUIText("Select invasion area", "InvasionAreaSelectionText",
                                     (3) * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                     (8) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                     Color.white,
                                     invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f);
            for (int index = 0; index < 7; index++)
            {
                Toggle tempToggle;
                GUIRoutines.CreateUIText(GlobalDefinitions.invasionAreas[index].name,
                                         "InvasionAreaSelectionText",
                                         2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         GlobalDefinitions.GUIUNITIMAGESIZE,
                                         GlobalDefinitions.GUIUNITIMAGESIZE * 1.25f - 0.5f * panelWidth,
                                         (index + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white,
                                         invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f);
                tempToggle = GUIRoutines.CreateToggle("InvasionAreaSelectionToggle" + index,
                                                      2 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                                      (index + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                      invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f).GetComponent <Toggle>();
                tempToggle.gameObject.AddComponent <InvasionSelectionToggleRoutines>();
                tempToggle.GetComponent <InvasionSelectionToggleRoutines>().index = index;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <InvasionSelectionToggleRoutines>().InvadedAreaSelected());
            }
        }
        /// <summary>
        /// Executes when the OK button is selected
        /// </summary>
        public void OkGameMode()
        {
            if (MainMenuRoutines.hotseatToggle.GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToLogFile("okGameMode: Setting up hotseat mode");
                GlobalDefinitions.gameMode          = GlobalDefinitions.GameModeValues.Hotseat;
                GlobalDefinitions.commandFileHeader = "Hotseat";
                GameControl.CreateStatesForHotSeatOrNetwork();
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState = GameControl.setUpStateInstance.GetComponent <SetUpState>();
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.Initialize();
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod(GameControl.inputMessage.GetComponent <InputMessage>());
                GlobalDefinitions.gameStarted = true;
                GlobalDefinitions.SwitchLocalControl(true);
                GUIRoutines.RemoveGUI(transform.parent.gameObject);
            }
            else if (MainMenuRoutines.AIToggle.GetComponent <Toggle>().isOn)
            {
                // Note: unlike hotseat or network the state transitions in AI are determined by the side being played so the state creation is called in the button routines
                // that are invoked by the user selecting the side to play
                GlobalDefinitions.WriteToLogFile("okGameMode: Setting up AI mode");
                GlobalDefinitions.commandFileHeader = "AI";
                GlobalDefinitions.AskUserWhichSideToPlay();
                GUIRoutines.RemoveGUI(transform.parent.gameObject);
            }
            //else if (MainMenuRoutines.peerToPeerNetworkToggle.GetComponent<Toggle>().isOn)
            //{
            //    GlobalDefinitions.WriteToLogFile("okGameMode: Setting up Peer to Peer Network mode");
            //    GlobalDefinitions.gameMode = GlobalDefinitions.GameModeValues.Peer2PeerNetwork;
            //    GlobalDefinitions.commandFileHeader = "Peer2PeerNetwork";
            //    GameControl.CreateStatesForHotSeatOrNetwork();
            //    //GameControl.fileTransferServerInstance.GetComponent<FileTransferServer>().initiateFileTransferServer();
            //    MainMenuRoutines.NetworkSettingsUI();

            //    GUIRoutines.RemoveGUI(transform.parent.gameObject);
            //}
        }
Exemple #14
0
        /// <summary>
        /// This routine goes through a series of checks to see if the units are setup properly.
        /// </summary>
        /// <returns></returns>
        public static bool UpdateHexFields()
        {
            bool returnState = true;

            // Do an initial load of the GermanUnitsOnBoardList
            GlobalDefinitions.germanUnitsOnBoard.Clear(); // Clear it out first in case multiple passes are made.
            foreach (Transform unit in GameObject.Find("Units On Board").transform)
            {
                if (unit.GetComponent <UnitDatabaseFields>().nationality == GlobalDefinitions.Nationality.German)
                {
                    GlobalDefinitions.germanUnitsOnBoard.Add(unit.gameObject);
                }
            }

            GlobalDefinitions.WriteToLogFile("updateHexFields: executing ... number of German units on board = " + GlobalDefinitions.germanUnitsOnBoard.Count);

            foreach (GameObject unit in GlobalDefinitions.germanUnitsOnBoard)
            {
                // Unhighlight the unit so that if all units pass they will be unhighlighted
                GlobalDefinitions.UnhighlightUnit(unit);

                // Not sure if this is needed.  Can't really be in "Units On Board" without a hex assignment
                if (unit.GetComponent <UnitDatabaseFields>().occupiedHex == null)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("Internal Error - Unit " + unit.GetComponent <UnitDatabaseFields>().name + " is not assigned a hex locunit.GetComponent<UnitDatabaseFields>().ation");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                // German static units must be on a coast or inland port hex
                else if (unit.GetComponent <UnitDatabaseFields>().germanStatic&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().coast&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().inlandPort&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().coastalPort)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage(unit.GetComponent <UnitDatabaseFields>().unitDesignation + " is a static unit and must start on a coast hex, a port, or an inland port");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                else if (((unit.name == "Armor-German-3SS") ||
                          (unit.name == "Armor-German-9SS") ||
                          (unit.name == "Armor-German-25SS") ||
                          (unit.name == "Armor-German-49SS") ||
                          (unit.name == "Armor-German-51SS") ||
                          (unit.name == "Armor-German-106") ||
                          (unit.name == "Armor-German-15SS")) &&
                         (!unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().germanRepalcement))
                {
                    GlobalDefinitions.GuiUpdateStatusMessage(unit.GetComponent <UnitDatabaseFields>().unitDesignation + " must start on a replacement hex (hexes in Germany with a star on them");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                // Setup the ZOC for the hex and its neighbors.  Note that I did not bother to do this while the user was moving
                // units around since I think it makes sense to just do it once when he is done.
                unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().inGermanZOC = true;
                foreach (HexDefinitions.HexSides hexSides in Enum.GetValues(typeof(HexDefinitions.HexSides)))
                {
                    if ((unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSides] != null) &&
                        (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <BooleanArrayData>().exertsZOC[(int)hexSides]))
                    {
                        unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSides].GetComponent <HexDatabaseFields>().inGermanZOC = true;
                    }
                }
            }
            if (!returnState)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Cannot exit setup until all issues are resolved");
            }
            return(returnState);
        }
        /// <summary>
        /// This routine is called to add back to limits when a unit returns to Britain by an undo action
        /// </summary>
        /// <param name="unit"></param>
        public void DecrementInvasionUnitLimits(GameObject unit)
        {
            // When returning a unit back to Britain, it only impacts the limits if it is being returned on the turn that it was landed.
            // Otherwise sending units back will allow the player to replace them with other units and still bring in the full
            // complement of units available for that turn.  The way that I can determine if the unit is being returned on the same turn
            // that it was landed is whetehr or not it has a beginning hex set.  If it does that means it started the turn on the board.
            if (unit.GetComponent <UnitDatabaseFields>().beginningTurnHex != null)
            {
                // No limits should be adjusted for landing this turn since the unit started the turn on the board
                return;
            }

            // The otehr special case I have to check for is an airborne unit being returned to Britain that did an airborne drop this turn.
            // The way that I can tell this is the case is that the airborne unit will not have an invasion index set to -1
            if (unit.GetComponent <UnitDatabaseFields>().airborne&& (unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex == -1))
            {
                GlobalDefinitions.currentAirborneDropsThisTurn--;
                return;
            }

            // Now the only units left are ones that were landed by land this turn

            int invasionAreaIndex = unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex;

            if ((GlobalDefinitions.invasionAreas[invasionAreaIndex].invaded) &&
                ((GlobalDefinitions.invasionAreas[invasionAreaIndex].turn == 1) || (GlobalDefinitions.invasionAreas[invasionAreaIndex].turn == 2)))
            {
                if (unit.GetComponent <UnitDatabaseFields>().armor)
                {
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].armorUnitsUsedThisTurn--;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn--;
                    GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn--;
                }
                // Note airborne counts against the infantry limit if brought in through the beach - which is silly because I've weeded out airborne units before this point
                else if (unit.GetComponent <UnitDatabaseFields>().infantry)
                {
                    // First check if the infantry used armor limits to land this turn
                    if (GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUsedAsArmorThisTurn > 0)
                    {
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].armorUnitsUsedThisTurn--;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUsedAsArmorThisTurn--;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn--;
                        GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn--;
                    }
                    else
                    {
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUnitsUsedThisTurn--;
                        GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn--;
                        GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn--;
                    }
                }
                else if (unit.GetComponent <UnitDatabaseFields>().airborne)
                {
                    // We've already taken care of airborne units that were dropped this turn so this unit has to have been landed
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].infantryUnitsUsedThisTurn--;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].airborneUsedAsInfantryThisTurn--;
                    GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn--;
                    GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn--;
                }
                else
                {
                    GlobalDefinitions.WriteToLogFile("decrementInvasionUnitLimits: ERROR - Most likely due to an HQ being landed during the first two turns.. This should never be executed");
                }
            }
            else
            {
                // This is a unit being landed in a non-invasion area so use the turn three limits
                GlobalDefinitions.invasionAreas[invasionAreaIndex].totalUnitsUsedThisTurn--;
                GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn--;
            }
        }
        public void ExchangeOKSelected()
        {
            List <GameObject> unitsToDelete = new List <GameObject>();

            // Determine if the user has selected enough factors
            if (GlobalDefinitions.exchangeFactorsSelected >= GlobalDefinitions.exchangeFactorsToLose)
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.OKEXCHANGEKEYWORD + " " + name);

                GlobalDefinitions.WriteToLogFile("exchangeOKSelected: attackerHadMostFactors = " + attackerHadMostFactors + " Units selected for exchange:");
                foreach (GameObject unit in GlobalDefinitions.unitsToExchange)
                {
                    GlobalDefinitions.WriteToLogFile("    unit " + unit.name);
                    unitsToDelete.Add(unit);
                }

                if (attackerHadMostFactors)
                {
                    foreach (GameObject unit in defendingUnits)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                    defendingUnits.Clear();

                    foreach (GameObject unit in unitsToDelete)
                    {
                        attackingUnits.Remove(unit); // This is needed to see if there are any attackers left at the end for post-combat movement
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                }
                else
                {
                    foreach (GameObject unit in attackingUnits)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                    attackingUnits.Clear();

                    foreach (GameObject unit in unitsToDelete)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                }

                GUIRoutines.RemoveGUI(GlobalDefinitions.ExchangeGUIInstance);

                if (attackerHadMostFactors && (GlobalDefinitions.hexesAvailableForPostCombatMovement.Count > 0) && (attackingUnits.Count > 0))
                {
                    CombatResolutionRoutines.SelectUnitsForPostCombatMovement(attackingUnits);
                }
                else
                {
                    // The CombatResolution table will be activated after the post movement combat units are selected which is why this check is needed.
                    GlobalDefinitions.combatResolutionGUIInstance.SetActive(true);
                }

                GlobalDefinitions.unitsToExchange.Clear();
            }
            else
            {
                GlobalDefinitions.WriteToLogFile("exchangeOKSelected: ERROR - Not enough factors selected");
            }
        }
Exemple #17
0
        /// <summary>
        /// Creates the state instances and sets up the state transitions for AI games
        /// </summary>
        /// <param name="nationalityBeingPlayed"></param>
        public static void CreateStatesForAI(GlobalDefinitions.Nationality nationalityBeingPlayed)
        {
            GlobalDefinitions.WriteToLogFile("createStatesForAI: executing");
            // The AI is playing the German side
            if (nationalityBeingPlayed == GlobalDefinitions.Nationality.Allied)
            {
                setUpStateInstance              = new GameObject("setUpStateInstance");
                germanAIStateInstance           = new GameObject("GermanAIStateInstance");
                turnInitializationStateInstance = new GameObject("turnInitializationStateInstance");
                alliedReplacementStateInstance  = new GameObject("alliedReplacementStateInstance");
                alliedSupplyStateInstance       = new GameObject("alliedSupplyStateInstance");
                alliedInvasionStateInstance     = new GameObject("alliedInvasionStateInstance");
                alliedAirborneStateInstance     = new GameObject("alliedAirborneStateInstance");
                alliedMovementStateInstance     = new GameObject("alliedMovementStateInstance");
                alliedCombatStateInstance       = new GameObject("alliedCombatStateInstance");
                alliedTacticalAirStateInstance  = new GameObject("alliedTacticalAirStateInstance");
                germanAISetupStateInstance      = new GameObject("germanAIStateSetupInstance");

                setUpStateInstance.AddComponent <SetUpState>();
                germanAISetupStateInstance.AddComponent <GermanAISetupState>();
                turnInitializationStateInstance.AddComponent <TurnInitializationState>();
                alliedReplacementStateInstance.AddComponent <AlliedReplacementState>();
                alliedSupplyStateInstance.AddComponent <SupplyState>();
                alliedInvasionStateInstance.AddComponent <AlliedInvasionState>();
                alliedAirborneStateInstance.AddComponent <AlliedAirborneState>();
                alliedMovementStateInstance.AddComponent <MovementState>();
                alliedCombatStateInstance.AddComponent <CombatState>();
                alliedTacticalAirStateInstance.AddComponent <AlliedTacticalAirState>();
                germanAIStateInstance.AddComponent <GermanAIState>();

                // AI TESTING
                germanCombatStateInstance = new GameObject("germanCombatStateInstance");
                germanCombatStateInstance.AddComponent <CombatState>();
                germanCombatStateInstance.GetComponent <CombatState>().nextGameState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();

                // Set up the state transitions
                setUpStateInstance.GetComponent <SetUpState>().nextGameState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
                germanAISetupStateInstance.GetComponent <GermanAISetupState>().nextGameState           = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
                turnInitializationStateInstance.GetComponent <TurnInitializationState>().nextGameState = alliedReplacementStateInstance.GetComponent <AlliedReplacementState>();
                alliedReplacementStateInstance.GetComponent <AlliedReplacementState>().nextGameState   = alliedSupplyStateInstance.GetComponent <SupplyState>();
                alliedSupplyStateInstance.GetComponent <SupplyState>().nextGameState                 = alliedInvasionStateInstance.GetComponent <AlliedInvasionState>();
                alliedInvasionStateInstance.GetComponent <AlliedInvasionState>().nextGameState       = alliedAirborneStateInstance.GetComponent <AlliedAirborneState>();
                alliedAirborneStateInstance.GetComponent <AlliedAirborneState>().nextGameState       = alliedMovementStateInstance.GetComponent <MovementState>();
                alliedMovementStateInstance.GetComponent <MovementState>().nextGameState             = alliedCombatStateInstance.GetComponent <CombatState>();
                alliedCombatStateInstance.GetComponent <CombatState>().nextGameState                 = alliedTacticalAirStateInstance.GetComponent <AlliedTacticalAirState>();
                alliedTacticalAirStateInstance.GetComponent <AlliedTacticalAirState>().nextGameState = germanAIStateInstance.GetComponent <GermanAIState>();
                germanAIStateInstance.GetComponent <GermanAIState>().nextGameState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();

                // Set up the correct nationality for the game states that share
                turnInitializationStateInstance.GetComponent <TurnInitializationState>().currentNationality = GlobalDefinitions.Nationality.Allied;
                alliedMovementStateInstance.GetComponent <MovementState>().currentNationality = GlobalDefinitions.Nationality.Allied;
                alliedCombatStateInstance.GetComponent <CombatState>().currentNationality     = GlobalDefinitions.Nationality.Allied;
            }

            // The AI is playing the Allied side
            else
            {
                setUpStateInstance = new GameObject("setUpStateInstance");
                turnInitializationStateInstance  = new GameObject("turnInitializationStateInstance");
                alliedAIStateInstance            = new GameObject("alliedAIStateInstance");
                alliedCombatStateInstance        = new GameObject("alliedCombatStateInstance");
                alliedAITacticalAirStateInstance = new GameObject("alliedAITacticalAirStateInstance");
                germanIsolationStateInstance     = new GameObject("germanIsolationStateInstance");
                germanReplacementStateInstance   = new GameObject("germanReplacementStateInstance");
                germanMovementStateInstance      = new GameObject("germanMovementStateInstance");
                germanCombatStateInstance        = new GameObject("germanCombatStateInstance");

                setUpStateInstance.AddComponent <SetUpState>();
                turnInitializationStateInstance.AddComponent <TurnInitializationState>();
                alliedAIStateInstance.AddComponent <AlliedAIState>();
                alliedCombatStateInstance.AddComponent <CombatState>();
                alliedAITacticalAirStateInstance.AddComponent <AlliedAITacticalAirState>();
                germanIsolationStateInstance.AddComponent <GermanIsolationState>();
                germanReplacementStateInstance.AddComponent <GermanReplacementState>();
                germanMovementStateInstance.AddComponent <MovementState>();
                germanCombatStateInstance.AddComponent <CombatState>();

                setUpStateInstance.GetComponent <SetUpState>().nextGameState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
                turnInitializationStateInstance.GetComponent <TurnInitializationState>().nextGameState = alliedAIStateInstance.GetComponent <AlliedAIState>();
                alliedAIStateInstance.GetComponent <AlliedAIState>().nextGameState   = alliedCombatStateInstance.GetComponent <CombatState>();
                alliedCombatStateInstance.GetComponent <CombatState>().nextGameState = alliedAITacticalAirStateInstance.GetComponent <AlliedAITacticalAirState>();
                alliedAITacticalAirStateInstance.GetComponent <AlliedAITacticalAirState>().nextGameState = germanIsolationStateInstance.GetComponent <GermanIsolationState>();
                germanIsolationStateInstance.GetComponent <GermanIsolationState>().nextGameState         = germanReplacementStateInstance.GetComponent <GermanReplacementState>();
                germanReplacementStateInstance.GetComponent <GermanReplacementState>().nextGameState     = germanMovementStateInstance.GetComponent <MovementState>();
                germanMovementStateInstance.GetComponent <MovementState>().nextGameState = germanCombatStateInstance.GetComponent <CombatState>();
                germanCombatStateInstance.GetComponent <CombatState>().nextGameState     = turnInitializationStateInstance.GetComponent <TurnInitializationState>();

                // Set up the correct nationality for the game states that share
                turnInitializationStateInstance.GetComponent <TurnInitializationState>().currentNationality = GlobalDefinitions.Nationality.Allied;
                germanIsolationStateInstance.GetComponent <GermanIsolationState>().currentNationality       = GlobalDefinitions.Nationality.German;
                //alliedMovementStateInstance.GetComponent<MovementState>().currentNationality = GlobalDefinitions.Nationality.Allied;
                alliedCombatStateInstance.GetComponent <CombatState>().currentNationality     = GlobalDefinitions.Nationality.Allied;
                germanMovementStateInstance.GetComponent <MovementState>().currentNationality = GlobalDefinitions.Nationality.German;
                germanCombatStateInstance.GetComponent <CombatState>().currentNationality     = GlobalDefinitions.Nationality.German;
            }
        }
Exemple #18
0
        /// <summary>
        /// This routine sets the game state to the side who is in control
        /// </summary>
        /// <param name="currentSide"></param> this is the side that is passed in the saved game file that should be in control
        public static void SetGameState(string currentSide)
        {
            if (Convert.ToString(currentSide) == "German")
            {
                // This executes when the German side is in control after the saved file is read in
                if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.AI)
                {
                    if (GlobalDefinitions.nationalityUserIsPlaying == GlobalDefinitions.Nationality.Allied)
                    {
                        // Check if this is a setup file that was read in.  The control will be for the German to play for when the player is
                        // playing the German side in order to give him a chance to update the setup.  But if the AI is playing the German then
                        // just go to the Allied invasion state
                        if (GlobalDefinitions.turnNumber == 0)
                        {
                            GlobalDefinitions.WriteToLogFile("setGameState: setting game state to turnInitializationStateInstance");
                            gameStateControlInstance.GetComponent <GameStateControl>().currentState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
                        }
                        else
                        {
                            GlobalDefinitions.WriteToLogFile("setGameState: setting game state to germanAIStateInstance");
                            gameStateControlInstance.GetComponent <GameStateControl>().currentState = germanAIStateInstance.GetComponent <GermanAIState>();
                        }
                    }
                    else
                    {
                        GlobalDefinitions.WriteToLogFile("setGameState: setting game state to germanIsolationStateInstance  turn number = " + GlobalDefinitions.turnNumber);
                        // Check if this is a setup file in order to allow the player to update the setup if he wants to
                        if (GlobalDefinitions.turnNumber == 0)
                        {
                            GlobalDefinitions.WriteToLogFile("setGameState: setting game state to setUpStateInstance");
                            gameStateControlInstance.GetComponent <GameStateControl>().currentState = setUpStateInstance.GetComponent <SetUpState>();
                        }

                        else
                        {
                            GlobalDefinitions.WriteToLogFile("setGameState: setting game state to germanIsolationStateInstance");
                            gameStateControlInstance.GetComponent <GameStateControl>().currentState = germanIsolationStateInstance.GetComponent <GermanIsolationState>();
                        }
                    }
                }
                else
                {
                    // Do not set the currentSidePlaying variable if it is an AI game since it will already have been set during the game selection
                    // This is being set for network play since it has no meaning in hotseat
                    GlobalDefinitions.nationalityUserIsPlaying = GlobalDefinitions.Nationality.German;
                    // Check if this is a setup file in order to allow the player to update the setup if he wants to
                    if (GlobalDefinitions.turnNumber == 0)
                    {
                        GlobalDefinitions.WriteToLogFile("setGameState: setting game state to setUpStateInstance");
                        gameStateControlInstance.GetComponent <GameStateControl>().currentState = setUpStateInstance.GetComponent <SetUpState>();
                    }
                    else
                    {
                        GlobalDefinitions.WriteToLogFile("setGameState: setting game state to germanIsolationStateInstance");
                        gameStateControlInstance.GetComponent <GameStateControl>().currentState = germanIsolationStateInstance.GetComponent <GermanIsolationState>();
                    }
                }
            }
            else
            {
                // The game state is for the Allied player to be in control
                // Note we don't need to check for a setup file here since that would indicate that the German side is in control
                GlobalDefinitions.WriteToLogFile("setGameState: Allied in control, setting game state to turnInitializationStateInstance");
                gameStateControlInstance.GetComponent <GameStateControl>().currentState = turnInitializationStateInstance.GetComponent <TurnInitializationState>();
                if (GlobalDefinitions.gameMode != GlobalDefinitions.GameModeValues.AI)
                {
                    // Do not set the currentSidePlaying variable if it is an AI game since it will already have been set during the game selection
                    // This is being set for network play since it has no meaning in hotseat
                    GlobalDefinitions.nationalityUserIsPlaying = GlobalDefinitions.Nationality.Allied;
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// This routine is what processes the message received from the opponent computer or from the saved command file when restarting a game
        /// </summary>
        /// <param name="message"></param>
        public static void ProcessCommand(string message)
        {
            char[]   delimiterChars = { ' ' };
            string[] switchEntries  = message.Split(delimiterChars);

            string[] lineEntries = message.Split(delimiterChars);
            // I am going to use the same routine to read records that is used when reading from a file.
            // In order to do this I need to drop the first word on the line since the files don't have key words
            for (int index = 0; index < (lineEntries.Length - 1); index++)
            {
                lineEntries[index] = lineEntries[index + 1];
            }

            switch (switchEntries[0])
            {
            case GlobalDefinitions.PLAYSIDEKEYWORD:
                if (switchEntries[1] == "German")
                {
                    GlobalDefinitions.sideControled = GlobalDefinitions.Nationality.German;
                }
                else
                {
                    GlobalDefinitions.sideControled = GlobalDefinitions.Nationality.Allied;
                }
                break;

            case GlobalDefinitions.PASSCONTROLKEYWORK:
                GlobalDefinitions.SwitchLocalControl(true);
                GlobalDefinitions.WriteToLogFile("processNetworkMessage: Message received to set local control");
                break;

            case GlobalDefinitions.SETCAMERAPOSITIONKEYWORD:
                Camera.main.transform.position = new Vector3(float.Parse(switchEntries[1]), float.Parse(switchEntries[2]), float.Parse(switchEntries[3]));
                Camera.main.GetComponent <Camera>().orthographicSize = float.Parse(switchEntries[4]);
                break;

            case GlobalDefinitions.MOUSESELECTIONKEYWORD:
                if (switchEntries[1] != "null")
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().hex = GameObject.Find(switchEntries[1]);
                }
                else
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().hex = null;
                }

                if (switchEntries[2] != "null")
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().unit = GameObject.Find(switchEntries[2]);
                }
                else
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().unit = null;
                }

                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod(GameControl.inputMessage.GetComponent <InputMessage>());
                break;

            case GlobalDefinitions.MOUSEDOUBLECLICKIONKEYWORD:
                GlobalDefinitions.Nationality passedNationality;

                if (switchEntries[2] == "German")
                {
                    passedNationality = GlobalDefinitions.Nationality.German;
                }
                else
                {
                    passedNationality = GlobalDefinitions.Nationality.Allied;
                }


                if (GlobalDefinitions.selectedUnit != null)
                {
                    GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
                }
                foreach (Transform hex in GameObject.Find("Board").transform)
                {
                    GlobalDefinitions.UnhighlightHex(hex.gameObject);
                }
                GlobalDefinitions.selectedUnit = null;


                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().CallMultiUnitDisplay(GameObject.Find(switchEntries[1]), passedNationality);
                break;

            case GlobalDefinitions.DISPLAYCOMBATRESOLUTIONKEYWORD:
                CombatResolutionRoutines.CombatResolutionDisplay();
                break;

            case GlobalDefinitions.NEXTPHASEKEYWORD:
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.ExecuteQuit();
                break;

            case GlobalDefinitions.EXECUTETACTICALAIROKKEYWORD:
                TacticalAirToggleRoutines.TacticalAirOK();
                break;

            case GlobalDefinitions.ADDCLOSEDEFENSEKEYWORD:
                GameObject.Find("CloseDefense").GetComponent <TacticalAirToggleRoutines>().AddCloseDefenseHex();
                break;

            case GlobalDefinitions.CANCELCLOSEDEFENSEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelCloseDefense();
                break;

            case GlobalDefinitions.LOCATECLOSEDEFENSEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateCloseDefense();
                break;

            case GlobalDefinitions.ADDRIVERINTERDICTIONKEYWORD:
                GameObject.Find("RiverInterdiction").GetComponent <TacticalAirToggleRoutines>().AddRiverInterdiction();
                break;

            case GlobalDefinitions.CANCELRIVERINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelRiverInterdiction();
                break;

            case GlobalDefinitions.LOCATERIVERINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateRiverInterdiction();
                break;

            case GlobalDefinitions.ADDUNITINTERDICTIONKEYWORD:
                GameObject.Find("UnitInterdiction").GetComponent <TacticalAirToggleRoutines>().AddInterdictedUnit();
                break;

            case GlobalDefinitions.CANCELUNITINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelInterdictedUnit();
                break;

            case GlobalDefinitions.LOCATEUNITINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateInterdictedUnit();
                break;

            case GlobalDefinitions.TACAIRMULTIUNITSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().MultiUnitSelection();
                break;

            case GlobalDefinitions.MULTIUNITSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.MULTIUNITSELECTIONCANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <MultiUnitMovementToggleRoutines>().CancelGui();
                break;

            case GlobalDefinitions.LOADCOMBATKEYWORD:
                GameObject GUIButtonInstance = new GameObject("GUIButtonInstance");
                GUIButtonInstance.AddComponent <GUIButtonRoutines>();
                GUIButtonInstance.GetComponent <GUIButtonRoutines>().LoadCombat();
                break;

            case GlobalDefinitions.SETCOMBATTOGGLEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RESETCOMBATTOGGLEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.COMBATGUIOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatGUIOK>().OkCombatGUISelection();
                break;

            case GlobalDefinitions.COMBATGUICANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatGUIOK>().CancelCombatGUISelection();
                break;

            case GlobalDefinitions.ADDCOMBATAIRSUPPORTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.REMOVECOMBATAIRSUPPORTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.COMBATRESOLUTIONSELECTEDKEYWORD:
                // Load the combat results; the die roll is on the Global variable
                //GlobalDefinitions.writeToLogFile("Die Roll 1 = " + GlobalDefinitions.dieRollResult1);
                //GlobalDefinitions.writeToLogFile("Die Roll 2 = " + GlobalDefinitions.dieRollResult2);
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().ResolutionSelected();
                break;

            case GlobalDefinitions.COMBATLOCATIONSELECTEDKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().LocateAttack();
                break;

            case GlobalDefinitions.COMBATCANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().CancelAttack();
                break;

            case GlobalDefinitions.COMBATOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().Ok();
                break;

            case GlobalDefinitions.CARPETBOMBINGRESULTSSELECTEDKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RETREATSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.SELECTPOSTCOMBATMOVEMENTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.DESELECTPOSTCOMBATMOVEMENTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.ADDEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.REMOVEEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.OKEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <ExchangeOKRoutines>().ExchangeOKSelected();
                break;

            case GlobalDefinitions.POSTCOMBATOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <PostCombatMovementOkRoutines>().ExecutePostCombatMovement();
                break;

            case GlobalDefinitions.DISPLAYALLIEDSUPPLYKEYWORD:
                if (switchEntries[1] == "True")
                {
                    GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CreateSupplySourceGUI(true);
                }
                else
                {
                    GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CreateSupplySourceGUI(false);
                }
                break;

            case GlobalDefinitions.SETSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RESETSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.LOCATESUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().LocateSupplySource();
                break;

            case GlobalDefinitions.OKSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().OkSupply();
                break;

            case GlobalDefinitions.OKSUPPLYWITHENDPHASEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().OkSupplyWithEndPhase();
                break;

            case GlobalDefinitions.CHANGESUPPLYSTATUSKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.YESBUTTONSELECTEDKEYWORD:
                GameObject.Find("YesButton").GetComponent <YesNoButtonRoutines>().YesButtonSelected();
                break;

            case GlobalDefinitions.NOBUTTONSELECTEDKEYWORD:
                GameObject.Find("NoButton").GetComponent <YesNoButtonRoutines>().NoButtonSelected();
                break;

            case GlobalDefinitions.SAVEFILENAMEKEYWORD:
                if (File.Exists(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt"))
                {
                    File.Delete(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt");
                }
                break;

            case GlobalDefinitions.SENDSAVEFILELINEKEYWORD:
                using (StreamWriter saveFile = File.AppendText(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt"))
                {
                    for (int index = 1; index < (switchEntries.Length); index++)
                    {
                        saveFile.Write(switchEntries[index] + " ");
                    }
                    saveFile.WriteLine();
                }
                break;

            case GlobalDefinitions.PLAYNEWGAMEKEYWORD:
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState = GameControl.setUpStateInstance.GetComponent <SetUpState>();
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.Initialize();

                // Set the global parameter on what file to use, can't pass it to the executeNoResponse since it is passed as a method delegate elsewhere
                GlobalDefinitions.germanSetupFileUsed = Convert.ToInt32(switchEntries[1]);

                GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteNewGame();
                break;

            case GlobalDefinitions.INVASIONAREASELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.CARPETBOMBINGSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.CARPETBOMBINGLOCATIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CarpetBombingToggleRoutines>().LocateCarpetBombingHex();
                break;

            case GlobalDefinitions.CARPETBOMBINGOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CarpetBombingOKRoutines>().CarpetBombingOK();
                break;

            case GlobalDefinitions.DIEROLLRESULT1KEYWORD:
                GlobalDefinitions.dieRollResult1 = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.DIEROLLRESULT2KEYWORD:
                GlobalDefinitions.dieRollResult2 = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.UNDOKEYWORD:
                GameControl.GUIButtonRoutinesInstance.GetComponent <GUIButtonRoutines>().ExecuteUndo();
                break;

            case GlobalDefinitions.CHATMESSAGEKEYWORD:
                string chatMessage = "";
                for (int index = 0; index < (switchEntries.Length - 1); index++)
                {
                    chatMessage += switchEntries[index + 1] + " ";
                }
                GlobalDefinitions.WriteToLogFile("Chat message received: " + chatMessage);
                GlobalDefinitions.AddChatMessage(chatMessage);
                break;
            //case GlobalDefinitions.SENDTURNFILENAMEWORD:
            //    // This command tells the remote computer what the name of the file is that will provide the saved turn file

            //    // The file name could have ' ' in it so need to reconstruct the full name
            //    string receivedFileName;
            //    receivedFileName = switchEntries[1];
            //    for (int i = 2; i < switchEntries.Length; i++)
            //        receivedFileName = receivedFileName + " " + switchEntries[i];

            //    GameControl.fileTransferServerInstance.GetComponent<FileTransferServer>().InitiateFileTransferServer();
            //    GlobalDefinitions.WriteToLogFile("Received name of save file, calling FileTransferServer: fileName = " + receivedFileName + "  path to save = " + GameControl.path);
            //    GameControl.fileTransferServerInstance.GetComponent<FileTransferServer>().RequestFile(TransportScript.remoteComputerIPAddress, receivedFileName, GameControl.path, true);
            //    break;

            case GlobalDefinitions.DISPLAYALLIEDSUPPLYRANGETOGGLEWORD:
                if (GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn)
                {
                    GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.DISPLAYGERMANSUPPLYRANGETOGGLEWORD:
                if (GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn)
                {
                    GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.DISPLAYMUSTATTACKTOGGLEWORD:
                if (GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn)
                {
                    GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.TOGGLEAIRSUPPORTCOMBATTOGGLE:
            {
                if (GlobalDefinitions.combatAirSupportToggle != null)
                {
                    if (GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn)
                    {
                        GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn = false;
                    }
                    else
                    {
                        GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn = true;
                    }
                }
                break;
            }

            case GlobalDefinitions.TOGGLECARPETBOMBINGCOMBATTOGGLE:
            {
                if (GlobalDefinitions.combatCarpetBombingToggle != null)
                {
                    if (GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn)
                    {
                        GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn = false;
                    }
                    else
                    {
                        GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn = true;
                    }
                }
                break;
            }

            case GlobalDefinitions.DISCONNECTFROMREMOTECOMPUTER:
            {
                // Quit the game and go back to the main menu
                GameObject guiButtonInstance = new GameObject("GUIButtonInstance");
                guiButtonInstance.AddComponent <GUIButtonRoutines>();
                guiButtonInstance.GetComponent <GUIButtonRoutines>().YesMain();
                break;
            }

            case GlobalDefinitions.ALLIEDREPLACEMENTKEYWORD:
                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().SelectAlliedReplacementUnit(GameObject.Find(switchEntries[1]));
                break;

            case GlobalDefinitions.GERMANREPLACEMENTKEYWORD:
                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().SelectGermanReplacementUnit(GameObject.Find(switchEntries[1]));
                break;

            case GlobalDefinitions.AGGRESSIVESETTINGKEYWORD:
                GlobalDefinitions.aggressiveSetting = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.DIFFICULTYSETTINGKEYWORD:
                GlobalDefinitions.difficultySetting = Convert.ToInt32(switchEntries[1]);
                break;

            default:
                GlobalDefinitions.WriteToLogFile("processCommand: Unknown network command received: " + message);
                break;
            }
        }
        /// <summary>
        /// This routine is called when a new defender is added to the attack and updates the toggles on the combat gui
        /// </summary>
        private void RefreshAttackersBasedOnDefenders()
        {
            // First go through and enable all the attacking units since if I don't once a unit is disabled it will never be enabled again and this way
            // I don't have to explicitly check for adjacency to all defenders

            foreach (GameObject attackingUnit in currentCombat.GetComponent <Combat>().attackingUnits)
            {
                foreach (Transform childTransform in transform.parent.transform)
                {
                    if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == attackingUnit))
                    {
                        // check if there is an invasion taking place and if so do not turn the check back on.
                        if (!GameControl.combatRoutinesInstance.GetComponent <CombatRoutines>().CheckForInvadingAttacker(childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit))
                        {
                            childTransform.gameObject.GetComponent <Toggle>().interactable = true;
                        }
                    }
                }
            }

            // Go through each of the defenders and gray out any attacker that isn't adjacent.  By going through each of the defenders I am left
            // with only attackers that are adjacent to all defending units
            foreach (GameObject defendingUnit in currentCombat.GetComponent <Combat>().defendingUnits)
            {
                // Only check for adjacency if the defnder is selected

                // When this is called because of the code changing a toggle status, the routine is called before the committed variable is set (since it is event triggered
                // I used to check the isCommittedToAttack variable but this doesn't work in complex situations.  Therefore I will check if the unit is committed to the attack by
                // checking the unit's toggle status

                bool defendererIsCommitted = false;
                foreach (Transform defenderChildTransform in transform.parent.transform)
                {
                    if ((defenderChildTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) &&
                        (defenderChildTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == defendingUnit))
                    {
                        if (defenderChildTransform.gameObject.GetComponent <Toggle>().isOn)
                        {
                            defendererIsCommitted = true;
                        }
                    }
                }

                if (defendererIsCommitted)
                {
                    foreach (GameObject attackingUnit in currentCombat.GetComponent <Combat>().attackingUnits)
                    {
                        if (!GlobalDefinitions.TwoUnitsAdjacent(attackingUnit, defendingUnit))
                        {
                            // The attacking unit is not adjacent to the defending unit so it needs to be greyed out and disabled in the display
                            foreach (Transform childTransform in transform.parent.transform)
                            {
                                if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == attackingUnit))
                                {
                                    GlobalDefinitions.WriteToLogFile("refreshAttackersBasedOnDefenders: decommitting attacker and making non-interactable " + attackingUnit.name);
                                    GlobalDefinitions.UnhighlightUnit(attackingUnit);
                                    attackingUnit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                                    childTransform.gameObject.GetComponent <Toggle>().isOn         = false;
                                    childTransform.gameObject.GetComponent <Toggle>().interactable = false;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// This routine reads a single record for a unit
        /// </summary>
        /// <param name="entries"></param>
        public void ProcessUnitRecord(string[] entries)
        {
            GameObject unit;

            unit = GameObject.Find(entries[0]);
            if (entries[1] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().occupiedHex = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().occupiedHex = GameObject.Find(entries[1]);
            }
            if (entries[2] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex = GameObject.Find(entries[2]);
            }
            unit.GetComponent <UnitDatabaseFields>().inBritain                     = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[3]);
            unit.GetComponent <UnitDatabaseFields>().unitInterdiction              = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[4]);
            unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex             = Convert.ToInt32(entries[5]);
            unit.GetComponent <UnitDatabaseFields>().availableForStrategicMovement = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[6]);
            unit.GetComponent <UnitDatabaseFields>().inSupply = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[7]);
            // Need to adjust the highlighting of the unit if it is out of supply
            GlobalDefinitions.UnhighlightUnit(unit);
            if (entries[8] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().supplySource = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().supplySource = GameObject.Find(entries[8]);
            }
            unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = Convert.ToInt32(entries[9]);
            unit.GetComponent <UnitDatabaseFields>().unitEliminated = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[10]);


            if (unit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
            {
                GeneralHexRoutines.PutUnitOnHex(unit, unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                unit.transform.parent = GlobalDefinitions.allUnitsOnBoard.transform;
            }
            else if (unit.GetComponent <UnitDatabaseFields>().unitEliminated)
            {
                unit.transform.parent   = GameObject.Find("Units Eliminated").transform;
                unit.transform.position = unit.GetComponent <UnitDatabaseFields>().OOBLocation;
            }
            else if (unit.GetComponent <UnitDatabaseFields>().inBritain)
            {
                unit.transform.parent   = GameObject.Find("Units In Britain").transform;
                unit.transform.position = unit.GetComponent <UnitDatabaseFields>().locationInBritain;
            }
            else
            {
                GlobalDefinitions.WriteToLogFile("processUnitRecord: Unit read error - " + entries[1] + ": found no location to place this unit");
            }

            if (!unit.GetComponent <UnitDatabaseFields>().unitEliminated&& !unit.GetComponent <UnitDatabaseFields>().inBritain)
            {
                if (unit.GetComponent <UnitDatabaseFields>().nationality == GlobalDefinitions.Nationality.Allied)
                {
                    GlobalDefinitions.alliedUnitsOnBoard.Add(unit);
                }
                else
                {
                    GlobalDefinitions.germanUnitsOnBoard.Add(unit);
                }
            }
        }
Exemple #22
0
        // Use this for initialization
        void Start()
        {
            GlobalDefinitions.InitializeFileNames();
            // Set up the log file
            path = System.IO.Directory.GetCurrentDirectory() + "\\";

            // Put the log and command file in a try block since an exception will be thrown if the game was installed in an un-writeable folder
            try
            {
                if (File.Exists(path + GlobalGameFields.logfile))
                {
                    File.Delete(path + GlobalGameFields.logfile);
                }

                using (StreamWriter logFile = File.AppendText(GameControl.path + GlobalGameFields.logfile))
                {
                    logFile.WriteLine("Starting game at: " + DateTime.Now);
                    logFile.WriteLine("GameControl start(): path = " + System.IO.Directory.GetCurrentDirectory() + "\\");
                }
            }
            catch
            {
                MessageBox.Show("ERROR: Cannot access log file - cannot continue");
                GlobalDefinitions.GuiUpdateStatusMessage("Internal Error - Cannot access log file - cannot continue");
            }

            GlobalDefinitions.WriteToLogFile("Game Version " + GlobalDefinitions.releaseVersion);

            // There are three files that should have been installed with the game.  Note, I could get rid of all three of these and just have the
            // board and the units built into the game rather than reading them.  But I haven't done this based on a somewhat vauge idea that this will
            // make future games easier to build.
            // The three files are:
            //      TGCBoardSetup.txt - this has been split into four files, each checked at time of execution 7/25/20
            //      TGCBritainUnitLocation.txt
            //      TGCGermanSetup.txt
            // Check here that the files exist.  If they don't then exit out now


            if (!File.Exists(path + GlobalGameFields.britainUnitLocationFile))
            {
                MessageBox.Show("ERROR: " + GlobalGameFields.britainUnitLocationFile + "  file not found - cannot continue");
                UnityEngine.Application.Quit();
            }
            else
            {
                GlobalGameFields.britainUnitLocationFile = path + GlobalGameFields.britainUnitLocationFile;
            }

            //if (!File.Exists(path + "TGCGermanSetup.txt"))
            if (!File.Exists(path + "GermanSetup//TGCGermanSetup1.txt"))
            {
                MessageBox.Show("ERROR: TGCGermanSetup1.txt file not found - cannot continue");
                UnityEngine.Application.Quit();
            }

            GlobalDefinitions.nextPhaseButton.GetComponent <UnityEngine.UI.Button>().interactable = false;
            GlobalDefinitions.undoButton.GetComponent <UnityEngine.UI.Button>().interactable      = false;
            GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().interactable = false;
            GlobalDefinitions.AssignCombatButton.GetComponent <UnityEngine.UI.Button>().interactable      = false;
            GlobalDefinitions.DisplayAllCombatsButton.GetComponent <UnityEngine.UI.Button>().interactable = false;
            GlobalDefinitions.AlliedSupplyRangeToggle.GetComponent <Toggle>().interactable = false;
            GlobalDefinitions.GermanSupplyRangeToggle.GetComponent <Toggle>().interactable = false;
            GlobalDefinitions.AlliedSupplySourcesButton.GetComponent <UnityEngine.UI.Button>().interactable = false;

            // Hide the chat screen.  We will turn it back on if the user selects a network game
            GameObject.Find("ChatInputField").GetComponent <InputField>().onEndEdit.AddListener(delegate { GlobalDefinitions.ExecuteChatMessage(); });
            GlobalDefinitions.chatPanel = GameObject.Find("ChatPanel");
            GlobalDefinitions.chatPanel.SetActive(false);

            // Add a canvas to add UI elements (i.e. text) to the board
            GlobalDefinitions.mapText      = new GameObject();
            GlobalDefinitions.mapText.name = "Map Text";
            GlobalDefinitions.mapText.transform.SetParent(GameObject.Find("Map Graphics").transform);
            GlobalDefinitions.mapGraphicCanvas = GlobalDefinitions.mapText.AddComponent <Canvas>();
            GlobalDefinitions.mapText.AddComponent <CanvasScaler>();
            GlobalDefinitions.mapGraphicCanvas.renderMode       = RenderMode.WorldSpace;
            GlobalDefinitions.mapGraphicCanvas.sortingLayerName = "Text";

            // The first thing that needs to be done is store the locations of the units.  They
            // are sitting on the order of battle sheet and this will be their "dead" location
            GlobalDefinitions.WriteToLogFile("Setting unit OOB locations");
            foreach (Transform unit in GameObject.Find("Units Eliminated").transform)
            {
                unit.GetComponent <UnitDatabaseFields>().OOBLocation = unit.position;
            }

            GlobalDefinitions.WriteToLogFile("GameControl start(): Creating Singletons");
            // Create singletons of each of the routine classes
            CreateSingletons();

            GlobalDefinitions.WriteToLogFile("GameControl start(): Setting up the map");
            // Set up the map from the read location
            createBoardInstance.GetComponent <CreateBoard>().ReadMapSetup();

            // Load the global for storing all hexes on the board
            //foreach (Transform hex in GameObject.Find("Board").transform)
            //    HexDefinitions.allHexesOnBoard.Add(hex.gameObject);

            // Deal with the configuration settings
            GlobalGameFields.settingsFile = path + GlobalGameFields.settingsFile;
            // Check if the setting file is present, if it isn't write out a default
            if (!File.Exists(GlobalGameFields.settingsFile))
            {
                GlobalDefinitions.difficultySetting = 5;
                GlobalDefinitions.aggressiveSetting = 3;
                readWriteRoutinesInstance.GetComponent <ReadWriteRoutines>().WriteSettingsFile(5, 3);
            }
            else
            {
                // If the file exists read the configuration settings
                readWriteRoutinesInstance.GetComponent <ReadWriteRoutines>().ReadSettingsFile();
            }
            // Reset the min/max odds since the aggressiveness has just been read
            CombatResolutionRoutines.AdjustAggressiveness();

            AIRoutines.SetIntrinsicHexValues();

            // AI TESTING
            hexValueGuiInstance = new GameObject();
            Canvas hexValueCanvas = hexValueGuiInstance.AddComponent <Canvas>();

            hexValueGuiInstance.AddComponent <CanvasScaler>();
            hexValueCanvas.renderMode       = RenderMode.WorldSpace;
            hexValueCanvas.sortingLayerName = "Hex";
            hexValueGuiInstance.name        = "hexValueGuiInstance";

            // AI TESTING
            //foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            //    GlobalDefinitions.createHexText(Convert.ToString(hex.GetComponent<HexDatabaseFields>().hexValue), hex.name + "HexValueText", 20, 20, hex.position.x, hex.position.y, 14, hexValueCanvas);

            GlobalDefinitions.WriteToLogFile("GameControl start(): Putting Allied units in Britain - reading from file: " + GlobalGameFields.britainUnitLocationFile);
            // When restarting a game the units won't have their Britain location loaded so this needs to be done before a restart file is read
            createBoardInstance.GetComponent <CreateBoard>().ReadBritainPlacement(GlobalGameFields.britainUnitLocationFile);

            GlobalDefinitions.WriteToLogFile("GameControl start(): Setting up invasion areas");
            createBoardInstance.GetComponent <CreateBoard>().SetupInvasionAreas();

            // Make sure the game doesn't start with selected unit or hex
            GlobalDefinitions.selectedUnit = null;
            GlobalDefinitions.startHex     = null;

            // Reset the list of active GUI's
            GUIRoutines.guiList.Clear();

            gameStateControlInstance = new GameObject("gameStateControl");
            gameStateControlInstance.AddComponent <GameStateControl>();
            inputMessage = new GameObject("inputMessage");
            inputMessage.AddComponent <InputMessage>();

            GlobalDefinitions.allUnitsOnBoard = GameObject.Find("Units On Board");

            // Turn off the background of the unit display panel
            GameObject.Find("UnitDisplayPanel").GetComponent <CanvasGroup>().alpha = 0;

            // Setup the state for when victory is achieved
            victoryState = new GameObject("victoryState");
            victoryState.AddComponent <VictoryState>();

            // At this point everything has been setup.  Call up GUI to have the user select the type of game being played
            GlobalDefinitions.WriteToLogFile("GameControl start(): calling getGameModeUI()");
            MainMenuRoutines.GetGameModeUI();
        }
Exemple #23
0
        /// <summary>
        /// This routine reads the contents of a save file
        /// </summary>
        /// <param name="fileName"></param>
        public void ReadTurnFile(string fileName)
        {
            char[] delimiterChars = { ' ' };
            string line;

            string[] lineEntries;
            string[] switchEntries;

            GlobalDefinitions.WriteToLogFile("readTurnFile: executing - passed file = " + fileName);

            StreamReader theReader = new StreamReader(fileName);

            using (theReader)
            {
                do
                {
                    line = theReader.ReadLine();
                    if (line != null)
                    {
                        switchEntries = line.Split(delimiterChars);
                        switch (switchEntries[0])
                        {
                        case "Turn":
                            GlobalDefinitions.turnNumber = Convert.ToInt32(switchEntries[1]);
                            GlobalDefinitions.GuiUpdateTurn();
                            break;

                        case "Game_Control":
                            GameControl.SetGameState(switchEntries[1]);
                            break;

                        case "Global_Definitions":
                            ReadGlobalVariables(switchEntries);
                            break;

                        case "Hexes":
                            line        = theReader.ReadLine();
                            lineEntries = line.Split(delimiterChars);
                            while (lineEntries[0] != "End")
                            {
                                string[] entries = line.Split(delimiterChars);
                                ProcessHexRecord(entries);

                                line        = theReader.ReadLine();
                                lineEntries = line.Split(delimiterChars);
                            }
                            break;

                        case "Units":
                            line        = theReader.ReadLine();
                            lineEntries = line.Split(delimiterChars);
                            while (lineEntries[0] != "End")
                            {
                                string[] entries = line.Split(delimiterChars);
                                ProcessUnitRecord(entries);

                                line        = theReader.ReadLine();
                                lineEntries = line.Split(delimiterChars);
                            }
                            break;
                        }
                    }
                }while (line != null);
                theReader.Close();

                GlobalDefinitions.WriteToLogFile("readTurnFile: File read complete.  Initialize Game State");

                // If we just read a setup file, put the player into the setup state so that he can update the setup if he wants.
                if ((GlobalDefinitions.turnNumber == 0) && (GlobalDefinitions.nationalityUserIsPlaying == GlobalDefinitions.Nationality.German))
                {
                    GlobalDefinitions.nextPhaseButton.GetComponent <Button>().interactable = true;
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <SetUpState>().ExecuteSelectUnit;
                }
                // Otherwise, execute the init for the next state
                else
                {
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.Initialize();
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// Executes when the user indicates he wants to go to main menu
        /// </summary>
        public void YesMain()
        {
            List <GameObject> removeUnitList = new List <GameObject>();

            // If this is a network game I've already checked that the player is in control
            //if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork)
            //{
            //    GlobalDefinitions.WriteToLogFile("YesMain: Calling ResetConnection()");
            //    //byte error;
            //    //NetworkTransport.Disconnect(TransportScript.receivedHostId, TransportScript.gameConnectionId, out error);
            //    //Network.Disconnect();
            //    TransportScript.ResetConnection(TransportScript.computerId);
            //}

            // Copy list so the guis can be removed
            List <GameObject> removeList = new List <GameObject>();

            foreach (GameObject gui in GUIRoutines.guiList)
            {
                removeList.Add(gui);
            }


            // Get rid of all active guis
            foreach (GameObject gui in removeList)
            {
                GUIRoutines.RemoveGUI(gui);
            }

            // Put all the units back on the OOB sheet
            foreach (Transform unit in GlobalDefinitions.allUnitsOnBoard.transform)
            {
                unit.GetComponent <UnitDatabaseFields>().unitInterdiction      = false;
                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                unit.GetComponent <UnitDatabaseFields>().hasMoved                    = false;
                unit.GetComponent <UnitDatabaseFields>().unitEliminated              = false;
                unit.GetComponent <UnitDatabaseFields>().occupiedHex                 = null;
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex            = null;
                unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex           = -1;
                unit.GetComponent <UnitDatabaseFields>().inSupply                    = true;
                unit.GetComponent <UnitDatabaseFields>().supplySource                = null;
                unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = 0;
                unit.GetComponent <UnitDatabaseFields>().remainingMovement           = unit.GetComponent <UnitDatabaseFields>().movementFactor;
                if (unit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
                {
                    GlobalDefinitions.UnhighlightUnit(unit.gameObject);
                    GeneralHexRoutines.RemoveUnitFromHex(unit.gameObject, unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                    unit.GetComponent <UnitDatabaseFields>().occupiedHex = null;
                }

                removeUnitList.Add(unit.gameObject);
            }

            foreach (GameObject unit in removeUnitList)
            {
                GlobalDefinitions.ReturnUnitToOOBShet(unit);
            }

            // Clear out the lists keeping track of both side's units on board
            GlobalDefinitions.alliedUnitsOnBoard.Clear();
            GlobalDefinitions.germanUnitsOnBoard.Clear();

            // Go through the hexes and reset all highlighting
            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                hex.GetComponent <HexDatabaseFields>().riverInterdiction   = false;
                hex.GetComponent <HexDatabaseFields>().closeDefenseSupport = false;
                hex.GetComponent <HexDatabaseFields>().successfullyInvaded = false;
                hex.GetComponent <HexDatabaseFields>().alliedControl       = false;
                hex.GetComponent <HexDatabaseFields>().inAlliedZOC         = false;
                hex.GetComponent <HexDatabaseFields>().inGermanZOC         = false;
                hex.GetComponent <HexDatabaseFields>().occupyingUnit.Clear();
                hex.GetComponent <HexDatabaseFields>().unitsExertingZOC.Clear();
                hex.GetComponent <HexDatabaseFields>().availableForMovement       = false;
                hex.GetComponent <HexDatabaseFields>().strategicRemainingMovement = 0;
                hex.GetComponent <HexDatabaseFields>().remainingMovement          = 0;
                hex.GetComponent <HexDatabaseFields>().supplySources.Clear();
                hex.GetComponent <HexDatabaseFields>().unitsThatCanBeSupplied.Clear();
                hex.GetComponent <HexDatabaseFields>().closeDefenseSupport = false;
                hex.GetComponent <HexDatabaseFields>().riverInterdiction   = false;
                hex.GetComponent <HexDatabaseFields>().carpetBombingActive = false;

                GlobalDefinitions.UnhighlightHex(hex.gameObject);
            }

            GlobalDefinitions.WriteToLogFile("Putting Allied units in Britain");
            // When restarting a game the units won't have their Britain location loaded so this needs to be done before a restart file is read
            GameControl.createBoardInstance.GetComponent <CreateBoard>().ReadBritainPlacement(GlobalGameFields.britainUnitLocationFile);

            GlobalDefinitions.ResetAllGlobalDefinitions();

            // Turn the button back on
            GlobalDefinitions.mainMenuButton.GetComponent <Button>().interactable = true;

            MainMenuRoutines.GetGameModeUI();
        }
        /// <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);
        }