diff --git a/Subsurface/Characters/Attack.cs b/Subsurface/Characters/Attack.cs index 650f17a03..ad88c766c 100644 --- a/Subsurface/Characters/Attack.cs +++ b/Subsurface/Characters/Attack.cs @@ -68,7 +68,7 @@ namespace Subsurface damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); - structureDamage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); + structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f); bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f); stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f); diff --git a/Subsurface/Characters/Character.cs b/Subsurface/Characters/Character.cs index 297ffb9d6..76356b75c 100644 --- a/Subsurface/Characters/Character.cs +++ b/Subsurface/Characters/Character.cs @@ -59,6 +59,9 @@ namespace Subsurface protected float oxygen; protected float drowningTime; + protected float health; + protected float maxHealth; + protected Item closestItem; protected bool isDead; @@ -73,6 +76,7 @@ namespace Subsurface protected float soundTimer; protected float soundInterval; + private float bleeding; private float blood; private Sound[] sounds; @@ -122,13 +126,19 @@ namespace Subsurface { get { - float totalHealth = 0.0f; - foreach (Limb l in animController.limbs) - { - totalHealth += (l.MaxHealth - l.Damage); + return health; + //float totalHealth = 0.0f; + //foreach (Limb l in animController.limbs) + //{ + // totalHealth += (l.MaxHealth - l.Damage); - } - return totalHealth/animController.limbs.Count(); + //} + //return totalHealth/animController.limbs.Count(); + } + set + { + health = MathHelper.Clamp(value, 0.0f, maxHealth); + if (health==0.0f) Kill(); } } @@ -301,6 +311,9 @@ namespace Subsurface //limb.prevPosition = ConvertUnits.ToDisplayUnits(position); } + maxHealth = ToolBox.GetAttributeFloat(doc.Root, "health", 100.0f); + health = maxHealth; + needsAir = ToolBox.GetAttributeBool(doc.Root, "needsair", false); drowningTime = ToolBox.GetAttributeFloat(doc.Root, "drowningtime", 10.0f); @@ -543,10 +556,10 @@ namespace Subsurface soundTimer = soundInterval; } - foreach (Limb limb in animController.limbs) - { - Blood = blood - limb.Bleeding * deltaTime * 0.1f; - } + //foreach (Limb limb in animController.limbs) + //{ + Blood = blood - bleeding * deltaTime; + //} if (aiController != null) aiController.Update(deltaTime); } @@ -587,19 +600,25 @@ namespace Subsurface } - private static GUIProgressBar drowningBar; + private static GUIProgressBar drowningBar, bloodBar; public void DrawHud(SpriteBatch spriteBatch, Camera cam) { if (drowningBar==null) { - int width = 200, height = 20; - drowningBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, 20, width, height), Color.Blue, 1.0f); + int width = 100, height = 20; + drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight/2, width, height), Color.Blue, 1.0f); + + bloodBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f); } drowningBar.BarSize = Controlled.Oxygen / 100.0f; if (drowningBar.BarSize < 1.0f) drowningBar.Draw(spriteBatch); + bloodBar.BarSize = Blood / 100.0f; + if (bloodBar.BarSize < 1.0f) + bloodBar.Draw(spriteBatch); + if (Controlled.Inventory != null) Controlled.Inventory.Draw(spriteBatch); @@ -674,7 +693,11 @@ namespace Subsurface closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f)); - return closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound); + AttackResult attackResult = closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound); + health -= attackResult.damage; + bleeding += attackResult.bleeding; + + return attackResult; } @@ -705,12 +728,14 @@ namespace Subsurface centerOfMass /= totalMass; + health = 0.0f; + foreach (Limb limb in animController.limbs) { Vector2 diff = centerOfMass - limb.SimPosition; if (diff == Vector2.Zero) continue; limb.body.ApplyLinearImpulse(diff * 10.0f); - limb.Damage = 100.0f; + // limb.Damage = 100.0f; } AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, torso.body.FarseerBody); @@ -739,7 +764,7 @@ namespace Subsurface if (isDead) return; //if the game is run by a client, characters are only killed when the server says so - if (Game1.client != null) + if (Game1.Client != null) { if (networkMessage) { @@ -751,14 +776,14 @@ namespace Subsurface } } - if (Game1.server != null) + if (Game1.Server != null) { new NetworkEvent(NetworkEventType.KillCharacter, ID, false); } - if (Game1.gameSession.crewManager!=null) + if (Game1.GameSession.crewManager!=null) { - Game1.gameSession.crewManager.KillCharacter(this); + Game1.GameSession.crewManager.KillCharacter(this); } isDead = true; @@ -876,9 +901,9 @@ namespace Subsurface else if (type == NetworkEventType.KillCharacter) { Kill(true); - if (Game1.client != null && controlled == this) + if (Game1.Client != null && controlled == this) { - Game1.client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); + Game1.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); } return; } @@ -970,7 +995,7 @@ namespace Subsurface if (controlled == this) controlled = null; - if (Game1.client!=null && Game1.client.Character == this) Game1.client.Character = null; + if (Game1.Client!=null && Game1.Client.Character == this) Game1.Client.Character = null; if (aiTarget != null) aiTarget.Remove(); diff --git a/Subsurface/Characters/Limb.cs b/Subsurface/Characters/Limb.cs index 5a15b2c70..3292ba9d6 100644 --- a/Subsurface/Characters/Limb.cs +++ b/Subsurface/Characters/Limb.cs @@ -41,9 +41,9 @@ namespace Subsurface public readonly bool ignoreCollisions; - private readonly float maxHealth; - private float damage; - private float bleeding; + //private readonly float maxHealth; + //private float damage; + //private float bleeding; public readonly float impactTolerance; @@ -122,26 +122,26 @@ namespace Subsurface get { return refJointIndex; } } - public float Damage - { - get { return damage; } - set - { - damage = Math.Max(value, 0.0f); - if (damage >=maxHealth) character.Kill(); - } - } + //public float Damage + //{ + // get { return damage; } + // set + // { + // damage = Math.Max(value, 0.0f); + // if (damage >=maxHealth) character.Kill(); + // } + //} - public float MaxHealth - { - get { return maxHealth; } - } + //public float MaxHealth + //{ + // get { return maxHealth; } + //} - public float Bleeding - { - get { return bleeding; } - set { bleeding = MathHelper.Clamp(value, 0.0f, 100.0f); } - } + //public float Bleeding + //{ + // get { return bleeding; } + // set { bleeding = MathHelper.Clamp(value, 0.0f, 100.0f); } + //} public Item WearingItem { @@ -208,7 +208,7 @@ namespace Subsurface steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.0f); - maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f); + //maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f); armorSector = ToolBox.GetAttributeVector2(element, "armorsector", Vector2.Zero); armorSector.X = MathHelper.ToRadians(armorSector.X); @@ -277,7 +277,7 @@ namespace Subsurface { hitArmor = true; damageSoundType = DamageSoundType.LimbArmor; - damage /= armorValue; + amount /= armorValue; bleedingAmount /= armorValue; } } @@ -287,8 +287,8 @@ namespace Subsurface AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position); } - Bleeding += bleedingAmount; - Damage += amount; + //Bleeding += bleedingAmount; + //Damage += amount; float bloodAmount = hitArmor ? 0 : (int)Math.Min((int)(amount * 2.0f), 20); //if (closestLimb.Damage>=100.0f) @@ -366,18 +366,18 @@ namespace Subsurface soundTimer -= deltaTime; - if (ToolBox.RandomFloat(0.0f, 1000.0f) < Bleeding) - { - Game1.particleManager.CreateParticle( - !inWater ? "blood" : "waterblood", - SimPosition, Vector2.Zero); - } + //if (ToolBox.RandomFloat(0.0f, 1000.0f) < Bleeding) + //{ + // Game1.particleManager.CreateParticle( + // !inWater ? "blood" : "waterblood", + // SimPosition, Vector2.Zero); + //} } public void Draw(SpriteBatch spriteBatch, bool debugDraw) { - Color color = new Color(1.0f, 1.0f - damage / maxHealth, 1.0f - damage / maxHealth); + Color color = Color.White;// new Color(1.0f, 1.0f - damage / maxHealth, 1.0f - damage / maxHealth); body.Dir = Dir; body.Draw(spriteBatch, sprite, color); diff --git a/Subsurface/Characters/Ragdoll.cs b/Subsurface/Characters/Ragdoll.cs index 42d5b4e92..48809eb49 100644 --- a/Subsurface/Characters/Ragdoll.cs +++ b/Subsurface/Characters/Ragdoll.cs @@ -298,7 +298,7 @@ namespace Subsurface if (impact > l.impactTolerance) { - l.Damage += (impact-l.impactTolerance*0.1f); + character.Health -= (impact-l.impactTolerance*0.1f); strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance); } } diff --git a/Subsurface/Content/Characters/Crawler/crawler.xml b/Subsurface/Content/Characters/Crawler/crawler.xml index f51510ed6..c2151cd42 100644 --- a/Subsurface/Content/Characters/Crawler/crawler.xml +++ b/Subsurface/Content/Characters/Crawler/crawler.xml @@ -26,7 +26,7 @@ - + diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index 685838c6a..d794b8eee 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -11,7 +11,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index 457745cf5..fe3d8c847 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -10,8 +10,8 @@ - - + + @@ -46,7 +46,7 @@ - + diff --git a/Subsurface/Content/Sounds/Music/Enter the Maze.ogg b/Subsurface/Content/Sounds/Music/Enter the Maze.ogg new file mode 100644 index 000000000..a2db0ebd2 Binary files /dev/null and b/Subsurface/Content/Sounds/Music/Enter the Maze.ogg differ diff --git a/Subsurface/Content/Sounds/Music/Unseen Horrors.ogg b/Subsurface/Content/Sounds/Music/Unseen Horrors.ogg new file mode 100644 index 000000000..b057c40cb Binary files /dev/null and b/Subsurface/Content/Sounds/Music/Unseen Horrors.ogg differ diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml index c9c2fa3b6..e5f706f98 100644 --- a/Subsurface/Content/Sounds/sounds.xml +++ b/Subsurface/Content/Sounds/sounds.xml @@ -25,4 +25,8 @@ + + + + \ No newline at end of file diff --git a/Subsurface/Content/randomevents.xml b/Subsurface/Content/randomevents.xml index 8ff17ce89..fbe619158 100644 --- a/Subsurface/Content/randomevents.xml +++ b/Subsurface/Content/randomevents.xml @@ -3,13 +3,15 @@ + difficulty="30" + minamount="2" maxamount="3" + starttimemin="5" starttimemax="10" + musictype="monster"/> + difficulty="50" + starttimemin="5" starttimemax="10" + musictype="monster"/> \ No newline at end of file diff --git a/Subsurface/DebugConsole.cs b/Subsurface/DebugConsole.cs index a4c2e7dd0..1ace775a9 100644 --- a/Subsurface/DebugConsole.cs +++ b/Subsurface/DebugConsole.cs @@ -148,8 +148,8 @@ namespace Subsurface { WayPoint spawnPoint = WayPoint.GetRandom(WayPoint.SpawnType.Human); Character.Controlled = new Character("Content/Characters/Human/human.xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition); - if (Game1.gameSession != null) Game1.gameSession.crewManager.AddCharacter(Character.Controlled); - if (Game1.gameSession != null) Game1.gameSession.crewManager.SelectCharacter(Character.Controlled); + if (Game1.GameSession != null) Game1.GameSession.crewManager.AddCharacter(Character.Controlled); + if (Game1.GameSession != null) Game1.GameSession.crewManager.SelectCharacter(Character.Controlled); } else { @@ -159,42 +159,42 @@ namespace Subsurface break; case "startserver": - if (Game1.server==null) - Game1.server = new GameServer(); + if (Game1.Server==null) + Game1.Server = new GameServer(); break; case "kick": - if (Game1.server == null) break; - Game1.server.KickPlayer(commands[1]); + if (Game1.Server == null) break; + Game1.Server.KickPlayer(commands[1]); break; case "startclient": if (commands.Length == 1) return; - if (Game1.client == null) + if (Game1.Client == null) { - Game1.client = new GameClient("Name"); - Game1.client.ConnectToServer(commands[1]); + Game1.Client = new GameClient("Name"); + Game1.Client.ConnectToServer(commands[1]); } break; case "mainmenuscreen": case "mainmenu": case "menu": - Game1.mainMenuScreen.Select(); + Game1.MainMenuScreen.Select(); break; case "gamescreen": case "game": - Game1.gameScreen.Select(); + Game1.GameScreen.Select(); break; case "editmapscreen": case "editmap": case "edit": - Game1.editMapScreen.Select(); + Game1.EditMapScreen.Select(); break; case "editcharacter": case "editchar": - Game1.editCharacterScreen.Select(); + Game1.EditCharacterScreen.Select(); break; case "editwater": case "water": - if (Game1.client== null) + if (Game1.Client== null) { Hull.EditWater = !Hull.EditWater; } @@ -206,7 +206,7 @@ namespace Subsurface break; case "lobbyscreen": case "lobby": - Game1.lobbyScreen.Select(); + Game1.LobbyScreen.Select(); break; case "savemap": Map.Loaded.SaveAs("Content/SavedMaps/" + commands[1]); @@ -215,6 +215,10 @@ namespace Subsurface case "loadmap": Map.Load("Content/SavedMaps/" + commands[1]); break; + case "messagebox": + if (commands.Length < 3) break; + new GUIMessageBox(commands[1], commands[2]); + break; case "debugdraw": Hull.DebugDraw = !Hull.DebugDraw; Ragdoll.DebugDraw = !Ragdoll.DebugDraw; diff --git a/Subsurface/Events/PropertyTask.cs b/Subsurface/Events/PropertyTask.cs index c972e2a2d..33220132c 100644 --- a/Subsurface/Events/PropertyTask.cs +++ b/Subsurface/Events/PropertyTask.cs @@ -8,9 +8,11 @@ public delegate bool IsFinishedHandler(); private IsFinishedHandler IsFinishedChecker; - public PropertyTask(TaskManager taskManager, Item item, IsFinishedHandler isFinished, float priority, string name) - : base(taskManager, priority, name) + public PropertyTask(Item item, IsFinishedHandler isFinished, float priority, string name) + : base(priority, name) { + if (taskManager == null) return; + this.item = item; IsFinishedChecker = isFinished; diff --git a/Subsurface/Events/RepairTask.cs b/Subsurface/Events/RepairTask.cs index 7175c4253..9e132bfae 100644 --- a/Subsurface/Events/RepairTask.cs +++ b/Subsurface/Events/RepairTask.cs @@ -4,9 +4,11 @@ { Item item; - public RepairTask(TaskManager taskManager, Item item, float priority, string name) - : base(taskManager, priority, name) + public RepairTask(Item item, float priority, string name) + : base(priority, name) { + if (taskManager == null) return; + this.item = item; taskManager.TaskStarted(this); diff --git a/Subsurface/Events/ScriptedEvent.cs b/Subsurface/Events/ScriptedEvent.cs index 831aed4fd..97db8b975 100644 --- a/Subsurface/Events/ScriptedEvent.cs +++ b/Subsurface/Events/ScriptedEvent.cs @@ -30,7 +30,7 @@ namespace Subsurface protected bool isStarted; protected bool isFinished; - + public string Name { get { return name; } @@ -46,6 +46,12 @@ namespace Subsurface get { return commonness; } } + public string MusicType + { + get; + set; + } + public bool IsStarted { get { return isStarted; } @@ -69,6 +75,10 @@ namespace Subsurface difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1); commonness = ToolBox.GetAttributeInt(element, "commonness", 1); + + MusicType = ToolBox.GetAttributeString(element, "musictype", "default"); + + if (element.Attribute("starttime") != null) { startTimeMax = ToolBox.GetAttributeInt(element, "starttime", 1); diff --git a/Subsurface/Events/ScriptedTask.cs b/Subsurface/Events/ScriptedTask.cs index 45ef1e0de..996b2ab5c 100644 --- a/Subsurface/Events/ScriptedTask.cs +++ b/Subsurface/Events/ScriptedTask.cs @@ -6,9 +6,13 @@ private bool prevStarted; - public ScriptedTask(TaskManager taskManager, ScriptedEvent scriptedEvent) - : base(taskManager, scriptedEvent.Difficulty, scriptedEvent.Name) + public ScriptedTask(ScriptedEvent scriptedEvent) + : base(scriptedEvent.Difficulty, scriptedEvent.Name) { + if (taskManager == null) return; + + this.musicType = scriptedEvent.MusicType; + this.scriptedEvent = scriptedEvent; scriptedEvent.Init(); } diff --git a/Subsurface/Events/Task.cs b/Subsurface/Events/Task.cs index 08dd5dade..004245bdd 100644 --- a/Subsurface/Events/Task.cs +++ b/Subsurface/Events/Task.cs @@ -8,6 +8,8 @@ namespace Subsurface private float priority; + protected string musicType; + protected TaskManager taskManager; protected bool isFinished; @@ -22,14 +24,22 @@ namespace Subsurface get { return priority; } } + public string MusicType + { + get { return musicType; } + } + public bool IsFinished { get { return isFinished; } } - public Task(TaskManager taskManager, float priority, string name) + public Task(float priority, string name) { - this.taskManager = taskManager; + if (Game1.GameSession==null || Game1.GameSession.taskManager == null) return; + + taskManager = Game1.GameSession.taskManager; + musicType = "repair"; this.priority = priority; this.name = name; diff --git a/Subsurface/Events/TaskManager.cs b/Subsurface/Events/TaskManager.cs index f039eee2b..2e4c8f524 100644 --- a/Subsurface/Events/TaskManager.cs +++ b/Subsurface/Events/TaskManager.cs @@ -6,10 +6,29 @@ namespace Subsurface { class TaskManager { + const float CriticalPriority = 50.0f; + private List tasks; private GUIListBox taskListBox; + public List Tasks + { + get { return tasks; } + } + + public bool CriticalTasks + { + get + { + foreach (Task task in tasks) + { + if (task.Priority >= CriticalPriority) return true; + } + return false; + } + } + public TaskManager(GameSession session) { tasks = new List(); @@ -45,7 +64,7 @@ namespace Subsurface for (int i = 0; i < scriptedEventCount; i++) { ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(); - AddTask(new ScriptedTask(this, scriptedEvent)); + AddTask(new ScriptedTask(scriptedEvent)); } } diff --git a/Subsurface/GUI/GUI.cs b/Subsurface/GUI/GUI.cs index f0a743c63..727f32001 100644 --- a/Subsurface/GUI/GUI.cs +++ b/Subsurface/GUI/GUI.cs @@ -272,10 +272,26 @@ namespace Subsurface if (Character.Controlled != null) Character.Controlled.DrawHud(spriteBatch, cam); DrawMessages(spriteBatch, (float)deltaTime); + + if (GUIMessageBox.messageBoxes.Count>0) + { + var messageBox = GUIMessageBox.messageBoxes.Peek(); + if (messageBox != null) messageBox.Draw(spriteBatch); + } + DebugConsole.Draw(spriteBatch); } + public static void Update(float deltaTime) + { + if (GUIMessageBox.messageBoxes.Count > 0) + { + var messageBox = GUIMessageBox.messageBoxes.Peek(); + if (messageBox != null) messageBox.Update(deltaTime); + } + } + public static void AddMessage(string message, Color color, float lifeTime = 3.0f) { Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f); diff --git a/Subsurface/GUI/GUIButton.cs b/Subsurface/GUI/GUIButton.cs index eed7ce64d..427484084 100644 --- a/Subsurface/GUI/GUIButton.cs +++ b/Subsurface/GUI/GUIButton.cs @@ -51,7 +51,7 @@ namespace Subsurface public override void Draw(SpriteBatch spriteBatch) { - if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled) + if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == this || IsParentOf(MouseOn))) { state = ComponentState.Hover; if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) @@ -66,8 +66,7 @@ namespace Subsurface if (OnClicked != null) { if (OnClicked(this, UserData)) state = ComponentState.Selected; - } - + } } } else @@ -87,7 +86,7 @@ namespace Subsurface DrawChildren(spriteBatch); - if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f*alpha, true); + if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true); } } } diff --git a/Subsurface/GUI/GUIComponent.cs b/Subsurface/GUI/GUIComponent.cs index 0c8b1e7ef..bea9cc29b 100644 --- a/Subsurface/GUI/GUIComponent.cs +++ b/Subsurface/GUI/GUIComponent.cs @@ -142,14 +142,27 @@ namespace Subsurface return null; } + public bool IsParentOf(GUIComponent component) + { + foreach (GUIComponent child in children) + { + if (child == component) return true; + if (child.IsParentOf(component)) return true; + } + + return false; + } + public virtual void Draw(SpriteBatch spriteBatch) { - Color newColor = color; - if (state == ComponentState.Selected) newColor = selectedColor; - if (state == ComponentState.Hover) newColor = hoverColor; - GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true); - DrawChildren(spriteBatch); + + //Color newColor = color; + //if (state == ComponentState.Selected) newColor = selectedColor; + //if (state == ComponentState.Hover) newColor = hoverColor; + + //GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true); + //DrawChildren(spriteBatch); } public virtual void Update(float deltaTime) diff --git a/Subsurface/GUI/GUIFrame.cs b/Subsurface/GUI/GUIFrame.cs index 33c18c969..ecfee361d 100644 --- a/Subsurface/GUI/GUIFrame.cs +++ b/Subsurface/GUI/GUIFrame.cs @@ -27,5 +27,17 @@ namespace Subsurface parent.AddChild(this); } + public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + + Color newColor = color; + if (state == ComponentState.Selected) newColor = selectedColor; + if (state == ComponentState.Hover) newColor = hoverColor; + + GUI.DrawRectangle(spriteBatch, rect, newColor * alpha, true); + DrawChildren(spriteBatch); + } + } } diff --git a/Subsurface/GUI/GUIListBox.cs b/Subsurface/GUI/GUIListBox.cs index ff20dd83c..8f5db6ddc 100644 --- a/Subsurface/GUI/GUIListBox.cs +++ b/Subsurface/GUI/GUIListBox.cs @@ -117,7 +117,7 @@ namespace Subsurface public override void Update(float deltaTime) { base.Update(deltaTime); - + scrollBar.Update(deltaTime); } @@ -188,7 +188,7 @@ namespace Subsurface public override void Draw(SpriteBatch spriteBatch) { - + base.Draw(spriteBatch); GUI.DrawRectangle(spriteBatch, rect, color*alpha, true); int x = rect.X, y = rect.Y; @@ -206,7 +206,6 @@ namespace Subsurface } } - for (int i = 0; i < children.Count; i++ ) { GUIComponent child = children[i]; @@ -232,7 +231,7 @@ namespace Subsurface if (CheckSelected() != selected.UserData) selected = null; } } - else if (child.Rect.Contains(PlayerInput.GetMouseState.Position) && enabled) + else if (enabled && (MouseOn==this || ( MouseOn!=null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.GetMouseState.Position)) { child.State = ComponentState.Hover; if (PlayerInput.LeftButtonClicked()) diff --git a/Subsurface/GUI/GUIMessageBox.cs b/Subsurface/GUI/GUIMessageBox.cs index f11d31889..1676c778f 100644 --- a/Subsurface/GUI/GUIMessageBox.cs +++ b/Subsurface/GUI/GUIMessageBox.cs @@ -3,27 +3,29 @@ using System.Collections.Generic; namespace Subsurface { - class GUIMessageBox + class GUIMessageBox : GUIFrame { public static Queue messageBoxes = new Queue(); const int DefaultWidth=400, DefaultHeight=200; - public delegate bool OnClickedHandler(GUIButton button, object obj); - public OnClickedHandler OnClicked; + //public delegate bool OnClickedHandler(GUIButton button, object obj); + //public OnClickedHandler OnClicked; - GUIFrame frame; + //GUIFrame frame; GUIButton[] buttons; public GUIMessageBox(string header, string text) : this(header, text, new string[] {"OK"}) - { } - - public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left |Alignment.Top)) { - frame = new GUIFrame(new Rectangle(Game1.GraphicsWidth/2-DefaultWidth/2, Game1.GraphicsHeight/2-DefaultHeight/2, DefaultWidth, DefaultHeight), - GUI.style.backGroundColor, Alignment.CenterX, GUI.style); - frame.Padding = GUI.style.smallPadding; + this.buttons[0].OnClicked = OkClicked; + } + + public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left | Alignment.Top)) + : base(new Rectangle(Game1.GraphicsWidth / 2 - DefaultWidth / 2, Game1.GraphicsHeight / 2 - DefaultHeight / 2, DefaultWidth, DefaultHeight), + GUI.style.backGroundColor, Alignment.CenterX, GUI.style) + { + Padding = GUI.style.smallPadding; if (buttons == null || buttons.Length == 0) { @@ -31,24 +33,25 @@ namespace Subsurface return; } - new GUITextBlock(new Rectangle(0, 5, 0, 30), header, Color.Transparent, Color.White, textAlignment, frame, true); - new GUITextBlock(new Rectangle(0,50,0,DefaultHeight-70),text, Color.Transparent, Color.White, textAlignment, frame, true); + new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, this, true); + new GUITextBlock(new Rectangle(0, 30, 0, DefaultHeight - 70), text, Color.Transparent, Color.White, textAlignment, this, true); int x = 0; this.buttons = new GUIButton[buttons.Length]; - for (int i=0; i @@ -179,19 +179,22 @@ namespace Subsurface PlayerInput.Update(deltaTime); + //if (PlayerInput.KeyDown(Keys.Escape)) Quit(); DebugConsole.Update(this, (float)deltaTime); - if (!DebugConsole.IsOpen || server != null || client != null) Screen.Selected.Update(deltaTime); + if (!DebugConsole.IsOpen || Server != null || Client != null) Screen.Selected.Update(deltaTime); - if (server != null) + GUI.Update((float)deltaTime); + + if (Server != null) { - server.Update(); + Server.Update(); } - else if (client != null) + else if (Client != null) { - client.Update(); + Client.Update(); } else { @@ -219,7 +222,7 @@ namespace Subsurface protected override void OnExiting(object sender, EventArgs args) { - if (client != null) client.Disconnect(); + if (Client != null) Client.Disconnect(); base.OnExiting(sender, args); } diff --git a/Subsurface/GameSession/GameMode.cs b/Subsurface/GameSession/GameMode.cs index 6cbe9a703..ab7e72f67 100644 --- a/Subsurface/GameSession/GameMode.cs +++ b/Subsurface/GameSession/GameMode.cs @@ -75,7 +75,7 @@ namespace Subsurface if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage; - Game1.gameSession.EndShift(null, null); + Game1.GameSession.EndShift(null, null); } public static void Init() diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs index 47b8fd635..bcb18bd55 100644 --- a/Subsurface/GameSession/GameSession.cs +++ b/Subsurface/GameSession/GameSession.cs @@ -4,6 +4,8 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using System.Text; +using System.Collections.Generic; namespace Subsurface { @@ -65,7 +67,7 @@ namespace Subsurface textBox.OnEnter = EnterChatMessage; this.gameMode = gameMode; - if (this.gameMode != null) this.gameMode.Start(Game1.netLobbyScreen.GameDuration); + if (this.gameMode != null) this.gameMode.Start(Game1.NetLobbyScreen.GameDuration); startTime = DateTime.Now; endTime = startTime + gameDuration; @@ -105,22 +107,41 @@ namespace Subsurface public bool EndShift(GUIButton button, object obj) { - if (Game1.server!=null) + if (Game1.Server!=null) { string endMessage = gameMode.EndMessage; - Game1.server.EndGame(endMessage); + Game1.Server.EndGame(endMessage); } - else if (Game1.client==null) + else if (Game1.Client==null) { + StringBuilder sb = new StringBuilder(); + List casualties = crewManager.characters.FindAll(c => c.IsDead); + + if (casualties.Any()) + { + sb.Append("Casualties: \n"); + foreach (Character c in casualties) + { + sb.Append(" - " + c.info.name + "\n"); + } + } + else + { + sb.Append("No casualties!"); + } + + new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString()); + + if (saveFile == null) return false; - Map.Loaded.SaveAs(Path.GetDirectoryName(saveFile) + "/"+ Path.GetFileName(saveFile)); + Map.Loaded.SaveAs(saveFile); crewManager.EndShift(); - Game1.lobbyScreen.Select(); + Game1.LobbyScreen.Select(); day++; } @@ -165,13 +186,13 @@ namespace Subsurface { if (string.IsNullOrWhiteSpace(message)) return false; - if (Game1.server!=null) + if (Game1.Server!=null) { - Game1.server.SendChatMessage(message); + Game1.Server.SendChatMessage(message); } - else if (Game1.client!=null) + else if (Game1.Client!=null) { - Game1.client.SendChatMessage(Game1.client.Name + ": " + message); + Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message); } textBox.Deselect(); @@ -197,6 +218,9 @@ namespace Subsurface public void Update(float deltaTime) { taskManager.Update(deltaTime); + endShiftButton.Enabled = !taskManager.CriticalTasks; + + endShiftButton.Update(deltaTime); textBox.Update(deltaTime); @@ -230,7 +254,7 @@ namespace Subsurface timerBar.Draw(spriteBatch); - if (Game1.client == null) endShiftButton.Draw(spriteBatch); + if (Game1.Client == null) endShiftButton.Draw(spriteBatch); } } } diff --git a/Subsurface/GameSession/TraitorMode.cs b/Subsurface/GameSession/TraitorMode.cs index 0557c6c45..e114f9fbb 100644 --- a/Subsurface/GameSession/TraitorMode.cs +++ b/Subsurface/GameSession/TraitorMode.cs @@ -40,21 +40,21 @@ namespace Subsurface if (traitor==null || target ==null) { - int clientCount = Game1.server.connectedClients.Count(); + int clientCount = Game1.Server.connectedClients.Count(); if (clientCount < 2) return; int traitorIndex = Game1.localRandom.Next(clientCount); - traitor = Game1.server.connectedClients[traitorIndex]; + traitor = Game1.Server.connectedClients[traitorIndex]; int targetIndex = 0; while (targetIndex==traitorIndex) { targetIndex = Game1.localRandom.Next(clientCount); } - target = Game1.server.connectedClients[targetIndex]; + target = Game1.Server.connectedClients[targetIndex]; - Game1.server.NewTraitor(traitor, target); + Game1.Server.NewTraitor(traitor, target); } else { diff --git a/Subsurface/Items/Components/Container.cs b/Subsurface/Items/Components/Container.cs index 3e4e74a9e..e1ebdd5a4 100644 --- a/Subsurface/Items/Components/Container.cs +++ b/Subsurface/Items/Components/Container.cs @@ -175,6 +175,8 @@ namespace Subsurface.Items.Components } else { + item.body.Enabled = true; + Matrix transform = Matrix.CreateRotationZ(item.body.Rotation); if (item.body.Dir==-1.0f) @@ -184,9 +186,7 @@ namespace Subsurface.Items.Components } transformedItemPos = Vector2.Transform(transformedItemPos, transform); transformedItemInterval = Vector2.Transform(transformedItemInterval, transform); - - - + transformedItemPos += ConvertUnits.ToDisplayUnits(item.body.Position); currentRotation += item.body.Rotation; @@ -230,7 +230,7 @@ namespace Subsurface.Items.Components if (inventory.TryPutItem(item)) { isActive = true; - if (hideItems) item.body.Enabled = false; + if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false; item.container = this.item; diff --git a/Subsurface/Items/Components/Door.cs b/Subsurface/Items/Components/Door.cs index 2f5b47d9e..bc212d7f5 100644 --- a/Subsurface/Items/Components/Door.cs +++ b/Subsurface/Items/Components/Door.cs @@ -199,7 +199,7 @@ namespace Subsurface.Items.Components { base.Move(amount); - linkedGap.Move(amount); + LinkedGap.Move(amount); body.SetTransform(body.Position + ConvertUnits.ToSimUnits(amount), 0.0f); diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index e57b3c3b9..c7d41824d 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Graphics; using Subsurface.Networking; using Subsurface.Items.Components; using System.IO; +using System.Globalization; namespace Subsurface { @@ -17,6 +18,8 @@ namespace Subsurface public readonly Sound sound; public readonly ActionType type; + public string volumeProperty; + public readonly float range; public ItemSound(Sound sound, ActionType type, float range) @@ -172,8 +175,9 @@ namespace Subsurface Sound sound = Sound.Load(filePath); float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); - - sounds.Add(new ItemSound(sound, type, range)); + ItemSound itemSound = new ItemSound(sound, type, range); + itemSound.volumeProperty = ToolBox.GetAttributeString(subElement, "volume", ""); + sounds.Add(itemSound); break; } @@ -193,16 +197,30 @@ namespace Subsurface int index = Game1.localRandom.Next(matchingSounds.Count); itemSound = sounds[index]; + if (itemSound.volumeProperty != "") + { + ObjectProperty op = null; + if (properties.TryGetValue(itemSound.volumeProperty.ToLower(), out op)) + { + float newVolume = 0.0f; + float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume); + volume = MathHelper.Clamp(newVolume, 0.0f, 1.0f); + } + + } + if (loop) loopingSound = itemSound; } - + if (loop) { + //if (loopingSound != null && loopingSound.volumeProperty != "") volume = float.Parse(properties[loopingSound.volumeProperty].GetValue().ToString()); loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range); } else { + itemSound.sound.Play(volume, itemSound.range, position); } } diff --git a/Subsurface/Items/Components/OxygenGenerator.cs b/Subsurface/Items/Components/OxygenGenerator.cs index f060f2be8..75e6bcc13 100644 --- a/Subsurface/Items/Components/OxygenGenerator.cs +++ b/Subsurface/Items/Components/OxygenGenerator.cs @@ -8,13 +8,15 @@ namespace Subsurface.Items.Components { PropertyTask powerUpTask; + float powerDownTimer; + bool running; List ventList; public bool IsRunning() { - return running && item.Condition>0.0f; + return (running && item.Condition>0.0f); } public OxygenGenerator(Item item, XElement element) @@ -38,13 +40,18 @@ namespace Subsurface.Items.Components if (voltage < minVoltage) { + powerDownTimer += deltaTime; running = false; - if (powerUpTask==null || powerUpTask.IsFinished) + if ((powerUpTask==null || powerUpTask.IsFinished) && powerDownTimer>5.0f) { - powerUpTask = new PropertyTask(Game1.gameSession.taskManager, item, IsRunning, 30.0f, "Turn on the oxygen generator"); + powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Turn on the oxygen generator"); } return; } + else + { + powerDownTimer = 0.0f; + } running = true; @@ -53,9 +60,15 @@ namespace Subsurface.Items.Components UpdateVents(deltaOxygen); + voltage = 0.0f; } + public override void UpdateBroken(float deltaTime, Camera cam) + { + powerDownTimer += deltaTime; + } + private void GetVents() { foreach (MapEntity entity in item.linkedTo) diff --git a/Subsurface/Items/Components/Powered.cs b/Subsurface/Items/Components/Powered.cs index e3651ccc4..1546f95a0 100644 --- a/Subsurface/Items/Components/Powered.cs +++ b/Subsurface/Items/Components/Powered.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Xml.Linq; namespace Subsurface.Items.Components @@ -62,7 +63,7 @@ namespace Subsurface.Items.Components { if (connection.name=="power_in") { - if (!float.TryParse(signal, out voltage)) + if (!float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out voltage)) { voltage = 0.0f; } diff --git a/Subsurface/Items/Components/Reactor.cs b/Subsurface/Items/Components/Reactor.cs index ca44980b5..d47887699 100644 --- a/Subsurface/Items/Components/Reactor.cs +++ b/Subsurface/Items/Components/Reactor.cs @@ -108,9 +108,8 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { - ApplyStatusEffects(ActionType.OnActive, deltaTime, null); - - + //ApplyStatusEffects(ActionType.OnActive, deltaTime, null); + fissionRate = Math.Min(fissionRate, AvailableFuel); float heat = 100 * fissionRate; @@ -128,7 +127,7 @@ namespace Subsurface.Items.Components { if (powerUpTask==null || powerUpTask.IsFinished) { - powerUpTask = new PropertyTask(Game1.gameSession.taskManager, item, IsRunning, 20.0f, "Power up the reactor"); + powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor"); } } @@ -208,7 +207,7 @@ namespace Subsurface.Items.Components { if (item.Condition <= 0.0f) return; - new RepairTask(Game1.gameSession.taskManager, item, 50.0f, "Reactor meltdown!"); + new RepairTask(item, 60.0f, "Reactor meltdown!"); item.Condition = 0.0f; fissionRate = 0.0f; coolingRate = 0.0f; diff --git a/Subsurface/Items/Components/RepairTool.cs b/Subsurface/Items/Components/RepairTool.cs index dd0012aaa..de5cfc1bd 100644 --- a/Subsurface/Items/Components/RepairTool.cs +++ b/Subsurface/Items/Components/RepairTool.cs @@ -118,7 +118,7 @@ namespace Subsurface.Items.Components { if (character.SecondaryKeyDown.State) { - targetLimb.Damage -= limbFixAmount; + targetLimb.character.Health += limbFixAmount; isActive = true; } } diff --git a/Subsurface/Items/Components/Throwable.cs b/Subsurface/Items/Components/Throwable.cs index bf21e5e73..a17372f1c 100644 --- a/Subsurface/Items/Components/Throwable.cs +++ b/Subsurface/Items/Components/Throwable.cs @@ -54,7 +54,7 @@ namespace Subsurface.Items.Components { Update(deltaTime, cam); } - + public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; @@ -68,11 +68,11 @@ namespace Subsurface.Items.Components AnimController ac = picker.animController; - ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), Vector2.Zero, holdAngle); + ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), aimPos, holdAngle); if (!throwing) return; - throwPos +=0.1f; + throwPos += deltaTime*5.0f; Vector2 throwVector = ConvertUnits.ToSimUnits(picker.CursorPosition) - item.body.Position; throwVector = Vector2.Normalize(throwVector); diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index a2b745a2e..0ddc1fdaa 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -388,7 +388,7 @@ namespace Subsurface ic.Update(deltaTime, cam); ic.PlaySound(ActionType.OnActive, 1.0f, Position, true); - ic.ApplyStatusEffects(ActionType.OnActive, 1.0f, null); + ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null); } else { diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs index b167034e8..e5d28e9cb 100644 --- a/Subsurface/Map/Map.cs +++ b/Subsurface/Map/Map.cs @@ -287,7 +287,7 @@ namespace Subsurface try { //string docString = doc.ToString(); - ToolBox.CompressStringToFile(filePath+".gz", doc.ToString()); + ToolBox.CompressStringToFile(filePath, doc.ToString()); } catch { @@ -295,7 +295,7 @@ namespace Subsurface } - doc.Save(filePath); + //doc.Save(filePath); } public static void PreloadMaps(string mapFolder) @@ -342,7 +342,15 @@ namespace Subsurface public Map(string filePath, string mapHash="") { this.filePath = filePath; - name = Path.GetFileNameWithoutExtension(filePath); + try + { + name = Path.GetFileNameWithoutExtension(filePath); + } + catch (Exception e) + { + DebugConsole.ThrowError("Error loading map " + filePath + "!", e); + } + if (mapHash != "") { @@ -505,12 +513,12 @@ namespace Subsurface { filePath = ""; - if (Game1.gameScreen.Cam != null) Game1.gameScreen.Cam.TargetPos = Vector2.Zero; + if (Game1.GameScreen.Cam != null) Game1.GameScreen.Cam.TargetPos = Vector2.Zero; Entity.RemoveAll(); - if (Game1.gameSession!=null) - Game1.gameSession.crewManager.EndShift(); + if (Game1.GameSession!=null) + Game1.GameSession.crewManager.EndShift(); PhysicsBody.list.Clear(); diff --git a/Subsurface/Map/Structure.cs b/Subsurface/Map/Structure.cs index d80521510..0bb628ef3 100644 --- a/Subsurface/Map/Structure.cs +++ b/Subsurface/Map/Structure.cs @@ -345,7 +345,7 @@ namespace Subsurface { if (!prefab.HasBody || prefab.IsPlatform) return; - if (Game1.client==null) + if (Game1.Client==null) SetDamage(sectionIndex, sections[sectionIndex].damage + damage); diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs index 5c52a6b20..2a2081060 100644 --- a/Subsurface/Networking/GameClient.cs +++ b/Subsurface/Networking/GameClient.cs @@ -134,11 +134,11 @@ namespace Subsurface.Networking int existingClients = inc.ReadInt32(); for (int i = 1; i <= existingClients; i++) { - Game1.netLobbyScreen.AddPlayer(inc.ReadString()); + Game1.NetLobbyScreen.AddPlayer(inc.ReadString()); } //add the name of own client to the lobby screen - Game1.netLobbyScreen.AddPlayer(name); + Game1.NetLobbyScreen.AddPlayer(name); CanStart = true; } @@ -147,7 +147,7 @@ namespace Subsurface.Networking string msg = inc.ReadString(); DebugConsole.ThrowError(msg); - Game1.mainMenuScreen.Select(); + Game1.MainMenuScreen.Select(); } break; case NetIncomingMessageType.StatusChanged: @@ -172,8 +172,8 @@ namespace Subsurface.Networking if (myCharacter.IsDead) { Character.Controlled = null; - Game1.gameScreen.Cam.TargetPos = Vector2.Zero; - Game1.gameScreen.Cam.Zoom = 1.0f; + Game1.GameScreen.Cam.TargetPos = Vector2.Zero; + Game1.GameScreen.Cam.Zoom = 1.0f; } else { @@ -228,7 +228,7 @@ namespace Subsurface.Networking string mapName = inc.ReadString(); string mapHash = inc.ReadString(); - Game1.netLobbyScreen.TrySelectMap(mapName, mapHash); + Game1.NetLobbyScreen.TrySelectMap(mapName, mapHash); //Map.Load(mapFile); @@ -240,8 +240,8 @@ namespace Subsurface.Networking TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0); //int gameModeIndex = inc.ReadInt32(); - Game1.gameSession = new GameSession("", false, duration); - Game1.gameSession.StartShift(1); + Game1.GameSession = new GameSession("", false, duration); + Game1.GameSession.StartShift(1); myCharacter = ReadCharacterData(inc); Character.Controlled = myCharacter; @@ -254,7 +254,7 @@ namespace Subsurface.Networking gameStarted = true; - Game1.gameScreen.Select(); + Game1.GameScreen.Select(); AddChatMessage("Press TAB to chat", ChatMessageType.Server); @@ -268,7 +268,7 @@ namespace Subsurface.Networking Client otherClient = new Client(); otherClient.name = inc.ReadString(); - Game1.netLobbyScreen.AddPlayer(otherClient.name); + Game1.NetLobbyScreen.AddPlayer(otherClient.name); //string newPlayerName = inc.ReadString(); //int newPlayerID = inc.ReadInt32(); @@ -285,7 +285,7 @@ namespace Subsurface.Networking string leavingName = inc.ReadString(); AddChatMessage(inc.ReadString(), ChatMessageType.Server); - Game1.netLobbyScreen.RemovePlayer(leavingName); + Game1.NetLobbyScreen.RemovePlayer(leavingName); break; case (byte)PacketTypes.KickedOut: @@ -293,7 +293,7 @@ namespace Subsurface.Networking DebugConsole.ThrowError(msg); - Game1.mainMenuScreen.Select(); + Game1.MainMenuScreen.Select(); break; case (byte)PacketTypes.Chatmessage: @@ -307,13 +307,13 @@ namespace Subsurface.Networking break; case (byte)PacketTypes.UpdateNetLobby: if (gameStarted) continue; - Game1.netLobbyScreen.ReadData(inc); + Game1.NetLobbyScreen.ReadData(inc); break; case (byte)PacketTypes.Traitor: string targetName = inc.ReadString(); - Game1.gameSession.NewChatMessage("You are an agent of Ordo Europae", messageColor[(int)ChatMessageType.Server]); - Game1.gameSession.NewChatMessage("Your secret task is to assassinate " + targetName + "!", messageColor[(int)ChatMessageType.Server]); + Game1.GameSession.NewChatMessage("You are an agent of Ordo Europae", messageColor[(int)ChatMessageType.Server]); + Game1.GameSession.NewChatMessage("Your secret task is to assassinate " + targetName + "!", messageColor[(int)ChatMessageType.Server]); break; } @@ -325,9 +325,9 @@ namespace Subsurface.Networking { Map.Unload(); - Game1.netLobbyScreen.Select(); + Game1.NetLobbyScreen.Select(); - if (Game1.gameSession!=null) Game1.gameSession.EndShift(null, null); + if (Game1.GameSession!=null) Game1.GameSession.EndShift(null, null); DebugConsole.ThrowError(endMessage); diff --git a/Subsurface/Networking/GameServer.cs b/Subsurface/Networking/GameServer.cs index a4b782e35..fe9dd925c 100644 --- a/Subsurface/Networking/GameServer.cs +++ b/Subsurface/Networking/GameServer.cs @@ -119,7 +119,7 @@ namespace Subsurface.Networking else { - Game1.netLobbyScreen.AddPlayer(sender.name); + Game1.NetLobbyScreen.AddPlayer(sender.name); // Notify the client that they have logged in outmsg = Server.CreateMessage(); @@ -271,12 +271,12 @@ namespace Subsurface.Networking int seed = DateTime.Now.Millisecond; Game1.random = new Random(seed); - Map selectedMap = Game1.netLobbyScreen.SelectedMap as Map; + Map selectedMap = Game1.NetLobbyScreen.SelectedMap as Map; selectedMap.Load(); - Game1.gameSession = new GameSession("", false, Game1.netLobbyScreen.GameDuration, Game1.netLobbyScreen.SelectedMode); - Game1.gameSession.StartShift(1); + Game1.GameSession = new GameSession("", false, Game1.NetLobbyScreen.GameDuration, Game1.NetLobbyScreen.SelectedMode); + Game1.GameSession.StartShift(1); //EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent); foreach (Client client in connectedClients) @@ -307,10 +307,10 @@ namespace Subsurface.Networking msg.Write(seed); - msg.Write(Game1.netLobbyScreen.SelectedMap.Name); - msg.Write(Game1.netLobbyScreen.SelectedMap.MapHash.MD5Hash); + msg.Write(Game1.NetLobbyScreen.SelectedMap.Name); + msg.Write(Game1.NetLobbyScreen.SelectedMap.MapHash.MD5Hash); - msg.Write(Game1.netLobbyScreen.GameDuration.TotalMinutes); + msg.Write(Game1.NetLobbyScreen.GameDuration.TotalMinutes); WriteCharacterData(msg, client.name, client.character); @@ -331,9 +331,9 @@ namespace Subsurface.Networking gameStarted = true; - Game1.gameScreen.Cam.TargetPos = Vector2.Zero; + Game1.GameScreen.Cam.TargetPos = Vector2.Zero; - Game1.gameScreen.Select(); + Game1.GameScreen.Select(); return true; } @@ -362,7 +362,7 @@ namespace Subsurface.Networking } } - Game1.netLobbyScreen.Select(); + Game1.NetLobbyScreen.Select(); DebugConsole.ThrowError(endMessage); } @@ -394,7 +394,7 @@ namespace Subsurface.Networking outmsg.Write(client.name); outmsg.Write(msg); - Game1.netLobbyScreen.RemovePlayer(client.name); + Game1.NetLobbyScreen.RemovePlayer(client.name); if (Server.Connections.Count > 0) { @@ -435,7 +435,7 @@ namespace Subsurface.Networking { NetOutgoingMessage msg = Server.CreateMessage(); msg.Write((byte)PacketTypes.UpdateNetLobby); - Game1.netLobbyScreen.WriteData(msg); + Game1.NetLobbyScreen.WriteData(msg); if (Server.Connections.Count > 0) { diff --git a/Subsurface/Networking/NetworkEvent.cs b/Subsurface/Networking/NetworkEvent.cs index 5544e590a..688c727b0 100644 --- a/Subsurface/Networking/NetworkEvent.cs +++ b/Subsurface/Networking/NetworkEvent.cs @@ -53,11 +53,11 @@ namespace Subsurface.Networking { if (isClient) { - if (Game1.server != null) return; + if (Game1.Server != null) return; } else { - if (Game1.server == null) return; + if (Game1.Server == null) return; } eventType = type; diff --git a/Subsurface/Networking/NetworkMember.cs b/Subsurface/Networking/NetworkMember.cs index be8c68799..bc4bad54f 100644 --- a/Subsurface/Networking/NetworkMember.cs +++ b/Subsurface/Networking/NetworkMember.cs @@ -37,8 +37,8 @@ namespace Subsurface.Networking public void AddChatMessage(string message, ChatMessageType messageType) { - Game1.netLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]); - if (Game1.gameSession != null) Game1.gameSession.NewChatMessage(message, messageColor[(int)messageType]); + Game1.NetLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]); + if (Game1.GameSession != null) Game1.GameSession.NewChatMessage(message, messageColor[(int)messageType]); GUI.PlayMessageSound(); } diff --git a/Subsurface/Screens/GameScreen.cs b/Subsurface/Screens/GameScreen.cs index 0444d78f5..f3fa6be7a 100644 --- a/Subsurface/Screens/GameScreen.cs +++ b/Subsurface/Screens/GameScreen.cs @@ -38,7 +38,7 @@ namespace Subsurface { base.Select(); - if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero); + //if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero); foreach (MapEntity entity in MapEntity.mapEntityList) entity.IsHighlighted = false; @@ -57,7 +57,7 @@ namespace Subsurface AmbientSoundManager.Update(); - Game1.gameSession.Update((float)deltaTime); + if (Game1.GameSession!=null) Game1.GameSession.Update((float)deltaTime); //EventManager.Update(gameTime); Character.UpdateAll(cam, (float)deltaTime); @@ -107,7 +107,7 @@ namespace Subsurface //---------------------------------------------------------------------------------------- spriteBatch.Begin(); - if (Game1.gameSession != null) Game1.gameSession.Draw(spriteBatch); + if (Game1.GameSession != null) Game1.GameSession.Draw(spriteBatch); //EventManager.DrawInfo(spriteBatch); diff --git a/Subsurface/Screens/LobbyScreen.cs b/Subsurface/Screens/LobbyScreen.cs index 5477bbc9f..bb33a69b7 100644 --- a/Subsurface/Screens/LobbyScreen.cs +++ b/Subsurface/Screens/LobbyScreen.cs @@ -105,7 +105,7 @@ namespace Subsurface private void UpdateCharacterLists() { characterList.ClearChildren(); - foreach (CharacterInfo c in Game1.gameSession.crewManager.characterInfos) + foreach (CharacterInfo c in Game1.GameSession.crewManager.characterInfos) { GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), @@ -117,7 +117,7 @@ namespace Subsurface } hireList.ClearChildren(); - foreach (CharacterInfo c in Game1.gameSession.hireManager.availableCharacters) + foreach (CharacterInfo c in Game1.GameSession.hireManager.availableCharacters) { GUIFrame frame = new GUIFrame( new Rectangle(0, 0, 0, 25), @@ -144,18 +144,27 @@ namespace Subsurface } } + public override void Update(double deltaTime) + { + base.Update(deltaTime); + + leftPanel.Update((float)deltaTime); + rightPanel[selectedRightPanel].Update((float)deltaTime); + shiftPanel.Update((float)deltaTime); + } + public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - if (characterList.CountChildren != Game1.gameSession.crewManager.characterInfos.Count - || hireList.CountChildren != Game1.gameSession.hireManager.availableCharacters.Count) + if (characterList.CountChildren != Game1.GameSession.crewManager.characterInfos.Count + || hireList.CountChildren != Game1.GameSession.hireManager.availableCharacters.Count) { UpdateCharacterLists(); } graphics.Clear(Color.CornflowerBlue); - Game1.gameScreen.DrawMap(graphics, spriteBatch); + Game1.GameScreen.DrawMap(graphics, spriteBatch); spriteBatch.Begin(); @@ -182,20 +191,20 @@ namespace Subsurface private string GetMoney() { - return "Money: " + ((Game1.gameSession == null) ? "" : Game1.gameSession.crewManager.Money.ToString()); + return "Money: " + ((Game1.GameSession == null) ? "" : Game1.GameSession.crewManager.Money.ToString()); } private string GetDay() { - return "Day #" + ((Game1.gameSession == null) ? "" : Game1.gameSession.Day.ToString()); + return "Day #" + ((Game1.GameSession == null) ? "" : Game1.GameSession.Day.ToString()); } private float GetWeekProgress() { - if (Game1.gameSession == null) return 0.0f; + if (Game1.GameSession == null) return 0.0f; - return (float)((Game1.gameSession.Day - 1) % 7) / 7.0f; + return (float)((Game1.GameSession.Day - 1) % 7) / 7.0f; } private bool HireCharacter(object selection) @@ -206,20 +215,20 @@ namespace Subsurface if (characterInfo == null) return false; - Game1.gameSession.TryHireCharacter(characterInfo); + Game1.GameSession.TryHireCharacter(characterInfo); return false; } private bool StartShift(GUIButton button, object selection) { - Map.Load(Game1.gameSession.SaveFile); + Map.Load(Game1.GameSession.SaveFile); - Game1.gameSession.StartShift(); + Game1.GameSession.StartShift(); //EventManager.StartShift(); - Game1.gameScreen.Select(); + Game1.GameScreen.Select(); return true; } diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs index 7037e87ef..c3eddf30e 100644 --- a/Subsurface/Screens/MainMenu.cs +++ b/Subsurface/Screens/MainMenu.cs @@ -112,8 +112,8 @@ namespace Subsurface private bool HostServerClicked(GUIButton button, object obj) { - Game1.netLobbyScreen.isServer = true; - Game1.netLobbyScreen.Select(); + Game1.NetLobbyScreen.isServer = true; + Game1.NetLobbyScreen.Select(); return true; } @@ -132,7 +132,7 @@ namespace Subsurface { graphics.Clear(Color.CornflowerBlue); - Game1.gameScreen.DrawMap(graphics, spriteBatch); + Game1.GameScreen.DrawMap(graphics, spriteBatch); spriteBatch.Begin(); @@ -150,9 +150,9 @@ namespace Subsurface if (selectedMap == null) return false; - Game1.gameSession = new GameSession(selectedMap.FilePath, true, TimeSpan.Zero); + Game1.GameSession = new GameSession(selectedMap.FilePath, true, TimeSpan.Zero); - Game1.lobbyScreen.Select(); + Game1.LobbyScreen.Select(); return true; } @@ -162,15 +162,15 @@ namespace Subsurface if (string.IsNullOrEmpty(nameBox.Text)) return false; if (string.IsNullOrEmpty(ipBox.Text)) return false; - Game1.client = new GameClient(nameBox.Text); - if (Game1.client.ConnectToServer(ipBox.Text)) + Game1.Client = new GameClient(nameBox.Text); + if (Game1.Client.ConnectToServer(ipBox.Text)) { - Game1.netLobbyScreen.Select(); + Game1.NetLobbyScreen.Select(); return true; } else { - Game1.client = null; + Game1.Client = null; return false; } } diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index 4c68283c5..9a81b0b9b 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -122,7 +122,7 @@ namespace Subsurface { infoFrame.ClearChildren(); - if (isServer && Game1.server == null) Game1.server = new GameServer(); + if (isServer && Game1.Server == null) Game1.Server = new GameServer(); textBox.Select(); @@ -132,7 +132,7 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, infoFrame); mapList = new GUIListBox(new Rectangle(0, 60, 200, 200), Color.White, infoFrame); mapList.OnSelected = SelectMap; - mapList.Enabled = (Game1.server!=null); + mapList.Enabled = (Game1.Server!=null); if (Map.SavedMaps.Count>0) { @@ -157,7 +157,7 @@ namespace Subsurface new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", Color.Transparent, Color.Black, Alignment.Left, infoFrame); modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), Color.White, infoFrame); - modeList.Enabled = (Game1.server != null); + modeList.Enabled = (Game1.Server != null); //modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent); foreach (GameMode mode in GameMode.list) @@ -180,16 +180,16 @@ namespace Subsurface durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.X + modeList.Rect.Width + GUI.style.smallPadding.X), modeList.Rect.Y + 30, 100, 20), Color.Gold, 0.1f, Alignment.Left, infoFrame); durationBar.BarSize = 0.1f; - durationBar.Enabled = (Game1.server != null); + durationBar.Enabled = (Game1.Server != null); - if (isServer && Game1.server!=null) + if (isServer && Game1.Server!=null) { GUIButton startButton = new GUIButton(new Rectangle(0,0,200,30), "Start", Color.White, Alignment.Right | Alignment.Bottom, infoFrame); - startButton.OnClicked = Game1.server.StartGame; + startButton.OnClicked = Game1.Server.StartGame; //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); - modeList.OnSelected = Game1.server.UpdateNetLobby; - durationBar.OnMoved = Game1.server.UpdateNetLobby; + modeList.OnSelected = Game1.Server.UpdateNetLobby; + durationBar.OnMoved = Game1.Server.UpdateNetLobby; if (mapList.CountChildren > 0) mapList.Select(Map.SavedMaps[0]); if (GameMode.list.Count > 0) modeList.Select(GameMode.list[0]); @@ -199,7 +199,7 @@ namespace Subsurface int x = playerFrame.Rect.Width / 2; GUITextBox playerName = new GUITextBox(new Rectangle(x, 0, 0, 20), Color.White, Color.Black, Alignment.Left | Alignment.Top, Alignment.Left, playerFrame); - playerName.Text = Game1.client.CharacterInfo.name; + playerName.Text = Game1.Client.CharacterInfo.name; playerName.OnEnter += ChangeCharacterName; new GUITextBlock(new Rectangle(x,40,200, 30), "Gender: ", Color.Transparent, Color.Black, @@ -240,7 +240,7 @@ namespace Subsurface private bool SelectMap(object obj) { - if (Game1.server != null) Game1.server.UpdateNetLobby(obj); + if (Game1.Server != null) Game1.Server.UpdateNetLobby(obj); Map map = (Map)obj; @@ -275,7 +275,7 @@ namespace Subsurface { base.Update(deltaTime); - Game1.gameScreen.Cam.MoveCamera((float)deltaTime); + Game1.GameScreen.Cam.MoveCamera((float)deltaTime); Vector2 pos = new Vector2( Map.Borders.X + Map.Borders.Width / 2, @@ -288,7 +288,7 @@ namespace Subsurface pos += offset * 0.8f; - Game1.gameScreen.Cam.TargetPos = pos; + Game1.GameScreen.Cam.TargetPos = pos; menu.Update((float)deltaTime); @@ -299,7 +299,7 @@ namespace Subsurface { graphics.Clear(Color.CornflowerBlue); - Game1.gameScreen.DrawMap(graphics, spriteBatch); + Game1.GameScreen.DrawMap(graphics, spriteBatch); spriteBatch.Begin(); @@ -310,18 +310,18 @@ namespace Subsurface spriteBatch.End(); - if (Game1.client != null) + if (Game1.Client != null) { - if (Game1.client.Character != null) + if (Game1.Client.Character != null) { Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 25.0f); - Vector2 pos = Game1.client.Character.Position; + Vector2 pos = Game1.Client.Character.Position; pos.Y = -pos.Y; Matrix transform = Matrix.CreateTranslation(new Vector3(-pos+position, 0.0f)); spriteBatch.Begin(SpriteSortMode.BackToFront, null,null,null,null,null,transform); - Game1.client.Character.Draw(spriteBatch); + Game1.Client.Character.Draw(spriteBatch); spriteBatch.End(); } else @@ -346,7 +346,7 @@ namespace Subsurface public bool StartGame(object obj) { - Game1.server.StartGame(null, obj); + Game1.Server.StartGame(null, obj); return true; } @@ -356,11 +356,11 @@ namespace Subsurface if (isServer) { - Game1.server.SendChatMessage("Server: " + message); + Game1.Server.SendChatMessage("Server: " + message); } else { - Game1.client.SendChatMessage(Game1.client.Name + ": " + message); + Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message); } return true; @@ -368,13 +368,13 @@ namespace Subsurface private void CreatePreviewCharacter() { - if (Game1.client.Character != null) Game1.client.Character.Remove(); + if (Game1.Client.Character != null) Game1.Client.Character.Remove(); Vector2 pos = new Vector2(1000.0f, 1000.0f); - Character character = new Character(Game1.client.CharacterInfo, pos); + Character character = new Character(Game1.Client.CharacterInfo, pos); - Game1.client.Character = character; + Game1.Client.Character = character; character.animController.isStanding = true; @@ -406,8 +406,8 @@ namespace Subsurface try { Gender gender = (Gender)obj; - Game1.client.CharacterInfo.gender = gender; - Game1.client.SendCharacterData(); + Game1.Client.CharacterInfo.gender = gender; + Game1.Client.SendCharacterData(); CreatePreviewCharacter(); } catch @@ -421,9 +421,9 @@ namespace Subsurface { if (string.IsNullOrEmpty(newName)) return false; - Game1.client.CharacterInfo.name = newName; - Game1.client.Name = newName; - Game1.client.SendCharacterData(); + Game1.Client.CharacterInfo.name = newName; + Game1.Client.Name = newName; + Game1.Client.SendCharacterData(); textBox.Text = newName; diff --git a/Subsurface/Sounds/AmbientSoundManager.cs b/Subsurface/Sounds/AmbientSoundManager.cs index 4ef624a7b..01053901e 100644 --- a/Subsurface/Sounds/AmbientSoundManager.cs +++ b/Subsurface/Sounds/AmbientSoundManager.cs @@ -6,6 +6,7 @@ using FarseerPhysics; using FarseerPhysics.Dynamics; using Microsoft.Xna.Framework; using Subsurface.Sounds; +using System.Collections.Generic; namespace Subsurface { @@ -33,14 +34,36 @@ namespace Subsurface } } + public class BackgroundMusic + { + public readonly string file; + public readonly string type; + + public readonly Vector2 priorityRange; + + public BackgroundMusic(string file, string type, Vector2 priorityRange) + { + this.file = file; + this.type = type; + this.priorityRange = priorityRange; + } + } + static class AmbientSoundManager { public static Sound[] flowSounds = new Sound[3]; + private const float MusicLerpSpeed = 0.01f; + private static Sound waterAmbience; private static int waterAmbienceIndex; private static DamageSound[] damageSounds; + + private static BackgroundMusic currentMusic; + private static BackgroundMusic targetMusic; + private static BackgroundMusic[] musicClips; + private static float musicVolume; public static void Init(string filePath) { @@ -57,7 +80,7 @@ namespace Subsurface var xDamageSounds = doc.Root.Elements("damagesound").ToList(); - if (!xDamageSounds.Any()) + if (xDamageSounds.Any()) { damageSounds = new DamageSound[xDamageSounds.Count()]; int i = 0; @@ -85,6 +108,24 @@ namespace Subsurface } } + var xMusic = doc.Root.Elements("music").ToList(); + + if (xMusic.Any()) + { + musicClips = new BackgroundMusic[xMusic.Count]; + int i = 0; + foreach (XElement element in xMusic) + { + string file = ToolBox.GetAttributeString(element, "file", "").ToLower(); + string type = ToolBox.GetAttributeString(element, "type", "").ToLower(); + Vector2 priority = ToolBox.GetAttributeVector2(element, "priorityrange", new Vector2(0.0f,100.0f)); + + musicClips[i] = new BackgroundMusic(file, type, priority); + + i++; + } + } + //Sound.StartStream("Content/Sounds/Music/Simplex.ogg", 0.3f); } @@ -92,6 +133,8 @@ namespace Subsurface public static void Update() { + UpdateMusic(); + float ambienceVolume = 0.5f; float lowpassHFGain = 1.0f; if (Character.Controlled != null) @@ -110,6 +153,64 @@ namespace Subsurface waterAmbienceIndex = waterAmbience.Loop(waterAmbienceIndex, ambienceVolume); } + private static void UpdateMusic() + { + + Task criticalTask = null; + if (Game1.GameSession!=null) + { + foreach (Task task in Game1.GameSession.taskManager.Tasks) + { + if (criticalTask == null || task.Priority > criticalTask.Priority) + { + criticalTask = task; + } + } + } + + List suitableMusic = null; + if (criticalTask == null) + { + suitableMusic = musicClips.Where(x => x.type == "default").ToList(); + + } + else + { + suitableMusic = musicClips.Where(x => + x.type == criticalTask.MusicType && + x.priorityRange.X < criticalTask.Priority && + x.priorityRange.Y > criticalTask.Priority).ToList(); + } + + if (suitableMusic.Count > 0 && !suitableMusic.Contains(currentMusic)) + { + int index = Game1.localRandom.Next(suitableMusic.Count()); + + if (currentMusic == null || suitableMusic[index].file != currentMusic.file) + { + targetMusic = suitableMusic[index]; + } + } + + if (targetMusic == null || currentMusic == null || targetMusic.file != currentMusic.file) + { + musicVolume = MathHelper.Lerp(musicVolume, 0.0f, MusicLerpSpeed); + if (currentMusic != null) Sound.StreamVolume(musicVolume); + + if (musicVolume < 0.01f) + { + Sound.StopStream(); + if (targetMusic != null) Sound.StartStream(targetMusic.file, musicVolume); + currentMusic = targetMusic; + } + } + else + { + musicVolume = MathHelper.Lerp(musicVolume, 0.3f, MusicLerpSpeed); + Sound.StreamVolume(musicVolume); + } + } + public static void PlayDamageSound(DamageSoundType damageType, float damage, Body body) { Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); diff --git a/Subsurface/Sounds/Sound.cs b/Subsurface/Sounds/Sound.cs index a0e0a6ca5..0901783e2 100644 --- a/Subsurface/Sounds/Sound.cs +++ b/Subsurface/Sounds/Sound.cs @@ -13,6 +13,8 @@ namespace Subsurface private static List loadedSounds = new List(); + private static OggStream stream; + private OggSound oggSound; string filePath; @@ -218,12 +220,17 @@ namespace Subsurface public static void StartStream(string file, float volume = 1.0f) { - SoundManager.StartStream(file, volume); + stream = SoundManager.StartStream(file, volume); } - public static void Stoptream() + public static void StreamVolume(float volume = 1.0f) { - SoundManager.StopStream(); + stream.Volume = volume; + } + + public static void StopStream() + { + if (stream!=null) SoundManager.StopStream(); } public static void Dispose() diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 0487c4712..006125002 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -75,7 +75,7 @@ - + @@ -586,6 +586,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest