Started moving single player campaign logic to an abstract CampaignMode class to make it reusable in the eventual multiplayer campaign
This commit is contained in:
@@ -10,12 +10,10 @@ namespace Barotrauma
|
||||
class CrewManager
|
||||
{
|
||||
public List<Character> characters;
|
||||
public List<CharacterInfo> characterInfos;
|
||||
public List<CharacterInfo> 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<Character>();
|
||||
characterInfos = new List<CharacterInfo>();
|
||||
CharacterInfos = new List<CharacterInfo>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
+49
-101
@@ -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<Submarine> 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<Submarine> leavingSubs = obj as List<Submarine>;
|
||||
if (leavingSubs == null) leavingSubs = new List<Submarine>() { 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);
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user