diff --git a/Subsurface/Content/Items/Button/beep.ogg b/Subsurface/Content/Items/Button/beep.ogg new file mode 100644 index 000000000..b7f3888d2 Binary files /dev/null and b/Subsurface/Content/Items/Button/beep.ogg differ diff --git a/Subsurface/Content/Items/Button/button.xml b/Subsurface/Content/Items/Button/button.xml index ad9cbab20..47510268a 100644 --- a/Subsurface/Content/Items/Button/button.xml +++ b/Subsurface/Content/Items/Button/button.xml @@ -12,6 +12,7 @@ + diff --git a/Subsurface/Content/Items/Door/door.ogg b/Subsurface/Content/Items/Door/door.ogg new file mode 100644 index 000000000..942f87ebd Binary files /dev/null and b/Subsurface/Content/Items/Door/door.ogg differ diff --git a/Subsurface/Content/Items/Door/doors.xml b/Subsurface/Content/Items/Door/doors.xml index 61842dd34..3fafbebbf 100644 --- a/Subsurface/Content/Items/Door/doors.xml +++ b/Subsurface/Content/Items/Door/doors.xml @@ -9,6 +9,7 @@ + @@ -32,6 +33,7 @@ + diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index f71d89bee..3cbef74f4 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -10,7 +10,7 @@ - + diff --git a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml index 61b7d1795..32f56a0c5 100644 --- a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml +++ b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml @@ -8,7 +8,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/Subsurface/Content/Items/Pump/pump.xml b/Subsurface/Content/Items/Pump/pump.xml index c7cfc0011..0a1ae3556 100644 --- a/Subsurface/Content/Items/Pump/pump.xml +++ b/Subsurface/Content/Items/Pump/pump.xml @@ -7,7 +7,7 @@ - + diff --git a/Subsurface/Content/Items/Reactor/reactor.ogg b/Subsurface/Content/Items/Reactor/reactor.ogg index 187933841..935fbb664 100644 Binary files a/Subsurface/Content/Items/Reactor/reactor.ogg and b/Subsurface/Content/Items/Reactor/reactor.ogg differ diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index faa1e0b76..41d310058 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -24,7 +24,7 @@ - + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index cc3ef1d93..619f92ab2 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -19,7 +19,7 @@ - + @@ -64,7 +64,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/railgunbarrel.png b/Subsurface/Content/Items/Weapons/railgunbarrel.png index 8765f90bd..4ab7ed948 100644 Binary files a/Subsurface/Content/Items/Weapons/railgunbarrel.png and b/Subsurface/Content/Items/Weapons/railgunbarrel.png differ diff --git a/Subsurface/Content/Items/Weapons/railgunbase.png b/Subsurface/Content/Items/Weapons/railgunbase.png index 00350556c..88c76993f 100644 Binary files a/Subsurface/Content/Items/Weapons/railgunbase.png and b/Subsurface/Content/Items/Weapons/railgunbase.png differ diff --git a/Subsurface/Content/Sounds/Damage/StructureBlunt6.ogg b/Subsurface/Content/Sounds/Damage/StructureBlunt6.ogg new file mode 100644 index 000000000..3593d8bc8 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/StructureBlunt6.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/StructureBlunt7.ogg b/Subsurface/Content/Sounds/Damage/StructureBlunt7.ogg new file mode 100644 index 000000000..5dd8ab616 Binary files /dev/null and b/Subsurface/Content/Sounds/Damage/StructureBlunt7.ogg differ diff --git a/Subsurface/Content/Sounds/Damage/StructureCrunch3.ogg b/Subsurface/Content/Sounds/Damage/StructureCrunch3.ogg index 5d36d00aa..47c218710 100644 Binary files a/Subsurface/Content/Sounds/Damage/StructureCrunch3.ogg and b/Subsurface/Content/Sounds/Damage/StructureCrunch3.ogg differ diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml index e1c7eb5fd..11b40db4f 100644 --- a/Subsurface/Content/Sounds/sounds.xml +++ b/Subsurface/Content/Sounds/sounds.xml @@ -4,7 +4,9 @@ - + + + diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index f659eafee..0a814d173 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -124,8 +124,6 @@ namespace Subsurface public void Translate(Vector2 amount) { position += amount; - Sound.CameraPos = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, 0.0f); - //UpdateTransform(); } @@ -152,6 +150,10 @@ namespace Subsurface prevPosition = position; prevZoom = zoom; + + + Sound.CameraPos = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, 0.0f); + } public void MoveCamera(float deltaTime) @@ -161,7 +163,6 @@ namespace Subsurface Vector2 moveCam = Vector2.Zero; if (targetPos == Vector2.Zero) { - if (PlayerInput.KeyDown(Keys.A)) moveCam.X -= moveSpeed; if (PlayerInput.KeyDown(Keys.D)) moveCam.X += moveSpeed; if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed; @@ -169,7 +170,8 @@ namespace Subsurface moveCam = moveCam * deltaTime * 60.0f; - Zoom = MathHelper.Clamp(Zoom + PlayerInput.ScrollWheelSpeed / 1000.0f, 0.1f, 2.0f); + + Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, 0.1f, 2.0f); } else { diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index 29af4ed48..6a9b616d8 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -225,9 +225,19 @@ namespace Subsurface float footMid = waist.SimPosition.X;// (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f; + int limbsInWater = 0; + foreach (Limb limb in Limbs) + { + if (limb.inWater) limbsInWater++; + } + + TargetMovement *= (1.0f - 0.5f*((float)limbsInWater/(float)Limbs.Count())); + movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp); movement.Y = 0.0f; + + //place the anchors of the head and the torso to make the ragdoll stand if (onGround && LowestLimb != null && (LowestLimb.SimPosition.Y-floorY < 0.5f || stairs != null) && head !=null) { @@ -588,7 +598,7 @@ namespace Subsurface float handCyclePos = walkPos / 2.0f; float handPosX = (float)Math.Cos(handCyclePos * Dir) * 0.4f; - float handPosY = (float)Math.Sin(handCyclePos * Dir) * 1.0f; + float handPosY = (float)Math.Sin(handCyclePos) * 1.0f; handPosY = MathHelper.Clamp(handPosY, -0.8f, 0.8f); Matrix rotationMatrix = Matrix.CreateRotationZ(torso.Rotation); diff --git a/Subsurface/Source/Characters/Ragdoll.cs b/Subsurface/Source/Characters/Ragdoll.cs index fcb068497..d40e3ae07 100644 --- a/Subsurface/Source/Characters/Ragdoll.cs +++ b/Subsurface/Source/Characters/Ragdoll.cs @@ -519,9 +519,7 @@ namespace Subsurface public void Update(Camera cam, float deltaTime) { UpdateNetplayerPosition(); - - - + Vector2 flowForce = Vector2.Zero; FindLowestLimb(); @@ -543,8 +541,7 @@ namespace Subsurface if (currentHull.Volume > currentHull.FullVolume * 0.95f || ConvertUnits.ToSimUnits(currentHull.Surface) - floorY > HeadPosition * 0.95f) - inWater = true; - + inWater = true; } foreach (Limb limb in Limbs) diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index fcf5de848..8cff35e83 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -290,6 +290,23 @@ namespace Subsurface if (commands.Length < 2) break; Submarine.Load(string.Join(" ", commands.Skip(1))); break; + case "cleansub": + for (int i = MapEntity.mapEntityList.Count-1; i>=0; i--) + { + MapEntity me = MapEntity.mapEntityList[i]; + + if (me.SimPosition.Length()>200.0f) + { + DebugConsole.NewMessage("Removed "+me.Name+" (simposition "+me.SimPosition+")", Color.Orange); + MapEntity.mapEntityList.RemoveAt(i); + } + else if (me.MoveWithLevel) + { + DebugConsole.NewMessage("Removed " + me.Name + " (MoveWithLevel==true)", Color.Orange); + MapEntity.mapEntityList.RemoveAt(i); + } + } + break; case "messagebox": if (commands.Length < 3) break; new GUIMessageBox(commands[1], commands[2]); diff --git a/Subsurface/Source/Events/Quests/SalvageQuest.cs b/Subsurface/Source/Events/Quests/SalvageQuest.cs index 7b4456dd6..7dfa65f52 100644 --- a/Subsurface/Source/Events/Quests/SalvageQuest.cs +++ b/Subsurface/Source/Events/Quests/SalvageQuest.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using FarseerPhysics; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -9,15 +10,15 @@ namespace Subsurface { class SalvageQuest : Quest { - ItemPrefab itemPrefab; + private ItemPrefab itemPrefab; - Item item; + private Item item; public override Vector2 RadarPosition { get { - return item.Position; + return ConvertUnits.ToDisplayUnits(item.SimPosition); } } @@ -39,17 +40,18 @@ namespace Subsurface Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count)]; item = new Item(itemPrefab, position + level.Position); + item.MoveWithLevel = true; //item.MoveWithLevel = true; } public override void End() { + item.Remove(); if (item.CurrentHull == null) { new GUIMessageBox("Quest failed", failureMessage); return; - } - item.Remove(); + } GiveReward(); diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index ed6b3e676..3182c8f86 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -157,6 +157,11 @@ namespace Subsurface base.Update(deltaTime); scrollBar.Update(deltaTime); + + if ((MouseOn==this || MouseOn==scrollBar || IsParentOf(MouseOn) )&& PlayerInput.ScrollWheelSpeed!=0) + { + scrollBar.BarScroll -= (PlayerInput.ScrollWheelSpeed/500.0f) * BarSize; + } } public void Select(int childIndex) @@ -237,7 +242,7 @@ namespace Subsurface if (!scrollBarHidden) Rect = new Rectangle(rect.X, rect.Y, rect.Width + scrollBar.Rect.Width, rect.Height); scrollBarHidden = true; } - + public override void Draw(SpriteBatch spriteBatch) { if (!Visible) return; diff --git a/Subsurface/Source/Items/Components/Container.cs b/Subsurface/Source/Items/Components/Container.cs index e252f75ae..e1638b337 100644 --- a/Subsurface/Source/Items/Components/Container.cs +++ b/Subsurface/Source/Items/Components/Container.cs @@ -209,7 +209,7 @@ namespace Subsurface.Items.Components if (inventory.TryPutItem(item)) { - isActive = true; + IsActive = true; if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false; item.container = this.item; diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index f6680e106..0bae0cea9 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -148,7 +148,7 @@ namespace Subsurface.Items.Components UpdateConvexHulls(); - isActive = true; + IsActive = true; } private void UpdateConvexHulls() @@ -240,7 +240,7 @@ namespace Subsurface.Items.Components { if (!isStuck) { - OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f); + OpenState += deltaTime * ((isOpen) ? 2.0f : -1.0f); LinkedGap.Open = openState; } @@ -327,10 +327,13 @@ namespace Subsurface.Items.Components if (connection.Name=="toggle") { isOpen = !isOpen; + PlaySound(ActionType.OnUse, item.Position); } else if (connection.Name == "set_state") { - isOpen = (signal!="0"); + bool newState = (signal!="0"); + if (isOpen!=newState) PlaySound(ActionType.OnUse, item.Position); + isOpen = newState; } //opening a partially stuck door makes it less stuck diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index fb253c34d..582d9d586 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -118,7 +118,7 @@ namespace Subsurface.Items.Components if (picker.Inventory == null) return; item.body.Enabled = true; - isActive = false; + IsActive = false; //item.Unequip(); @@ -140,7 +140,7 @@ namespace Subsurface.Items.Components if (picker.TrySelectItem(item)) { item.body.Enabled = true; - isActive = true; + IsActive = true; } } @@ -151,7 +151,7 @@ namespace Subsurface.Items.Components picker.DeselectItem(item); item.body.Enabled = false; - isActive = false; + IsActive = false; } public override bool Pick(Character picker) @@ -213,7 +213,7 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; - if (!picker.HasSelectedItem(item)) isActive = false; + if (!picker.HasSelectedItem(item)) IsActive = false; ApplyStatusEffects(ActionType.OnActive, deltaTime, picker); diff --git a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs index 80be13d01..dd10991e0 100644 --- a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -73,7 +73,7 @@ namespace Subsurface.Items.Components hitting = true; - isActive = true; + IsActive = true; return true; } @@ -93,7 +93,7 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; - if (!picker.HasSelectedItem(item)) isActive = false; + if (!picker.HasSelectedItem(item)) IsActive = false; if (!picker.GetInputState(InputType.SecondaryHeld) && !hitting) hitPos = 0.0f; diff --git a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs index 9af04c513..d05a882f3 100644 --- a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs @@ -46,7 +46,7 @@ namespace Subsurface.Items.Components if (reload < 0.0f) { reload = 0.0f; - isActive = false; + IsActive = false; } } @@ -54,7 +54,7 @@ namespace Subsurface.Items.Components { if (character == null) return false; if (!character.GetInputState(InputType.SecondaryHeld) || reload > 0.0f) return false; - isActive = true; + IsActive = true; reload = 1.0f; List limbBodies = new List(); diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 5332654d7..7a1e7134e 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -106,7 +106,7 @@ namespace Subsurface.Items.Components //if (DoesUseFail(character)) return false; - isActive = true; + IsActive = true; Vector2 targetPosition = item.body.SimPosition; //targetPosition = targetPosition.X, -targetPosition.Y); @@ -200,7 +200,7 @@ namespace Subsurface.Items.Components public override void Draw(SpriteBatch spriteBatch, bool editing) { - if (!isActive) return; + if (!IsActive) return; //Vector2 particleSpeed = new Vector2( // (float)Math.Cos(item.body.Rotation), @@ -219,7 +219,7 @@ namespace Subsurface.Items.Components //GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f); - isActive = false; + IsActive = false; } diff --git a/Subsurface/Source/Items/Components/Holdable/Throwable.cs b/Subsurface/Source/Items/Components/Holdable/Throwable.cs index 1904a7dd8..8293a205e 100644 --- a/Subsurface/Source/Items/Components/Holdable/Throwable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Throwable.cs @@ -48,7 +48,7 @@ namespace Subsurface.Items.Components throwing = true; - isActive = true; + IsActive = true; return true; } @@ -73,7 +73,7 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; - if (!picker.HasSelectedItem(item)) isActive = false; + if (!picker.HasSelectedItem(item)) IsActive = false; if (!picker.GetInputState(InputType.SecondaryHeld) && !throwing) throwPos = 0.0f; diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index e1e21f037..fd80536fc 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -25,7 +25,7 @@ namespace Subsurface.Items.Components public readonly bool Loop; - public ItemSound(Sound sound, ActionType type, float range, bool loop = true) + public ItemSound(Sound sound, ActionType type, float range, bool loop = false) { this.Sound = sound; this.Type = type; @@ -45,7 +45,7 @@ namespace Subsurface.Items.Components protected string name; - protected bool isActive; + private bool isActive; protected bool characterUsable; @@ -255,7 +255,8 @@ namespace Subsurface.Items.Components Sound sound = Sound.Load(filePath); float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); - ItemSound itemSound = new ItemSound(sound, type, range); + bool loop = ToolBox.GetAttributeBool(subElement, "loop", false); + ItemSound itemSound = new ItemSound(sound, type, range, loop); itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", ""); itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f); sounds.Add(itemSound); @@ -299,7 +300,9 @@ namespace Subsurface.Items.Components } else { - itemSound.Sound.Play(GetSoundVolume(itemSound), itemSound.Range, position); + float volume = GetSoundVolume(itemSound); + if (volume == 0.0f) return; + itemSound.Sound.Play(volume, itemSound.Range, position); } } } @@ -322,14 +325,21 @@ namespace Subsurface.Items.Components private float GetSoundVolume(ItemSound sound) { + if (sound == null) return 0.0f; if (sound.VolumeProperty == "") return 1.0f; ObjectProperty op = null; if (properties.TryGetValue(sound.VolumeProperty.ToLower(), out op)) { float newVolume = 0.0f; - float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume); - + try + { + newVolume = (float)op.GetValue(); + } + catch + { + return 0.0f; + } newVolume *= sound.VolumeMultiplier; return MathHelper.Clamp(newVolume, 0.0f, 1.0f); diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs index 4a96bad0a..ccdfcbaf9 100644 --- a/Subsurface/Source/Items/Components/Machines/Controller.cs +++ b/Subsurface/Source/Items/Components/Machines/Controller.cs @@ -59,7 +59,7 @@ namespace Subsurface.Items.Components limbPositions.Add(lp); } - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) @@ -76,7 +76,7 @@ namespace Subsurface.Items.Components character.AnimController.Anim = AnimController.Animation.None; character = null; } - isActive = false; + IsActive = false; return; } @@ -131,9 +131,9 @@ namespace Subsurface.Items.Components public override bool Use(float deltaTime, Character activator = null) { - if (activator.SelectedConstruction != item) + if (character==null || activator!=character || character.SelectedConstruction != item) { - activator = null; + character = null; return false; } @@ -146,8 +146,7 @@ namespace Subsurface.Items.Components public override void SecondaryUse(float deltaTime, Character character = null) { - if (character == null) return; - if (character.SelectedConstruction!=item) + if (this.character == null || this.character!=character || this.character.SelectedConstruction!=item) { character = null; return; @@ -186,6 +185,9 @@ namespace Subsurface.Items.Components public override bool Pick(Character picker) { item.SendSignal("1", "signal_out"); + + PlaySound(ActionType.OnUse, item.Position); + return true; } @@ -194,7 +196,7 @@ namespace Subsurface.Items.Components if (character!=null && character.SelectedConstruction == item) { character = null; - isActive = false; + IsActive = false; if (activator != null) activator.AnimController.Anim = AnimController.Animation.None; return false; @@ -204,7 +206,7 @@ namespace Subsurface.Items.Components character = activator; if (activator == null) return false; - isActive = true; + IsActive = true; } item.SendSignal("1", "signal_out"); diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index 42ab8fb06..6713f43ef 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -49,7 +49,7 @@ namespace Subsurface.Items.Components public Engine(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; } public float CurrentVolume diff --git a/Subsurface/Source/Items/Components/Machines/Fabricator.cs b/Subsurface/Source/Items/Components/Machines/Fabricator.cs index b3146d961..63f4dc89d 100644 --- a/Subsurface/Source/Items/Components/Machines/Fabricator.cs +++ b/Subsurface/Source/Items/Components/Machines/Fabricator.cs @@ -157,7 +157,7 @@ namespace Subsurface.Items.Components itemList.Enabled = false; fabricatedItem = obj as FabricableItem; - isActive = true; + IsActive = true; timeUntilReady = fabricatedItem.RequiredTime; @@ -179,7 +179,7 @@ namespace Subsurface.Items.Components new Item(fabricatedItem.TargetItem, item.Position); - isActive = false; + IsActive = false; fabricatedItem = null; } diff --git a/Subsurface/Source/Items/Components/Machines/MiniMap.cs b/Subsurface/Source/Items/Components/Machines/MiniMap.cs index 03798047e..f0813d3ef 100644 --- a/Subsurface/Source/Items/Components/Machines/MiniMap.cs +++ b/Subsurface/Source/Items/Components/Machines/MiniMap.cs @@ -11,7 +11,7 @@ namespace Subsurface.Items.Components public MiniMap(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs b/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs index 0d6f6c187..c50e2b1d6 100644 --- a/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs +++ b/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs @@ -19,10 +19,16 @@ namespace Subsurface.Items.Components return (running && item.Condition>0.0f); } + public float CurrFlow + { + get; + private set; + } + public OxygenGenerator(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; ventList = new List(); @@ -34,6 +40,7 @@ namespace Subsurface.Items.Components { base.Update(deltaTime, cam); + CurrFlow = 0.0f; currPowerConsumption = powerConsumption; if (item.CurrentHull == null) return; @@ -54,11 +61,11 @@ namespace Subsurface.Items.Components } running = true; - - float deltaOxygen = Math.Min(voltage, 1.0f) * 50000.0f; - item.CurrentHull.Oxygen += deltaOxygen * deltaTime; - UpdateVents(deltaOxygen); + CurrFlow = Math.Min(voltage, 1.0f) * 50000.0f; + item.CurrentHull.Oxygen += CurrFlow * deltaTime; + + UpdateVents(CurrFlow); voltage = 0.0f; diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index 13989f9c1..8b9e5c31c 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -35,6 +35,16 @@ namespace Subsurface.Items.Components set { maxFlow = value; } } + float currFlow; + public float CurrFlow + { + get + { + if (!IsActive) return 0.0f; + return Math.Abs(currFlow); + } + } + public Pump(Item item, XElement element) : base(item, element) { @@ -55,6 +65,8 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { + currFlow = 0.0f; + if (targetLevel != null) { float hullPercentage = 0.0f; @@ -71,14 +83,14 @@ namespace Subsurface.Items.Components float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage; //flowPercentage = maxFlow * powerFactor; - float deltaVolume = (flowPercentage/100.0f) * maxFlow * powerFactor; - - hull1.Volume += deltaVolume; + currFlow = (flowPercentage / 100.0f) * maxFlow * powerFactor; + + hull1.Volume += currFlow; if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f; if (hull2 != null) { - hull2.Volume -= deltaVolume; + hull2.Volume -= currFlow; if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f; } @@ -90,28 +102,6 @@ namespace Subsurface.Items.Components hull1 = Hull.FindHull(item.Position, item.CurrentHull); } - //private void GetHulls() - //{ - // hull1 = null; - // hull2 = null; - - // foreach (MapEntity e in item.linkedTo) - // { - // Hull hull = e as Hull; - // if (hull == null) continue; - - // if (hull1 == null) - // { - // hull1 = hull; - // } - // else if (hull2 == null && hull != hull1) - // { - // hull2 = hull; - // break; - // } - // } - //} - public override void DrawHUD(SpriteBatch spriteBatch, Character character) { int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; @@ -120,11 +110,11 @@ namespace Subsurface.Items.Components GuiFrame.Draw(spriteBatch); - if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 100, 40), ((isActive) ? "TURN OFF" : "TURN ON"))) + if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 100, 40), ((IsActive) ? "TURN OFF" : "TURN ON"))) { targetLevel = null; - isActive = !isActive; - if (!isActive) currPowerConsumption = 0.0f; + IsActive = !IsActive; + if (!IsActive) currPowerConsumption = 0.0f; item.NewComponentEvent(this, true); } @@ -148,11 +138,11 @@ namespace Subsurface.Items.Components if (connection.Name == "toggle") { - isActive = !isActive; + IsActive = !IsActive; } else if (connection.Name == "set_active") { - isActive = (signal != "0"); + IsActive = (signal != "0"); } else if (connection.Name == "set_speed") { @@ -171,13 +161,13 @@ namespace Subsurface.Items.Components } } - if (!isActive) currPowerConsumption = 0.0f; + if (!IsActive) currPowerConsumption = 0.0f; } public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) { message.Write(Convert.ToByte(flowPercentage+100)); - message.Write(isActive); + message.Write(IsActive); } public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) @@ -200,7 +190,7 @@ namespace Subsurface.Items.Components } FlowPercentage = newFlow; - isActive = newActive; + IsActive = newActive; } } } diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index 52921dca3..b542a6f9b 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -77,7 +77,7 @@ namespace Subsurface.Items.Components if (voltage < minVoltage) return; - if (GUI.DrawButton(spriteBatch, new Rectangle(x+20, y+20, 200, 30), "Activate Radar")) isActive = !isActive; + if (GUI.DrawButton(spriteBatch, new Rectangle(x+20, y+20, 200, 30), "Activate Radar")) IsActive = !IsActive; int radius = GuiFrame.Rect.Height / 2 - 10; DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); @@ -92,7 +92,7 @@ namespace Subsurface.Items.Components //lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Math.Min(width, height) / 2.0f; //GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green); - if (!isActive) return; + if (!IsActive) return; if (pingCircle!=null) { diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 8cfc099b9..45b2c3a14 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -132,7 +132,7 @@ namespace Subsurface.Items.Components powerPerTemp = 1.0f; - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) @@ -288,7 +288,7 @@ namespace Subsurface.Items.Components bool valueChanged = false; public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - isActive = true; + IsActive = true; int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index feb9ee919..c028307ee 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -62,7 +62,7 @@ namespace Subsurface.Items.Components public Steering(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index c7607a661..73e8303a0 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -72,7 +72,7 @@ namespace Subsurface.Items.Components //maxRechargeSpeed = ToolBox.GetAttributeFloat(element, "maxinput", 10.0f); //maxOutput = ToolBox.GetAttributeFloat(element, "maxoutput", 10.0f); - isActive = true; + IsActive = true; } public override bool Pick(Character picker) diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 0b13702de..529e466c5 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -27,7 +27,7 @@ namespace Subsurface.Items.Components public PowerTransfer(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Components/Power/Powered.cs b/Subsurface/Source/Items/Components/Power/Powered.cs index 1e5334b99..22ff97bc9 100644 --- a/Subsurface/Source/Items/Components/Power/Powered.cs +++ b/Subsurface/Source/Items/Components/Power/Powered.cs @@ -45,11 +45,11 @@ namespace Subsurface.Items.Components [HasDefaultValue(false,true)] public override bool IsActive { - get { return isActive; } + get { return base.IsActive; } set { - isActive = value; - if (!isActive) currPowerConsumption = 0.0f; + base.IsActive = value; + if (!value) currPowerConsumption = 0.0f; } } @@ -101,7 +101,6 @@ namespace Subsurface.Items.Components powerOnSound.Play(1.0f, 600.0f, item.Position); powerOnSoundPlayed = true; } - ApplyStatusEffects(ActionType.OnActive, deltaTime); } else if (voltage < 0.1f) { diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 956665a6c..2179c60b8 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -123,12 +123,12 @@ namespace Subsurface.Items.Components GameMain.World.RemoveJoint(stickJoint); stickJoint = null; - isActive = false; + IsActive = false; } } else { - isActive = false; + IsActive = false; } } @@ -209,7 +209,7 @@ namespace Subsurface.Items.Components stickTarget = targetBody; GameMain.World.AddJoint(stickJoint); - isActive = true; + IsActive = true; return false; } diff --git a/Subsurface/Source/Items/Components/Rope.cs b/Subsurface/Source/Items/Components/Rope.cs index 5b2c2824d..391042ced 100644 --- a/Subsurface/Source/Items/Components/Rope.cs +++ b/Subsurface/Source/Items/Components/Rope.cs @@ -179,7 +179,7 @@ namespace Subsurface.Items.Components { item.Combine(projectile); ropeBodies[ropeBodies.Length - 1].Enabled = false; - isActive = false; + IsActive = false; } } @@ -235,7 +235,7 @@ namespace Subsurface.Items.Components { if (joint != null) joint.Enabled = false; } - isActive = false; + IsActive = false; } } @@ -243,7 +243,7 @@ namespace Subsurface.Items.Components { base.Draw(spriteBatch); - if (!isActive) return; + if (!IsActive) return; RevoluteJoint firstJoint = null; @@ -279,7 +279,7 @@ namespace Subsurface.Items.Components public void Attach(Item projectile) { reload = 0.5f; - isActive = true; + IsActive = true; this.projectile = projectile; //Projectile projectileComponent = projectile.GetComponent(); diff --git a/Subsurface/Source/Items/Components/Signal/AndComponent.cs b/Subsurface/Source/Items/Components/Signal/AndComponent.cs index e19898ce9..7d4e0ca01 100644 --- a/Subsurface/Source/Items/Components/Signal/AndComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/AndComponent.cs @@ -60,12 +60,12 @@ namespace Subsurface.Items.Components case "signal_in1": if (signal == "0") return; timeSinceReceived[0] = 0.0f; - isActive = true; + IsActive = true; break; case "signal_in2": if (signal == "0") return; timeSinceReceived[1] = 0.0f; - isActive = true; + IsActive = true; break; case "set_output": output = signal; diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index 467341d1a..e67e320b6 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -30,7 +30,7 @@ namespace Subsurface.Items.Components } } - isActive = true; + IsActive = true; } public override void DrawHUD(SpriteBatch spriteBatch, Character character) @@ -67,7 +67,7 @@ namespace Subsurface.Items.Components public override bool Select(Character picker) { user = picker; - isActive = true; + IsActive = true; return true; } diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index 27e439af2..29c0e5660 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -75,7 +75,7 @@ namespace Subsurface.Items.Components light = new LightSource(item.Position, 100.0f, Color.White); - isActive = true; + IsActive = true; //lightColor = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One)); } @@ -124,7 +124,7 @@ namespace Subsurface.Items.Components public override void Draw(SpriteBatch spriteBatch, bool editing) { - if (!isActive) + if (!IsActive) { light.Color = Color.Transparent; } @@ -144,10 +144,10 @@ namespace Subsurface.Items.Components switch (connection.Name) { case "toggle": - isActive = !isActive; + IsActive = !IsActive; break; case "set_state": - isActive = (signal != "0"); + IsActive = (signal != "0"); break; } } diff --git a/Subsurface/Source/Items/Components/Signal/OxygenDetector.cs b/Subsurface/Source/Items/Components/Signal/OxygenDetector.cs index 9e8940764..f52764f97 100644 --- a/Subsurface/Source/Items/Components/Signal/OxygenDetector.cs +++ b/Subsurface/Source/Items/Components/Signal/OxygenDetector.cs @@ -11,7 +11,7 @@ namespace Subsurface.Items.Components { hull = Hull.FindHull(item.Position); - isActive = true; + IsActive = true; } public override void OnMapLoaded() diff --git a/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs b/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs index 36d2e5353..5b294b0f1 100644 --- a/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs @@ -48,7 +48,7 @@ namespace Subsurface.Items.Components public RegExFindComponent(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index d8ddde6ca..cdd8a64bd 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -115,7 +115,7 @@ namespace Subsurface.Items.Components item.body.Enabled = false; - isActive = false; + IsActive = false; //Nodes = prevNodes; CleanNodes(); @@ -128,21 +128,21 @@ namespace Subsurface.Items.Components { ClearConnections(); - isActive = true; + IsActive = true; } public override void Unequip(Character character) { ClearConnections(); - isActive = false; + IsActive = false; } public override void Drop(Character dropper) { ClearConnections(); - isActive = false; + IsActive = false; } public override void Update(float deltaTime, Camera cam) @@ -289,7 +289,7 @@ namespace Subsurface.Items.Components DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], item.Color); } - if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) + if (IsActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance) { DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, item.Color * 0.5f); //nodes.Add(newNodePos); diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index d8e7252f0..47d9f0406 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -73,7 +73,7 @@ namespace Subsurface.Items.Components public Turret(Item item, XElement element) : base(item, element) { - isActive = true; + IsActive = true; barrelSprite = new Sprite(Path.GetDirectoryName(item.Prefab.ConfigFile) + "/" +element.Attribute("barrelsprite").Value, ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero)); @@ -81,7 +81,10 @@ namespace Subsurface.Items.Components public override void Draw(SpriteBatch spriteBatch, bool editing) { - barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f); + barrelSprite.Draw(spriteBatch, + new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, Color.White, + rotation + MathHelper.PiOver2, 1.0f, + SpriteEffects.None, item.Sprite.Depth+0.01f); } public override void Update(float deltaTime, Camera cam) @@ -198,7 +201,7 @@ namespace Subsurface.Items.Components targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); - isActive = true; + IsActive = true; break; case "trigger_in": diff --git a/Subsurface/Source/Items/Components/Wearable.cs b/Subsurface/Source/Items/Components/Wearable.cs index 6b9d18378..bc3232869 100644 --- a/Subsurface/Source/Items/Components/Wearable.cs +++ b/Subsurface/Source/Items/Components/Wearable.cs @@ -114,7 +114,7 @@ namespace Subsurface.Items.Components item.body.Enabled = false; - isActive = true; + IsActive = true; limb[i] = equipLimb; equipLimb.WearingItem = this; @@ -129,7 +129,7 @@ namespace Subsurface.Items.Components base.Drop(dropper); picker = null; - isActive = false; + IsActive = false; } public override void Unequip(Character character) @@ -147,7 +147,7 @@ namespace Subsurface.Items.Components equipLimb.WearingItemSprite = null; } - isActive = false; + IsActive = false; } public override void UpdateBroken(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 1dd6b05a1..8a80ce6c7 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -78,6 +78,14 @@ namespace Subsurface get { return prefab.PickDistance; } } + public override Vector2 SimPosition + { + get + { + return (body==null) ? base.SimPosition : body.SimPosition; + } + } + protected Color spriteColor; [Editable, HasDefaultValue("1.0,1.0,1.0,1.0", true)] public string SpriteColor diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 243502db5..9445e49c0 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -24,7 +24,7 @@ namespace Subsurface private static Texture2D shaftTexture; //how close the sub has to be to start/endposition to exit - const float ExitDistance = 3000.0f; + const float ExitDistance = 6000.0f; private string seed; diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 78d29e55d..bf86dc7f1 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -90,7 +90,7 @@ namespace Subsurface rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f); - if (MoveWithLevel) rectPos += Level.Loaded.Position; + //if (MoveWithLevel) rectPos += Level.Loaded.Position; return rectPos; } } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index e9cb8e845..0f7c23b1b 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -249,7 +249,10 @@ namespace Subsurface Body closestBody = null; GameMain.World.RayCast((fixture, point, normal, fraction) => { - if (fixture == null || fixture.CollisionCategories == Category.None) return -1; + if (fixture == null || + fixture.CollisionCategories == Category.None || + fixture.CollisionCategories == Physics.CollisionMisc) return -1; + if (ignoredBodies != null && ignoredBodies.Contains(fixture.Body)) return -1; Structure structure = fixture.Body.UserData as Structure; @@ -430,6 +433,7 @@ namespace Subsurface foreach (MapEntity e in MapEntity.mapEntityList) { + if (e.MoveWithLevel) continue; e.Save(doc); } diff --git a/Subsurface/Source/Map/SubmarineHull.cs b/Subsurface/Source/Map/SubmarineHull.cs index c0fdeded5..1da8249aa 100644 --- a/Subsurface/Source/Map/SubmarineHull.cs +++ b/Subsurface/Source/Map/SubmarineHull.cs @@ -97,12 +97,14 @@ namespace Subsurface body.CollisionCategories = Physics.CollisionMisc; body.CollidesWith = Physics.CollisionLevel; + body.Restitution = 0.0f; body.FixedRotation = true; body.Awake = true; body.SleepingAllowed = false; - body.GravityScale = 0.0f; + body.IgnoreGravity = true; body.OnCollision += OnCollision; - body.OnSeparation += OnSeparation; + //body.OnSeparation += OnSeparation; + body.UserData = this; } @@ -194,28 +196,9 @@ namespace Subsurface //hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position; //hullBody.SetTransform(Vector2.Zero , 0.0f); - body.LinearVelocity = -body.Position / (float)Physics.step; + body.SetTransform(Vector2.Zero, 0.0f);// .LinearVelocity = -body.Position / (float)Physics.step; + body.LinearVelocity = Vector2.Zero; - if (collidingCell == null) - { - collisionRigidness = MathHelper.Lerp(collisionRigidness, 1.0f, 0.1f); - return; - } - - foreach (GraphEdge ge in collidingCell.edges) - { - Body wallBody = Submarine.PickBody( - ConvertUnits.ToSimUnits(ge.point1 + GameMain.GameSession.Level.Position), - ConvertUnits.ToSimUnits(ge.point2 + GameMain.GameSession.Level.Position), new List() { collidingCell.body }); - if (wallBody == null || wallBody.UserData == null) continue; - - Structure structure = wallBody.UserData as Structure; - if (structure == null) continue; - structure.AddDamage( - structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)), 50.0f); - } - - collidingCell = null; } private Vector2 CalculateBuoyancy() @@ -244,7 +227,6 @@ namespace Subsurface speed += force / mass; } - VoronoiCell collidingCell; public bool OnCollision(Fixture f1, Fixture f2, Contact contact) { VoronoiCell cell = f2.Body.UserData as VoronoiCell; @@ -255,7 +237,7 @@ namespace Subsurface } Vector2 normal = contact.Manifold.LocalNormal; - Vector2 simSpeed = ConvertUnits.ToSimUnits(speed); + Vector2 simSpeed = ConvertUnits.ToSimUnits(speed) + body.LinearVelocity; float impact = Vector2.Dot(simSpeed, normal); Vector2 u = Vector2.Dot(simSpeed, -normal) * -normal; @@ -292,27 +274,53 @@ namespace Subsurface } System.Diagnostics.Debug.WriteLine("IMPACT: " + impact + " normal: " + normal + " simspeed: " + simSpeed + " u: " + u + " w: " + w); - if (impact < 4.0f) + if (impact < 3.0f) { - speed = ConvertUnits.ToDisplayUnits(w * 0.9f - u * 0.2f); + speed = ConvertUnits.ToDisplayUnits(w * 0.45f - u * 0.25f); return true; } else { speed = ConvertUnits.ToDisplayUnits(w * 0.9f + u * 0.5f); + + //FixedArray2 worldPoints; + //contact.GetWorldManifold(out normal, out worldPoints); + + //if (contact.Manifold.PointCount >= 1) + //{ + // Vector2 contactPoint = worldPoints[0]; + + // Body wallBody = Submarine.PickBody(contactPoint, contactPoint + normal, new List() { cell.body }); + + // if (wallBody!=null && wallBody.UserData!=null) + // { + // Structure s = wallBody.UserData as Structure; + // } + //} + + foreach (GraphEdge ge in cell.edges) + { + Body wallBody = Submarine.PickBody( + ConvertUnits.ToSimUnits(ge.point1 + GameMain.GameSession.Level.Position + normal), + ConvertUnits.ToSimUnits(ge.point2 + GameMain.GameSession.Level.Position + normal), new List() { cell.body }); + if (wallBody == null || wallBody.UserData == null) continue; + + Structure structure = wallBody.UserData as Structure; + if (structure == null) continue; + structure.AddDamage( + structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)), impact*50.0f); + } } collisionRigidness = 0.8f; - collidingCell = cell; - return true; } - public void OnSeparation(Fixture f1, Fixture f2) - { - collidingCell = null; - } + //public void OnSeparation(Fixture f1, Fixture f2) + //{ + // collidingCell = null; + //} } } diff --git a/Subsurface/Source/Particles/ParticleManager.cs b/Subsurface/Source/Particles/ParticleManager.cs index 7c7bdff86..865184618 100644 --- a/Subsurface/Source/Particles/ParticleManager.cs +++ b/Subsurface/Source/Particles/ParticleManager.cs @@ -54,7 +54,9 @@ namespace Subsurface.Particles public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation=0.0f) { - if (!Submarine.RectContains(cam.WorldView, position)) return null; + //if (!Submarine.RectContains(cam.WorldView, position)) return null; + if (!cam.WorldView.Contains(position)) return null; + if (particleCount >= MaxParticles) return null; if (particles[particleCount] == null) particles[particleCount] = new Particle(); diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index a67c2e7c2..ef124abe9 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -206,8 +206,11 @@ namespace Subsurface public override void Update(double deltaTime) { - if (GUIComponent.MouseOn == null) cam.MoveCamera((float)deltaTime); - cam.Zoom = MathHelper.Clamp(cam.Zoom + PlayerInput.ScrollWheelSpeed / 1000.0f, 0.1f, 2.0f); + if (GUIComponent.MouseOn == null) + { + cam.MoveCamera((float)deltaTime); + //cam.Zoom = MathHelper.Clamp(cam.Zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f)*cam.Zoom, 0.1f, 2.0f); + } if (characterMode) { @@ -278,12 +281,8 @@ namespace Subsurface if (selectedTab > -1) GUItabs[selectedTab].Draw(spriteBatch); - GUI.Draw((float)deltaTime, spriteBatch, cam); - //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); - - - + if (characterMode) { if (dummyCharacter != null) @@ -312,17 +311,17 @@ namespace Subsurface } - if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) - { - Inventory.draggingItem = null; - } + //if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) + //{ + // Inventory.draggingItem = null; + //} } else { MapEntity.Edit(spriteBatch, cam); } - + GUI.Draw((float)deltaTime, spriteBatch, cam); spriteBatch.End(); diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index eb718cf44..4665bb1eb 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -300,16 +300,16 @@ namespace Subsurface saveFileFrame.UserData = "savefileframe"; saveFileFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); - new GUITextBlock(new Rectangle(0,0,0,20), fileName, GUI.Style, saveFileFrame); + new GUITextBlock(new Rectangle(0,0,0,20), fileName, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, saveFileFrame, false, GUI.LargeFont); - new GUITextBlock(new Rectangle(0, 30, 0, 20), subName, GUI.Style, saveFileFrame); + new GUITextBlock(new Rectangle(0, 35, 0, 20), "Submarine: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(15, 52, 0, 20), subName, GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(0, 70, 0, 20), "Last saved: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(15, 85, 0, 20), saveTime, GUI.Style, saveFileFrame).Font = GUI.SmallFont; - new GUITextBlock(new Rectangle(0, 50, 0, 20), "Last saved: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; - new GUITextBlock(new Rectangle(15, 65, 0, 20), saveTime, GUI.Style, saveFileFrame).Font = GUI.SmallFont; - - new GUITextBlock(new Rectangle(0, 85, 0, 20), "Map seed: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; - new GUITextBlock(new Rectangle(15, 100, 0, 20), mapseed, GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(0, 105, 0, 20), "Map seed: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(15, 120, 0, 20), mapseed, GUI.Style, saveFileFrame).Font = GUI.SmallFont; var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, GUI.Style, saveFileFrame); deleteSaveButton.UserData = fileName; diff --git a/Subsurface/Source/Sounds/AmbientSoundManager.cs b/Subsurface/Source/Sounds/AmbientSoundManager.cs index 0c2002499..b563b86e6 100644 --- a/Subsurface/Source/Sounds/AmbientSoundManager.cs +++ b/Subsurface/Source/Sounds/AmbientSoundManager.cs @@ -161,14 +161,14 @@ namespace Subsurface startDrone = null; } - float ambienceVolume = 0.6f; + float ambienceVolume = 0.8f; float lowpassHFGain = 1.0f; if (Character.Controlled != null) { AnimController animController = Character.Controlled.AnimController; if (animController.HeadInWater) { - ambienceVolume = 0.8f; + ambienceVolume = 1.0f; ambienceVolume += animController.Limbs[0].LinearVelocity.Length(); lowpassHFGain = 0.2f; @@ -262,7 +262,7 @@ namespace Subsurface public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position) { - damage = MathHelper.Clamp(damage, 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(); if (!sounds.Any()) return; diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 6ec1da84e..f99b9c715 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -183,9 +183,9 @@ namespace Subsurface } return sourceIndex; - } + } - return SoundManager.Loop(this, sourceIndex, position, volume, volume); + return SoundManager.Loop(this, sourceIndex, relativePos, volume); } diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 10f818a4f..6caac3dd5 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -16,13 +16,13 @@ namespace Subsurface.Sounds private static int[] alBuffers = new int[DefaultSourceCount]; private static int lowpassFilterId; - private static float overrideLowPassGain; + //private static float overrideLowPassGain; - public static float OverrideLowPassGain - { - get { return overrideLowPassGain; } - set { overrideLowPassGain = MathHelper.Clamp(overrideLowPassGain, 0.0f, 1.0f); } - } + //public static float OverrideLowPassGain + //{ + // get { return overrideLowPassGain; } + // set { overrideLowPassGain = MathHelper.Clamp(overrideLowPassGain, 0.0f, 1.0f); } + //} static AudioContext AC; @@ -139,17 +139,20 @@ namespace Subsurface.Sounds alBuffers[i] = sound.AlBufferId; OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, false); - position /= 1000.0f; - - //System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset); - OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcef.Gain, volume); - OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); - OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, sound.AlBufferId); - ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain)); - ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId); - ALHelper.Check(); + + UpdateSoundPosition(i, position, volume); + + //position /= 1000.0f; + + ////System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset); + //OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcef.Gain, volume); + //OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); + + //ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain); + //ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId); + //ALHelper.Check(); //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); OpenTK.Audio.OpenAL.AL.SourcePlay(alSources[i]); @@ -164,13 +167,13 @@ namespace Subsurface.Sounds public static int Loop(Sound sound, int sourceIndex, float volume = 1.0f) { - return Loop(sound,sourceIndex, Vector2.Zero, volume, 0.0f); + return Loop(sound,sourceIndex, Vector2.Zero, volume); } - public static int Loop(Sound sound, int sourceIndex, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f) + public static int Loop(Sound sound, int sourceIndex, Vector2 position, float volume = 1.0f) { if (sourceIndex<1) { - sourceIndex = Play(sound, position, volume, lowPassGain); + sourceIndex = Play(sound, position, volume); if (sourceIndex>0) { AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); @@ -181,8 +184,13 @@ namespace Subsurface.Sounds } else { + UpdateSoundPosition(sourceIndex, position, volume); + + //position /= 1000.0f; + + //OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); - AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); + //AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); ALHelper.Check(); return sourceIndex; } @@ -257,7 +265,7 @@ namespace Subsurface.Sounds { if (ALHelper.Efx.IsInitialized) { - overrideLowPassGain = value; + lowPassHfGain = value; for (int i = 0; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused) @@ -284,7 +292,7 @@ namespace Subsurface.Sounds // } //} - public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f, float lowPassGain = 0.0f) + public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f) { if (sourceIndex < 1) return; @@ -296,7 +304,9 @@ namespace Subsurface.Sounds OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume); OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); - ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain)); + float lowPassGain = lowPassHfGain / Math.Max(position.Length()*5.0f,1.0f); + + ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain); ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId); ALHelper.Check(); } diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 493c0afeb..0598b915f 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -815,9 +815,15 @@ PreserveNewest + + PreserveNewest + PreserveNewest + + PreserveNewest + PreserveNewest @@ -896,6 +902,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Subsurface.csproj.user b/Subsurface/Subsurface.csproj.user index d8060d791..c2dd67340 100644 --- a/Subsurface/Subsurface.csproj.user +++ b/Subsurface/Subsurface.csproj.user @@ -9,7 +9,7 @@ en-US false - ProjectFiles + ShowAllFiles diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 0babd0184..89957f99c 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ