Beispiel #1
0
 /// <summary>
 /// Executes when the toggle is changed, highlights the hexes that were under Allied control in the current turn
 /// </summary>
 public void DisplayHisoricalProgress()
 {
     if (GameObject.Find("ShowHistoryToggle").GetComponent <Toggle>().isOn)
     {
         // The toggle is on so highlight the hexes
         foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
         {
             if ((hex.GetComponent <HexDatabaseFields>().historyWeekCaptured <= GlobalDefinitions.turnNumber) &&
                 !hex.GetComponent <HexDatabaseFields>().sea&& !hex.GetComponent <HexDatabaseFields>().bridge)
             {
                 Renderer targetRenderer = hex.GetComponent(typeof(SpriteRenderer)) as Renderer;
                 //hex.transform.localScale = new Vector2(0.75f, 0.75f);
                 targetRenderer.sortingLayerName = "Highlight";
                 targetRenderer.material.color   = Color.blue;
                 targetRenderer.sortingOrder     = 2;
             }
         }
     }
     else
     {
         // The toggle is off so unhightlight the hexes
         foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
         {
             GlobalDefinitions.UnhighlightHex(hex);
         }
     }
 }
        /// <summary>
        /// Determines the hex that the selected unit will invade from.
        /// </summary>
        /// <param name="selectedUnit"></param>
        public void GetUnitInvasionHex(GameObject selectedUnit, GameObject selectedHex)
        {
            if (selectedHex != null)
            {
                if (selectedHex.GetComponent <HexDatabaseFields>().availableForMovement)
                {
                    GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().LandAlliedUnitFromOffBoard(selectedUnit, selectedHex, false);
                }
                else
                {
                    GlobalDefinitions.GuiDisplayUnitsOnHex(selectedHex);
                    GlobalDefinitions.GuiUpdateStatusMessage("Hex selected is not available for invasion, must select a highlighted hex");
                }
            }
            else
            {
                GlobalDefinitions.GuiUpdateStatusMessage("No hex selected, must select a highlighted hex");
            }

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

            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                GlobalDefinitions.UnhighlightHex(hex.gameObject);
                hex.GetComponent <HexDatabaseFields>().availableForMovement = false;
            }
        }
Beispiel #3
0
        public void CancelCloseDefense()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.CANCELCLOSEDEFENSEKEYWORD + " " + name);

            for (int index = 0; index < GlobalDefinitions.closeDefenseHexes.Count; index++)
            {
                if (GlobalDefinitions.closeDefenseHexes[index] == hex)
                {
                    GlobalDefinitions.closeDefenseHexes[index].GetComponent <HexDatabaseFields>().closeDefenseSupport = false;
                    GlobalDefinitions.UnhighlightHex(GlobalDefinitions.closeDefenseHexes[index]);
                    GlobalDefinitions.closeDefenseHexes.Remove(hex);
                }
            }
            GlobalDefinitions.tacticalAirMissionsThisTurn--;
            GUIRoutines.RemoveGUI(GlobalDefinitions.tacticalAirGUIInstance);
            CombatResolutionRoutines.CreateTacticalAirGUI();
        }
Beispiel #4
0
        public void CancelRiverInterdiction()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.CANCELRIVERINTERDICTIONKEYWORD + " " + name);

            for (int index = 0; index < GlobalDefinitions.riverInderdictedHexes.Count; index++)
            {
                if (GlobalDefinitions.riverInderdictedHexes[index] == hex)
                {
                    GlobalDefinitions.riverInderdictedHexes[index].GetComponent <HexDatabaseFields>().riverInterdiction = false;
                    GlobalDefinitions.UnhighlightHex(GlobalDefinitions.riverInderdictedHexes[index]);
                    GlobalDefinitions.riverInderdictedHexes.Remove(hex);
                }
            }
            GlobalDefinitions.tacticalAirMissionsThisTurn--;
            GUIRoutines.RemoveGUI(GlobalDefinitions.tacticalAirGUIInstance);
            CombatResolutionRoutines.CreateTacticalAirGUI();
        }
Beispiel #5
0
        /// <summary>
        /// This routine reads a single record for a hex
        /// </summary>
        /// <param name="entries"></param>
        public void ProcessHexRecord(string[] entries)
        {
            GameObject hex;

            hex = GameObject.Find(entries[0]);

            hex.GetComponent <HexDatabaseFields>().inGermanZOC         = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[1]);
            hex.GetComponent <HexDatabaseFields>().inAlliedZOC         = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[2]);
            hex.GetComponent <HexDatabaseFields>().alliedControl       = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[3]);
            hex.GetComponent <HexDatabaseFields>().successfullyInvaded = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[4]);
            hex.GetComponent <HexDatabaseFields>().closeDefenseSupport = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[5]);
            hex.GetComponent <HexDatabaseFields>().riverInterdiction   = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[6]);

            // By calling the unhighlight rouitne (no hexes should be highlighted at this point) it will
            // turn close defense and interdicted river hexes the correct color
            GlobalDefinitions.UnhighlightHex(GameObject.Find(entries[0]));
        }
        /// <summary>
        /// This routine resets all the counters associated with the units used in the invasion area for the turn
        /// </summary>
        public void InitializeAreaCounters()
        {
            foreach (InvasionArea targetArea in GlobalDefinitions.invasionAreas)
            {
                targetArea.airborneUnitsUsedThisTurn      = 0;
                targetArea.armorUnitsUsedThisTurn         = 0;
                targetArea.infantryUnitsUsedThisTurn      = 0;
                targetArea.totalUnitsUsedThisTurn         = 0;
                targetArea.infantryUsedAsArmorThisTurn    = 0;
                targetArea.airborneUsedAsInfantryThisTurn = 0;
            }

            GlobalDefinitions.numberAlliedReinforcementsLandedThisTurn = 0;

            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                hex.GetComponent <HexDatabaseFields>().availableForMovement = false;
                GlobalDefinitions.UnhighlightHex(hex.gameObject);
            }
        }
Beispiel #7
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();
        }
Beispiel #8
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;
            }
        }
Beispiel #9
0
        private float initialTouch; // Used to check if the mouse click is a double click
        void Update()
        {
            if (GlobalDefinitions.gameStarted)
            {
                if (GlobalDefinitions.localControl || (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Hotseat))
                {
                    if (!GlobalDefinitions.commandFileBeingRead)
                    {
                        // Left mouse button click
                        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
                        {
                            // Check if the user double clicked
                            if ((Time.time < initialTouch + 0.5f) &&
                                ((gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedMovementStateInstance") ||
                                 (gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanMovementStateInstance") ||
                                 (gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "setUpStateInstance")))
                            {
                                // When we have a double click that means that there was already a single click that would have selected a unit
                                // Unhighlight it and then remove it
                                if (GlobalDefinitions.selectedUnit != null)
                                {
                                    GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
                                }
                                foreach (Transform hex in GameObject.Find("Board").transform)
                                {
                                    GlobalDefinitions.UnhighlightHex(hex.gameObject);
                                }
                                GlobalDefinitions.selectedUnit = null;

                                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.SETCAMERAPOSITIONKEYWORD + " " + Camera.main.transform.position.x + " " + Camera.main.transform.position.y + " " + Camera.main.transform.position.z + " " + Camera.main.GetComponent <Camera>().orthographicSize);

                                // I had a bug where double clicking on an off-board unit causes an exception in the following line because it is assuming a hex is being clicked
                                if (GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition) != null)
                                {
                                    GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.MOUSEDOUBLECLICKIONKEYWORD + " " + GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition).name + " " + gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality);
                                }

                                movementRoutinesInstance.GetComponent <MovementRoutines>().CallMultiUnitDisplay(GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition),
                                                                                                                gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality);
                            }
                            // If not double click then process a normal click
                            else
                            {
                                inputMessage.GetComponent <InputMessage>().hex  = GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition);
                                inputMessage.GetComponent <InputMessage>().unit = GeneralHexRoutines.GetUnitWithoutHex(Input.mousePosition);

                                RecordMouseClick(inputMessage.GetComponent <InputMessage>().unit, inputMessage.GetComponent <InputMessage>().hex);

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

                            initialTouch = Time.time;
                        }
                    }

                    // Note that the EventSystem check is to ensure the mouse isn't clicking a ui button
                    //else if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
                    //{
                    //    // This is a left mouse button click to select a unit or hex
                    //    inputMessage.GetComponent<InputMessage>().hex = GlobalDefinitions.getHexFromUserInput(Input.mousePosition);
                    //    inputMessage.GetComponent<InputMessage>().unit = GlobalDefinitions.getUnitWithoutHex(Input.mousePosition);

                    //    gameStateControlInstance.GetComponent<gameStateControl>().currentState.executeMethod(inputMessage.GetComponent<InputMessage>());
                    //    if ((GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Network) && (GlobalDefinitions.localControl))
                    //        sendMouseClickToNetwork(inputMessage.GetComponent<InputMessage>().unit, inputMessage.GetComponent<InputMessage>().hex);
                    //}

                    // Even though this is for when the player is in control, still need to check for chat messages
                    //if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork)
                    //{
                    //    string message;

                    //    NetworkEventType receivedNetworkEvent = TransportScript.checkForNetworkEvent(out message);

                    //    if (receivedNetworkEvent == NetworkEventType.DataEvent)
                    //    {
                    //        // The only message that is valid when in control is a chat message

                    //        char[] delimiterChars = { ' ' };
                    //        string[] switchEntries = message.Split(delimiterChars);

                    //        switch (switchEntries[0])
                    //        {
                    //            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;
                    //            default:
                    //                GlobalDefinitions.WriteToLogFile("ERROR: unexpected data message received when in control (only chat message valid - message = " + message);
                    //                break;
                    //        }
                    //    }
                    //}

                    // Since I have enabled chat I have to do something to get hotkeys since chat will execute the hotkeys
                    //else if (Input.GetKeyDown(KeyCode.R))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().executeCombatResolution();
                    //}

                    //else if (Input.GetKeyDown(KeyCode.Q))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().goToNextPhase();
                    //}

                    //else if (Input.GetKeyDown(KeyCode.U))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().executeUndo();
                    //}
                }

                //else if (!GlobalDefinitions.localControl && (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork))
                //{
                //    string message;
                //    NetworkEventType receivedNetworkEvent = TransportScript.checkForNetworkEvent(out message);

                //    if (receivedNetworkEvent == NetworkEventType.DataEvent)
                //        ExecuteGameCommand.ProcessCommand(message);
                //}

                else if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.AI)
                {
                    // The user side is controled by the hotseat section above.  The AI doesn't need anything during update since its states don't have input or transitions.
                }

                else if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.ClientServerNetwork)
                {
                }
            }
        }