Option to configure damage sounds for structures with a specific tag, some new sounds

This commit is contained in:
Regalis
2016-12-21 00:07:25 +02:00
parent 32c7edba1c
commit c01ac33e1d
16 changed files with 100 additions and 35 deletions
+18
View File
@@ -1462,6 +1462,24 @@
<None Include="Content\Sounds\firelarge.ogg"> <None Include="Content\Sounds\firelarge.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\Sounds\Damage\GlassBreak1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\GlassBreak2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\GlassBreak3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\GlassImpact1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\GlassImpact2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\GlassImpact3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Music\amb_JD_drone_clattering_machine.ogg"> <None Include="Content\Sounds\Music\amb_JD_drone_clattering_machine.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -108,22 +108,22 @@
<sprite texture="Content/Map/testroom.png" sourcerect="550,804,24,96" depth = "0.85" /> <sprite texture="Content/Map/testroom.png" sourcerect="550,804,24,96" depth = "0.85" />
</CableHolderVertical> </CableHolderVertical>
<topwindow width="128" height="49" body="true" health="100"> <topwindow width="128" height="49" body="true" health="100" tags="glass">
<sprite texture="Content/Map/testroom.png" sourcerect="208,848,128,80" depth ="0.05"/> <sprite texture="Content/Map/testroom.png" sourcerect="208,848,128,80" depth ="0.05"/>
<backgroundsprite texture="Content/Map/testroom.png" sourcerect="344,848,128,80" depth ="0.85"/> <backgroundsprite texture="Content/Map/testroom.png" sourcerect="344,848,128,80" depth ="0.85"/>
</topwindow> </topwindow>
<verticalwindow width="128" height ="224" body="true" health="100"> <verticalwindow width="128" height ="224" body="true" health="100" tags="glass">
<sprite texture="Content/Map/testroom.png" sourcerect="368,544,128,224" depth ="0.05"/> <sprite texture="Content/Map/testroom.png" sourcerect="368,544,128,224" depth ="0.05"/>
<backgroundsprite texture="Content/Map/testroom.png" sourcerect="239,544,128,224" depth ="0.85"/> <backgroundsprite texture="Content/Map/testroom.png" sourcerect="239,544,128,224" depth ="0.85"/>
</verticalwindow> </verticalwindow>
<horizontalresizablewindow width="128" height ="64" body="true" health="100" resizehorizontal="true"> <horizontalresizablewindow width="128" height ="64" body="true" health="100" tags="glass" resizehorizontal="true">
<sprite texture="Content/Map/testroom.png" sourcerect="207,771,128,64" depth ="0.06"/> <sprite texture="Content/Map/testroom.png" sourcerect="207,771,128,64" depth ="0.06"/>
<backgroundsprite texture="Content/Map/testroom.png" sourcerect="337,771,128,64" depth ="0.85"/> <backgroundsprite texture="Content/Map/testroom.png" sourcerect="337,771,128,64" depth ="0.85"/>
</horizontalresizablewindow> </horizontalresizablewindow>
<verticalresizablewindow width = "64" height ="128" body="true" health="100" resizevertical="true"> <verticalresizablewindow width = "64" height ="128" body="true" health="100" tags="glass" resizevertical="true">
<sprite texture="Content/Map/testroom.png" sourcerect="896,80,64,128" depth ="0.06"/> <sprite texture="Content/Map/testroom.png" sourcerect="896,80,64,128" depth ="0.06"/>
<backgroundsprite texture="Content/Map/testroom.png" sourcerect="961,80,64,128" depth ="0.85"/> <backgroundsprite texture="Content/Map/testroom.png" sourcerect="961,80,64,128" depth ="0.85"/>
</verticalresizablewindow> </verticalresizablewindow>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+8
View File
@@ -11,6 +11,13 @@
<damagesound file="Content/Sounds/Damage/StructureBlunt9.ogg" damagerange="80.0,100.0" damagesoundtype="StructureBlunt"/> <damagesound file="Content/Sounds/Damage/StructureBlunt9.ogg" damagerange="80.0,100.0" damagesoundtype="StructureBlunt"/>
<damagesound file="Content/Sounds/Damage/StructureBlunt10.ogg" damagerange="80.0,100.0" damagesoundtype="StructureBlunt"/> <damagesound file="Content/Sounds/Damage/StructureBlunt10.ogg" damagerange="80.0,100.0" damagesoundtype="StructureBlunt"/>
<damagesound file="Content/Sounds/Damage/GlassImpact1.ogg" damagerange="0.0,10.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/GlassImpact2.ogg" damagerange="5.0,15.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/GlassImpact3.ogg" damagerange="10.0,20.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/GlassBreak1.ogg" damagerange="20.0,50.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/GlassBreak1.ogg" damagerange="25.0,80.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/GlassBreak1.ogg" damagerange="50.0,100.0" damagesoundtype="StructureBlunt" requiredtag="glass"/>
<damagesound file="Content/Sounds/Damage/StructureCrunch1.ogg" damagerange="0.0,40.0" damagesoundtype="StructureSlash"/> <damagesound file="Content/Sounds/Damage/StructureCrunch1.ogg" damagerange="0.0,40.0" damagesoundtype="StructureSlash"/>
<damagesound file="Content/Sounds/Damage/StructureCrunch2.ogg" damagerange="5.0,70.0" damagesoundtype="StructureSlash"/> <damagesound file="Content/Sounds/Damage/StructureCrunch2.ogg" damagerange="5.0,70.0" damagesoundtype="StructureSlash"/>
@@ -32,6 +39,7 @@
<damagesound file="Content/Sounds/Damage/HitArmor2.ogg" damagerange="5.0,80.0" damagesoundtype="LimbArmor"/> <damagesound file="Content/Sounds/Damage/HitArmor2.ogg" damagerange="5.0,80.0" damagesoundtype="LimbArmor"/>
<damagesound file="Content/Sounds/Damage/HitArmor3.ogg" damagerange="40.0,100.0" damagesoundtype="LimbArmor"/> <damagesound file="Content/Sounds/Damage/HitArmor3.ogg" damagerange="40.0,100.0" damagesoundtype="LimbArmor"/>
<damagesound file="Content/Sounds/Damage/creak1.ogg" damagesoundtype="Pressure"/> <damagesound file="Content/Sounds/Damage/creak1.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak2.ogg" damagesoundtype="Pressure"/> <damagesound file="Content/Sounds/Damage/creak2.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak3.ogg" damagesoundtype="Pressure"/> <damagesound file="Content/Sounds/Damage/creak3.ogg" damagesoundtype="Pressure"/>
+19 -4
View File
@@ -142,11 +142,12 @@ namespace Barotrauma
} }
} }
public static void RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage) /// <summary>
/// Returns a dictionary where the keys are the structures that took damage and the values are the amount of damage taken
/// </summary>
public static Dictionary<Structure,float> RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage)
{ {
List<Structure> structureList = new List<Structure>(); List<Structure> structureList = new List<Structure>();
float dist = 600.0f; float dist = 600.0f;
foreach (MapEntity entity in MapEntity.mapEntityList) foreach (MapEntity entity in MapEntity.mapEntityList)
{ {
@@ -161,14 +162,28 @@ namespace Barotrauma
} }
} }
Dictionary<Structure, float> damagedStructures = new Dictionary<Structure, float>();
foreach (Structure structure in structureList) foreach (Structure structure in structureList)
{ {
for (int i = 0; i < structure.SectionCount; i++) for (int i = 0; i < structure.SectionCount; i++)
{ {
float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i, true), worldPosition) / worldRange); 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;
} }
} }
} }
+5
View File
@@ -151,6 +151,11 @@ namespace Barotrauma
} }
} }
public List<string> Tags
{
get { return prefab.tags; }
}
public override Rectangle Rect public override Rectangle Rect
{ {
get get
+2 -15
View File
@@ -86,21 +86,8 @@ namespace Barotrauma
StructurePrefab sp = new StructurePrefab(); StructurePrefab sp = new StructurePrefab();
sp.name = element.Name.ToString(); sp.name = element.Name.ToString();
//Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1)); sp.tags = new List<string>();
sp.tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(','));
//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);
//}
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
+23 -3
View File
@@ -492,8 +492,6 @@ namespace Barotrauma
Vector2 lastContactPoint = worldPoints[0]; Vector2 lastContactPoint = worldPoints[0];
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint));
if (Character.Controlled != null && Character.Controlled.Submarine == submarine) if (Character.Controlled != null && Character.Controlled.Submarine == submarine)
{ {
GameMain.GameScreen.Cam.Shake = impact * 2.0f; GameMain.GameScreen.Cam.Shake = impact * 2.0f;
@@ -526,7 +524,29 @@ namespace Barotrauma
item.body.ApplyLinearImpulse(item.body.Mass * impulse); 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<Structure,float> 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);
}
} }
} }
+17 -5
View File
@@ -28,11 +28,15 @@ namespace Barotrauma
public readonly Sound sound; 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.sound = sound;
this.damageRange = damageRange; this.damageRange = damageRange;
this.damageType = damageType; this.damageType = damageType;
this.requiredTag = requiredTag;
} }
} }
@@ -154,10 +158,13 @@ namespace Barotrauma
if (damageSound == null) continue; if (damageSound == null) continue;
DamageSoundType damageSoundType = DamageSoundType.None; DamageSoundType damageSoundType = DamageSoundType.None;
Enum.TryParse<DamageSoundType>(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType); Enum.TryParse<DamageSoundType>(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType);
damageSounds.Add(new DamageSound( 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; break;
default: default:
@@ -390,10 +397,15 @@ namespace Barotrauma
PlayDamageSound(damageType, damage, bodyPosition, 800.0f); 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<string> tags = null)
{ {
damage = MathHelper.Clamp(damage+Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f); 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; if (!sounds.Any()) return;
int selectedSound = Rand.Int(sounds.Count); int selectedSound = Rand.Int(sounds.Count);