예제 #1
0
        /// <summary>
        /// Executes when the user wants to display the current combats
        /// </summary>
        public void ExecuteCombatResolution()
        {
            if (GUIRoutines.guiList.Count == 0)
            {
                if (GlobalDefinitions.allCombats.Count > 0)
                {
                    // Turn off the button
                    GameObject.Find("ResolveCombatButton").GetComponent <Button>().interactable = false;

                    CombatResolutionRoutines.CombatResolutionDisplay();

                    // When this is called by the AI then the line below end up calling two guis when the command file is being read
                    if (!GlobalDefinitions.AICombat)
                    {
                        GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.DISPLAYCOMBATRESOLUTIONKEYWORD);
                    }
                }
                else
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No combats have been assigned therefore there is nothing to resolve");
                }
            }
            else
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Resolve the currently displayed menu before trying to bring up combat display");
            }
        }
예제 #2
0
        public void MultiUnitSelection()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.TACAIRMULTIUNITSELECTIONKEYWORD + " " + name);

            GUIRoutines.RemoveGUI(GlobalDefinitions.tacticalAirGUIInstance);
            CombatResolutionRoutines.AddInterdictedUnitToList(unit);
        }
        /// <summary>
        /// Called when the ok button is selected
        /// </summary>
        public void OkSelected()
        {
            GlobalDefinitions.aggressiveSetting = (int)GameObject.Find("AgressivenessSlider").GetComponent <Slider>().value;
            GlobalDefinitions.difficultySetting = (int)GameObject.Find("DifficultySlider").GetComponent <Slider>().value;
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.AGGRESSIVESETTINGKEYWORD + " " + (int)GameObject.Find("AgressivenessSlider").GetComponent <Slider>().value);
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.DIFFICULTYSETTINGKEYWORD + " " + (int)GameObject.Find("DifficultySlider").GetComponent <Slider>().value);
            // Write out the values of the sliders to the settings file
            GameControl.readWriteRoutinesInstance.GetComponent <ReadWriteRoutines>().WriteSettingsFile(GlobalDefinitions.difficultySetting, GlobalDefinitions.aggressiveSetting);
            CombatResolutionRoutines.AdjustAggressiveness();

            CancelSelected();
        }
예제 #4
0
        public void CancelInterdictedUnit()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.CANCELUNITINTERDICTIONKEYWORD + " " + name);

            for (int index = 0; index < GlobalDefinitions.interdictedUnits.Count; index++)
            {
                if (GlobalDefinitions.interdictedUnits[index] == unit)
                {
                    GlobalDefinitions.interdictedUnits[index].GetComponent <UnitDatabaseFields>().unitInterdiction = false;
                    GlobalDefinitions.interdictedUnits.Remove(unit);
                }
            }
            GlobalDefinitions.tacticalAirMissionsThisTurn--;
            GUIRoutines.RemoveGUI(GlobalDefinitions.tacticalAirGUIInstance);
            CombatResolutionRoutines.CreateTacticalAirGUI();
        }
예제 #5
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();
        }
예제 #6
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();
        }
 public void CarpetBombingResultsSelected()
 {
     if (gameObject.GetComponent <Toggle>().isOn)
     {
         if ((GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork) && (!GlobalDefinitions.localControl))
         {
             GUIRoutines.RemoveGUI(transform.parent.gameObject);
             CombatResolutionRoutines.ExecuteCombatResults(defendingUnits, attackingUnits, combatOdds, dieRollResult, combatResults, buttonLocation);
         }
         else
         {
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.COMBATRESOLUTIONSELECTEDKEYWORD + " " + GlobalDefinitions.CombatResultToggleName);
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.CARPETBOMBINGRESULTSSELECTEDKEYWORD + " " + name + " " + dieRollResult);
             GUIRoutines.RemoveGUI(transform.parent.gameObject);
             CombatResolutionRoutines.ExecuteCombatResults(defendingUnits, attackingUnits, combatOdds, dieRollResult, combatResults, buttonLocation);
         }
     }
 }
예제 #8
0
        /// <summary>
        /// Called when a unit is selected from the gui to retreat when there are multiple units avaialble
        /// </summary>
        public void SelectUnitsToMove()
        {
            if (GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.RETREATSELECTIONKEYWORD + " " + name);

                // The unit has been selected so move it to the zero position in the list since that is what will be moved
                GlobalDefinitions.retreatingUnits.Remove(GetComponent <RetreatToggleRoutines>().unit);
                GlobalDefinitions.retreatingUnits.Insert(0, GetComponent <RetreatToggleRoutines>().unit);

                List <GameObject> retreatHexes = CombatResolutionRoutines.ReturnRetreatHexes(GetComponent <RetreatToggleRoutines>().unit);
                if (retreatHexes.Count > 0)
                {
                    GlobalDefinitions.HighlightUnit(unit);
                    foreach (GameObject hex in retreatHexes)
                    {
                        GlobalDefinitions.HighlightHexForMovement(hex);
                    }
                    GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod =
                        GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <CombatState>().ExecuteRetreatMovement;
                }

                // This executes when there is no retreat available for the unit.  While the units without retreat available is checked early on,
                // this is a case where there was more than one unit that needed to retreat but there wasn't room for all of them
                else
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("No retreat available - eliminating unit" + unit.name);
                    GlobalDefinitions.MoveUnitToDeadPile(unit);
                    GlobalDefinitions.retreatingUnits.RemoveAt(0);

                    // Need to call selection routines in case there are more units that cannot retreat
                    CombatResolutionRoutines.SelectUnitsForRetreat();
                }
                GUIRoutines.RemoveGUI(transform.parent.gameObject);
            }
        }
예제 #9
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;
            }
        }
예제 #10
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();
        }
        /// <summary>
        /// This routine is called when the user selects the Resolve button for a combat
        /// </summary>
        public void ResolutionSelected()
        {
            // Write out the name of the toggle being executed in order to send it once the die roll is known
            if (GlobalDefinitions.localControl)
            {
                GlobalDefinitions.CombatResultToggleName = name;
            }

            // If combat resolution hasn't started then check to make sure all required combats have been created
            if (!GlobalDefinitions.combatResolutionStarted)
            {
                if (CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true))
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("Cannot start combat resolution, highlighted units must be committed to combat first.");
                }
                else
                {
                    // All required units are attacking or being attacked
                    GlobalDefinitions.combatResolutionStarted = true;

                    // Get rid of the "Continue" button since combat resolution has started
                    GlobalDefinitions.combatResolutionOKButton.SetActive(false);

                    // Once combat resolution starts, canceling an attack is no longer an option so get rid of all cancel buttons
                    // Also can't assign any more air support so make those toggles non-interactive
                    foreach (GameObject combat in GlobalDefinitions.allCombats)
                    {
                        if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied)
                        {
                            combat.GetComponent <Combat>().airSupportToggle.interactable = false;
                        }
                        DestroyImmediate(combat.GetComponent <Combat>().cancelButton.gameObject);
                    }

                    // Only check for carpet bombing if Allies are attacking.  This is needed to keep the German attacks from being loaded
                    if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied)
                    {
                        GlobalDefinitions.combatResultsFromLastTurn.Clear();
                        GlobalDefinitions.hexesAttackedLastTurn.Clear();
                        // Store all hexes being attacked this turn.  Used for carpet bombing availability next turn
                        foreach (GameObject combat in GlobalDefinitions.allCombats)
                        {
                            foreach (GameObject defender in combat.GetComponent <Combat>().defendingUnits)
                            {
                                if (!GlobalDefinitions.hexesAttackedLastTurn.Contains(defender.GetComponent <UnitDatabaseFields>().occupiedHex))
                                {
                                    GlobalDefinitions.hexesAttackedLastTurn.Add(defender.GetComponent <UnitDatabaseFields>().occupiedHex);
                                }
                            }
                        }
                    }
                }
            }

            if (GlobalDefinitions.combatResolutionStarted)
            {
                CombatResolutionRoutines.DetermineCombatResults(curentCombat, gameObject.GetComponent <RectTransform>().anchoredPosition);

                // Get rid of the locate button on the attack being resolved, can't gaurantee that the units are still there after resolution
                DestroyImmediate(curentCombat.GetComponent <Combat>().locateButton.gameObject);
                //Get rid of the resolve button since the battle has been resolved.  This is also used to determine if all combats have been resolved.
                //DestroyImmediate(GameObject.Find(GlobalDefinitions.CombatResultToggleName));
                GUIRoutines.RemoveGUI(gameObject);
            }

            // Check if all the attacks have been resolved by seeing if there are any more Resolve buttons left
            bool allAttacksResolved = true;

            foreach (GameObject combat in GlobalDefinitions.allCombats)
            {
                if (combat.GetComponent <Combat>().resolveButton != null)
                {
                    allAttacksResolved = false;
                }
            }

            // If all attacks have been resolved turn on the quit button (which is the continue button with the text changed
            if (allAttacksResolved)
            {
                GlobalDefinitions.combatResolutionOKButton.SetActive(true);
                GlobalDefinitions.combatResolutionOKButton.GetComponent <Button>().GetComponentInChildren <Text>().text = "Quit";
            }
        }
        /// <summary>
        /// Called from the combat resolution gui to cancel a combat - determined by the combatResoultionArrayIndex loaded
        /// </summary>
        public void CancelAttack()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.COMBATCANCELKEYWORD + " " + name);

            // Since we are going to reset the mustBeAttackedUnits list I need to clear out all the highlighting since
            // there are cases where units were added to the list because of cross river attacks but haven't been assigned
            // to a combat yet.  If I don't clear highlighting here they won't be reset because they aren't mustBeAttackedUnits anymore

            foreach (GameObject unit in curentCombat.GetComponent <Combat>().defendingUnits)
            {
                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                GlobalDefinitions.UnhighlightUnit(unit);
            }

            foreach (GameObject unit in curentCombat.GetComponent <Combat>().attackingUnits)
            {
                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                GlobalDefinitions.UnhighlightUnit(unit);
            }

            // Check if we need to give a air mission back
            if (curentCombat.GetComponent <Combat>().attackAirSupport)
            {
                GlobalDefinitions.tacticalAirMissionsThisTurn--;
            }

            // Need to check if we need to give back carpet bombing
            if (curentCombat.GetComponent <Combat>().carpetBombing)
            {
                GlobalDefinitions.carpetBombingUsedThisTurn = false;
                GlobalDefinitions.numberOfCarpetBombingsUsed--;
                curentCombat.GetComponent <Combat>().carpetBombing = false;
                curentCombat.GetComponent <Combat>().defendingUnits[0].GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().carpetBombingActive = false;
            }

            GlobalDefinitions.allCombats.Remove(curentCombat);

            // Need to get rid of all the buttons and toggles in the remaining combats since they will be regenerated
            foreach (GameObject combat in GlobalDefinitions.allCombats)
            {
                DestroyImmediate(combat.GetComponent <Combat>().locateButton);
                DestroyImmediate(combat.GetComponent <Combat>().resolveButton);
                DestroyImmediate(combat.GetComponent <Combat>().cancelButton);
                DestroyImmediate(combat.GetComponent <Combat>().airSupportToggle);
            }

            GUIRoutines.RemoveGUI(GlobalDefinitions.combatResolutionGUIInstance);

            if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedCombatStateInstance") ||
                (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanCombatStateInstance") ||
                GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn)
            {
                CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true);
            }
            else
            {
                CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, false);
            }

            if (GlobalDefinitions.allCombats.Count > 0)
            {
                CombatResolutionRoutines.CombatResolutionDisplay();
            }
            else
            {
                // If the last battle has been canceled then turn the button back on
                GameObject.Find("ResolveCombatButton").GetComponent <Button>().interactable = true;
            }
        }
        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");
            }
        }