diff --git a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj index b36eb2f25..6746c650c 100644 --- a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj +++ b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj @@ -91,7 +91,7 @@ - + diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs index c9100cea6..ec018ff6a 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs @@ -152,7 +152,7 @@ namespace Barotrauma if (Screen.Selected == GameMain.GameScreen && GameMain.GameSession != null) { - SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode; + SinglePlayerCampaign spMode = GameMain.GameSession.GameMode as SinglePlayerCampaign; if (spMode != null) { button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, "", pauseMenu); @@ -165,7 +165,7 @@ namespace Barotrauma if (Screen.Selected == GameMain.LobbyScreen) { - SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode; + SinglePlayerCampaign spMode = GameMain.GameSession.GameMode as SinglePlayerCampaign; if (spMode != null) { button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, "", pauseMenu); diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 53076d912..b27125bee 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -10,12 +10,10 @@ namespace Barotrauma class CrewManager { public List characters; - public List characterInfos; + public List CharacterInfos; public int WinningTeam = 1; - private int money; - private GUIFrame guiFrame; private GUIListBox listBox, orderListBox; @@ -26,16 +24,10 @@ namespace Barotrauma get { return commander; } } - public int Money - { - get { return money; } - set { money = (int)Math.Max(value, 0.0f); } - } - public CrewManager() { characters = new List(); - characterInfos = new List(); + CharacterInfos = new List(); guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent); guiFrame.Padding = Vector4.One * 5.0f; @@ -49,20 +41,16 @@ namespace Barotrauma orderListBox.OnSelected = SelectCharacterOrder; commander = new CrewCommander(this); - - money = 10000; } public CrewManager(XElement element) : this() { - money = ToolBox.GetAttributeInt(element, "money", 0); - foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "character") continue; - characterInfos.Add(new CharacterInfo(subElement)); + CharacterInfos.Add(new CharacterInfo(subElement)); } } @@ -120,9 +108,9 @@ namespace Barotrauma public void AddCharacter(Character character) { characters.Add(character); - if (!characterInfos.Contains(character.Info)) + if (!CharacterInfos.Contains(character.Info)) { - characterInfos.Add(character.Info); + CharacterInfos.Add(character.Info); } if (character is AICharacter) @@ -280,21 +268,21 @@ namespace Barotrauma listBox.ClearChildren(); characters.Clear(); - WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub, false); + WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(CharacterInfos, Submarine.MainSub, false); for (int i = 0; i < waypoints.Length; i++) { Character character; - if (characterInfos[i].HullID != null) + if (CharacterInfos[i].HullID != null) { - var hull = Entity.FindEntityByID((ushort)characterInfos[i].HullID) as Hull; + var hull = Entity.FindEntityByID((ushort)CharacterInfos[i].HullID) as Hull; if (hull == null) continue; - character = Character.Create(characterInfos[i], hull.WorldPosition); + character = Character.Create(CharacterInfos[i], hull.WorldPosition); } else { - character = Character.Create(characterInfos[i], waypoints[i].WorldPosition); + character = Character.Create(CharacterInfos[i], waypoints[i].WorldPosition); Character.Controlled = character; if (character.Info != null && !character.Info.StartItemsGiven) @@ -320,8 +308,8 @@ namespace Barotrauma continue; } - CharacterInfo deadInfo = characterInfos.Find(x => c.Info == x); - if (deadInfo != null) characterInfos.Remove(deadInfo); + CharacterInfo deadInfo = CharacterInfos.Find(x => c.Info == x); + if (deadInfo != null) CharacterInfos.Remove(deadInfo); } characters.Clear(); @@ -344,10 +332,8 @@ namespace Barotrauma public void Save(XElement parentElement) { XElement element = new XElement("crew"); - - element.Add(new XAttribute("money", money)); - - foreach (CharacterInfo ci in characterInfos) + + foreach (CharacterInfo ci in CharacterInfos) { ci.Save(element); } diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerMode.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs similarity index 80% rename from Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerMode.cs rename to Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs index 5b42c64ba..d3b1feacb 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs @@ -6,19 +6,10 @@ using System.Xml.Linq; namespace Barotrauma { - class SinglePlayerMode : GameMode + class SinglePlayerCampaign : CampaignMode { - //private const int StartCharacterAmount = 3; - - //public readonly CrewManager CrewManager; - //public readonly HireManager hireManager; - private GUIButton endRoundButton; - - public readonly CargoManager CargoManager; - - public Map Map; - + private bool crewDead; private float endTimer; @@ -29,31 +20,14 @@ namespace Barotrauma private Submarine leavingSub; private bool atEndPosition; - public override Mission Mission + protected CrewManager CrewManager { - get - { - return Map.SelectedConnection.Mission; - } + get { return GameMain.GameSession?.CrewManager; } } - public int Money - { - get { return GameMain.GameSession.CrewManager.Money; } - set { GameMain.GameSession.CrewManager.Money = value; } - } - - private CrewManager CrewManager - { - get { return GameMain.GameSession.CrewManager; } - } - - public SinglePlayerMode(GameModePreset preset, object param) + public SinglePlayerCampaign(GameModePreset preset, object param) : base(preset, param) - { - - CargoManager = new CargoManager(); - + { endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 220, 20, 200, 25), "End round", null, Alignment.TopLeft, Alignment.Center, ""); endRoundButton.Font = GUI.SmallFont; endRoundButton.OnClicked = TryEndRound; @@ -73,48 +47,11 @@ namespace Barotrauma jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Mechanic"); break; } - - CharacterInfo characterInfo = - new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab); - CrewManager.characterInfos.Add(characterInfo); + + CrewManager.CharacterInfos.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab)); } - } - - public SinglePlayerMode(XElement element) - : this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null) - { - foreach (XElement subElement in element.Elements()) - { - switch (subElement.Name.ToString().ToLowerInvariant()) - { - case "crew": - GameMain.GameSession.CrewManager = new CrewManager(subElement); - break; - case "map": - Map = Map.Load(subElement); - break; - } - } - - //backwards compatibility with older save files - if (Map==null) - { - string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a"); - - GenerateMap(mapSeed); - - Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0)); - } - - savedOnStart = true; - } - - public void GenerateMap(string seed) - { - Map = new Map(seed, 1000); - } - + public override void Start() { CargoManager.CreateItems(); @@ -134,22 +71,15 @@ namespace Barotrauma public bool TryHireCharacter(HireManager hireManager, CharacterInfo characterInfo) { - if (CrewManager.Money < characterInfo.Salary) return false; + if (Money < characterInfo.Salary) return false; hireManager.availableCharacters.Remove(characterInfo); - CrewManager.characterInfos.Add(characterInfo); - - CrewManager.Money -= characterInfo.Salary; + CrewManager.CharacterInfos.Add(characterInfo); + Money -= characterInfo.Salary; return true; } - - public string GetMoney() - { - return "Money: " + CrewManager.Money; - } - - + private Submarine GetLeavingSub() { if (Character.Controlled != null && Character.Controlled.Submarine != null) @@ -170,15 +100,6 @@ namespace Barotrauma return null; } - private List GetSubsToLeaveBehind(Submarine leavingSub) - { - //leave subs behind if they're not docked to the leaving sub and not at the same exit - return Submarine.Loaded.FindAll(s => - s != leavingSub && - !leavingSub.DockedTo.Contains(s) && - (s.AtEndPosition != leavingSub.AtEndPosition || s.AtStartPosition != leavingSub.AtStartPosition)); - } - public override void Draw(SpriteBatch spriteBatch) { if (!isRunning|| GUI.DisableHUD) return; @@ -218,9 +139,7 @@ namespace Barotrauma if (!isRunning) return; base.AddToGUIUpdateList(); - CrewManager.AddToGUIUpdateList(); - endRoundButton.AddToGUIUpdateList(); } @@ -361,12 +280,12 @@ namespace Barotrauma List leavingSubs = obj as List; if (leavingSubs == null) leavingSubs = new List() { GetLeavingSub() }; - + var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f); SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endround" : "crewdead"; - CoroutineManager.StartCoroutine(EndCinematic(cinematic),"EndCinematic"); + CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic"); return true; } @@ -391,14 +310,43 @@ namespace Barotrauma yield return CoroutineStatus.Success; } - public void Save(XElement element) + public static SinglePlayerCampaign Load(XElement element) { - //element.Add(new XAttribute("day", day)); - XElement modeElement = new XElement("gamemode"); + SinglePlayerCampaign campaign = new SinglePlayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null); - //modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex)); - //modeElement.Add(new XAttribute("mapseed", Map.Seed)); + foreach (XElement subElement in element.Elements()) + { + switch (subElement.Name.ToString().ToLowerInvariant()) + { + case "crew": + GameMain.GameSession.CrewManager = new CrewManager(subElement); + break; + case "map": + campaign.map = Map.Load(subElement); + break; + } + } + + campaign.Money = ToolBox.GetAttributeInt(element, "money", 0); + + //backwards compatibility with older save files + if (campaign.map == null) + { + string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a"); + campaign.GenerateMap(mapSeed); + campaign.map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0)); + } + + campaign.savedOnStart = true; + + return campaign; + } + + public override void Save(XElement element) + { + XElement modeElement = new XElement("gamemode"); + modeElement.Add(new XAttribute("money", Money)); CrewManager.Save(modeElement); Map.Save(modeElement); diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/TutorialType.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/TutorialType.cs index 6a969fe64..c1c31cf68 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/TutorialType.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/TutorialType.cs @@ -37,11 +37,11 @@ namespace Barotrauma.Tutorials { GameMain.GameSession = new GameSession(Submarine.MainSub, "", GameModePreset.list.Find(gm => gm.Name.ToLowerInvariant() == "tutorial")); - (GameMain.GameSession.gameMode as TutorialMode).tutorialType = this; + (GameMain.GameSession.GameMode as TutorialMode).tutorialType = this; GameMain.GameSession.StartRound("tuto"); - GameMain.GameSession.TaskManager.Events.Clear(); + GameMain.GameSession.EventManager.Events.Clear(); GameMain.GameScreen.Select(); } diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs index 198223404..b5ea938c3 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs @@ -15,7 +15,7 @@ namespace Barotrauma { get { - SinglePlayerMode mode = (gameMode as SinglePlayerMode); + SinglePlayerCampaign mode = (GameMode as SinglePlayerCampaign); return (mode == null) ? null : mode.Map; } } @@ -132,21 +132,21 @@ namespace Barotrauma { infoButton.AddToGUIUpdateList(); - if (gameMode != null) gameMode.AddToGUIUpdateList(); + if (GameMode != null) GameMode.AddToGUIUpdateList(); if (infoFrame != null) infoFrame.AddToGUIUpdateList(); } public void Update(float deltaTime) { - TaskManager.Update(deltaTime); + EventManager.Update(deltaTime); if (GUI.DisableHUD) return; //guiRoot.Update(deltaTime); infoButton.Update(deltaTime); - if (gameMode != null) gameMode.Update(deltaTime); + if (GameMode != null) GameMode.Update(deltaTime); if (Mission != null) Mission.Update(deltaTime); if (infoFrame != null) { @@ -165,23 +165,26 @@ namespace Barotrauma infoButton.Draw(spriteBatch); - if (gameMode != null) gameMode.Draw(spriteBatch); + if (GameMode != null) GameMode.Draw(spriteBatch); if (infoFrame != null) infoFrame.Draw(spriteBatch); } public void Save(string filePath) { + if (!(GameMode is CampaignMode)) + { + throw new NotSupportedException("GameSessions can only be saved when playing in a campaign mode."); + } + XDocument doc = new XDocument( new XElement("Gamesession")); var now = DateTime.Now; doc.Root.Add(new XAttribute("savetime", now.ToShortTimeString() + ", " + now.ToShortDateString())); - doc.Root.Add(new XAttribute("submarine", submarine == null ? "" : submarine.Name)); - doc.Root.Add(new XAttribute("mapseed", Map.Seed)); - ((SinglePlayerMode)gameMode).Save(doc.Root); + ((CampaignMode)GameMode).Save(doc.Root); try { diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 5c0d192f6..0b9c1aad8 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -724,7 +724,7 @@ namespace Barotrauma.Networking { if (!gameStarted) yield return CoroutineStatus.Success; - if (GameMain.GameSession != null) GameMain.GameSession.gameMode.End(endMessage); + if (GameMain.GameSession != null) GameMain.GameSession.GameMode.End(endMessage); gameStarted = false; Character.Controlled = null; diff --git a/Barotrauma/BarotraumaClient/Source/Screens/LobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/LobbyScreen.cs index 24ae8e2ca..c140231cc 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/LobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/LobbyScreen.cs @@ -23,7 +23,7 @@ namespace Barotrauma private GUIListBox selectedItemList; private GUIListBox storeItemList; - private SinglePlayerMode gameMode; + private SinglePlayerCampaign gameMode; private GUIFrame previewFrame; @@ -158,7 +158,7 @@ namespace Barotrauma { base.Select(); - gameMode = GameMain.GameSession.gameMode as SinglePlayerMode; + gameMode = GameMain.GameSession.GameMode as SinglePlayerCampaign; UpdateCharacterLists(); } @@ -237,7 +237,6 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, 100, 0, 20), "Reward: " + mission.Reward+" credits", "", locationPanel); new GUITextBlock(new Rectangle(0, 130, 0, 0), mission.Description, "", locationPanel, true); - } startButton.Enabled = true; @@ -248,7 +247,7 @@ namespace Barotrauma private void UpdateCharacterLists() { characterList.ClearChildren(); - foreach (CharacterInfo c in CrewManager.characterInfos) + foreach (CharacterInfo c in CrewManager.CharacterInfos) { c.CreateCharacterFrame(characterList, c.Name + " ("+c.Job.Name+") ", c); } @@ -298,7 +297,7 @@ namespace Barotrauma CreateItemFrame(prefab, selectedItemList, selectedItemList.Rect.Width); - buyButton.Enabled = CrewManager.Money >= selectedItemCost; + buyButton.Enabled = gameMode.Money >= selectedItemCost; return false; } @@ -317,9 +316,9 @@ namespace Barotrauma { int cost = selectedItemCost; - if (CrewManager.Money < cost) return false; + if (gameMode.Money < cost) return false; - CrewManager.Money -= cost; + gameMode.Money -= cost; for (int i = selectedItemList.children.Count-1; i>=0; i--) { @@ -363,7 +362,7 @@ namespace Barotrauma public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - if (characterList.CountChildren != CrewManager.characterInfos.Count) + if (characterList.CountChildren != CrewManager.CharacterInfos.Count) { UpdateCharacterLists(); } @@ -457,7 +456,7 @@ namespace Barotrauma private string GetMoney() { - return "Money: " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", CrewManager.Money)) + " credits"; + return "Money: " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", gameMode.Money)) + " credits"; } private bool SelectCharacter(GUIComponent component, object selection) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs index b97166aa8..2ca22e5d9 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs @@ -508,8 +508,8 @@ namespace Barotrauma GUI.Draw((float)deltaTime, spriteBatch, null); - GUI.Font.DrawString(spriteBatch, "Barotrauma v"+GameMain.Version, new Vector2(10, GameMain.GraphicsHeight-20), Color.White); - + GUI.Font.DrawString(spriteBatch, "Barotrauma v" + GameMain.Version, new Vector2(10, GameMain.GraphicsHeight - 20), Color.White); + spriteBatch.End(); } @@ -542,15 +542,10 @@ namespace Barotrauma selectedSub = new Submarine(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"), ""); GameMain.GameSession = new GameSession(selectedSub, saveNameBox.Text, GameModePreset.list.Find(gm => gm.Name == "Single Player")); - (GameMain.GameSession.gameMode as SinglePlayerMode).GenerateMap(seedBox.Text); + (GameMain.GameSession.GameMode as CampaignMode).GenerateMap(seedBox.Text); GameMain.LobbyScreen.Select(); - - //new GUIMessageBox("Welcome to Barotrauma!", "Please note that the single player mode is very unfinished at the moment; "+ - //"for example, the NPCs don't have an AI yet and there are only a couple of different quests to complete. The multiplayer "+ - //"mode should be much more enjoyable to play at the moment, so my recommendation is to try out and get a hang of the game mechanics "+ - //"in the single player mode and then move on to multiplayer. Have fun!\n - Regalis, the main dev of Subsurface", 400, 350); - + return true; } diff --git a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems index 3681a9335..0b6765fbe 100644 --- a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems +++ b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems @@ -1366,9 +1366,11 @@ + + diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index c684070c1..2e6059673 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -169,7 +169,7 @@ namespace Barotrauma #if CLIENT if (GameMain.GameSession != null) { - SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode; + SinglePlayerCampaign mode = GameMain.GameSession.GameMode as SinglePlayerCampaign; if (mode != null) { Character.Controlled = spawnedCharacter; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/Mission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/Mission.cs index 573ab3ad9..e8cbddff2 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/Mission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/Mission.cs @@ -248,12 +248,10 @@ namespace Barotrauma public void GiveReward() { -#if CLIENT - var mode = GameMain.GameSession.gameMode as SinglePlayerMode; + var mode = GameMain.GameSession.GameMode as CampaignMode; if (mode == null) return; mode.Money += reward; -#endif } } } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs new file mode 100644 index 000000000..097a01a1b --- /dev/null +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/CampaignMode.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Xml.Linq; + +namespace Barotrauma +{ + abstract class CampaignMode : GameMode + { + public readonly CargoManager CargoManager; + + const int InitialMoney = 10000; + + protected Map map; + public Map Map + { + get { return map; } + } + + public override Mission Mission + { + get + { + return Map.SelectedConnection.Mission; + } + } + + private int money; + public int Money + { + get { return money; } + set { money = Math.Max(value, 0); } + } + + public CampaignMode(GameModePreset preset, object param) + : base(preset, param) + { + Money = InitialMoney; + CargoManager = new CargoManager(); + } + + public void GenerateMap(string seed) + { + map = new Map(seed, 1000); + } + + protected List GetSubsToLeaveBehind(Submarine leavingSub) + { + //leave subs behind if they're not docked to the leaving sub and not at the same exit + return Submarine.Loaded.FindAll(s => + s != leavingSub && + !leavingSub.DockedTo.Contains(s) && + (s.AtEndPosition != leavingSub.AtEndPosition || s.AtStartPosition != leavingSub.AtStartPosition)); + } + + public override void End(string endMessage = "") + { + base.End(endMessage); + } + + public abstract void Save(XElement element); + } +} diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs index f3d054beb..052eb8477 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs @@ -34,7 +34,7 @@ namespace Barotrauma public static void Init() { #if CLIENT - new GameModePreset("Single Player", typeof(SinglePlayerMode), true); + new GameModePreset("Single Player", typeof(SinglePlayerCampaign), true); new GameModePreset("Tutorial", typeof(TutorialMode), true); #endif diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs new file mode 100644 index 000000000..3d67f4260 --- /dev/null +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Linq; + +namespace Barotrauma +{ + class MultiplayerCampaign : CampaignMode + { + public MultiplayerCampaign(GameModePreset preset, object param) : + base(preset, param) + { + } + + public override void Save(XElement element) + { + throw new NotImplementedException(); + } + } +} diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs index 7b1d735a9..c4570f4b0 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs @@ -7,9 +7,9 @@ namespace Barotrauma { public enum InfoFrameTab { Crew, Mission, ManagePlayers }; - public readonly EventManager TaskManager; + public readonly EventManager EventManager; - public readonly GameMode gameMode; + public readonly GameMode GameMode; //two locations used as the start and end in the MP mode private Location[] dummyLocations; @@ -79,14 +79,14 @@ namespace Barotrauma { get { return saveFile; } } - - public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType="") + + public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType = "") { Submarine.MainSub = submarine; GameMain.GameSession = this; - TaskManager = new EventManager(this); + EventManager = new EventManager(this); this.saveFile = saveFile; @@ -97,7 +97,7 @@ namespace Barotrauma infoButton.OnClicked = ToggleInfoFrame; #endif - if (gameModePreset != null) gameMode = gameModePreset.Instantiate(missionType); + if (gameModePreset != null) GameMode = gameModePreset.Instantiate(missionType); this.submarine = submarine; } @@ -117,7 +117,7 @@ namespace Barotrauma { if (subElement.Name.ToString().ToLowerInvariant() != "gamemode") continue; - gameMode = new SinglePlayerMode(subElement); + GameMode = SinglePlayerCampaign.Load(subElement); } #endif } @@ -186,18 +186,18 @@ namespace Barotrauma submarine.SetPosition(submarine.FindSpawnPos(level.StartPosition - new Vector2(0.0f, 2000.0f))); } - if (gameMode.Mission != null) + if (GameMode.Mission != null) { - currentMission = gameMode.Mission; + currentMission = GameMode.Mission; } - if (gameMode!=null) gameMode.Start(); + if (GameMode!=null) GameMode.Start(); - if (gameMode.Mission != null) Mission.Start(Level.Loaded); + if (GameMode.Mission != null) Mission.Start(Level.Loaded); - TaskManager.StartRound(level); + EventManager.StartRound(level); - if (gameMode != null) gameMode.MsgBox(); + if (GameMode != null) GameMode.MsgBox(); Entity.Spawner = new EntitySpawner(); @@ -234,7 +234,7 @@ namespace Barotrauma } #endif - TaskManager.EndRound(); + EventManager.EndRound(); currentMission = null; diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index 89dbc0546..a9e7acd8e 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -554,7 +554,7 @@ namespace Barotrauma.Networking //game already started -> send start message immediately if (gameStarted) { - SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClient); + SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClient); } } break; @@ -1131,8 +1131,8 @@ namespace Barotrauma.Networking GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]); - if (GameMain.GameSession.gameMode.Mission != null && - GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients, out hostTeam)) + if (GameMain.GameSession.GameMode.Mission != null && + GameMain.GameSession.GameMode.Mission.AssignTeamIDs(connectedClients, out hostTeam)) { teamCount = 2; } @@ -1149,8 +1149,8 @@ namespace Barotrauma.Networking GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage); bool missionAllowRespawn = - !(GameMain.GameSession.gameMode is MissionMode) || - ((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn; + !(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn; if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); @@ -1261,7 +1261,7 @@ namespace Barotrauma.Networking } } - SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients); + SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClients); yield return CoroutineStatus.Running; @@ -1308,8 +1308,8 @@ namespace Barotrauma.Networking msg.Write(selectedMode.Name); bool missionAllowRespawn = - !(GameMain.GameSession.gameMode is MissionMode) || - ((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn; + !(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn; msg.Write(AllowRespawn && missionAllowRespawn); msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub @@ -1350,7 +1350,7 @@ namespace Barotrauma.Networking } Mission mission = GameMain.GameSession.Mission; - GameMain.GameSession.gameMode.End(endMessage); + GameMain.GameSession.GameMode.End(endMessage); if (autoRestart) {