diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 912d15e6b..f65ad9123 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -1462,6 +1462,24 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Items/Weapons/railgun.ogg b/Subsurface/Content/Items/Weapons/railgun.ogg index ea3128b57..8ff5c558c 100644 Binary files a/Subsurface/Content/Items/Weapons/railgun.ogg and b/Subsurface/Content/Items/Weapons/railgun.ogg differ diff --git a/Subsurface/Content/Items/warningSiren.ogg b/Subsurface/Content/Items/warningSiren.ogg index bd8cb29d3..7f89d7239 100644 Binary files a/Subsurface/Content/Items/warningSiren.ogg and b/Subsurface/Content/Items/warningSiren.ogg differ diff --git a/Subsurface/Content/Map/StructurePrefabs.xml b/Subsurface/Content/Map/StructurePrefabs.xml index 92442cdf6..02a982966 100644 --- a/Subsurface/Content/Map/StructurePrefabs.xml +++ b/Subsurface/Content/Map/StructurePrefabs.xml @@ -108,22 +108,22 @@ - + - + - + - + diff --git a/Subsurface/Content/Sounds/Damage/GlassBreak1.ogg b/Subsurface/Content/Sounds/Damage/GlassBreak1.ogg new file mode 100644 index 000000000..f4e9e097b Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassBreak1.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/GlassBreak2.ogg b/Subsurface/Content/Sounds/Damage/GlassBreak2.ogg new file mode 100644 index 000000000..893966b63 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassBreak2.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/GlassBreak3.ogg b/Subsurface/Content/Sounds/Damage/GlassBreak3.ogg new file mode 100644 index 000000000..20d38fdb3 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassBreak3.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/GlassImpact1.ogg b/Subsurface/Content/Sounds/Damage/GlassImpact1.ogg new file mode 100644 index 000000000..239c2ae98 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassImpact1.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/GlassImpact2.ogg b/Subsurface/Content/Sounds/Damage/GlassImpact2.ogg new file mode 100644 index 000000000..5f5fbda38 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassImpact2.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/GlassImpact3.ogg b/Subsurface/Content/Sounds/Damage/GlassImpact3.ogg new file mode 100644 index 000000000..75ea3aee2 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/GlassImpact3.ogg differ diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml index 5cc56f402..f3ccdc486 100644 --- a/Subsurface/Content/Sounds/sounds.xml +++ b/Subsurface/Content/Sounds/sounds.xml @@ -10,7 +10,14 @@ - + + + + + + + + @@ -30,7 +37,8 @@ - + + diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index 1f91af870..ba3a750f3 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -142,11 +142,12 @@ namespace Barotrauma } } - public static void RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage) + /// + /// Returns a dictionary where the keys are the structures that took damage and the values are the amount of damage taken + /// + public static Dictionary RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage) { - List structureList = new List(); - - + List structureList = new List(); float dist = 600.0f; foreach (MapEntity entity in MapEntity.mapEntityList) { @@ -161,14 +162,28 @@ namespace Barotrauma } } + Dictionary damagedStructures = new Dictionary(); foreach (Structure structure in structureList) { for (int i = 0; i < structure.SectionCount; i++) { float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i, true), worldPosition) / worldRange); - if (distFactor > 0.0f) structure.AddDamage(i, damage * distFactor); - } + if (distFactor <= 0.0f) continue; + + structure.AddDamage(i, damage * distFactor); + + if (damagedStructures.ContainsKey(structure)) + { + damagedStructures[structure] += damage * distFactor; + } + else + { + damagedStructures.Add(structure, damage * distFactor); + } + } } + + return damagedStructures; } } } diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 77c998493..1ed8c370c 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -151,6 +151,11 @@ namespace Barotrauma } } + public List Tags + { + get { return prefab.tags; } + } + public override Rectangle Rect { get diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs index 3492fad31..b99087775 100644 --- a/Subsurface/Source/Map/StructurePrefab.cs +++ b/Subsurface/Source/Map/StructurePrefab.cs @@ -85,22 +85,9 @@ namespace Barotrauma { StructurePrefab sp = new StructurePrefab(); sp.name = element.Name.ToString(); - - //Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1)); - //Rectangle sourceRect = new Rectangle( - // (int)sourceVector.X, - // (int)sourceVector.Y, - // (int)sourceVector.Z, - // (int)sourceVector.W); - - //if (element.Attribute("sprite") != null) - //{ - // sp.sprite = new Sprite(element.Attribute("sprite").Value, sourceRect, Vector2.Zero); - - // sp.sprite.Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f); - - //} + sp.tags = new List(); + sp.tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(',')); foreach (XElement subElement in element.Elements()) { diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index c9c904ef9..9b4ab743b 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -492,8 +492,6 @@ namespace Barotrauma Vector2 lastContactPoint = worldPoints[0]; - SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint)); - if (Character.Controlled != null && Character.Controlled.Submarine == submarine) { GameMain.GameScreen.Cam.Shake = impact * 2.0f; @@ -526,7 +524,29 @@ namespace Barotrauma item.body.ApplyLinearImpulse(item.body.Mass * impulse); } - Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier); + var damagedStructures = Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier); + + //play a damage sound for the structure that took the most damage + float maxDamage = 0.0f; + Structure maxDamageStructure = null; + foreach (KeyValuePair structureDamage in damagedStructures) + { + if (maxDamageStructure == null || structureDamage.Value > maxDamage) + { + maxDamage = structureDamage.Value; + maxDamageStructure = structureDamage.Key; + } + } + + if (maxDamageStructure != null) + { + SoundPlayer.PlayDamageSound( + DamageSoundType.StructureBlunt, + impact * 10.0f, + ConvertUnits.ToDisplayUnits(lastContactPoint), + MathHelper.Clamp(maxDamage * 4.0f, 1000.0f, 4000.0f), + maxDamageStructure.Tags); + } } } diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs index 6d483ec57..a25b40c00 100644 --- a/Subsurface/Source/Sounds/SoundPlayer.cs +++ b/Subsurface/Source/Sounds/SoundPlayer.cs @@ -28,11 +28,15 @@ namespace Barotrauma public readonly Sound sound; - public DamageSound(Sound sound, Vector2 damageRange, DamageSoundType damageType) + public readonly string requiredTag; + + public DamageSound(Sound sound, Vector2 damageRange, DamageSoundType damageType, string requiredTag = "") { this.sound = sound; this.damageRange = damageRange; this.damageType = damageType; + + this.requiredTag = requiredTag; } } @@ -154,10 +158,13 @@ namespace Barotrauma if (damageSound == null) continue; DamageSoundType damageSoundType = DamageSoundType.None; - Enum.TryParse(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType); + damageSounds.Add(new DamageSound( - damageSound, ToolBox.GetAttributeVector2(subElement, "damagerange", new Vector2(0.0f, 100.0f)), damageSoundType)); + damageSound, + ToolBox.GetAttributeVector2(subElement, "damagerange", new Vector2(0.0f, 100.0f)), + damageSoundType, + ToolBox.GetAttributeString(subElement, "requiredtag", ""))); break; default: @@ -390,10 +397,15 @@ namespace Barotrauma PlayDamageSound(damageType, damage, bodyPosition, 800.0f); } - public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f) + public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f, List tags = null) { damage = MathHelper.Clamp(damage+Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f); - var sounds = damageSounds.Where(x => damage >= x.damageRange.X && damage <= x.damageRange.Y && x.damageType == damageType).ToList(); + var sounds = damageSounds.FindAll(s => + damage >= s.damageRange.X && + damage <= s.damageRange.Y && + s.damageType == damageType && + (string.IsNullOrEmpty(s.requiredTag) || (tags != null && tags.Contains(s.requiredTag)))); + if (!sounds.Any()) return; int selectedSound = Rand.Int(sounds.Count);