diff --git a/Farseer Physics Engine 3.5/Dynamics/Body.cs b/Farseer Physics Engine 3.5/Dynamics/Body.cs index febc7d8f8..1d48115c3 100644 --- a/Farseer Physics Engine 3.5/Dynamics/Body.cs +++ b/Farseer Physics Engine 3.5/Dynamics/Body.cs @@ -779,6 +779,8 @@ namespace FarseerPhysics.Dynamics /// The world rotation in radians. public void SetTransform(Vector2 position, float rotation) { + Debug.Assert(position.IsValid()); + SetTransform(ref position, rotation); } @@ -823,6 +825,8 @@ namespace FarseerPhysics.Dynamics /// The world position of the point of application. public void ApplyForce(Vector2 force, Vector2 point) { + Debug.Assert(force.IsValid()); + ApplyForce(ref force, ref point); } @@ -841,6 +845,8 @@ namespace FarseerPhysics.Dynamics /// The force. public void ApplyForce(Vector2 force) { + Debug.Assert(force.IsValid()); + ApplyForce(ref force, ref _xf.p); } @@ -898,6 +904,8 @@ namespace FarseerPhysics.Dynamics /// The world impulse vector, usually in N-seconds or kg-m/s. public void ApplyLinearImpulse(Vector2 impulse) { + Debug.Assert(impulse.IsValid()); + ApplyLinearImpulse(ref impulse); } @@ -911,6 +919,8 @@ namespace FarseerPhysics.Dynamics /// The world position of the point of application. public void ApplyLinearImpulse(Vector2 impulse, Vector2 point) { + Debug.Assert(impulse.IsValid()); + ApplyLinearImpulse(ref impulse, ref point); } diff --git a/Subsurface/Content/Items/Tools/plasmaCutter.ogg b/Subsurface/Content/Items/Tools/plasmaCutter.ogg index c7d38dc98..a23c35600 100644 Binary files a/Subsurface/Content/Items/Tools/plasmaCutter.ogg and b/Subsurface/Content/Items/Tools/plasmaCutter.ogg differ diff --git a/Subsurface/Content/Items/Tools/weldingTool.ogg b/Subsurface/Content/Items/Tools/weldingTool.ogg index 4e8d70ba1..e6f4b7172 100644 Binary files a/Subsurface/Content/Items/Tools/weldingTool.ogg and b/Subsurface/Content/Items/Tools/weldingTool.ogg differ diff --git a/Subsurface/Content/Items/Weapons/railgunbarrel.png b/Subsurface/Content/Items/Weapons/railgunbarrel.png index 4ab7ed948..85f795ef8 100644 Binary files a/Subsurface/Content/Items/Weapons/railgunbarrel.png and b/Subsurface/Content/Items/Weapons/railgunbarrel.png differ diff --git a/Subsurface/Content/Sounds/Music/Static Motion.ogg b/Subsurface/Content/Sounds/Music/Static Motion.ogg new file mode 100644 index 000000000..58e875f87 Binary files /dev/null and b/Subsurface/Content/Sounds/Music/Static Motion.ogg differ diff --git a/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg b/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg new file mode 100644 index 000000000..279894262 Binary files /dev/null and b/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg differ diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml index 11b40db4f..95075bb76 100644 --- a/Subsurface/Content/Sounds/sounds.xml +++ b/Subsurface/Content/Sounds/sounds.xml @@ -32,6 +32,8 @@ - + + + \ No newline at end of file diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index 0a814d173..71c5a45a4 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -48,7 +48,7 @@ namespace Subsurface worldView = new Rectangle( (int)(center.X - newWidth / 2.0f), - (int)(center.Y - newHeight / 2.0f), + (int)(center.Y + newHeight / 2.0f), (int)newWidth, (int)newHeight); diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index fc5d47fca..6c1547203 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -312,8 +312,12 @@ namespace Subsurface //limb.body.ApplyTorque(limb.Mass * -20.0f * character.animController.Dir * dir); } - limb.body.ApplyLinearImpulse(limb.Mass * 10.0f * - Vector2.Normalize(attackPosition - limb.SimPosition)); + Vector2 diff = attackPosition - limb.SimPosition; + if (diff.LengthSquared() > 0.00001f) + { + limb.body.ApplyLinearImpulse(limb.Mass * 10.0f * + Vector2.Normalize(attackPosition - limb.SimPosition)); + } steeringManager.SteeringSeek(attackPosition + (limb.SimPosition-Position), 5.0f); diff --git a/Subsurface/Source/Characters/AI/SteeringManager.cs b/Subsurface/Source/Characters/AI/SteeringManager.cs index 23e96941d..f63e29f44 100644 --- a/Subsurface/Source/Characters/AI/SteeringManager.cs +++ b/Subsurface/Source/Characters/AI/SteeringManager.cs @@ -64,6 +64,9 @@ namespace Subsurface private Vector2 DoSteeringSeek(Vector2 target, float speed = 1.0f) { Vector2 targetVel = target - host.Position; + + if (targetVel.LengthSquared() < 0.00001f) return Vector2.Zero; + targetVel = Vector2.Normalize(targetVel) * speed; Vector2 newSteering = targetVel - host.Steering; diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 715a95443..4fd273ae8 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -862,7 +862,6 @@ namespace Subsurface { sounds[i].Play(1.0f, 2000.0f, AnimController.Limbs[0].body.FarseerBody); - Debug.WriteLine("playing: " + sounds[i]); return; } n++; @@ -944,7 +943,7 @@ namespace Subsurface { joint.LimitEnabled = false; } - Kill(true); + Kill(); } private IEnumerable DeathAnim(Camera cam) @@ -955,6 +954,7 @@ namespace Subsurface float timer = 0.0f; Color prevAmbientLight = GameMain.LightManager.AmbientLight; + Color darkLight = new Color(0.2f,0.2f,0.2f, 1.0f); while (timer < dimDuration) { @@ -968,7 +968,7 @@ namespace Subsurface cam.OffsetAmount = 0.0f; } - GameMain.LightManager.AmbientLight = Color.Lerp(prevAmbientLight, Color.DarkGray, timer / dimDuration); + GameMain.LightManager.AmbientLight = Color.Lerp(prevAmbientLight, darkLight, timer / dimDuration); } yield return CoroutineStatus.Running; @@ -984,7 +984,7 @@ namespace Subsurface { lerpLightBack = Math.Min(lerpLightBack + 0.05f, 1.0f); - GameMain.LightManager.AmbientLight = Color.Lerp(Color.DarkGray, prevAmbientLight, lerpLightBack); + GameMain.LightManager.AmbientLight = Color.Lerp(darkLight, prevAmbientLight, lerpLightBack); yield return CoroutineStatus.Running; } @@ -996,17 +996,7 @@ namespace Subsurface if (isDead) return; //if the game is run by a client, characters are only killed when the server says so - if (GameMain.Client != null) - { - if (networkMessage) - { - new NetworkEvent(NetworkEventType.KillCharacter, ID, true); - } - else - { - return; - } - } + if (GameMain.Client != null && GameMain.Server==null && !networkMessage) return; CoroutineManager.StartCoroutine(DeathAnim(GameMain.GameScreen.Cam)); @@ -1052,7 +1042,6 @@ namespace Subsurface if (type == NetworkEventType.PickItem) { message.Write((int)data); - Debug.WriteLine("pickitem"); return; } else if (type == NetworkEventType.KillCharacter) @@ -1140,7 +1129,6 @@ namespace Subsurface Item item = FindEntityByID(itemId) as Item; if (item != null) { - Debug.WriteLine("pickitem "+itemId ); item.Pick(this); } @@ -1151,7 +1139,7 @@ namespace Subsurface Kill(true); if (GameMain.NetworkMember != null && controlled == this) { - GameMain.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); + GameMain.NetworkMember.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); GameMain.LightManager.LosEnabled = false; } return; diff --git a/Subsurface/Source/Characters/FishAnimController.cs b/Subsurface/Source/Characters/FishAnimController.cs index dda729e26..096a9193b 100644 --- a/Subsurface/Source/Characters/FishAnimController.cs +++ b/Subsurface/Source/Characters/FishAnimController.cs @@ -132,7 +132,7 @@ namespace Subsurface void UpdateSineAnim(float deltaTime) { movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f); - if (movement == Vector2.Zero) return; + if (movement.LengthSquared() < 0.00001f) return; if (!inWater) movement.Y = Math.Min(0.0f, movement.Y); diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index 6a9b616d8..1cbd69add 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -401,14 +401,14 @@ namespace Subsurface } } - for (int i = 0; i < 2; i++) - { - Limb leg = (i == 0) ? rightFoot : leftFoot; + //for (int i = 0; i < 2; i++) + //{ + // Limb leg = (i == 0) ? rightLeg : leftLeg; - if (leg.SimPosition.Y < torso.SimPosition.Y) continue; + // if (leg.SimPosition.Y < waist.SimPosition.Y) continue; - leg.body.ApplyTorque(-Dir * leg.Mass * 20.0f); - } + // //leg.body.ApplyTorque(Dir * leg.Mass * 50.0f); + //} } @@ -416,27 +416,17 @@ namespace Subsurface { movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp); - if (inWater && movement != Vector2.Zero) + if (inWater && movement.LengthSquared()>0.00001f) { movement = Vector2.Normalize(movement); } - - if (!MathUtils.IsValid(movement)) - { - int a = 1; - } - + RefLimb.pullJoint.Enabled = true; RefLimb.pullJoint.WorldAnchorB = RefLimb.SimPosition + movement*0.15f; RefLimb.body.SmoothRotate(0.0f); - if (!MathUtils.IsValid(RefLimb.body.SimPosition)) - { - int a = 1; - } - foreach (Limb l in Limbs) { if (l==RefLimb) continue; diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 0bae0cea9..10f5ec551 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -240,7 +240,7 @@ namespace Subsurface.Items.Components { if (!isStuck) { - OpenState += deltaTime * ((isOpen) ? 2.0f : -1.0f); + OpenState += deltaTime * ((isOpen) ? 2.0f : -2.0f); LinkedGap.Open = openState; } diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index 582d9d586..0f834c0b5 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -221,7 +221,7 @@ namespace Subsurface.Items.Components AnimController ac = picker.AnimController; - //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; + //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.GetInputState(InputType.SecondaryHeld), holdAngle); } diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 7a1e7134e..b6b55e8db 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -111,11 +111,11 @@ namespace Subsurface.Items.Components Vector2 targetPosition = item.body.SimPosition; //targetPosition = targetPosition.X, -targetPosition.Y); - float degreeOfSuccess = DegreeOfSuccess(character); + float degreeOfSuccess = DegreeOfSuccess(character)/100.0f; - if (Rand.Range(0.0f, 1.0f) > degreeOfSuccess * degreeOfSuccess) + if (Rand.Range(0.0f, 0.5f) > degreeOfSuccess) { - ApplyStatusEffects(ActionType.OnFailure, 1.0f, character); + ApplyStatusEffects(ActionType.OnFailure, deltaTime, character); return false; } @@ -147,7 +147,7 @@ namespace Subsurface.Items.Components targetStructure.HighLightSection(sectionIndex); - targetStructure.AddDamage(sectionIndex, -structureFixAmount); + targetStructure.AddDamage(sectionIndex, -structureFixAmount*degreeOfSuccess); //if the next section is small enough, apply the effect to it as well //(to make it easier to fix a small "left-over" section) @@ -155,7 +155,7 @@ namespace Subsurface.Items.Components if (nextSectionLength > 0 && nextSectionLength < Structure.wallSectionSize * 0.3f) { targetStructure.HighLightSection(sectionIndex + 1); - targetStructure.AddDamage(sectionIndex + 1, -structureFixAmount); + targetStructure.AddDamage(sectionIndex + 1, -structureFixAmount * degreeOfSuccess); } } @@ -163,7 +163,7 @@ namespace Subsurface.Items.Components { if (character.GetInputState(InputType.SecondaryHeld)) { - targetLimb.character.Health += limbFixAmount; + targetLimb.character.Health += limbFixAmount * degreeOfSuccess; //isActive = true; } } diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index fd80536fc..2d4da696e 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -277,12 +277,12 @@ namespace Subsurface.Items.Components private int loopingSoundIndex; public void PlaySound(ActionType type, Vector2 position) { + List matchingSounds = sounds.FindAll(x => x.Type == type); + if (matchingSounds.Count == 0) return; + ItemSound itemSound = null; if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex)) { - List matchingSounds = sounds.FindAll(x => x.Type == type); - if (matchingSounds.Count == 0) return; - int index = Rand.Int(matchingSounds.Count); itemSound = matchingSounds[index]; } diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 2179c60b8..eb1864165 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -151,7 +151,6 @@ namespace Subsurface.Items.Components } } - item.body.FarseerBody.OnCollision -= OnProjectileCollision; item.body.FarseerBody.IsBullet = false; @@ -181,17 +180,21 @@ namespace Subsurface.Items.Components } var containedItems = item.ContainedItems; - if (containedItems == null) return true; - foreach (Item contained in containedItems) + if (containedItems != null) { - if (contained.body != null) + foreach (Item contained in containedItems) { - contained.SetTransform(item.SimPosition, contained.body.Rotation); + if (contained.body != null) + { + contained.SetTransform(item.SimPosition, contained.body.Rotation); + } + contained.Condition = 0.0f; } - contained.Condition = 0.0f; } - return false; + return (f2.CollisionCategories != Physics.CollisionCharacter); + + //return false; } private bool StickToTarget(Body targetBody, Vector2 axis) diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index 7a3c6a468..e9d83d45b 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -108,7 +108,12 @@ namespace Subsurface protected void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true) { - if (item.inventory != null && removeItem) item.inventory.RemoveItem(item); + if (item.inventory != null && removeItem) + { + item.Drop(); + item.inventory.RemoveItem(item); + } + items[i] = item; item.inventory = this; if (item.body!=null) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 8a80ce6c7..367a376a9 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -482,7 +482,11 @@ namespace Subsurface { if (ic.Parent != null) ic.IsActive = ic.Parent.IsActive; - if (ic.WasUsed) ic.StopSounds(ActionType.OnUse); + if (!ic.WasUsed) + { + ic.StopSounds(ActionType.OnUse); + } + ic.WasUsed = false; if (!ic.IsActive) continue; @@ -861,8 +865,8 @@ namespace Subsurface { ic.WasUsed = true; - ic.PlaySound(ActionType.OnUse, Position); - + ic.PlaySound(ActionType.OnUse, body==null ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition)); + ic.ApplyStatusEffects(ActionType.OnUse, deltaTime, character); if (ic.DeleteOnUse) remove = true; diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index d04cba010..d35d0d4ba 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -85,30 +85,7 @@ namespace Subsurface if (attack.GetStructureDamage(1.0f) > 0.0f) { - List structureList = new List(); - - float dist = 600.0f; - foreach (MapEntity entity in MapEntity.mapEntityList) - { - Structure structure = entity as Structure; - if (structure == null) continue; - - if (structure.HasBody && - !structure.IsPlatform && - Vector2.Distance(structure.Position, displayPosition) < dist*3.0f) - { - structureList.Add(structure); - } - } - - foreach (Structure structure in structureList) - { - for (int i = 0; i < structure.SectionCount; i++) - { - float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i), displayPosition) / displayRange); - if (distFactor > 0.0f) structure.AddDamage(i, attack.GetStructureDamage(1.0f)*distFactor); - } - } + RangedStructureDamage(displayPosition, displayRange, attack.GetStructureDamage(1.0f)); } if (force == 0.0f && attack.Stun == 0.0f && attack.GetDamage(1.0f) == 0.0f) return; @@ -154,5 +131,34 @@ namespace Subsurface yield return CoroutineStatus.Success; } + + public static void RangedStructureDamage(Vector2 displayPosition, float displayRange, float damage) + { + List structureList = new List(); + + + float dist = 600.0f; + foreach (MapEntity entity in MapEntity.mapEntityList) + { + Structure structure = entity as Structure; + if (structure == null) continue; + + if (structure.HasBody && + !structure.IsPlatform && + Vector2.Distance(structure.Position, displayPosition) < dist * 3.0f) + { + structureList.Add(structure); + } + } + + foreach (Structure structure in structureList) + { + for (int i = 0; i < structure.SectionCount; i++) + { + float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i), displayPosition) / displayRange); + if (distFactor > 0.0f) structure.AddDamage(i, damage * distFactor); + } + } + } } } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 4c41965d6..9ed1a8c4d 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -222,7 +222,7 @@ namespace Subsurface for (int i = 0; i < waveY.Length; i++) { float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i])); - if (maxDelta > Rand.Range(0.2f,10.0f)) + if (maxDelta > Rand.Range(1.0f,10.0f)) { GameMain.ParticleManager.CreateParticle("mist", new Vector2(rect.X + WaveWidth * i,surface + waveY[i]), diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 808dd31f3..cbff2b873 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -388,7 +388,9 @@ namespace Subsurface { if (!prefab.HasBody || prefab.IsPlatform) return; - if (GameMain.Client==null) + if (sectionIndex < 0 || sectionIndex > sections.Length - 1) return; + + if (GameMain.Client == null) SetDamage(sectionIndex, sections[sectionIndex].damage + damage); } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 0f7c23b1b..90344ebef 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -314,21 +314,21 @@ namespace Subsurface return closestBody; } - public static Body PickBody(Vector2 point) - { - Body foundBody = null; - AABB aabb = new AABB(point, point); + //public static Body PickBody(Vector2 point) + //{ + // Body foundBody = null; + // AABB aabb = new AABB(point, point); - GameMain.World.QueryAABB(p => - { - foundBody = p.Body; + // GameMain.World.QueryAABB(p => + // { + // foundBody = p.Body; - return true; + // return true; - }, ref aabb); + // }, ref aabb); - return foundBody; - } + // return foundBody; + //} //public static bool InsideWall(Vector2 point) //{ @@ -348,7 +348,7 @@ namespace Subsurface { if (Level.Loaded == null) return; - subBody.Update(deltaTime); + if (subBody!=null) subBody.Update(deltaTime); } public void ApplyForce(Vector2 force) diff --git a/Subsurface/Source/Map/SubmarineHull.cs b/Subsurface/Source/Map/SubmarineHull.cs index 1da8249aa..b313f4068 100644 --- a/Subsurface/Source/Map/SubmarineHull.cs +++ b/Subsurface/Source/Map/SubmarineHull.cs @@ -16,7 +16,11 @@ namespace Subsurface { class SubmarineBody { + //structure damage = impact * damageMultiplier + const float DamageMultiplier = 50.0f; + const float Friction = 0.2f, Restitution = 0.0f; + public List HullVertices { get; @@ -30,6 +34,11 @@ namespace Subsurface private Vector2 speed; private Vector2 targetPosition; + + float mass = 10000.0f; + + private Vector2? lastContactPoint; + private VoronoiCell lastContactCell; public Rectangle Borders { @@ -103,7 +112,7 @@ namespace Subsurface body.SleepingAllowed = false; body.IgnoreGravity = true; body.OnCollision += OnCollision; - //body.OnSeparation += OnSeparation; + body.OnSeparation += OnSeparation; body.UserData = this; } @@ -163,7 +172,12 @@ namespace Subsurface public void Update(float deltaTime) { - Vector2 translateAmount = speed * deltaTime; + if (body.Position!=Vector2.Zero) + { + UpdateColliding(); + } + + Vector2 translateAmount = speed * deltaTime; translateAmount += ConvertUnits.ToDisplayUnits(body.Position) * collisionRigidness; if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, sub.Position) > 50.0f) @@ -181,14 +195,14 @@ namespace Subsurface Vector2 totalForce = CalculateBuoyancy(); - float dragCoefficient = 0.00001f; - - float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length(); - float drag = speedLength * speedLength * dragCoefficient * mass; - - if (speed != Vector2.Zero) + if (speed.LengthSquared() > 0.000001f) { - totalForce += -Vector2.Normalize(speed) * drag; + float dragCoefficient = 0.00001f; + + float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length(); + float drag = speedLength * speedLength * dragCoefficient * mass; + + totalForce += -Vector2.Normalize(speed) * drag; } ApplyForce(totalForce); @@ -215,35 +229,39 @@ namespace Subsurface float neutralPercentage = 0.07f; - float buoyancy = neutralPercentage - waterPercentage; + float buoyancy = Math.Max(neutralPercentage - waterPercentage, -neutralPercentage*2.0f); buoyancy *= mass * 30.0f; return new Vector2(0.0f, buoyancy); } - float mass = 10000.0f; public void ApplyForce(Vector2 force) { - speed += force / mass; + Speed += force / mass; } - public bool OnCollision(Fixture f1, Fixture f2, Contact contact) + private void UpdateColliding() { - VoronoiCell cell = f2.Body.UserData as VoronoiCell; - if (cell == null) - { - speed = new Vector2(speed.X * 0.9f, speed.Y * 0.2f); - return true; - } + if (body.Position.LengthSquared()<0.00001f) return; - Vector2 normal = contact.Manifold.LocalNormal; - Vector2 simSpeed = ConvertUnits.ToSimUnits(speed) + body.LinearVelocity; - float impact = Vector2.Dot(simSpeed, normal); + Vector2 normal = Vector2.Normalize(body.Position); + Vector2 simSpeed = ConvertUnits.ToSimUnits(speed); - Vector2 u = Vector2.Dot(simSpeed, -normal) * -normal; - Vector2 w = simSpeed - u; + float impact = Vector2.Dot(simSpeed, -normal); - Vector2 limbForce = normal * impact; + if (impact < 0.0f) return; + + Vector2 u = Vector2.Dot(simSpeed, -normal) * normal; + Vector2 w = (simSpeed + u); + + speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution); + + if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return; + + AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint)); + GameMain.GameScreen.Cam.Shake = impact * 2.0f; + + Vector2 limbForce = -normal * impact*0.5f; float length = limbForce.Length(); if (length > 10.0f) limbForce = (limbForce / length) * 10.0f; @@ -261,66 +279,125 @@ namespace Subsurface } } - if (impact >= 1.0f) - { - AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, cell.body); + Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint), impact*50.0f, impact*DamageMultiplier); - FarseerPhysics.Common.FixedArray2 worldPoints; - contact.GetWorldManifold(out normal, out worldPoints); + //Body wallBody = Submarine.PickBody( + // (Vector2)lastContactPoint - body.Position, + // (Vector2)lastContactPoint + body.Position * 10.0f, + // new List() { lastContactCell.body }); - AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(worldPoints[0])); + //if (wallBody == null || wallBody.UserData == null) return; + + //var damageable = wallBody.UserData as IDamageable; + //Structure structure = wallBody.UserData as Structure; - GameMain.GameScreen.Cam.Shake = impact * 2.0f; - } + //if (structure == null) return; + + //int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)); - System.Diagnostics.Debug.WriteLine("IMPACT: " + impact + " normal: " + normal + " simspeed: " + simSpeed + " u: " + u + " w: " + w); - if (impact < 3.0f) - { - 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; - - return true; + //for (int i = sectionIndex - (int)(impact / 5.0f); i < sectionIndex + (int)(impact / 5.0f); i++) + //{ + // structure.AddDamage(i, impact * DamageMultiplier); + //} } - //public void OnSeparation(Fixture f1, Fixture f2) - //{ - // collidingCell = null; - //} + public bool OnCollision(Fixture f1, Fixture f2, Contact contact) + { + VoronoiCell cell = f2.Body.UserData as VoronoiCell; + if (cell == null) + { + lastContactCell = null; + lastContactPoint = null; + return true; + } + + lastContactCell = cell; + + Vector2 normal; + FarseerPhysics.Common.FixedArray2 worldPoints; + contact.GetWorldManifold(out normal, out worldPoints); + + lastContactPoint = worldPoints[0]; + + return true; + + //Vector2 normal = contact.Manifold.LocalNormal; + //Vector2 simSpeed = ConvertUnits.ToSimUnits(speed); + //float impact = Vector2.Dot(-simSpeed, normal); + + ////Vector2 u = Vector2.Dot(simSpeed, -normal) * -normal; + ////Vector2 w = simSpeed - u; + + //Vector2 limbForce = normal * impact; + + ////float length = limbForce.Length(); + ////if (length > 10.0f) limbForce = (limbForce / length) * 10.0f; + + ////foreach (Character c in Character.CharacterList) + ////{ + //// if (c.AnimController.CurrentHull == null) continue; + + //// if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f; + + //// foreach (Limb limb in c.AnimController.Limbs) + //// { + //// if (c.AnimController.LowestLimb == limb) continue; + //// limb.body.ApplyLinearImpulse(limb.Mass * limbForce); + //// } + ////} + + //System.Diagnostics.Debug.WriteLine("IMPACT: " + impact + " normal: " + normal + " simspeed: " + simSpeed); + //if (impact > 1.0f) + //{ + + // contact.GetWorldManifold(out normal, out worldPoints); + + // lastContactPoint = worldPoints[0]; + + // AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(worldPoints[0])); + + // GameMain.GameScreen.Cam.Shake = impact * 2.0f; + + // //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; + + //return true; + } + + public void OnSeparation(Fixture f1, Fixture f2) + { + lastContactPoint = null; + } } } diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index 6a7a3c99d..dfaac9fb6 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -216,6 +216,12 @@ namespace Subsurface.Networking inGameHUD.Update(deltaTime); if (crewFrameOpen) crewFrame.Update(deltaTime); + + if (Character.Controlled != null && Character.Controlled.IsDead) + { + GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; + GameMain.LightManager.LosEnabled = false; + } } if (PlayerInput.KeyHit(Keys.Tab)) diff --git a/Subsurface/Source/Particles/ParticleManager.cs b/Subsurface/Source/Particles/ParticleManager.cs index 865184618..08291162b 100644 --- a/Subsurface/Source/Particles/ParticleManager.cs +++ b/Subsurface/Source/Particles/ParticleManager.cs @@ -54,8 +54,8 @@ 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 (!cam.WorldView.Contains(position)) return null; + if (!Submarine.RectContains(cam.WorldView, position)) return null; + //if (!cam.WorldView.Contains(position)) return null; if (particleCount >= MaxParticles) return null; diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index af6d5b60d..58f5cdfd2 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -47,6 +47,13 @@ namespace Subsurface entity.IsHighlighted = false; } + public override void Deselect() + { + base.Deselect(); + + Sounds.SoundManager.LowPassHFGain = 1.0f; + } + /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. @@ -60,16 +67,16 @@ namespace Subsurface AmbientSoundManager.Update(); - //if (Game1.GameSession != null && Game1.GameSession.Level != null) - //{ - // Vector2 targetMovement = Vector2.Zero; - // if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f; - // if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f; - // if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f; - // if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f; + if (GameMain.GameSession != null && GameMain.GameSession.Level != null) + { + Vector2 targetMovement = Vector2.Zero; + if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f; + if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f; + if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f; + if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f; - // Game1.GameSession.Submarine.ApplyForce(targetMovement * 100000.0f); - //} + GameMain.GameSession.Submarine.ApplyForce(targetMovement * 100000.0f); + } if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime); //EventManager.Update(gameTime); @@ -99,7 +106,7 @@ namespace Subsurface Ragdoll.UpdateAll(cam, (float)Physics.step); - if (GameMain.GameSession != null && GameMain.GameSession.Level != null) + if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine!=null) { GameMain.GameSession.Submarine.Update((float)Physics.step); } diff --git a/Subsurface/Source/Sounds/OggStream.cs b/Subsurface/Source/Sounds/OggStream.cs index 8e120144f..8050ecc4e 100644 --- a/Subsurface/Source/Sounds/OggStream.cs +++ b/Subsurface/Source/Sounds/OggStream.cs @@ -47,10 +47,14 @@ namespace Subsurface.Sounds public static void Check() { +#if !DEBUG + return; +#endif + ALError error; if ((error = AL.GetError()) != ALError.NoError) { - DebugConsole.ThrowError(AL.GetErrorString(error)); + DebugConsole.ThrowError("OpenAL error: "+AL.GetErrorString(error)); } } } diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index f99b9c715..cedb9ebbb 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -77,6 +77,8 @@ namespace Subsurface public int Play(float volume = 1.0f) { + if (volume <= 0.0f) return -1; + alSourceId = SoundManager.Play(this, volume); return alSourceId; } @@ -90,7 +92,9 @@ namespace Subsurface Vector2 relativePos = GetRelativePosition(position); float volume = GetVolume(relativePos, range, baseVolume); - alSourceId = SoundManager.Play(this, relativePos, volume, volume); + if (volume <= 0.0f) return -1; + + alSourceId = SoundManager.Play(this, relativePos, volume); return alSourceId; diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 6caac3dd5..06cf5f7ff 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -44,7 +44,7 @@ namespace Subsurface.Sounds //alFilters.Add(alFilterId); ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilteri.FilterType, (int)OpenTK.Audio.OpenAL.EfxFilterType.Lowpass); - //LowPassHFGain = 1; + LowPassHFGain = 1.0f; } @@ -115,7 +115,7 @@ namespace Subsurface.Sounds //return -1; } - public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f) + public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f, bool loop=false) { //for (int i = 2; i < DefaultSourceCount; i++) //{ @@ -137,26 +137,19 @@ namespace Subsurface.Sounds // position /= 1000.0f; alBuffers[i] = sound.AlBufferId; - OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, false); + OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, loop); OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, sound.AlBufferId); 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]); + + + //sound.sourceIndex = i; return i; @@ -171,14 +164,19 @@ namespace Subsurface.Sounds } public static int Loop(Sound sound, int sourceIndex, Vector2 position, float volume = 1.0f) { + if (!MathUtils.IsValid(volume)) + { + volume = 0.0f; + } + if (sourceIndex<1) { - sourceIndex = Play(sound, position, volume); - if (sourceIndex>0) - { - AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); - AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); - } + sourceIndex = Play(sound, position, volume, 0.0f, true); + //if (sourceIndex>0) + //{ + // AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); + // AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); + //} ALHelper.Check(); return sourceIndex; } @@ -233,7 +231,7 @@ namespace Subsurface.Sounds public static void Stop(int sourceIndex) { if (sourceIndex < 1) return; - + var state = AL.GetSourceState(alSources[sourceIndex]); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { @@ -296,19 +294,25 @@ namespace Subsurface.Sounds { if (sourceIndex < 1) return; + if (!MathUtils.IsValid(position)) + { + position = Vector2.Zero; + } + //Resume(sourceIndex); position/= 1000.0f; - //System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset); 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); - float lowPassGain = lowPassHfGain / Math.Max(position.Length()*5.0f,1.0f); + 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(); + + } public static OggStream StartStream(string file, float volume = 1.0f) diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 0598b915f..ff09d1ac4 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -911,6 +911,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 89957f99c..1a110377f 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ