- Autorestart works in campaign mode.
- The server select a random destination when the campaign starts and after each round, so the campaign can be played even if there's no host/client to choose the destinations. (TODO: make it possible to vote for the destination?) - Reverting to the previous save if the entire crew is dead works correctly now. - Clients load the campaign saves after receiving them (-> discovered locations/connections are synced with clients).
This commit is contained in:
@@ -156,8 +156,12 @@ namespace Barotrauma
|
|||||||
if (spMode != null)
|
if (spMode != null)
|
||||||
{
|
{
|
||||||
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, "", pauseMenu);
|
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, "", pauseMenu);
|
||||||
button.OnClicked += TogglePauseMenu;
|
button.OnClicked += (btn, userData) =>
|
||||||
button.OnClicked += GameMain.GameSession.LoadPrevious;
|
{
|
||||||
|
TogglePauseMenu(btn, userData);
|
||||||
|
GameMain.GameSession.LoadPrevious();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
y += 60;
|
y += 60;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,8 +219,13 @@ namespace Barotrauma
|
|||||||
summaryScreen.RemoveChild(summaryScreen.children.Find(c => c is GUIButton));
|
summaryScreen.RemoveChild(summaryScreen.children.Find(c => c is GUIButton));
|
||||||
|
|
||||||
var okButton = new GUIButton(new Rectangle(-120, 0, 100, 30), "Load game", Alignment.BottomRight, "", summaryScreen);
|
var okButton = new GUIButton(new Rectangle(-120, 0, 100, 30), "Load game", Alignment.BottomRight, "", summaryScreen);
|
||||||
okButton.OnClicked += GameMain.GameSession.LoadPrevious;
|
okButton.OnClicked += (GUIButton button, object obj) =>
|
||||||
okButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return true; };
|
{
|
||||||
|
GameMain.GameSession.LoadPrevious();
|
||||||
|
GameMain.LobbyScreen.Select();
|
||||||
|
GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Quit", Alignment.BottomRight, "", summaryScreen);
|
var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Quit", Alignment.BottomRight, "", summaryScreen);
|
||||||
quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
|
quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
|
||||||
@@ -322,7 +327,7 @@ namespace Barotrauma
|
|||||||
GameMain.GameSession.CrewManager = new CrewManager(subElement);
|
GameMain.GameSession.CrewManager = new CrewManager(subElement);
|
||||||
break;
|
break;
|
||||||
case "map":
|
case "map":
|
||||||
campaign.map = Map.Load(subElement);
|
campaign.map = Map.LoadNew(subElement);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,6 @@ namespace Barotrauma
|
|||||||
get { return roundSummary; }
|
get { return roundSummary; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadPrevious(GUIButton button, object obj)
|
|
||||||
{
|
|
||||||
Submarine.Unload();
|
|
||||||
|
|
||||||
SaveUtil.LoadGame(savePath);
|
|
||||||
|
|
||||||
GameMain.LobbyScreen.Select();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ToggleInfoFrame(GUIButton button, object obj)
|
private bool ToggleInfoFrame(GUIButton button, object obj)
|
||||||
{
|
{
|
||||||
if (infoFrame == null)
|
if (infoFrame == null)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ namespace Barotrauma
|
|||||||
private static Texture2D iceCraters;
|
private static Texture2D iceCraters;
|
||||||
private static Texture2D iceCrack;
|
private static Texture2D iceCrack;
|
||||||
|
|
||||||
|
private Location highlightedLocation;
|
||||||
|
|
||||||
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
|
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
|
||||||
{
|
{
|
||||||
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
|
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
|
||||||
|
|||||||
@@ -1118,15 +1118,11 @@ namespace Barotrauma.Networking
|
|||||||
if (GameMain.GameSession.Submarine == null)
|
if (GameMain.GameSession.Submarine == null)
|
||||||
{
|
{
|
||||||
var gameSessionDoc = SaveUtil.LoadGameSessionDoc(GameMain.GameSession.SavePath);
|
var gameSessionDoc = SaveUtil.LoadGameSessionDoc(GameMain.GameSession.SavePath);
|
||||||
string subPath = Path.Combine(SaveUtil.TempPath, ToolBox.GetAttributeString(gameSessionDoc.Root, "submarine", "")) + ".sub";
|
string subPath = Path.Combine(SaveUtil.TempPath, ToolBox.GetAttributeString(gameSessionDoc.Root, "submarine", "")) + ".sub";
|
||||||
|
|
||||||
GameMain.GameSession.Submarine = new Submarine(subPath, "");
|
GameMain.GameSession.Submarine = new Submarine(subPath, "");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
SaveUtil.DecompressToDirectory(GameMain.GameSession.SavePath, SaveUtil.TempPath, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SaveUtil.LoadGame(GameMain.GameSession.SavePath, GameMain.GameSession);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,15 @@ namespace Barotrauma.Networking
|
|||||||
void FinishUPnP()
|
void FinishUPnP()
|
||||||
{
|
{
|
||||||
upnpBox.Close(null, null);
|
upnpBox.Close(null, null);
|
||||||
|
|
||||||
|
if (server.UPnP.Status == UPnPStatus.NotAvailable)
|
||||||
|
{
|
||||||
|
new GUIMessageBox("Error", "UPnP not available");
|
||||||
|
}
|
||||||
|
else if (server.UPnP.Status == UPnPStatus.Discovering)
|
||||||
|
{
|
||||||
|
new GUIMessageBox("Error", "UPnP discovery timed out");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StartGameClicked(GUIButton button, object obj)
|
public bool StartGameClicked(GUIButton button, object obj)
|
||||||
|
|||||||
@@ -1181,6 +1181,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
var moneyText = new GUITextBlock(new Rectangle(120,0,200,20), "Money", "", Alignment.BottomLeft, Alignment.TopLeft, campaignContainer);
|
var moneyText = new GUITextBlock(new Rectangle(120,0,200,20), "Money", "", Alignment.BottomLeft, Alignment.TopLeft, campaignContainer);
|
||||||
moneyText.TextGetter = campaignUI.GetMoney;
|
moneyText.TextGetter = campaignUI.GetMoney;
|
||||||
|
|
||||||
|
var restartText = new GUITextBlock(new Rectangle(-250, -20, 100, 30), "", "", Alignment.BottomRight, Alignment.BottomLeft, campaignContainer);
|
||||||
|
restartText.Font = GUI.SmallFont;
|
||||||
|
restartText.TextGetter = AutoRestartText;
|
||||||
}
|
}
|
||||||
modeList.Select(2, true);
|
modeList.Select(2, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
setupBox.Close();
|
setupBox.Close();
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||||
|
campaign.Map.SelectRandomLocation(true);
|
||||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||||
campaign.LastSaveID++;
|
campaign.LastSaveID++;
|
||||||
};
|
};
|
||||||
@@ -86,7 +87,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
setupBox.Close();
|
setupBox.Close();
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||||
|
campaign.Map.SelectRandomLocation(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
var cancelButton = new GUIButton(new Rectangle(0,0,120,30), "Cancel", Alignment.BottomLeft, "", setupBox.InnerFrame);
|
var cancelButton = new GUIButton(new Rectangle(0,0,120,30), "Cancel", Alignment.BottomLeft, "", setupBox.InnerFrame);
|
||||||
@@ -123,6 +125,7 @@ namespace Barotrauma
|
|||||||
campaign.SetDelegates();
|
campaign.SetDelegates();
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||||
|
GameMain.GameSession.Map.SelectRandomLocation(true);
|
||||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||||
campaign.LastSaveID++;
|
campaign.LastSaveID++;
|
||||||
|
|
||||||
@@ -145,6 +148,7 @@ namespace Barotrauma
|
|||||||
SaveUtil.LoadGame(saveFiles[saveIndex]);
|
SaveUtil.LoadGame(saveFiles[saveIndex]);
|
||||||
((MultiplayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
|
((MultiplayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
|
||||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||||
|
GameMain.GameSession.Map.SelectRandomLocation(true);
|
||||||
|
|
||||||
DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
|
DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
|
||||||
});
|
});
|
||||||
@@ -179,118 +183,103 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Client != null)
|
||||||
{
|
{
|
||||||
lastUpdateID++;
|
GameMain.GameSession.EndRound("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastUpdateID++;
|
||||||
|
|
||||||
bool success =
|
bool success =
|
||||||
GameMain.Server.ConnectedClients.Any(c => c.inGame && c.Character != null && !c.Character.IsDead) ||
|
GameMain.Server.ConnectedClients.Any(c => c.inGame && c.Character != null && !c.Character.IsDead) ||
|
||||||
(GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);
|
(GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);
|
||||||
|
|
||||||
/*if (success)
|
/*if (success)
|
||||||
|
{
|
||||||
|
if (subsToLeaveBehind == null || leavingSub == null)
|
||||||
{
|
{
|
||||||
if (subsToLeaveBehind == null || leavingSub == null)
|
DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
|
||||||
|
|
||||||
|
leavingSub = GetLeavingSub();
|
||||||
|
|
||||||
|
subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
GameMain.GameSession.EndRound("");
|
||||||
|
|
||||||
|
//TODO: save player inventories between mp campaign rounds
|
||||||
|
|
||||||
|
//remove all items that are in someone's inventory
|
||||||
|
foreach (Character c in Character.CharacterList)
|
||||||
|
{
|
||||||
|
if (c.Inventory == null) continue;
|
||||||
|
foreach (Item item in c.Inventory.Items)
|
||||||
|
{
|
||||||
|
if (item != null) item.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
bool atEndPosition = Submarine.MainSub.AtEndPosition;
|
||||||
|
|
||||||
|
/*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
|
||||||
|
{
|
||||||
|
Submarine.MainSub = leavingSub;
|
||||||
|
|
||||||
|
GameMain.GameSession.Submarine = leavingSub;
|
||||||
|
|
||||||
|
foreach (Submarine sub in subsToLeaveBehind)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
|
MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
|
||||||
|
LinkedSubmarine.CreateDummy(leavingSub, sub);
|
||||||
leavingSub = GetLeavingSub();
|
|
||||||
|
|
||||||
subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
|
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
GameMain.GameSession.EndRound("");
|
if (atEndPosition)
|
||||||
|
|
||||||
//TODO: save player inventories between mp campaign rounds
|
|
||||||
|
|
||||||
//remove all items that are in someone's inventory
|
|
||||||
foreach (Character c in Character.CharacterList)
|
|
||||||
{
|
{
|
||||||
if (c.Inventory == null) continue;
|
Map.MoveToNextLocation();
|
||||||
foreach (Item item in c.Inventory.Items)
|
|
||||||
{
|
//select a random location to make sure we've got some destination
|
||||||
if (item != null) item.Remove();
|
//to head towards even if the host/clients don't select anything
|
||||||
}
|
map.SelectRandomLocation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||||
{
|
|
||||||
bool atEndPosition = Submarine.MainSub.AtEndPosition;
|
|
||||||
|
|
||||||
/*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
|
|
||||||
{
|
|
||||||
Submarine.MainSub = leavingSub;
|
|
||||||
|
|
||||||
GameMain.GameSession.Submarine = leavingSub;
|
|
||||||
|
|
||||||
foreach (Submarine sub in subsToLeaveBehind)
|
|
||||||
{
|
|
||||||
MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
|
|
||||||
LinkedSubmarine.CreateDummy(leavingSub, sub);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (atEndPosition)
|
|
||||||
{
|
|
||||||
Map.MoveToNextLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
#if CLIENT
|
|
||||||
var summaryScreen = GUIMessageBox.VisibleBox;
|
|
||||||
if (summaryScreen != null)
|
|
||||||
{
|
|
||||||
summaryScreen = summaryScreen.children[0];
|
|
||||||
summaryScreen.RemoveChild(summaryScreen.children.Find(c => c is GUIButton));
|
|
||||||
|
|
||||||
var okButton = new GUIButton(new Rectangle(-120, 0, 100, 30), "Load game", Alignment.BottomRight, "", summaryScreen);
|
|
||||||
okButton.OnClicked += GameMain.GameSession.LoadPrevious;
|
|
||||||
okButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return true; };
|
|
||||||
|
|
||||||
var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Quit", Alignment.BottomRight, "", summaryScreen);
|
|
||||||
quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
|
|
||||||
quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return true; };
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GameMain.GameSession.EndRound("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiplayerCampaign Load(XElement element)
|
public static MultiplayerCampaign LoadNew(XElement element)
|
||||||
{
|
{
|
||||||
MultiplayerCampaign campaign = new MultiplayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Campaign"), null);
|
MultiplayerCampaign campaign = new MultiplayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Campaign"), null);
|
||||||
|
campaign.Load(element);
|
||||||
|
campaign.SetDelegates();
|
||||||
|
|
||||||
|
return campaign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Load(XElement element)
|
||||||
|
{
|
||||||
|
Money = ToolBox.GetAttributeInt(element, "money", 0);
|
||||||
|
|
||||||
foreach (XElement subElement in element.Elements())
|
foreach (XElement subElement in element.Elements())
|
||||||
{
|
{
|
||||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||||
{
|
{
|
||||||
case "map":
|
case "map":
|
||||||
campaign.map = Map.Load(subElement);
|
if (map == null)
|
||||||
|
{
|
||||||
|
map = Map.LoadNew(subElement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
map.Load(subElement);
|
||||||
|
}
|
||||||
break;
|
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.SetDelegates();
|
|
||||||
|
|
||||||
return campaign;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Save(XElement element)
|
public override void Save(XElement element)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public readonly EventManager EventManager;
|
public readonly EventManager EventManager;
|
||||||
|
|
||||||
public readonly GameMode GameMode;
|
public GameMode GameMode;
|
||||||
|
|
||||||
//two locations used as the start and end in the MP mode
|
//two locations used as the start and end in the MP mode
|
||||||
private Location[] dummyLocations;
|
private Location[] dummyLocations;
|
||||||
@@ -51,19 +51,19 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public Location StartLocation
|
public Location StartLocation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Map != null) return Map.CurrentLocation;
|
if (Map != null) return Map.CurrentLocation;
|
||||||
|
|
||||||
if (dummyLocations==null)
|
if (dummyLocations == null)
|
||||||
{
|
{
|
||||||
CreateDummyLocations();
|
CreateDummyLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
return dummyLocations[0];
|
return dummyLocations[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location EndLocation
|
public Location EndLocation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -118,12 +118,11 @@ namespace Barotrauma
|
|||||||
Submarine.MainSub = submarine;
|
Submarine.MainSub = submarine;
|
||||||
|
|
||||||
GameMain.GameSession = this;
|
GameMain.GameSession = this;
|
||||||
|
|
||||||
selectedSub.Name = ToolBox.GetAttributeString(doc.Root, "submarine", selectedSub.Name);
|
selectedSub.Name = ToolBox.GetAttributeString(doc.Root, "submarine", selectedSub.Name);
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
CrewManager = new CrewManager();
|
CrewManager = new CrewManager();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
foreach (XElement subElement in doc.Root.Elements())
|
foreach (XElement subElement in doc.Root.Elements())
|
||||||
{
|
{
|
||||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||||
@@ -135,11 +134,10 @@ namespace Barotrauma
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case "multiplayercampaign":
|
case "multiplayercampaign":
|
||||||
GameMode = MultiplayerCampaign.Load(subElement);
|
GameMode = MultiplayerCampaign.LoadNew(subElement);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateDummyLocations()
|
private void CreateDummyLocations()
|
||||||
@@ -162,6 +160,12 @@ namespace Barotrauma
|
|||||||
dummyLocations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f));
|
dummyLocations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LoadPrevious()
|
||||||
|
{
|
||||||
|
Submarine.Unload();
|
||||||
|
SaveUtil.LoadGame(savePath);
|
||||||
|
}
|
||||||
|
|
||||||
public void StartRound(string levelSeed, bool loadSecondSub = false)
|
public void StartRound(string levelSeed, bool loadSecondSub = false)
|
||||||
{
|
{
|
||||||
@@ -297,5 +301,31 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Load(XElement saveElement)
|
||||||
|
{
|
||||||
|
foreach (XElement subElement in saveElement.Elements())
|
||||||
|
{
|
||||||
|
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||||
|
{
|
||||||
|
#if CLIENT
|
||||||
|
case "gamemode": //legacy support
|
||||||
|
case "singleplayercampaign":
|
||||||
|
GameMode = SinglePlayerCampaign.Load(subElement);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case "multiplayercampaign":
|
||||||
|
MultiplayerCampaign mpCampaign = GameMode as MultiplayerCampaign;
|
||||||
|
if (mpCampaign == null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error while loading a save file: the save file is for a multiplayer campaign but the current gamemode is "+GameMode.GetType().ToString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpCampaign.Load(subElement);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ namespace Barotrauma
|
|||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
private Location selectedLocation;
|
private Location selectedLocation;
|
||||||
|
|
||||||
private Location highlightedLocation;
|
|
||||||
|
|
||||||
private LocationConnection selectedConnection;
|
private LocationConnection selectedConnection;
|
||||||
|
|
||||||
public Action<Location, LocationConnection> OnLocationSelected;
|
public Action<Location, LocationConnection> OnLocationSelected;
|
||||||
@@ -66,35 +64,6 @@ namespace Barotrauma
|
|||||||
get { return locations; }
|
get { return locations; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map Load(XElement element)
|
|
||||||
{
|
|
||||||
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
|
|
||||||
|
|
||||||
int size = ToolBox.GetAttributeInt(element, "size", 1000);
|
|
||||||
Map map = new Map(mapSeed, size);
|
|
||||||
|
|
||||||
map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
|
||||||
|
|
||||||
string discoveredStr = ToolBox.GetAttributeString(element, "discovered", "");
|
|
||||||
|
|
||||||
string[] discoveredStrs = discoveredStr.Split(',');
|
|
||||||
for (int i = 0; i < discoveredStrs.Length; i++)
|
|
||||||
{
|
|
||||||
int index = -1;
|
|
||||||
if (int.TryParse(discoveredStrs[i], out index)) map.locations[index].Discovered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
string passedStr = ToolBox.GetAttributeString(element, "passed", "");
|
|
||||||
string[] passedStrs = passedStr.Split(',');
|
|
||||||
for (int i = 0; i < passedStrs.Length; i++)
|
|
||||||
{
|
|
||||||
int index = -1;
|
|
||||||
if (int.TryParse(passedStrs[i], out index)) map.connections[index].Passed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map(string seed, int size)
|
public Map(string seed, int size)
|
||||||
{
|
{
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
@@ -410,6 +379,54 @@ namespace Barotrauma
|
|||||||
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
|
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SelectRandomLocation(bool preferUndiscovered)
|
||||||
|
{
|
||||||
|
List<Location> nextLocations = currentLocation.Connections.Select(c => c.OtherLocation(currentLocation)).ToList();
|
||||||
|
List<Location> undiscoveredLocations = nextLocations.FindAll(l => !l.Discovered);
|
||||||
|
|
||||||
|
if (undiscoveredLocations.Count > 0 && preferUndiscovered)
|
||||||
|
{
|
||||||
|
SelectLocation(undiscoveredLocations[Rand.Int(undiscoveredLocations.Count, Rand.RandSync.Unsynced)]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectLocation(nextLocations[Rand.Int(nextLocations.Count, Rand.RandSync.Unsynced)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map LoadNew(XElement element)
|
||||||
|
{
|
||||||
|
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
|
||||||
|
|
||||||
|
int size = ToolBox.GetAttributeInt(element, "size", 1000);
|
||||||
|
Map map = new Map(mapSeed, size);
|
||||||
|
map.Load(element);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Load(XElement element)
|
||||||
|
{
|
||||||
|
SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||||
|
|
||||||
|
string discoveredStr = ToolBox.GetAttributeString(element, "discovered", "");
|
||||||
|
|
||||||
|
string[] discoveredStrs = discoveredStr.Split(',');
|
||||||
|
for (int i = 0; i < discoveredStrs.Length; i++)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
if (int.TryParse(discoveredStrs[i], out index)) locations[index].Discovered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string passedStr = ToolBox.GetAttributeString(element, "passed", "");
|
||||||
|
string[] passedStrs = passedStr.Split(',');
|
||||||
|
for (int i = 0; i < passedStrs.Length; i++)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
if (int.TryParse(passedStrs[i], out index)) connections[index].Passed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Save(XElement element)
|
public void Save(XElement element)
|
||||||
{
|
{
|
||||||
XElement mapElement = new XElement("map");
|
XElement mapElement = new XElement("map");
|
||||||
|
|||||||
@@ -190,17 +190,6 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
FinishUPnP();
|
FinishUPnP();
|
||||||
|
|
||||||
#if CLIENT
|
|
||||||
if (server.UPnP.Status == UPnPStatus.NotAvailable)
|
|
||||||
{
|
|
||||||
new GUIMessageBox("Error", "UPnP not available");
|
|
||||||
}
|
|
||||||
else if (server.UPnP.Status == UPnPStatus.Discovering)
|
|
||||||
{
|
|
||||||
new GUIMessageBox("Error", "UPnP discovery timed out");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPublic)
|
if (isPublic)
|
||||||
@@ -376,9 +365,9 @@ namespace Barotrauma.Networking
|
|||||||
(myCharacter == null || myCharacter.IsDead || myCharacter.IsUnconscious);
|
(myCharacter == null || myCharacter.IsDead || myCharacter.IsUnconscious);
|
||||||
|
|
||||||
//restart if all characters are dead or submarine is at the end of the level
|
//restart if all characters are dead or submarine is at the end of the level
|
||||||
if ((autoRestart && isCrewDead)
|
if ((autoRestart && isCrewDead)
|
||||||
||
|
||
|
||||||
(EndRoundAtLevelEnd && Submarine.MainSub != null && Submarine.MainSub.AtEndPosition && Submarine.MainSubs[1]==null))
|
(EndRoundAtLevelEnd && Submarine.MainSub != null && Submarine.MainSub.AtEndPosition && Submarine.MainSubs[1] == null))
|
||||||
{
|
{
|
||||||
if (AutoRestart && isCrewDead)
|
if (AutoRestart && isCrewDead)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Xml.Linq;
|
|||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
public partial class SaveUtil
|
partial class SaveUtil
|
||||||
{
|
{
|
||||||
public static string SaveFolder = "Data" + Path.DirectorySeparatorChar + "Saves";
|
public static string SaveFolder = "Data" + Path.DirectorySeparatorChar + "Saves";
|
||||||
public static string MultiplayerSaveFolder = "Data" + Path.DirectorySeparatorChar + "Saves" + Path.DirectorySeparatorChar + "Multiplayer";
|
public static string MultiplayerSaveFolder = "Data" + Path.DirectorySeparatorChar + "Saves" + Path.DirectorySeparatorChar + "Multiplayer";
|
||||||
@@ -92,6 +92,13 @@ namespace Barotrauma
|
|||||||
GameMain.GameSession = new GameSession(selectedSub, filePath, doc);
|
GameMain.GameSession = new GameSession(selectedSub, filePath, doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LoadGame(string filePath, GameSession gameSession)
|
||||||
|
{
|
||||||
|
DecompressToDirectory(filePath, TempPath, null);
|
||||||
|
XDocument doc = ToolBox.TryLoadXml(Path.Combine(TempPath, "gamesession.xml"));
|
||||||
|
gameSession.Load(doc.Root);
|
||||||
|
}
|
||||||
|
|
||||||
public static XDocument LoadGameSessionDoc(string filePath)
|
public static XDocument LoadGameSessionDoc(string filePath)
|
||||||
{
|
{
|
||||||
string tempPath = Path.Combine(SaveFolder, "temp");
|
string tempPath = Path.Combine(SaveFolder, "temp");
|
||||||
@@ -110,8 +117,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static void DeleteSave(string filePath)
|
public static void DeleteSave(string filePath)
|
||||||
{
|
{
|
||||||
//filePath = Path.Combine(SaveFolder, filePath + ".save");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(filePath);
|
File.Delete(filePath);
|
||||||
|
|||||||
Reference in New Issue
Block a user