Updated to MonoGame 3.6 + Directory refactor

- Barotrauma's projects are in the Barotrauma directory
- All libraries are in the Libraries directory
- MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?)
- NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred
- Removed Content/effects.mgfx as it didn't seem to be used anywhere
- Removed some references to Subsurface directory
- Renamed Launcher2 to Launcher
This commit is contained in:
juanjp600
2017-06-27 09:52:57 -03:00
parent 330b24bcf6
commit 4d225c65f2
1301 changed files with 169 additions and 77952 deletions
@@ -0,0 +1,50 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;
namespace Barotrauma
{
class CargoManager
{
private List<ItemPrefab> purchasedItems;
public CargoManager()
{
purchasedItems = new List<ItemPrefab>();
}
public void AddItem(ItemPrefab item)
{
purchasedItems.Add(item);
}
public void CreateItems()
{
WayPoint wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub);
if (wp==null)
{
DebugConsole.ThrowError("The submarine must have a waypoint marked as Cargo for bought items to be placed correctly!");
return;
}
Hull cargoRoom = Hull.FindHull(wp.WorldPosition);
if (cargoRoom == null)
{
DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!");
return;
}
foreach (ItemPrefab prefab in purchasedItems)
{
Vector2 position = new Vector2(
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
cargoRoom.Rect.Y - cargoRoom.Rect.Height + prefab.Size.Y/2);
new Item(prefab, position, wp.Submarine);
}
purchasedItems.Clear();
}
}
}
@@ -0,0 +1,104 @@
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
partial class GameMode
{
public static List<GameModePreset> PresetList = new List<GameModePreset>();
protected DateTime startTime;
//public readonly bool IsSinglePlayer;
protected bool isRunning;
//protected string name;
protected GameModePreset preset;
private string endMessage;
public virtual Mission Mission
{
get { return null; }
}
public bool IsRunning
{
get { return isRunning; }
}
public bool IsSinglePlayer
{
get { return preset.IsSinglePlayer; }
}
public string Name
{
get { return preset.Name; }
}
public string EndMessage
{
get { return endMessage; }
}
public GameModePreset Preset
{
get { return preset; }
}
public GameMode(GameModePreset preset, object param)
{
this.preset = preset;
}
public virtual void Start()
{
startTime = DateTime.Now;
//if (duration!=TimeSpan.Zero)
//{
// endTime = startTime + duration;
// this.duration = duration;
// timerBar = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null);
//}
endMessage = "The round has ended!";
isRunning = true;
}
public virtual void MsgBox() { }
public virtual void AddToGUIUpdateList() { }
public virtual void Update(float deltaTime)
{
//if (!isRunning) return;
//if (duration != TimeSpan.Zero)
//{
// double elapsedTime = (DateTime.Now - startTime).TotalSeconds;
// timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds);
//}
//if (DateTime.Now >= endTime)
//{
// End(endMessage);
//}
}
public virtual void End(string endMessage = "")
{
isRunning = false;
if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
GameMain.GameSession.EndShift(endMessage);
}
}
}
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Barotrauma
{
class GameModePreset
{
public static List<GameModePreset> list = new List<GameModePreset>();
public ConstructorInfo Constructor;
public string Name;
public bool IsSinglePlayer;
public string Description;
public GameModePreset(string name, Type type, bool isSinglePlayer = false)
{
this.Name = name;
Constructor = type.GetConstructor(new Type[] { typeof(GameModePreset), typeof(object) });
IsSinglePlayer = isSinglePlayer;
list.Add(this);
}
public GameMode Instantiate(object param)
{
object[] lobject = new object[] { this, param };
return (GameMode)Constructor.Invoke(lobject);
}
public static void Init()
{
#if CLIENT
new GameModePreset("Single Player", typeof(SinglePlayerMode), true);
new GameModePreset("Tutorial", typeof(TutorialMode), true);
#endif
var mode = new GameModePreset("SandBox", typeof(GameMode), false);
mode.Description = "A game mode with no specific objectives.";
//mode = new GameModePreset("Traitor", typeof(TraitorMode), false);
//mode.Description = "One of the players is selected as a traitor and given a secret objective. "
// + "The rest of the crew will win if they reach the end of the level or kill the traitor "
// + "before the objective is completed.";
mode = new GameModePreset("Mission", typeof(MissionMode), false);
mode.Description = "The crew must work together to complete a specific task, such as retrieving "
+ "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends "
+ "when the task is completed or everyone in the crew has died.";
}
}
}
@@ -0,0 +1,26 @@
using Microsoft.Xna.Framework;
namespace Barotrauma
{
partial class MissionMode : GameMode
{
private Mission mission;
public override Mission Mission
{
get
{
return mission;
}
}
public MissionMode(GameModePreset preset, object param)
: base(preset, param)
{
Location[] locations = { GameMain.GameSession.StartLocation, GameMain.GameSession.EndLocation };
MTRandom rand = new MTRandom(ToolBox.StringToInt(GameMain.NetLobbyScreen.LevelSeed));
mission = Mission.LoadRandom(locations, rand, param as string);
}
}
}
@@ -0,0 +1,125 @@
using Barotrauma.Networking;
using System.Collections.Generic;
namespace Barotrauma
{
partial class TraitorManager
{
public Character TraitorCharacter
{
get { return traitorCharacter; }
}
public Character TargetCharacter
{
get { return targetCharacter; }
}
private Character traitorCharacter, targetCharacter;
public TraitorManager(GameServer server)
{
Start(server);
}
private void Start(GameServer server)
{
if (server == null) return;
List<Character> characters = new List<Character>();
foreach (Client client in server.ConnectedClients)
{
if (client.Character != null)
characters.Add(client.Character);
}
if (server.Character!= null) characters.Add(server.Character);
if (characters.Count < 2)
{
traitorCharacter = null;
targetCharacter = null;
return;
}
int traitorIndex = Rand.Range(0, characters.Count);
int targetIndex = Rand.Range(0, characters.Count);
while (targetIndex == traitorIndex)
{
targetIndex = Rand.Range(0, characters.Count);
}
traitorCharacter = characters[traitorIndex];
targetCharacter = characters[targetIndex];
#if CLIENT
if (server.Character == null)
{
new GUIMessageBox("New traitor", traitorCharacter.Name + " is the traitor and the target is " + targetCharacter.Name+".");
}
else if (server.Character == traitorCharacter)
{
CreateStartPopUp(traitorCharacter.Name);
return;
}
#endif
}
public string GetEndMessage()
{
if (GameMain.Server == null || traitorCharacter == null || targetCharacter == null) return "";
string endMessage = "";
if (targetCharacter.IsDead && !traitorCharacter.IsDead)
{
endMessage = traitorCharacter.Name + " was a traitor! ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
endMessage += " task was to assassinate " + targetCharacter.Name + ". The task was successful.";
}
else if (targetCharacter.IsDead && traitorCharacter.IsDead)
{
endMessage = traitorCharacter.Name + " was a traitor! ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
endMessage += " task was to assassinate " + targetCharacter.Name + ". The task was successful, but luckily the bastard didn't make it out alive either.";
}
else if (traitorCharacter.IsDead)
{
endMessage = traitorCharacter.Name + " was a traitor! ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
endMessage += " task was to assassinate " + targetCharacter.Name + ", but ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "he" : "she";
endMessage += " got " + ((traitorCharacter.Info.Gender == Gender.Male) ? "himself" : "herself");
endMessage += " killed before completing it.";
}
else
{
endMessage = traitorCharacter.Name + " was a traitor! ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
endMessage += " task was to assassinate " + targetCharacter.Name + ". ";
endMessage += (Submarine.MainSub.AtEndPosition) ?
"The task was unsuccessful - the submarine has reached its destination." :
"The task was unsuccessful.";
}
return endMessage;
}
//public void CharacterLeft(Character character)
//{
// if (character != traitorCharacter && character != targetCharacter) return;
// if (character == traitorCharacter)
// {
// string endMessage = "The traitor has disconnected from the server.";
// End(endMessage);
// }
// else if (character == targetCharacter)
// {
// string endMessage = "The traitor's target has disconnected from the server.";
// End(endMessage);
// }
//}
}
}
@@ -0,0 +1,265 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Linq;
namespace Barotrauma
{
partial class GameSession
{
public enum InfoFrameTab { Crew, Mission, ManagePlayers };
public readonly TaskManager TaskManager;
public readonly GameMode gameMode;
//two locations used as the start and end in the MP mode
private Location[] dummyLocations;
private string saveFile;
private Submarine submarine;
#if CLIENT
public CrewManager CrewManager;
#endif
private Mission currentMission;
public Mission Mission
{
get
{
return currentMission;
}
}
private Level level;
public Level Level
{
get { return level; }
}
public Location StartLocation
{
get
{
if (Map != null) return Map.CurrentLocation;
if (dummyLocations==null)
{
CreateDummyLocations();
}
return dummyLocations[0];
}
}
public Location EndLocation
{
get
{
if (Map != null) return Map.SelectedLocation;
if (dummyLocations == null)
{
CreateDummyLocations();
}
return dummyLocations[1];
}
}
public Submarine Submarine
{
get { return submarine; }
set { submarine = value; }
}
public string SaveFile
{
get { return saveFile; }
}
public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType="")
{
Submarine.MainSub = submarine;
GameMain.GameSession = this;
TaskManager = new TaskManager(this);
this.saveFile = saveFile;
#if CLIENT
CrewManager = new CrewManager();
infoButton = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", "", null);
infoButton.OnClicked = ToggleInfoFrame;
#endif
if (gameModePreset != null) gameMode = gameModePreset.Instantiate(missionType);
this.submarine = submarine;
}
public GameSession(Submarine selectedSub, string saveFile, XDocument doc)
: this(selectedSub, saveFile)
{
Submarine.MainSub = submarine;
GameMain.GameSession = this;
selectedSub.Name = ToolBox.GetAttributeString(doc.Root, "submarine", selectedSub.Name);
#if CLIENT
CrewManager = new CrewManager();
foreach (XElement subElement in doc.Root.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "gamemode") continue;
gameMode = new SinglePlayerMode(subElement);
}
#endif
}
private void CreateDummyLocations()
{
dummyLocations = new Location[2];
string seed = "";
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
{
seed = GameMain.GameSession.Level.Seed;
}
else if (GameMain.NetLobbyScreen != null)
{
seed = GameMain.NetLobbyScreen.LevelSeed;
}
MTRandom rand = new MTRandom(ToolBox.StringToInt(seed));
for (int i = 0; i < 2; i++)
{
dummyLocations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f));
}
}
public void StartShift(string levelSeed, bool loadSecondSub = false)
{
Level randomLevel = Level.CreateRandom(levelSeed);
StartShift(randomLevel, true, loadSecondSub);
}
public void StartShift(Level level, bool reloadSub = true, bool loadSecondSub = false)
{
#if CLIENT
GameMain.LightManager.LosEnabled = GameMain.NetworkMember == null || GameMain.NetworkMember.CharacterInfo != null;
#endif
this.level = level;
if (submarine==null)
{
DebugConsole.ThrowError("Couldn't start game session, submarine not selected");
return;
}
if (reloadSub || Submarine.MainSub != submarine) submarine.Load(true);
Submarine.MainSub = submarine;
if (loadSecondSub)
{
if (Submarine.MainSubs[1] == null)
{
Submarine.MainSubs[1] = new Submarine(Submarine.MainSub.FilePath,Submarine.MainSub.MD5Hash.Hash,true);
Submarine.MainSubs[1].Load(false);
}
else if (reloadSub)
{
Submarine.MainSubs[1].Load(false);
}
}
if (level != null)
{
level.Generate();
submarine.SetPosition(submarine.FindSpawnPos(level.StartPosition - new Vector2(0.0f, 2000.0f)));
#if CLIENT
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(80);
#endif
}
if (gameMode.Mission != null)
{
currentMission = gameMode.Mission;
}
if (gameMode!=null) gameMode.Start();
if (gameMode.Mission != null) Mission.Start(Level.Loaded);
TaskManager.StartShift(level);
if (gameMode != null) gameMode.MsgBox();
Entity.Spawner = new EntitySpawner();
#if CLIENT
shiftSummary = new ShiftSummary(this);
GameMain.GameScreen.ColorFade(Color.Black, Color.TransparentBlack, 5.0f);
SoundPlayer.SwitchMusic();
#endif
}
public void EndShift(string endMessage)
{
if (Mission != null) Mission.End();
if (GameMain.Server != null)
{
//CoroutineManager.StartCoroutine(GameMain.Server.EndGame(endMessage));
}
else if (GameMain.Client == null)
{
//Submarine.Unload();
GameMain.LobbyScreen.Select();
}
#if CLIENT
if (shiftSummary != null)
{
GUIFrame summaryFrame = shiftSummary.CreateSummaryFrame(endMessage);
GUIMessageBox.MessageBoxes.Add(summaryFrame);
var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, "", summaryFrame.children[0]);
okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(summaryFrame); return true; };
}
#endif
TaskManager.EndShift();
currentMission = null;
StatusEffect.StopAll();
}
public void KillCharacter(Character character)
{
#if CLIENT
CrewManager.KillCharacter(character);
#endif
}
public void ReviveCharacter(Character character)
{
#if CLIENT
CrewManager.ReviveCharacter(character);
#endif
}
}
}
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
{
static class InfoTextManager
{
private static Dictionary<string, List<string>> infoTexts;
static InfoTextManager()
{
LoadInfoTexts(Path.Combine("Content", "InfoTexts.xml"));
}
private static void LoadInfoTexts(string file)
{
infoTexts = new Dictionary<string, List<string>>();
XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null || doc.Root == null) return;
foreach (XElement subElement in doc.Root.Elements())
{
string infoName = subElement.Name.ToString().ToLowerInvariant();
List<string> infoList = null;
if (!infoTexts.TryGetValue(infoName, out infoList))
{
infoList = new List<string>();
infoTexts.Add(infoName, infoList);
}
infoList.Add(subElement.ElementInnerText());
}
}
public static string GetInfoText(string infoName)
{
List<string> infoList = null;
if (!infoTexts.TryGetValue(infoName.ToLowerInvariant(), out infoList) || !infoList.Any())
{
#if DEBUG
return "Info text \"" + infoName + "\" not found";
#else
return "";
#endif
}
string text = infoList[Rand.Int(infoList.Count)];
#if CLIENT
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
text = text.Replace("[" + inputType.ToString() + "]", GameMain.Config.KeyBind(inputType).ToString());
}
#endif
if (Submarine.MainSub != null) text = text.Replace("[sub]", Submarine.MainSub.Name);
if (GameMain.GameSession != null && GameMain.GameSession.StartLocation != null)
{
text = text.Replace("[location]", GameMain.GameSession.StartLocation.Name);
}
return text;
}
}
}