diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 42058a519..02c92edaf 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -515,7 +515,10 @@ PreserveNewest - + + PreserveNewest + + PreserveNewest @@ -585,6 +588,7 @@ PreserveNewest + Designer PreserveNewest @@ -600,6 +604,7 @@ PreserveNewest + Designer PreserveNewest @@ -611,10 +616,10 @@ PreserveNewest Designer - + PreserveNewest - + PreserveNewest @@ -885,6 +890,7 @@ PreserveNewest + Designer PreserveNewest diff --git a/Subsurface/Content/Items/Lockers/cabinets.png b/Subsurface/Content/Items/Containers/cabinets.png similarity index 100% rename from Subsurface/Content/Items/Lockers/cabinets.png rename to Subsurface/Content/Items/Containers/cabinets.png diff --git a/Subsurface/Content/Items/Containers/containers.xml b/Subsurface/Content/Items/Containers/containers.xml new file mode 100644 index 000000000..53d8a3c4d --- /dev/null +++ b/Subsurface/Content/Items/Containers/containers.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Containers/crates.png b/Subsurface/Content/Items/Containers/crates.png new file mode 100644 index 000000000..7fbd7dc63 Binary files /dev/null and b/Subsurface/Content/Items/Containers/crates.png differ diff --git a/Subsurface/Content/Items/Lockers/locker.png b/Subsurface/Content/Items/Containers/locker.png similarity index 100% rename from Subsurface/Content/Items/Lockers/locker.png rename to Subsurface/Content/Items/Containers/locker.png diff --git a/Subsurface/Content/Items/Jobgear/misc.xml b/Subsurface/Content/Items/Jobgear/misc.xml index 8c4629268..6029e6240 100644 --- a/Subsurface/Content/Items/Jobgear/misc.xml +++ b/Subsurface/Content/Items/Jobgear/misc.xml @@ -1,4 +1,20 @@  + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Subsurface/Content/Items/Medical/medical.xml b/Subsurface/Content/Items/Medical/medical.xml index e49e0e638..e9986d730 100644 --- a/Subsurface/Content/Items/Medical/medical.xml +++ b/Subsurface/Content/Items/Medical/medical.xml @@ -290,6 +290,7 @@ + @@ -349,7 +350,25 @@ - + + + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Weapons/explosives.xml b/Subsurface/Content/Items/Weapons/explosives.xml index 2118c8f4f..e555532c6 100644 --- a/Subsurface/Content/Items/Weapons/explosives.xml +++ b/Subsurface/Content/Items/Weapons/explosives.xml @@ -29,6 +29,26 @@ + + + + + + + + + + + + + + + + @@ -47,6 +67,7 @@ + @@ -81,4 +102,31 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index 02975be2a..a50d834ad 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -172,7 +172,7 @@ category="Equipment" pickdistance="200" price="500" - tags="weapon" + tags="weapon,smallitem" description="HONK"> diff --git a/Subsurface/Data/ContentPackages/Vanilla 0.3.xml b/Subsurface/Data/ContentPackages/Vanilla 0.3.xml index a2fcd44e4..01edf30c6 100644 --- a/Subsurface/Data/ContentPackages/Vanilla 0.3.xml +++ b/Subsurface/Data/ContentPackages/Vanilla 0.3.xml @@ -4,6 +4,7 @@ + @@ -19,7 +20,6 @@ - diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs index 347453cfb..b0985f2e7 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs @@ -179,9 +179,6 @@ namespace Barotrauma public void DrawSprites(SpriteBatch spriteBatch, Camera cam) { - Stopwatch sw = new Stopwatch(); - sw.Start(); - Rectangle indices = Rectangle.Empty; indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize) - 1; if (indices.X >= sprites.GetLength(0)) return; @@ -189,7 +186,6 @@ namespace Barotrauma indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height) / (float)GridSize) - 1; if (indices.Y >= sprites.GetLength(1)) return; - indices.Width = (int)Math.Ceiling(cam.WorldView.Right / (float)GridSize) + 1; if (indices.Width < 0) return; indices.Height = (int)Math.Ceiling(cam.WorldView.Y / (float)GridSize) + 1; @@ -212,9 +208,6 @@ namespace Barotrauma } } } - - sw.Stop(); - Debug.WriteLine(sw.ElapsedMilliseconds + " - "+sw.ElapsedTicks); } private BackgroundSpritePrefab GetRandomPrefab() diff --git a/Subsurface/Source/Characters/StatusEffect.cs b/Subsurface/Source/Characters/StatusEffect.cs index 0cc621309..3da1ab535 100644 --- a/Subsurface/Source/Characters/StatusEffect.cs +++ b/Subsurface/Source/Characters/StatusEffect.cs @@ -219,17 +219,7 @@ namespace Barotrauma } protected void Apply(float deltaTime, Entity entity, List targets) - { - - if (explosion != null) explosion.Explode(entity.WorldPosition); - - if (FireSize > 0.0f) - { - var fire = new FireSource(entity.WorldPosition); - - fire.Size = new Vector2(FireSize, fire.Size.Y); - } - + { if (sound != null) sound.Play(1.0f, 1000.0f, entity.WorldPosition); if (useItem) @@ -259,8 +249,16 @@ namespace Barotrauma ApplyToProperty(property, propertyEffects[i], deltaTime); } } - } + + if (explosion != null) explosion.Explode(entity.WorldPosition); + + if (FireSize > 0.0f) + { + var fire = new FireSource(entity.WorldPosition); + + fire.Size = new Vector2(FireSize, fire.Size.Y); + } } private IEnumerable ApplyToPropertyOverDuration(float duration, ObjectProperty property, object value) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 90f39e1f2..df8dc53dd 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -12,13 +12,18 @@ using Barotrauma.Items.Components; using System.ComponentModel; using System.Collections.ObjectModel; using FarseerPhysics.Dynamics; +using FarseerPhysics.Dynamics.Contacts; namespace Barotrauma { public enum ActionType { - Always, OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure, OnBroken, OnFire, InWater + Always, OnPicked, OnUse, + OnWearing, OnContaining, OnContained, + OnActive, OnFailure, OnBroken, + OnFire, InWater, + OnImpact } class Item : MapEntity, IDamageable, IPropertyObject @@ -109,6 +114,11 @@ namespace Barotrauma get { return prefab.Description; } } + public float ImpactTolerance + { + get { return prefab.ImpactTolerance; } + } + public override Sprite Sprite { get { return prefab.sprite; } @@ -383,6 +393,12 @@ namespace Barotrauma } } + //containers need to handle collision events to notify items inside them about the impact + if (ImpactTolerance > 0.0f || GetComponent() != null) + { + if (body != null) body.FarseerBody.OnCollision += OnCollision; + } + InsertToList(); ItemList.Add(this); } @@ -729,6 +745,27 @@ namespace Barotrauma body.ApplyTorque(body.AngularVelocity * volume * -0.05f); } + private bool OnCollision(Fixture f1, Fixture f2, Contact contact) + { + Vector2 normal = contact.Manifold.LocalNormal; + + float impact = Vector2.Dot(f1.Body.LinearVelocity, -normal); + + if (ImpactTolerance > 0.0f && impact > ImpactTolerance) ApplyStatusEffects(ActionType.OnImpact, 1.0f); + + var containedItems = ContainedItems; + if (containedItems != null) + { + foreach (Item contained in containedItems) + { + if (contained.body == null) continue; + contained.OnCollision(f1, f2, contact); + } + } + + return true; + } + public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { Color color = (isSelected && editing) ? color = Color.Red : spriteColor; diff --git a/Subsurface/Source/Items/ItemPrefab.cs b/Subsurface/Source/Items/ItemPrefab.cs index f33ba443c..10342da36 100644 --- a/Subsurface/Source/Items/ItemPrefab.cs +++ b/Subsurface/Source/Items/ItemPrefab.cs @@ -45,6 +45,8 @@ namespace Barotrauma public readonly bool FireProof; + private float impactTolerance; + public string ConfigFile { get { return configFile; } @@ -87,6 +89,13 @@ namespace Barotrauma get { return offsetOnSelected; } } + + public float ImpactTolerance + { + get { return impactTolerance; } + set { impactTolerance = Math.Max(value, 0.0f); } + } + public bool CanUseOnSelf { get; @@ -213,7 +222,9 @@ namespace Barotrauma CanUseOnSelf = ToolBox.GetAttributeBool(element, "canuseonself", false); - FireProof = ToolBox.GetAttributeBool(element, "fireproof", false); + FireProof = ToolBox.GetAttributeBool(element, "fireproof", false); + + ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f); string categoriesStr = ToolBox.GetAttributeString(element, "category", "Misc"); diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index 0bf66e201..9fb34e25c 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -39,8 +39,6 @@ namespace Barotrauma { GameMain.ParticleManager.CreateParticle("shockwave", worldPosition, Vector2.Zero, 0.0f, hull); - - } for (int i = 0; i < attack.Range * 0.1f; i++) @@ -79,6 +77,21 @@ namespace Barotrauma ApplyExplosionForces(worldPosition, attack.Range, force, attack.GetDamage(1.0f), attack.Stun); + if (flames) + { + foreach (Item item in Item.ItemList) + { + if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue; + //if (item.ParentInventory != null) return; + + if (Vector2.Distance(item.WorldPosition, worldPosition) > attack.Range * 0.1f) continue; + + //item.Condition -= (float)Math.Sqrt(size.X) * deltaTime; + + item.ApplyStatusEffects(ActionType.OnFire, 1.0f); + } + } + } private IEnumerable DimLight() diff --git a/Subsurface/Source/Map/FireSource.cs b/Subsurface/Source/Map/FireSource.cs index 4b7e9f104..7545fa229 100644 --- a/Subsurface/Source/Map/FireSource.cs +++ b/Subsurface/Source/Map/FireSource.cs @@ -250,7 +250,7 @@ namespace Barotrauma foreach (Item item in Item.ItemList) { if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue; - if (item.ParentInventory != null) return; + //if (item.ParentInventory != null) return; float range = (float)Math.Sqrt(size.X) * 10.0f; if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue; diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index b2f0faad0..57e586dca 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -492,10 +492,10 @@ namespace Barotrauma SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint)); GameMain.GameScreen.Cam.Shake = impact * 2.0f; - Vector2 limbForce = direction * impact * 0.5f; + Vector2 impulse = direction * impact * 0.5f; - float length = limbForce.Length(); - if (length > 5.0f) limbForce = (limbForce / length) * 5.0f; + float length = impulse.Length(); + if (length > 5.0f) impulse = (impulse / length) * 5.0f; foreach (Character c in Character.CharacterList) { @@ -506,10 +506,17 @@ namespace Barotrauma foreach (Limb limb in c.AnimController.Limbs) { if (c.AnimController.LowestLimb == limb) continue; - limb.body.ApplyLinearImpulse(limb.Mass * limbForce); + limb.body.ApplyLinearImpulse(limb.Mass * impulse); } } + foreach (Item item in Item.ItemList) + { + if (item.Submarine != submarine || item.CurrentHull == null || item.body == null) continue; + + item.body.ApplyLinearImpulse(item.body.Mass * impulse); + } + Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier); }