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:
@@ -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<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 End(string endMessage = "")
|
||||
{
|
||||
base.End(endMessage);
|
||||
}
|
||||
|
||||
public abstract void Save(XElement element);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user