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

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;
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)
{
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;
}
}
}

View File

@@ -151,6 +151,11 @@ namespace Barotrauma
}
}
public List<string> Tags
{
get { return prefab.tags; }
}
public override Rectangle Rect
{
get

View File

@@ -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<string>();
sp.tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(','));
foreach (XElement subElement in element.Elements())
{

View File

@@ -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<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);
}
}
}