diff --git a/Subsurface/Characters/Character.cs b/Subsurface/Characters/Character.cs index f5dc11ff7..cbabf9a79 100644 --- a/Subsurface/Characters/Character.cs +++ b/Subsurface/Characters/Character.cs @@ -654,10 +654,8 @@ namespace Subsurface } } - public void AddDamage(Vector2 position, float amount, float bleedingAmount, float stun) + public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound = false) { - int bloodAmount = 0; - animController.StunTimer = Math.Max(animController.StunTimer, stun); Limb closestLimb = null; @@ -676,35 +674,9 @@ namespace Subsurface if (pull != Vector2.Zero) pull = Vector2.Normalize(pull); closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f)); - closestLimb.Bleeding += bleedingAmount; - closestLimb.Damage += amount; - bloodAmount = (int)Math.Min((int)(amount*2.0f),20); - //if (closestLimb.Damage>=100.0f) - //{ - // bloodAmount *= 2; - // foreach (var joint in animController.limbJoints) - // { - // if (!(joint.BodyA == closestLimb.body.FarseerBody) && !(joint.BodyB == closestLimb.body.FarseerBody)) continue; - - // joint.Enabled = false; - // break; - // } - //} - for (int i = 0; i < bloodAmount; i++) - { - Vector2 particleVel = closestLimb.SimPosition-position; - if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel); + closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound); - Game1.particleManager.CreateParticle("blood", - closestLimb.SimPosition, - particleVel * ToolBox.RandomFloat(1.0f,3.0f)); - } - - for (int i = 0; i < bloodAmount / 2; i++) - { - Game1.particleManager.CreateParticle("waterblood",closestLimb.SimPosition,Vector2.Zero); - } } public void Stun() diff --git a/Subsurface/Characters/Limb.cs b/Subsurface/Characters/Limb.cs index 53cce8d37..92af66772 100644 --- a/Subsurface/Characters/Limb.cs +++ b/Subsurface/Characters/Limb.cs @@ -41,12 +41,15 @@ namespace Subsurface public readonly bool ignoreCollisions; - private float maxHealth; + private readonly float maxHealth; private float damage; private float bleeding; public readonly float impactTolerance; + private readonly Vector2 armorSector; + private readonly float armorValue; + Sound hitSound; //a timer for delaying when a hitsound/attacksound can be played again public float soundTimer; @@ -206,6 +209,12 @@ namespace Subsurface steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.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); + armorSector.Y = MathHelper.ToRadians(armorSector.Y); + + armorValue = Math.Max(ToolBox.GetAttributeFloat(element, "armor", 1.0f), 1.0f); body.BodyType = BodyType.Dynamic; body.FarseerBody.AngularDamping = LimbAngularDamping; @@ -248,6 +257,62 @@ namespace Subsurface body.ApplyLinearImpulse((deltaPos - vel * 0.5f) * body.Mass, pullPos); } + public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound) + { + DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash; + + + if (armorSector != Vector2.Zero) + { + float rot = body.Rotation; + if (Dir == -1) rot -= MathHelper.Pi; + + Vector2 armorLimits = new Vector2(rot-armorSector.X*Dir, rot-armorSector.Y*Dir); + + float mid = (armorLimits.X + armorLimits.Y) / 2.0f; + + float angleDiff = ToolBox.GetShortestAngle(ToolBox.VectorToAngle(position - SimPosition), mid); + + if (Math.Abs(angleDiff) < (armorSector.Y-armorSector.X) / 2.0f) return; + } + + if (playSound) + { + AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position); + } + + Bleeding += bleedingAmount; + Damage += amount; + + float bloodAmount = (int)Math.Min((int)(amount * 2.0f), 20); + //if (closestLimb.Damage>=100.0f) + //{ + // bloodAmount *= 2; + // foreach (var joint in animController.limbJoints) + // { + // if (!(joint.BodyA == closestLimb.body.FarseerBody) && !(joint.BodyB == closestLimb.body.FarseerBody)) continue; + + // joint.Enabled = false; + // break; + // } + //} + + for (int i = 0; i < bloodAmount; i++) + { + Vector2 particleVel = SimPosition - position; + if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel); + + Game1.particleManager.CreateParticle("blood", + SimPosition, + particleVel * ToolBox.RandomFloat(1.0f, 3.0f)); + } + + for (int i = 0; i < bloodAmount / 2; i++) + { + Game1.particleManager.CreateParticle("waterblood", SimPosition, Vector2.Zero); + } + } + public void Update(float deltaTime) { if (LinearVelocity.X>100.0f) diff --git a/Subsurface/Characters/LimbAttack.cs b/Subsurface/Characters/LimbAttack.cs index 96cf795b7..3aa4f2968 100644 --- a/Subsurface/Characters/LimbAttack.cs +++ b/Subsurface/Characters/LimbAttack.cs @@ -8,11 +8,11 @@ using System.Xml.Linq; namespace Subsurface { - + public enum DamageType { None, Blunt, Slash }; class Attack { - public enum DamageType { None, Blunt, Slash }; + public enum Type { @@ -70,26 +70,26 @@ namespace Subsurface public void DoDamage(IDamageable target, Vector2 position, float deltaTime, bool playSound=true) { float damageAmount = 0.0f; - DamageSoundType damageSoundType = DamageSoundType.None; + //DamageSoundType damageSoundType = DamageSoundType.None; if (target as Character == null) { damageAmount = structureDamage; - damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt: DamageSoundType.StructureSlash; + //damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt: DamageSoundType.StructureSlash; } else { damageAmount = damage; - damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash; + //damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash; } - - if (playSound) AmbientSoundManager.PlayDamageSound(damageSoundType, damageAmount, position); + //damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash; + //if (playSound) AmbientSoundManager.PlayDamageSound(damageSoundType, damageAmount, position); if (duration > 0.0f) damageAmount *= deltaTime; float bleedingAmount = (duration == 0.0f) ? bleedingDamage : bleedingDamage * deltaTime; - if (damageAmount>0.0f) target.AddDamage(position, damageAmount, bleedingAmount, stun); + if (damageAmount>0.0f) target.AddDamage(position, damageType, damageAmount, bleedingAmount, stun, playSound); } } } diff --git a/Subsurface/Characters/StatusEffect.cs b/Subsurface/Characters/StatusEffect.cs index af84101e2..fbede10d3 100644 --- a/Subsurface/Characters/StatusEffect.cs +++ b/Subsurface/Characters/StatusEffect.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using System.Xml.Linq; @@ -9,6 +10,7 @@ namespace Subsurface class StatusEffect { + [Flags] public enum Target { @@ -20,6 +22,8 @@ namespace Subsurface public string[] propertyNames; private object[] propertyEffects; + + private bool disableDeltaTime; private string[] onContainingNames; @@ -60,7 +64,9 @@ namespace Subsurface { IEnumerable attributes = element.Attributes(); List propertyAttributes = new List(); - + + disableDeltaTime = ToolBox.GetAttributeBool(element, "disabledeltatime", false); + foreach (XAttribute attribute in attributes) { switch (attribute.Name.ToString()) @@ -179,13 +185,14 @@ namespace Subsurface protected void ApplyToProperty(ObjectProperty property, object value, float deltaTime) { + if (disableDeltaTime) deltaTime = 1.0f; Type type = value.GetType(); if (type == typeof(float)) { property.TrySetValue((float)property.GetValue() + (float)value * deltaTime); } - if (type == typeof(int)) + else if (type == typeof(int)) { property.TrySetValue((int)property.GetValue() + (int)value * deltaTime); } diff --git a/Subsurface/Content/Characters/Crawler/crawler.xml b/Subsurface/Content/Characters/Crawler/crawler.xml index e98a1bdd9..6123d043a 100644 --- a/Subsurface/Content/Characters/Crawler/crawler.xml +++ b/Subsurface/Content/Characters/Crawler/crawler.xml @@ -10,7 +10,7 @@ flip="true"> - + diff --git a/Subsurface/Content/Items/Diving/divinggear.xml b/Subsurface/Content/Items/Diving/divinggear.xml index b2e8911af..cdd318394 100644 --- a/Subsurface/Content/Items/Diving/divinggear.xml +++ b/Subsurface/Content/Items/Diving/divinggear.xml @@ -11,7 +11,7 @@ - + @@ -38,7 +38,7 @@ - + diff --git a/Subsurface/Content/Items/OxygenGenerator/item.xml b/Subsurface/Content/Items/OxygenGenerator/item.xml index 09e5d2639..50a16e7b0 100644 --- a/Subsurface/Content/Items/OxygenGenerator/item.xml +++ b/Subsurface/Content/Items/OxygenGenerator/item.xml @@ -6,7 +6,7 @@ - + diff --git a/Subsurface/Content/Items/fuelrod.png b/Subsurface/Content/Items/Reactor/fuelrod.png similarity index 100% rename from Subsurface/Content/Items/fuelrod.png rename to Subsurface/Content/Items/Reactor/fuelrod.png diff --git a/Subsurface/Content/Items/heatabsorber.png b/Subsurface/Content/Items/Reactor/heatabsorber.png similarity index 100% rename from Subsurface/Content/Items/heatabsorber.png rename to Subsurface/Content/Items/Reactor/heatabsorber.png diff --git a/Subsurface/Content/Items/Reactor/reactor.ogg b/Subsurface/Content/Items/Reactor/reactor.ogg new file mode 100644 index 000000000..187933841 Binary files /dev/null and b/Subsurface/Content/Items/Reactor/reactor.ogg differ diff --git a/Subsurface/Content/Items/reactor.png b/Subsurface/Content/Items/Reactor/reactor.png similarity index 100% rename from Subsurface/Content/Items/reactor.png rename to Subsurface/Content/Items/Reactor/reactor.png diff --git a/Subsurface/Content/Items/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml similarity index 84% rename from Subsurface/Content/Items/reactor.xml rename to Subsurface/Content/Items/Reactor/reactor.xml index 66ae3bffe..685838c6a 100644 --- a/Subsurface/Content/Items/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -11,7 +11,7 @@ - + @@ -20,7 +20,9 @@ - + + + diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index a801f4b9b..457745cf5 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -28,8 +28,8 @@ - - + + diff --git a/Subsurface/Content/Items/railgun.xml b/Subsurface/Content/Items/railgun.xml index 146d49270..e2803a3d6 100644 --- a/Subsurface/Content/Items/railgun.xml +++ b/Subsurface/Content/Items/railgun.xml @@ -10,7 +10,7 @@ - + diff --git a/Subsurface/Items/Components/Container.cs b/Subsurface/Items/Components/Container.cs index f7472cd6d..8536adae7 100644 --- a/Subsurface/Items/Components/Container.cs +++ b/Subsurface/Items/Components/Container.cs @@ -110,7 +110,7 @@ namespace Subsurface.Items.Components if (contained.body!=null) contained.body.Enabled = false; - RelatedItem ri = containableItems.Find(x => x.MatchesItem(item)); + RelatedItem ri = containableItems.Find(x => x.MatchesItem(contained)); if (ri == null) continue; foreach (StatusEffect effect in ri.statusEffects) diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index 9e04d3bc2..365b1fe3c 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -9,19 +9,20 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Subsurface.Networking; using Subsurface.Items.Components; +using System.IO; namespace Subsurface { - struct ItemSound + class ItemSound { - public readonly byte index; + public readonly Sound sound; public readonly ActionType type; public readonly float range; - public ItemSound(int index, ActionType type, float range) + public ItemSound(Sound sound, ActionType type, float range) { - this.index = (byte)index; + this.sound = sound; this.type = type; this.range = range; } @@ -150,10 +151,12 @@ namespace Subsurface statusEffects.Add(StatusEffect.Load(subElement)); break; case "sound": - string filePath = ToolBox.GetAttributeString(subElement, "path", ""); + string filePath = ToolBox.GetAttributeString(subElement, "file", ""); if (filePath=="") continue; + if (!filePath.Contains("\\")) filePath = Path.GetDirectoryName(item.Prefab.ConfigFile)+"\\"+filePath; + + //int index = item.Prefab.sounds.FindIndex(x => x.FilePath == filePath); - int index = item.Prefab.sounds.FindIndex(x => x.FilePath == filePath); ActionType type; @@ -167,34 +170,41 @@ namespace Subsurface break; } + Sound sound = Sound.Load(filePath); + float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); - sounds.Add(new ItemSound(index, type, range)); + sounds.Add(new ItemSound(sound, type, range)); break; } } } + private ItemSound loopingSound; private int loopingSoundIndex; public void PlaySound(ActionType type, float volume, Vector2 position, bool loop=false) { - if (loop && Sounds.SoundManager.IsPlaying(loopingSoundIndex)) return; + ItemSound itemSound = null; + if (!loop || !Sounds.SoundManager.IsPlaying(loopingSoundIndex)) + { + List matchingSounds = sounds.FindAll(x => x.type == type); + if (matchingSounds.Count == 0) return; + + int index = Game1.localRandom.Next(matchingSounds.Count); + itemSound = sounds[index]; + + if (loop) loopingSound = itemSound; + } - List matchingSounds = sounds.FindAll(x => x.type == type); - if (matchingSounds.Count == 0 || item.Prefab.sounds.Count == 0) return; - - int index = Game1.localRandom.Next(Math.Min(matchingSounds.Count, item.Prefab.sounds.Count)); - - Sound sound = item.Prefab.sounds[matchingSounds[index].index]; if (loop) { - loopingSoundIndex = sound.Loop(loopingSoundIndex, volume, position, matchingSounds[index].range); + loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range); } else { - sound.Play(volume, matchingSounds[index].range, position); + itemSound.sound.Play(volume, itemSound.range, position); } } diff --git a/Subsurface/Items/Components/Reactor.cs b/Subsurface/Items/Components/Reactor.cs index b6c9bbb1b..e2f4279b9 100644 --- a/Subsurface/Items/Components/Reactor.cs +++ b/Subsurface/Items/Components/Reactor.cs @@ -91,6 +91,8 @@ namespace Subsurface.Items.Components public float ExtraCooling { get; set; } + public float AvailableFuel { get; set; } + public Reactor(Item item, XElement element) : base(item, element) { @@ -109,6 +111,8 @@ namespace Subsurface.Items.Components { ApplyStatusEffects(ActionType.OnActive, deltaTime, null); + + fissionRate = Math.Min(fissionRate, AvailableFuel); float heat = 100 * fissionRate; float heatDissipation = 50 * coolingRate + ExtraCooling; @@ -157,6 +161,7 @@ namespace Subsurface.Items.Components //fission rate can't be lowered below a certain amount if the core is too hot FissionRate = Math.Max(fissionRate, heat / 200.0f); + //the power generated by the reactor is equal to the temperature currPowerConsumption = -temperature*powerPerTemp; @@ -169,6 +174,7 @@ namespace Subsurface.Items.Components UpdateGraph(deltaTime); ExtraCooling = 0.0f; + AvailableFuel = 0.0f; } public override void UpdateBroken(float deltaTime, Camera cam) diff --git a/Subsurface/Items/Components/Signal/Connection.cs b/Subsurface/Items/Components/Signal/Connection.cs index 613ac367c..355ac550e 100644 --- a/Subsurface/Items/Components/Signal/Connection.cs +++ b/Subsurface/Items/Components/Signal/Connection.cs @@ -334,16 +334,8 @@ namespace Subsurface.Items.Components if (!mouseIn) return; end = PlayerInput.MousePosition; } - else if (draggingConnected == null) - { - if (Vector2.Distance(end, PlayerInput.MousePosition)<20.0f) - { - item.IsHighlighted = true; - //start dragging the wire - if (PlayerInput.LeftButtonDown()) draggingConnected = wireItem; - } - } + bool mouseOn = false; int textX = (int)start.X; float connLength = 10.0f; @@ -358,9 +350,12 @@ namespace Subsurface.Items.Components } else { - wireVertical.DrawTiled(spriteBatch, - new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2, - new Vector2(wireVertical.size.X, (float)Math.Abs((end.Y + wireCorner.size.Y) - start.Y)), Color.White); + Vector2 pos = new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2; + Vector2 size = new Vector2(wireVertical.size.X, (float)Math.Abs((end.Y + wireCorner.size.Y) - start.Y)); + wireVertical.DrawTiled(spriteBatch, pos, size, Color.White); + + Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y); + if (rect.Contains(PlayerInput.MousePosition)) mouseOn = true; float dir = (end.X > start.X) ? -1.0f : 1.0f; @@ -371,16 +366,29 @@ namespace Subsurface.Items.Components float wireStartX = start.X - wireCorner.size.X / 2 * dir; float wireEndX = end.X + connLength * dir; - wireHorizontal.DrawTiled(spriteBatch, new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2), - new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y), Color.White); - + pos = new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2); + size = new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y); + + wireHorizontal.DrawTiled(spriteBatch, pos, size, Color.White); + rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y); + if (rect.Contains(PlayerInput.MousePosition)) mouseOn = true; connector.Draw(spriteBatch, end, -MathHelper.PiOver2*dir); } + + if (draggingConnected == null) + { + if (mouseOn || Vector2.Distance(end, PlayerInput.MousePosition)<20.0f) + { + item.IsHighlighted = true; + //start dragging the wire + if (PlayerInput.LeftButtonDown()) draggingConnected = wireItem; + } + } spriteBatch.DrawString(GUI.font, item.Name, new Vector2(textX, start.Y-30), - Color.White, + mouseOn ? Color.Gold : Color.White, MathHelper.PiOver2, GUI.font.MeasureString(item.Name)*0.5f, 1.0f, SpriteEffects.None, 0.0f); diff --git a/Subsurface/Items/Components/Throwable.cs b/Subsurface/Items/Components/Throwable.cs index aa5694c36..0a3382ba2 100644 --- a/Subsurface/Items/Components/Throwable.cs +++ b/Subsurface/Items/Components/Throwable.cs @@ -17,8 +17,9 @@ namespace Subsurface.Items.Components bool throwing; [HasDefaultValue(1.0f, false)] - private float ThrowForce + public float ThrowForce { + get { return throwForce; } set { throwForce = value; } } diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index 8fbaf4dab..c87ccf2ec 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -370,7 +370,7 @@ namespace Subsurface } - public void AddDamage(Vector2 position, float amount, float bleedingAmount, float stun) + public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound = true) { Condition -= amount; } @@ -384,8 +384,7 @@ namespace Subsurface if (condition > 0.0f) { ic.Update(deltaTime, cam); - - + ic.PlaySound(ActionType.OnActive, 1.0f, Position, true); ic.ApplyStatusEffects(ActionType.OnActive, 1.0f, null); } diff --git a/Subsurface/Items/ItemPrefab.cs b/Subsurface/Items/ItemPrefab.cs index 6edd0cadc..8ef98db68 100644 --- a/Subsurface/Items/ItemPrefab.cs +++ b/Subsurface/Items/ItemPrefab.cs @@ -26,7 +26,7 @@ namespace Subsurface float pickDistance; - public List sounds; + //public List sounds; //an area next to the construction //the construction can be Activated() by a character inside the area @@ -201,16 +201,17 @@ namespace Subsurface } } - sounds = new List(); - var soundElements = element.Descendants("Sound"); - foreach (XElement soundElement in soundElements) - { - string soundPath = ToolBox.GetAttributeString(soundElement, "path", ""); - if (soundPath == "") continue; + //sounds = new List(); + //var soundElements = element.Descendants(); + //foreach (XElement soundElement in soundElements) + //{ + // if (soundElement.Name.ToString().ToLower() != "sound") continue; + // string soundPath = ToolBox.GetAttributeString(soundElement, "path", ""); + // if (soundPath == "") continue; - Sound sound = Sound.Load(soundPath); - if (sound != null) sounds.Add(sound); - } + // Sound sound = Sound.Load(soundPath); + // if (sound != null) sounds.Add(sound); + //} list.Add(this); } diff --git a/Subsurface/Map/Explosion.cs b/Subsurface/Map/Explosion.cs index 98fa14c33..268ca4911 100644 --- a/Subsurface/Map/Explosion.cs +++ b/Subsurface/Map/Explosion.cs @@ -97,7 +97,7 @@ namespace Subsurface { distFactor = 1.0f - Vector2.Distance(limb.SimPosition, position)/range; - c.AddDamage(limb.SimPosition, damage * distFactor, 0.0f, stun * distFactor); + c.AddDamage(limb.SimPosition, DamageType.None, damage * distFactor, 0.0f, stun * distFactor); if (force>0.0f) { diff --git a/Subsurface/Map/Gap.cs b/Subsurface/Map/Gap.cs index fe950b008..7ce9f5e6d 100644 --- a/Subsurface/Map/Gap.cs +++ b/Subsurface/Map/Gap.cs @@ -214,24 +214,13 @@ namespace Subsurface soundVolume = soundVolume + ((flowForce.Length() < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f); soundVolume = MathHelper.Clamp(soundVolume, 0.0f, 1.0f); - //if (soundVolume < 0.01f) - //{ - // if (soundIndex > -1) - // { - // Sound.Stop(soundIndex); - // soundIndex = -1; - // } + int index = (int)Math.Floor(flowForce.Length() / 100.0f); + index = Math.Min(index,2); - //} - //else - { - int index = (int)Math.Floor(flowForce.Length() / 100.0f); - index = Math.Min(index,2); - - soundIndex = AmbientSoundManager.flowSounds[index].Loop(soundIndex, soundVolume, Position, 2000.0f); - //soundVolume = Math.Max(0.0f, soundVolume-deltaTime); - //Sound.UpdatePosition(soundIndex, Position, 2000.0f); - } + soundIndex = AmbientSoundManager.flowSounds[index].Loop(soundIndex, soundVolume, Position, 2000.0f); + //soundVolume = Math.Max(0.0f, soundVolume-deltaTime); + //Sound.UpdatePosition(soundIndex, Position, 2000.0f); + flowForce = Vector2.Zero; @@ -386,7 +375,7 @@ namespace Subsurface { float delta = Math.Min(hull2.Volume - hull2.FullVolume + Hull.MaxCompress / 2.0f, deltaTime * 8000.0f * sizeModifier); - flowForce = new Vector2(0.0f, Math.Min(hull2.Pressure-hull1.Pressure,500.0f)); + flowForce = new Vector2(0.0f, Math.Min(hull2.Pressure - hull1.Pressure, 500.0f)); delta = Math.Max(delta, 0.0f); hull1.Volume += delta; @@ -444,6 +433,7 @@ namespace Subsurface //} } } + if (open > 0.0f) { if (hull1.Volume>hull1.FullVolume && hull2.Volume>hull2.FullVolume) @@ -458,9 +448,6 @@ namespace Subsurface hull2.LethalPressure = 0.0f; } } - - - } void UpdateRoomToOut(float deltaTime) @@ -526,7 +513,7 @@ namespace Subsurface } else { - flowForce = new Vector2(0.0f,delta); + flowForce = new Vector2(0.0f, delta); } } } @@ -539,9 +526,9 @@ namespace Subsurface float totalOxygen = hull1.Oxygen + hull2.Oxygen; float totalVolume = (hull1.FullVolume + hull2.FullVolume); - - hull1.Oxygen += Math.Sign(totalOxygen*hull1.FullVolume/(totalVolume) - hull1.Oxygen) * Hull.OxygenDistributionSpeed; - hull2.Oxygen += Math.Sign(totalOxygen*hull2.FullVolume/(totalVolume) - hull2.Oxygen) * Hull.OxygenDistributionSpeed; + + hull1.Oxygen += Math.Sign(totalOxygen * hull1.FullVolume / (totalVolume) - hull1.Oxygen) * Hull.OxygenDistributionSpeed; + hull2.Oxygen += Math.Sign(totalOxygen * hull2.FullVolume / (totalVolume) - hull2.Oxygen) * Hull.OxygenDistributionSpeed; } public override void Remove() diff --git a/Subsurface/Map/IDamageable.cs b/Subsurface/Map/IDamageable.cs index 3b98c3abc..b737175f5 100644 --- a/Subsurface/Map/IDamageable.cs +++ b/Subsurface/Map/IDamageable.cs @@ -14,6 +14,6 @@ namespace Subsurface get; } - void AddDamage(Vector2 position, float amount, float bleedingAmount, float stun); + void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound=true); } } diff --git a/Subsurface/Map/Structure.cs b/Subsurface/Map/Structure.cs index e56375816..7547fa831 100644 --- a/Subsurface/Map/Structure.cs +++ b/Subsurface/Map/Structure.cs @@ -378,7 +378,7 @@ namespace Subsurface sections[sectionIndex].rect.Y - sections[sectionIndex].rect.Height / 2.0f); } - public void AddDamage(Vector2 position, float amount, float bleedingAmount, float stun) + public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound = false) { if (!prefab.HasBody || prefab.IsPlatform) return; @@ -387,6 +387,11 @@ namespace Subsurface Game1.particleManager.CreateParticle("dustcloud", ConvertUnits.ToSimUnits(SectionPosition(i)), 0.0f, 0.0f); + if (playSound) + { + DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash; + AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position); + } AddDamage(i, amount); } diff --git a/Subsurface/Sounds/Sound.cs b/Subsurface/Sounds/Sound.cs index fe5571fc9..82706c7aa 100644 --- a/Subsurface/Sounds/Sound.cs +++ b/Subsurface/Sounds/Sound.cs @@ -72,58 +72,74 @@ namespace Subsurface return SoundManager.Play(this, volume); } - public int Play(float volume, float range, Vector2 position) + public int Play(float baseVolume, float range, Vector2 position) { //position = new Vector2(position.X - CameraPos.X, position.Y - CameraPos.Y); //volume = (range == 0.0f) ? 0.0f : MathHelper.Clamp(volume * (range - position.Length())/range, 0.0f, 1.0f); - int newIndex = SoundManager.Play(this, volume); + Vector2 relativePos = GetRelativePosition(position); + float volume = GetVolume(relativePos, range, baseVolume); - if (newIndex == -1) return -1; + return SoundManager.Play(this, relativePos, volume, volume); - return UpdatePosition(newIndex, position, range, volume); + //if (newIndex == -1) return -1; + + //return UpdatePosition(newIndex, position, range, volume); } public int Play(float volume, float range, Body body) { - Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); + //Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); //bodyPosition.Y = -bodyPosition.Y; - return Play(volume, range, bodyPosition); + + return Play(volume, range, ConvertUnits.ToDisplayUnits(body.Position)); } - public static int UpdatePosition(int sourceIndex, Vector2 position, float range, float baseVolume = 1.0f) + private float GetVolume(Vector2 relativePosition, float range, float baseVolume) { - position = new Vector2(position.X - CameraPos.X, position.Y - CameraPos.Y); - float volume = (range == 0.0f) ? 0.0f : MathHelper.Clamp(baseVolume * (range - position.Length())/range, 0.0f, 1.0f); + float volume = (range == 0.0f) ? 0.0f : MathHelper.Clamp(baseVolume * (range - relativePosition.Length()) / range, 0.0f, 1.0f); - if (volume <= 0.0f) - { - if (sourceIndex > 0) - { - SoundManager.Stop(sourceIndex); - sourceIndex = -1; - } - - return sourceIndex; - } - - SoundManager.UpdateSoundPosition(sourceIndex, position, volume); - - return sourceIndex; + return volume; } - public int UpdatePosition(int sourceIndex, Body body, float range, float baseVolume = 1.0f) + private Vector2 GetRelativePosition(Vector2 position) { - Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); - bodyPosition.Y = -bodyPosition.Y; - return UpdatePosition(sourceIndex, bodyPosition, range, baseVolume); + return new Vector2(position.X - CameraPos.X, position.Y - CameraPos.Y); } + //public static int UpdatePosition(int sourceIndex, Vector2 position, float range, float baseVolume = 1.0f) + //{ + // position = new Vector2(position.X - CameraPos.X, position.Y - CameraPos.Y); + // float volume = (range == 0.0f) ? 0.0f : MathHelper.Clamp(baseVolume * (range - position.Length())/range, 0.0f, 1.0f); + + // if (volume <= 0.0f) + // { + // if (sourceIndex > 0) + // { + // SoundManager.Stop(sourceIndex); + // sourceIndex = -1; + // } + + // return sourceIndex; + // } + + // SoundManager.UpdateSoundPosition(sourceIndex, position, volume, volume); + + // return sourceIndex; + //} + + //public int UpdatePosition(int sourceIndex, Body body, float range, float baseVolume = 1.0f) + //{ + // Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); + // bodyPosition.Y = -bodyPosition.Y; + // return UpdatePosition(sourceIndex, bodyPosition, range, baseVolume); + //} + public int Loop(int sourceIndex, float volume) { - if (volume == 0.0f) + if (volume <= 0.0f) { if (sourceIndex > 0) { @@ -139,8 +155,12 @@ namespace Subsurface return newIndex; } - public int Loop(int sourceIndex, float volume, Vector2 position, float range) + public int Loop(int sourceIndex, float baseVolume, Vector2 position, float range) { + + Vector2 relativePos = GetRelativePosition(position); + float volume = GetVolume(relativePos, range, baseVolume); + if (volume <= 0.0f) { if (sourceIndex > 0) @@ -152,9 +172,11 @@ namespace Subsurface return sourceIndex; } - int newIndex = SoundManager.Loop(this, sourceIndex, volume); - return UpdatePosition(newIndex, position, range, volume); + + return SoundManager.Loop(this, sourceIndex, position, volume, volume); + + //return UpdatePosition(newIndex, position, range, volume); } diff --git a/Subsurface/Sounds/SoundManager.cs b/Subsurface/Sounds/SoundManager.cs index e34535605..6ad81ccda 100644 --- a/Subsurface/Sounds/SoundManager.cs +++ b/Subsurface/Sounds/SoundManager.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using Microsoft.Xna.Framework; using OpenTK.Audio; using OpenTK.Audio.OpenAL; +using System; namespace Subsurface.Sounds { @@ -13,8 +14,15 @@ namespace Subsurface.Sounds private static List alSources = new List(); private static int[] alBuffers = new int[DefaultSourceCount]; private static int lowpassFilterId; - - + + private static float overrideLowPassGain; + + public static float OverrideLowPassGain + { + get { return overrideLowPassGain; } + set { overrideLowPassGain = MathHelper.Clamp(overrideLowPassGain, 0.0f, 1.0f); } + } + static AudioContext AC; public static OggStreamer oggStreamer; @@ -34,7 +42,7 @@ namespace Subsurface.Sounds lowpassFilterId = ALHelper.Efx.GenFilter(); //alFilters.Add(alFilterId); ALHelper.Efx.Filter(lowpassFilterId, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass); - + //LowPassHFGain = 1; } @@ -72,6 +80,7 @@ namespace Subsurface.Sounds public static int Play(Sound sound, float volume = 1.0f) { + return Play(sound, Vector2.Zero, volume, 0.0f); //for (int i = 2; i < DefaultSourceCount; i++) //{ // AL.SourceStop(alSources[i]); @@ -80,6 +89,43 @@ namespace Subsurface.Sounds // System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i])); //} + //for (int i = 1; i < DefaultSourceCount; i++) + //{ + // //find a source that's free to use (not playing or paused) + // if (AL.GetSourceState(alSources[i]) == ALSourceState.Playing + // || AL.GetSourceState(alSources[i]) == ALSourceState.Paused) continue; + + // //if (position!=Vector2.Zero) + // // position /= 1000.0f; + + // alBuffers[i]=sound.AlBufferId; + // AL.Source(alSources[i], ALSourceb.Looping, false); + // AL.Source(alSources[i], ALSource3f.Position, 0.0f, 0.0f, 0.0f); + // AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId); + // AL.Source(alSources[i], ALSourcef.Gain, volume); + // //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); + // AL.SourcePlay(alSources[i]); + + // //sound.sourceIndex = i; + + // return i; + //} + + //return -1; + } + + public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f) + { + //for (int i = 2; i < DefaultSourceCount; i++) + //{ + // AL.SourceStop(alSources[i]); + // AL.Source(alSources[i], ALSourceb.Looping, false); + // System.Diagnostics.Debug.WriteLine(i + ": " + AL.GetSourceState(alSources[i])); + // System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i])); + //} + + + for (int i = 1; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused) @@ -89,11 +135,21 @@ namespace Subsurface.Sounds //if (position!=Vector2.Zero) // position /= 1000.0f; - alBuffers[i]=sound.AlBufferId; + alBuffers[i] = sound.AlBufferId; AL.Source(alSources[i], ALSourceb.Looping, false); - AL.Source(alSources[i], ALSource3f.Position, 0.0f, 0.0f, 0.0f); - AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId); + + position /= 1000.0f; + + //System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset); AL.Source(alSources[i], ALSourcef.Gain, volume); + AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); + + AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId); + + ALHelper.Efx.Filter(lowpassFilterId, EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain)); + ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId); + ALHelper.Check(); + //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); AL.SourcePlay(alSources[i]); @@ -105,22 +161,28 @@ namespace Subsurface.Sounds return -1; } - public static int Loop(Sound sound, int sourceIndex, float volume) + public static int Loop(Sound sound, int sourceIndex, float volume = 1.0f) + { + return Loop(sound,sourceIndex, Vector2.Zero, volume, 0.0f); + } + public static int Loop(Sound sound, int sourceIndex, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f) { if (sourceIndex<1) { - sourceIndex = Play(sound, volume); + sourceIndex = Play(sound, position, volume, lowPassGain); if (sourceIndex>0) { AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); } + ALHelper.Check(); return sourceIndex; } else { AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); + ALHelper.Check(); return sourceIndex; } } @@ -195,6 +257,7 @@ namespace Subsurface.Sounds { if (ALHelper.Efx.IsInitialized) { + overrideLowPassGain = value; for (int i = 0; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused) @@ -221,17 +284,21 @@ namespace Subsurface.Sounds // } //} - public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f) + public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f, float lowPassGain = 0.0f) { if (sourceIndex < 1) return; //Resume(sourceIndex); position/= 1000.0f; - + //System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset); AL.Source(alSources[sourceIndex], ALSourcef.Gain, baseVolume); AL.Source(alSources[sourceIndex], ALSource3f.Position, position.X, position.Y, 0.0f); + + ALHelper.Efx.Filter(lowpassFilterId, EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain)); + ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId); + ALHelper.Check(); } public static OggStream StartStream(string file, float volume = 1.0f) diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index ae23e5186..c78456ab4 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -350,7 +350,7 @@ PreserveNewest Designer - + PreserveNewest @@ -368,7 +368,7 @@ PreserveNewest - + PreserveNewest @@ -426,10 +426,10 @@ PreserveNewest - + PreserveNewest - + PreserveNewest Designer @@ -549,6 +549,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Subsurface.csproj.user b/Subsurface/Subsurface.csproj.user index 693505ea4..505c3a0bf 100644 --- a/Subsurface/Subsurface.csproj.user +++ b/Subsurface/Subsurface.csproj.user @@ -9,6 +9,6 @@ en-US false - ShowAllFiles + ProjectFiles \ No newline at end of file diff --git a/Subsurface/ToolBox.cs b/Subsurface/ToolBox.cs index 36a833b14..d92e39ab7 100644 --- a/Subsurface/ToolBox.cs +++ b/Subsurface/ToolBox.cs @@ -200,8 +200,12 @@ namespace Subsurface public static object GetAttributeObject(XAttribute attribute) { if (attribute == null) return null; - string value = attribute.Value.ToString(); + return ParseToObject(attribute.Value.ToString()); + } + + public static object ParseToObject(string value) + { float floatVal; int intVal; if (value.ToString().Contains(".") && float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out floatVal)) diff --git a/Subsurface_Solution.sln b/Subsurface_Solution.sln index 69dd83e63..a9464db71 100644 --- a/Subsurface_Solution.sln +++ b/Subsurface_Solution.sln @@ -166,7 +166,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection EndGlobal diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index c11d8b0dc..b988f097f 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ