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