public void NewSavedGameOK() { if (GlobalDefinitions.newGameToggle.GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToLogFile("newSavedGameOK: Starting new game"); GUIRoutines.RemoveGUI(transform.parent.gameObject); GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteNewGame(); } else if (GlobalDefinitions.savedGameToggle.GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToLogFile("newSavedGameOK: Starting saved game"); // Since at this point we know we are starting a new game and not running the command file, remove the command file if (!GlobalDefinitions.commandFileBeingRead) { GlobalDefinitions.DeleteCommandFile(); } GUIRoutines.RemoveGUI(transform.parent.gameObject); GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteSavedGame(); } else if (GlobalDefinitions.commandFileToggle.GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToLogFile("newSavedGameOK: Executing command file"); GUIRoutines.RemoveGUI(transform.parent.gameObject); GameControl.setUpStateInstance.GetComponent <SetUpState>().ReadCommandFile(); } }
/// <summary> /// This is the routine called to write out the save turn file /// </summary> public void WriteSaveTurnFile(string saveFileType) { // There are three types of saved files: setup, end of Allied turn, and end of German turn. The name of the file reflects this using the string passed string turnString; if (GlobalDefinitions.turnNumber < 10) { turnString = "0" + GlobalDefinitions.turnNumber.ToString(); } else { turnString = GlobalDefinitions.turnNumber.ToString(); } StreamWriter fileWriter = new StreamWriter(GameControl.path + "TGCOutputFiles\\TGCSaveFile_Turn" + turnString + "_" + saveFileType + ".txt"); if (fileWriter == null) { GlobalDefinitions.GuiUpdateStatusMessage("Unable to open save file " + GameControl.path + "TGCOutputFiles\\TGCSaveFile_Turn" + turnString + "_" + saveFileType + ".txt"); } else { fileWriter.WriteLine("Turn " + GlobalDefinitions.turnNumber); fileWriter.Write("Global_Definitions "); GlobalDefinitions.WriteGlobalVariables(fileWriter); fileWriter.WriteLine("Hexes"); foreach (GameObject hex in HexDefinitions.allHexesOnBoard) { hex.GetComponent <HexDatabaseFields>().WriteHexFields(fileWriter); } fileWriter.WriteLine("End"); fileWriter.WriteLine("Units"); foreach (Transform unit in GameObject.Find("Units Eliminated").transform) { unit.GetComponent <UnitDatabaseFields>().WriteUnitFields(fileWriter); } foreach (Transform unit in GlobalDefinitions.allUnitsOnBoard.transform) { unit.GetComponent <UnitDatabaseFields>().WriteUnitFields(fileWriter); } foreach (Transform unit in GameObject.Find("Units In Britain").transform) { unit.GetComponent <UnitDatabaseFields>().WriteUnitFields(fileWriter); } fileWriter.WriteLine("End"); // In network mode the Game Control loads the currentState and it works best if everything is set before it gets called. fileWriter.Write("Game_Control "); if (saveFileType == "Setup") { fileWriter.Write("German"); } else { fileWriter.Write(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality); } fileWriter.WriteLine(); fileWriter.Close(); // A new saved file has been written so delete the current command file and load the new turn file if (!GlobalDefinitions.commandFileBeingRead) { if (File.Exists(GameControl.path + GlobalGameFields.commandFile)) { GlobalDefinitions.DeleteCommandFile(); } using (StreamWriter writeFile = File.AppendText(GameControl.path + GlobalGameFields.commandFile)) { writeFile.WriteLine(GlobalDefinitions.AGGRESSIVESETTINGKEYWORD + " " + GlobalDefinitions.aggressiveSetting); writeFile.WriteLine(GlobalDefinitions.DIFFICULTYSETTINGKEYWORD + " " + GlobalDefinitions.difficultySetting); writeFile.WriteLine("SavedTurnFile " + GameControl.path + "TGCOutputFiles\\TGCSaveFile_Turn" + turnString + "_" + saveFileType + ".txt"); } } } }