Beispiel #1
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 #2
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();
        }