diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 7fad6b22c..b8a2c539b 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -591,6 +591,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Characters/Coelanth/coelanth.xml b/Subsurface/Content/Characters/Coelanth/coelanth.xml index 66786ce8e..db5ad56dd 100644 --- a/Subsurface/Content/Characters/Coelanth/coelanth.xml +++ b/Subsurface/Content/Characters/Coelanth/coelanth.xml @@ -15,7 +15,7 @@ - + diff --git a/Subsurface/Content/Map/iceWall.png b/Subsurface/Content/Map/iceWall.png new file mode 100644 index 000000000..e5ad5fd10 Binary files /dev/null and b/Subsurface/Content/Map/iceWall.png differ diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index 2aac86935..e4d4e20bf 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -174,6 +174,11 @@ namespace Barotrauma if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed; if (PlayerInput.KeyDown(Keys.W)) moveCam.Y += moveSpeed; + if (Submarine.Loaded!=null) + { + moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity*deltaTime); + } + moveCam = moveCam * deltaTime * 60.0f; } diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 1c1b00e1a..85016b0c9 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -192,6 +192,7 @@ namespace Barotrauma raycastTimer = RaycastInterval; } + steeringManager.SteeringAvoid(deltaTime, 1.0f); steeringManager.SteeringSeek(attackSimPosition); //check if any of the limbs is close enough to attack the target @@ -322,7 +323,7 @@ namespace Barotrauma attackTimer += deltaTime; limb.body.ApplyTorque(limb.Mass * 50.0f * Character.AnimController.Dir * dir); - limb.attack.DoDamage(Character, damageTarget, limb.SimPosition, deltaTime, (limb.soundTimer <= 0.0f)); + limb.attack.DoDamage(Character, damageTarget, limb.WorldPosition, deltaTime, (limb.soundTimer <= 0.0f)); limb.soundTimer = Limb.SoundInterval; } diff --git a/Subsurface/Source/Characters/AI/PathFinder.cs b/Subsurface/Source/Characters/AI/PathFinder.cs index 9f8b8cb5d..d6ccf8b9e 100644 --- a/Subsurface/Source/Characters/AI/PathFinder.cs +++ b/Subsurface/Source/Characters/AI/PathFinder.cs @@ -218,7 +218,7 @@ namespace Barotrauma //a node that hasn't been searched yet if (nextNode.state==0) { - nextNode.H = Vector2.DistanceSquared(nextNode.Position,end.Position); + nextNode.H = Vector2.Distance(nextNode.Position,end.Position); if (GetNodePenalty != null) { diff --git a/Subsurface/Source/Characters/AI/SteeringManager.cs b/Subsurface/Source/Characters/AI/SteeringManager.cs index 92962fbc6..d523e492e 100644 --- a/Subsurface/Source/Characters/AI/SteeringManager.cs +++ b/Subsurface/Source/Characters/AI/SteeringManager.cs @@ -144,11 +144,14 @@ namespace Barotrauma avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - obstaclePosition); } - else + else if (closestBody.UserData is Item) { Item item = closestBody.UserData as Item; - if (item != null) avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition); - + avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition); + } + else + { + avoidSteering = Vector2.Normalize(host.SimPosition - Submarine.LastPickedPosition); } } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 0f5432c86..513b08e6a 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -388,14 +388,14 @@ namespace Barotrauma float volume = stairs == null ? impact/5.0f : impact; volume= Math.Min(impact, 1.0f); - if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.body.FarseerBody); + if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition); if (impact > l.impactTolerance) { character.Health -= (impact - l.impactTolerance * 0.1f); strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance); - SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody); + SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body); if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact; } diff --git a/Subsurface/Source/Characters/Attack.cs b/Subsurface/Source/Characters/Attack.cs index bd59c5923..530981cc7 100644 --- a/Subsurface/Source/Characters/Attack.cs +++ b/Subsurface/Source/Characters/Attack.cs @@ -122,7 +122,7 @@ namespace Barotrauma } - public AttackResult DoDamage(IDamageable attacker, IDamageable target, Vector2 position, float deltaTime, bool playSound = true) + public AttackResult DoDamage(IDamageable attacker, IDamageable target, Vector2 worldPosition, float deltaTime, bool playSound = true) { float damageAmount = 0.0f; //DamageSoundType damageSoundType = DamageSoundType.None; @@ -139,15 +139,15 @@ namespace Barotrauma if (particleEmitterPrefab != null) { - particleEmitterPrefab.Emit(position); + particleEmitterPrefab.Emit(worldPosition); } if (sound != null) { - sound.Play(1.0f, 500.0f, position); + sound.Play(1.0f, 500.0f, worldPosition); } - return target.AddDamage(attacker, position, this, deltaTime, playSound); + return target.AddDamage(attacker, worldPosition, this, deltaTime, playSound); } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index e2cf4a5b7..f91e1a1df 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -448,7 +448,7 @@ namespace Barotrauma } } - AnimController.FindHull(null, false); + AnimController.FindHull(null); if (AnimController.CurrentHull != null) Submarine = AnimController.CurrentHull.Submarine; CharacterList.Add(this); @@ -741,7 +741,7 @@ namespace Barotrauma { Limb head = AnimController.GetLimb(LimbType.Head); - Lights.LightManager.ViewPos = WorldPosition; + Lights.LightManager.ViewPos = DrawPosition; if (!DisableControls) { @@ -1010,7 +1010,7 @@ namespace Barotrauma AnimController.DebugDraw(spriteBatch); } - Vector2 healthBarPos = new Vector2(WorldPosition.X - 50, -WorldPosition.Y - 100.0f); + Vector2 healthBarPos = new Vector2(DrawPosition.X - 50, -DrawPosition.Y - 100.0f); GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false); GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true); } @@ -1028,17 +1028,16 @@ namespace Barotrauma if (soundStates[i] != state) continue; if (n == selectedSound && sounds[i]!=null) { - sounds[i].Play(1.0f, 2000.0f, - AnimController.Limbs[0].body.FarseerBody); + sounds[i].Play(1.0f, 2000.0f, AnimController.Limbs[0].WorldPosition); return; } n++; } } - public virtual AttackResult AddDamage(IDamageable attacker, Vector2 simPosition, Attack attack, float deltaTime, bool playSound = false) + public virtual AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false) { - return AddDamage(simPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound); + return AddDamage(worldPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound); } public AttackResult AddDamage(Vector2 simPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound) @@ -1103,7 +1102,7 @@ namespace Barotrauma // limb.Damage = 100.0f; } - SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body.FarseerBody); + SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body); for (int i = 0; i < 10; i++) { diff --git a/Subsurface/Source/Characters/StatusEffect.cs b/Subsurface/Source/Characters/StatusEffect.cs index a8826ac87..0a0d3f6da 100644 --- a/Subsurface/Source/Characters/StatusEffect.cs +++ b/Subsurface/Source/Characters/StatusEffect.cs @@ -215,7 +215,7 @@ namespace Barotrauma if (explosion != null) explosion.Explode(entity.WorldPosition); if (Fire) new FireSource(ConvertUnits.ToDisplayUnits(entity.SimPosition)); - if (sound != null) sound.Play(1.0f, 1000.0f, ConvertUnits.ToDisplayUnits(entity.SimPosition)); + if (sound != null) sound.Play(1.0f, 1000.0f, entity.WorldPosition); for (int i = 0; i < propertyNames.Count(); i++) { diff --git a/Subsurface/Source/CoroutineManager.cs b/Subsurface/Source/CoroutineManager.cs index a9bb06ee5..861124e70 100644 --- a/Subsurface/Source/CoroutineManager.cs +++ b/Subsurface/Source/CoroutineManager.cs @@ -66,18 +66,18 @@ namespace Barotrauma } } - try - { + //try + //{ Coroutines[i].MoveNext(); - } +// } - catch (Exception e) - { -#if DEBUG - DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message); -#endif - Coroutines.RemoveAt(i); - } +// catch (Exception e) +// { +//#if DEBUG +// DebugConsole.ThrowError("Coroutine " + Coroutines[i] + " threw an exception: " + e.Message); +//#endif +// Coroutines.RemoveAt(i); +// } } } diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index b0d7d1ec3..7f94e35ab 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -287,6 +287,9 @@ namespace Barotrauma commands[1] = commands[1].ToLower(); Character.Controlled = Character.CharacterList.Find(c => !c.IsNetworkPlayer && c.Name.ToLower() == commands[1]); break; + case "godmode": + Submarine.Loaded.GodMode = !Submarine.Loaded.GodMode; + break; case "heal": if (Character.Controlled != null) { diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index 3c0c51a56..06acb234f 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -113,7 +113,7 @@ namespace Barotrauma { guiFrame.Update(deltaTime); - if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.I)) + if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.C)) { commander.ToggleGUIFrame(); } diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index fb23a0644..016de1795 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -262,7 +262,7 @@ namespace Barotrauma.Items.Components if (Math.Sign(l.SimPosition.X - item.SimPosition.X) != dir) { l.body.SetTransform(new Vector2(item.SimPosition.X + dir * simSize.X*1.2f, item.SimPosition.Y), l.body.Rotation); - SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 1.0f, l.body.FarseerBody); + SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 1.0f, l.body); //c.AddDamage(item.SimPosition, DamageType.Blunt, 1.0f, 0.0f, 0.0f, true); l.body.ApplyLinearImpulse(new Vector2(dir * 0.5f, isOpen ? 0.0f : -1.0f)); @@ -358,7 +358,7 @@ namespace Barotrauma.Items.Components else if (connection.Name == "set_state") { bool newState = (signal!="0"); - if (isOpen!=newState) PlaySound(ActionType.OnUse, item.Position); + if (isOpen!=newState) PlaySound(ActionType.OnUse, item.WorldPosition); isOpen = newState; } diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index 3ab8b457b..6fda8667c 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -236,6 +236,8 @@ namespace Barotrauma.Items.Components AnimController ac = picker.AnimController; + item.Submarine = picker.Submarine; + //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); diff --git a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs index e4252a6cd..b06348507 100644 --- a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -194,7 +194,7 @@ namespace Barotrauma.Items.Components if (target == null) return false; - if (attack!=null) attack.DoDamage(user, target, item.Position, 1.0f); + if (attack!=null) attack.DoDamage(user, target, item.WorldPosition, 1.0f); RestoreCollision(); hitting = false; diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 7476bc20c..90658eb4a 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -322,6 +322,8 @@ namespace Barotrauma.Items.Components if (itemSound.Loop) { loopingSound = itemSound; + + loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range); } else { diff --git a/Subsurface/Source/Items/Components/ItemContainer.cs b/Subsurface/Source/Items/Components/ItemContainer.cs index d2a9c716b..777cb1e94 100644 --- a/Subsurface/Source/Items/Components/ItemContainer.cs +++ b/Subsurface/Source/Items/Components/ItemContainer.cs @@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components if (item.body == null) { transformedItemPos = new Vector2(item.Rect.X, item.Rect.Y); - if (item.Submarine != null) transformedItemPos += item.Submarine.Position; + if (item.Submarine != null) transformedItemPos += item.Submarine.DrawPosition; transformedItemPos = transformedItemPos + itemPos; } else diff --git a/Subsurface/Source/Items/Components/ItemLabel.cs b/Subsurface/Source/Items/Components/ItemLabel.cs index 2fca7a515..814db280a 100644 --- a/Subsurface/Source/Items/Components/ItemLabel.cs +++ b/Subsurface/Source/Items/Components/ItemLabel.cs @@ -61,6 +61,7 @@ namespace Barotrauma.Items.Components { base.Draw(spriteBatch, editing); + textBlock.Rect = new Rectangle(item.WorldRect.X, -(item.WorldRect.Y - item.Rect.Height/2), item.Rect.Width, item.Rect.Height); textBlock.Draw(spriteBatch); } } diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs index ea21d683e..ea2d91c34 100644 --- a/Subsurface/Source/Items/Components/Machines/Controller.cs +++ b/Subsurface/Source/Items/Components/Machines/Controller.cs @@ -169,7 +169,7 @@ namespace Barotrauma.Items.Components { item.SendSignal("1", "signal_out"); - PlaySound(ActionType.OnUse, item.Position); + PlaySound(ActionType.OnUse, item.WorldPosition); return true; } diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index ff74c3a86..6018172d8 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -115,162 +115,160 @@ namespace Barotrauma.Items.Components float radius = rect.Width / 2.0f; float simScale = 1.5f; + + if (Level.Loaded != null) + { + List cells = Level.Loaded.GetCells(item.WorldPosition, 7); - return; + foreach (VoronoiCell cell in cells) + { - //if (Level.Loaded != null) - //{ - // List cells = Level.Loaded.GetCells(Submarine.Loaded.Position, 7); + foreach (GraphEdge edge in cell.edges) + { + //if (!edge.isSolid) continue; + float cellDot = Vector2.Dot(cell.Center - item.WorldPosition, (edge.point1 + edge.point2) / 2.0f - cell.Center); + //if (cellDot > 0) continue; - // foreach (VoronoiCell cell in cells) - // { + float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center-item.WorldPosition)); + facingDot = 1.0f;// MathHelper.Clamp(facingDot, -1.0f, 1.0f); - // foreach (GraphEdge edge in cell.edges) - // { - // //if (!edge.isSolid) continue; - // float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center); - // if (cellDot > 0) continue; + Vector2 point1 = (edge.point1); + Vector2 point2 = (edge.point2); - // float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center + Level.Loaded.Position)); - // facingDot = MathHelper.Clamp(facingDot, -1.0f, 1.0f); + float length = (point1 - point2).Length(); + for (float x = 0; x < length; x += Rand.Range(600.0f, 800.0f)) + { + Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x; - // Vector2 point1 = (edge.point1 + Level.Loaded.Position); - // Vector2 point2 = (edge.point2 + Level.Loaded.Position); + float pointDist = Vector2.Distance(item.WorldPosition, point) * displayScale; - // float length = (point1 - point2).Length(); - // for (float x=0; x radius) continue; - // if (pointDist < prevPingRadius || pointDist > pingRadius) continue; + if (pointDist > radius) continue; + if (pointDist < prevPingRadius || pointDist > pingRadius) continue; - // float step = 5.0f * (Math.Abs(facingDot)+1.0f); - // float alpha = Rand.Range(1.5f, 2.0f); - // for (float z = 0; z radius) continue; + foreach (Character c in Character.CharacterList) + { + if (c.AnimController.CurrentHull != null) continue; + + foreach (Limb limb in c.AnimController.Limbs) + { + float pointDist = (limb.WorldPosition - item.WorldPosition).Length() * displayScale; + + if (limb.SimPosition == Vector2.Zero || pointDist > radius) continue; - // if (pointDist > radius) continue; - // if (pointDist > prevPingRadius && pointDist < pingRadius) - // { - // var blip = new RadarBlip(pos - Level.Loaded.Position, 1.0f); - // radarBlips.Add(blip); - // } - // } - //} + if (pointDist > radius) continue; + if (pointDist > prevPingRadius && pointDist < pingRadius) + { + var blip = new RadarBlip(limb.WorldPosition, 1.0f); + radarBlips.Add(blip); + } + } + } - //foreach (RadarBlip radarBlip in radarBlips) - //{ - // DrawBlip(spriteBatch,radarBlip, center, Color.Green * radarBlip.FadeTimer, radius); - //} + foreach (RadarBlip radarBlip in radarBlips) + { + DrawBlip(spriteBatch, radarBlip, center, Color.Green * radarBlip.FadeTimer, radius); + } + + prevPingRadius = pingRadius; + + if (screenOverlay != null) + { + screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width / screenOverlay.size.X); + } //prevPingRadius = pingRadius; - //if (screenOverlay!=null) - //{ - // screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X); - //} - - ////prevPingRadius = pingRadius; - - //if (GameMain.GameSession == null) return; + if (GameMain.GameSession == null) return; - //DrawMarker(spriteBatch, - // (GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name, - // (Level.Loaded.StartPosition + Level.Loaded.Position), displayScale, center, (rect.Width * 0.55f)); + DrawMarker(spriteBatch, + (GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name, + (Level.Loaded.StartPosition), displayScale, center, (rect.Width * 0.55f)); - //DrawMarker(spriteBatch, - // (GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name, - // (Level.Loaded.EndPosition + Level.Loaded.Position), displayScale, center, (rect.Width * 0.55f)); + DrawMarker(spriteBatch, + (GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name, + (Level.Loaded.EndPosition), displayScale, center, (rect.Width * 0.55f)); - //if (GameMain.GameSession.Quest != null) - //{ - // var quest = GameMain.GameSession.Quest; + if (GameMain.GameSession.Quest != null) + { + var quest = GameMain.GameSession.Quest; - // if (!string.IsNullOrWhiteSpace(quest.RadarLabel)) - // { - // DrawMarker(spriteBatch, - // quest.RadarLabel, - // quest.RadarPosition, displayScale, center, (rect.Width * 0.55f)); - // } - //} + if (!string.IsNullOrWhiteSpace(quest.RadarLabel)) + { + DrawMarker(spriteBatch, + quest.RadarLabel, + quest.RadarPosition, displayScale, center, (rect.Width * 0.55f)); + } + } - //if (!GameMain.DebugDraw) return; + if (!GameMain.DebugDraw) return; - //var steering = item.GetComponent(); - //if (steering == null || steering.SteeringPath == null) return; + var steering = item.GetComponent(); + if (steering == null || steering.SteeringPath == null) return; - //Vector2 prevPos = Vector2.Zero; + Vector2 prevPos = Vector2.Zero; - //foreach (WayPoint wp in steering.SteeringPath.Nodes) - //{ - // Vector2 pos = (wp.Position - Submarine.Loaded.Position) * displayScale; - // if (pos.Length() > radius) continue; + foreach (WayPoint wp in steering.SteeringPath.Nodes) + { + Vector2 pos = (wp.Position - item.WorldPosition) * displayScale; + if (pos.Length() > radius) continue; - // pos.Y = -pos.Y; - // pos += center; + pos.Y = -pos.Y; + pos += center; - // GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X -3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode==wp) ? Color.LightGreen : Color.Green, false); + GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - 3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode == wp) ? Color.LightGreen : Color.Green, false); - // if (prevPos!=Vector2.Zero) - // { - // GUI.DrawLine(spriteBatch, pos, prevPos, Color.Green); - // } + if (prevPos != Vector2.Zero) + { + GUI.DrawLine(spriteBatch, pos, prevPos, Color.Green); + } - // prevPos = pos; - //} + prevPos = pos; + } - //voltage = 0.0f; + voltage = 0.0f; } private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius) { - Vector2 pos = (blip.Position) * displayScale; + + Vector2 pos = (blip.Position-item.WorldPosition) * displayScale; pos.Y = -pos.Y; if (pos.Length() > radius) diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index fff87c0d5..d14179c52 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -41,7 +41,7 @@ namespace Barotrauma.Items.Components { if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false); steeringPath = pathFinder.FindPath( - ConvertUnits.ToSimUnits(Submarine.Loaded.Position), + ConvertUnits.ToSimUnits(item.WorldPosition), ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); } } @@ -160,31 +160,31 @@ namespace Barotrauma.Items.Components { autopilotRayCastTimer -= deltaTime; - steeringPath.CheckProgress(ConvertUnits.ToSimUnits(Submarine.Loaded.Position), 10.0f); + steeringPath.CheckProgress(ConvertUnits.ToSimUnits(item.WorldPosition), 10.0f); if (autopilotRayCastTimer<=0.0f && steeringPath.NextNode != null) { - Vector2 diff = ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - Submarine.Loaded.Position); + Vector2 diff = ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - item.WorldPosition); - bool nextVisible = true; - for (int x = -1; x < 2; x += 2) - { - for (int y = -1; y < 2; y += 2) - { - Vector2 cornerPos = - new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f; + //bool nextVisible = true; + //for (int x = -1; x < 2; x += 2) + //{ + // for (int y = -1; y < 2; y += 2) + // { + // Vector2 cornerPos = + // new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f; - cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f); + // cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f); - if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue; + // if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue; - nextVisible = false; - x = 2; - y = 2; - } - } + // nextVisible = false; + // x = 2; + // y = 2; + // } + //} - if (nextVisible) steeringPath.SkipToNextNode(); + //if (nextVisible) steeringPath.SkipToNextNode(); autopilotRayCastTimer = AutopilotRayCastInterval; } @@ -193,8 +193,8 @@ namespace Barotrauma.Items.Components { float prediction = 5.0f; - Vector2 futurePosition = ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity) * prediction; - Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition); + Vector2 futurePosition = ConvertUnits.ToDisplayUnits(item.Submarine.Velocity) * prediction; + Vector2 targetSpeed = ((steeringPath.CurrentNode.WorldPosition - item.WorldPosition) - futurePosition); targetSpeed = Vector2.Normalize(targetSpeed); TargetVelocity = targetSpeed * 100.0f; diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index c777e3a0f..27b4fea6c 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -62,7 +62,7 @@ namespace Barotrauma.Items.Components if (pt.item.Condition<=0.0f && prevCondition > 0.0f) { - sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.Position); + sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition); Vector2 baseVel = Rand.Vector(300.0f); for (int i = 0; i < 10; i++) diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 719dac46c..3f94f2d36 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -169,11 +169,11 @@ namespace Barotrauma.Items.Components Structure structure; if ((limb = (f2.Body.UserData as Limb)) != null) { - attackResult = attack.DoDamage(User, limb.character, item.SimPosition, 1.0f); + attackResult = attack.DoDamage(User, limb.character, item.WorldPosition, 1.0f); } else if ((structure = (f2.Body.UserData as Structure)) != null) { - attackResult = attack.DoDamage(User, structure, item.SimPosition, 1.0f); + attackResult = attack.DoDamage(User, structure, item.WorldPosition, 1.0f); } } diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index e100f3022..820063d4a 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -98,6 +98,10 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { base.Update(deltaTime, cam); + if (item.CurrentHull != null) + { + //light.Submarine = item.CurrentHull.Submarine; + } if (item.container != null) { @@ -107,7 +111,7 @@ namespace Barotrauma.Items.Components if (item.body != null) { - light.Position = ConvertUnits.ToDisplayUnits(item.body.SimPosition); + light.Position = item.WorldPosition; } if (powerConsumption == 0.0f) @@ -121,7 +125,7 @@ namespace Barotrauma.Items.Components if (Rand.Range(0.0f, 1.0f) < 0.05f && voltage < Rand.Range(0.0f, minVoltage)) { - if (voltage > 0.1f) sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 400.0f, item.Position); + if (voltage > 0.1f) sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 400.0f, item.WorldPosition); lightBrightness = 0.0f; } else diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index a338b94f1..6d4af4164 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -314,7 +314,11 @@ namespace Barotrauma.Items.Components for (int i = 1; i < Nodes.Count; i++) { - GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 3, (int)-Nodes[i].Y - 3, 6, 6), Color.Red, true, 0.0f); + Vector2 worldPos = Nodes[i]; + if (item.Submarine != null) worldPos += item.Submarine.Position; + worldPos.Y = -worldPos.Y; + + GUI.DrawRectangle(spriteBatch, worldPos+new Vector2(-3,3), new Vector2(6, 6), Color.Red, true, 0.0f); if (GUIComponent.MouseOn != null || Vector2.Distance(GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), Nodes[i]) > 10.0f) @@ -322,7 +326,7 @@ namespace Barotrauma.Items.Components continue; } - GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 10, (int)-Nodes[i].Y - 10, 20, 20), Color.Red, false, 0.0f); + GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-10, 10), new Vector2(20, 20), Color.Red, false, 0.0f); if (selectedNodeIndex == null && !MapEntity.SelectedAny) { diff --git a/Subsurface/Source/Items/Components/Wearable.cs b/Subsurface/Source/Items/Components/Wearable.cs index f052172f1..7aba939e4 100644 --- a/Subsurface/Source/Items/Components/Wearable.cs +++ b/Subsurface/Source/Items/Components/Wearable.cs @@ -165,7 +165,7 @@ namespace Barotrauma.Items.Components ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker); - PlaySound(ActionType.OnWearing, picker.Position); + PlaySound(ActionType.OnWearing, picker.WorldPosition); if (containedItems == null) return; for (int j = 0; j rect.Center.X) { - GUI.DrawRectangle(sb, new Rectangle(rect.Right, -rect.Y, 10, rect.Height), Color.Green * 0.3f, true); + GUI.DrawRectangle(sb, new Rectangle(WorldRect.Right, -WorldRect.Y, 10, rect.Height), Color.Green * 0.3f, true); } else { - GUI.DrawRectangle(sb, new Rectangle(rect.X - 10, -rect.Y, 10, rect.Height), Color.Green * 0.3f, true); + GUI.DrawRectangle(sb, new Rectangle(WorldRect.X - 10, -WorldRect.Y, 10, rect.Height), Color.Green * 0.3f, true); } } } @@ -172,13 +172,13 @@ namespace Barotrauma { for (int i = 0; i < linkedTo.Count; i++) { - if (linkedTo[i].Rect.Y - linkedTo[i].Rect.Height/2.0f > rect.Y) + if (linkedTo[i].Rect.Y - linkedTo[i].Rect.Height / 2.0f > WorldRect.Y) { - GUI.DrawRectangle(sb, new Rectangle(rect.X, -rect.Y - 10, rect.Width, 10), Color.Green * 0.3f, true); + GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y - 10, rect.Width, 10), Color.Green * 0.3f, true); } else { - GUI.DrawRectangle(sb, new Rectangle(rect.X, -rect.Y + rect.Height, rect.Width, 10), Color.Green * 0.3f, true); + GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y + rect.Height, rect.Width, 10), Color.Green * 0.3f, true); } } } @@ -186,7 +186,7 @@ namespace Barotrauma if (isSelected) { GUI.DrawRectangle(sb, - new Vector2(rect.X - 5, -rect.Y - 5), + new Vector2(WorldRect.X - 5, -WorldRect.Y - 5), new Vector2(rect.Width + 10, rect.Height + 10), Color.Red); } @@ -200,7 +200,7 @@ namespace Barotrauma int index = (int)Math.Floor(flowForce.Length() / 100.0f); index = Math.Min(index,2); - soundIndex = SoundPlayer.flowSounds[index].Loop(soundIndex, soundVolume, Position, 2000.0f); + soundIndex = SoundPlayer.flowSounds[index].Loop(soundIndex, soundVolume, WorldPosition, 2000.0f); flowForce = Vector2.Zero; lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, 0.05f); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 6c5e52e89..94eb23689 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -156,7 +156,7 @@ namespace Barotrauma surface = rect.Y - rect.Height; aiTarget = new AITarget(this); - aiTarget.SightRange = (rect.Width + rect.Height)*10.0f; + aiTarget.SightRange = (rect.Width + rect.Height)*5.0f; hullList.Add(this); @@ -170,8 +170,8 @@ namespace Barotrauma public override bool Contains(Vector2 position) { - return (Submarine.RectContains(rect, position) && - !Submarine.RectContains(new Rectangle(rect.X + 8, rect.Y - 8, rect.Width - 16, rect.Height - 16), position)); + return (Submarine.RectContains(WorldRect, position) && + !Submarine.RectContains(MathUtils.ExpandRect(WorldRect, -8), position)); } public int GetWaveIndex(Vector2 position) @@ -353,25 +353,28 @@ namespace Barotrauma { if (!editing && !GameMain.DebugDraw) return; - GUI.DrawRectangle(spriteBatch, - new Vector2(rect.X, -rect.Y), - new Vector2(rect.Width, rect.Height), - isHighlighted ? Color.Green : Color.Blue); + Rectangle drawRect = + Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); GUI.DrawRectangle(spriteBatch, - new Rectangle(rect.X, -rect.Y, rect.Width, rect.Height), + new Vector2(drawRect.X, -drawRect.Y), + new Vector2(rect.Width, rect.Height), + Color.Blue); + + GUI.DrawRectangle(spriteBatch, + new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), Color.Red*((100.0f-OxygenPercentage)/400.0f), true); spriteBatch.DrawString(GUI.Font, "Pressure: " + ((int)pressure - rect.Y).ToString() + - " - Oxygen: "+((int)OxygenPercentage), new Vector2(rect.X+10, -rect.Y+10), Color.Black); - spriteBatch.DrawString(GUI.Font, volume +" / "+ FullVolume, new Vector2(rect.X+10, -rect.Y+30), Color.Black); + " - Oxygen: " + ((int)OxygenPercentage), new Vector2(drawRect.X + 10, -drawRect.Y + 10), Color.Black); + spriteBatch.DrawString(GUI.Font, volume + " / " + FullVolume, new Vector2(drawRect.X + 10, -drawRect.Y + 30), Color.Black); - if (isSelected && editing) + if ((isSelected || isHighlighted) && editing) { GUI.DrawRectangle(spriteBatch, - new Vector2(rect.X - 5, -rect.Y - 5), - new Vector2(rect.Width + 10, rect.Height + 10), - Color.Red); + new Vector2(drawRect.X + 5, -drawRect.Y + 5), + new Vector2(rect.Width - 10, rect.Height - 10), + isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true); } } @@ -380,13 +383,13 @@ namespace Barotrauma if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return; //calculate where the surface should be based on the water volume - float top = rect.Y+Submarine.Position.Y; + float top = rect.Y+Submarine.DrawPosition.Y; float bottom = top - rect.Height; float surfaceY = bottom + Volume / rect.Width; //interpolate the position of the rendered surface towards the "target surface" - surface = surface + ((surfaceY - Submarine.Position.Y) - surface) / 10.0f; - float drawSurface = surface + Submarine.Position.Y; + surface = surface + ((surfaceY - Submarine.DrawPosition.Y) - surface) / 10.0f; + float drawSurface = surface + Submarine.DrawPosition.Y; Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; @@ -407,7 +410,7 @@ namespace Barotrauma Vector2[] uvCoords = new Vector2[4]; for (int i = 0; i < 4; i++ ) { - corners[i] += new Vector3(Submarine.Loaded.Position, 0.0f); + corners[i] += new Vector3(Submarine.DrawPosition, 0.0f); uvCoords[i] = Vector2.Transform(new Vector2(corners[i].X, -corners[i].Y), transform); } @@ -424,7 +427,7 @@ namespace Barotrauma return; } - float x = rect.X+Submarine.Position.X; + float x = rect.X + Submarine.DrawPosition.X; int start = (int)Math.Floor((cam.WorldView.X - x) / WaveWidth); start = Math.Max(start, 0); diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 53361633b..750bc26d6 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -6,6 +6,7 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Voronoi2; @@ -324,7 +325,12 @@ namespace Barotrauma wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f, (side == 0 ? -1 : 1) * (i == 0 ? 1 : 2)); - wrappingWalls[side, i].Vertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List()); + wrappingWalls[side, i].Vertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List(), false); + //wrappingWalls[side, i].Cells[0].edges[1].isSolid = false; + //wrappingWalls[side, i].Cells[0].edges[3].isSolid = false; + + //wrappingWalls[side, i].Cells[wrappingWalls[side, i].Cells.Count-1].edges[1].isSolid = false; + //wrappingWalls[side, i].Cells[wrappingWalls[side, i].Cells.Count - 1].edges[3].isSolid = false; } } @@ -616,7 +622,7 @@ namespace Barotrauma } - private VertexPositionTexture[] GeneratePolygons(List cells, List emptyCells) + private VertexPositionTexture[] GeneratePolygons(List cells, List emptyCells, bool setSolid=true) { List verticeList = new List(); //bodies = new List(); @@ -639,7 +645,7 @@ namespace Barotrauma VoronoiCell adjacentCell = ge.AdjacentCell(cell); if (adjacentCell!=null && cells.Contains(adjacentCell)) continue; - ge.isSolid = true; + if (setSolid) ge.isSolid = true; if (!bodyPoints.Contains(ge.point1)) bodyPoints.Add(ge.point1); if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2); @@ -651,15 +657,14 @@ namespace Barotrauma continue; } - var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); - for (int i = 0; i < triangles.Count; i++) - { - foreach (Vector2 vertex in triangles[i]) - { - verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 0.0f), vertex/1000.0f)); - } - } - + //var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); + //for (int i = 0; i < triangles.Count; i++) + //{ + // foreach (Vector2 vertex in triangles[i]) + // { + // verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 0.0f), vertex/1000.0f)); + // } + //} if (bodyPoints.Count < 2) continue; @@ -679,7 +684,7 @@ namespace Barotrauma bodyPoints[i] = ConvertUnits.ToSimUnits(bodyPoints[i]); } - triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center); + var triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center); Body edgeBody = new Body(GameMain.World); @@ -701,9 +706,152 @@ namespace Barotrauma bodies.Add(edgeBody); } + + verticeList = GenerateWallShapes(cells); + return verticeList.ToArray(); } + private List GenerateWallShapes(List cells) + { + float wallThickness = 500.0f; + + List verticeList = new List(); + + foreach (VoronoiCell cell in cells) + { + if (cell.body == null) continue; + foreach (GraphEdge edge in cell.edges) + { + if (edge.cell1 != null && edge.cell1.body == null) edge.cell1 = null; + if (edge.cell2 != null && edge.cell2.body == null) edge.cell2 = null; + + //CompareCCW compare = new CompareCCW(cell.Center); + //if (compare.Compare(edge.point1, edge.point2) == -1) + //{ + // var temp = edge.point1; + // edge.point1 = edge.point2; + // edge.point2 = temp; + //} + } + } + + foreach (VoronoiCell cell in cells) + { + if (cell.body == null) continue; + foreach (GraphEdge edge in cell.edges) + { + if (!edge.isSolid) continue; + + GraphEdge leftEdge = null, rightEdge = null; + + foreach (GraphEdge edge2 in cell.edges) + { + if (edge == edge2) continue; + if (edge.point1 == edge2.point1 || + edge.point1 == edge2.point2) + { + leftEdge = edge2; + } + else if(edge.point2 == edge2.point2 || edge.point2 == edge2.point1) + { + rightEdge = edge2; + } + } + + Vector2 leftNormal = Vector2.Zero, rightNormal = Vector2.Zero; + + if (leftEdge == null) + { + leftNormal = GetEdgeNormal(edge, cell); + } + else + { + leftNormal = (leftEdge.isSolid) ? + Vector2.Normalize(GetEdgeNormal(leftEdge) + GetEdgeNormal(edge, cell)) : + Vector2.Normalize(leftEdge.Center - edge.point1); + } + + + if (rightEdge == null) + { + rightNormal = GetEdgeNormal(edge, cell); + } + else + { + rightNormal = (rightEdge.isSolid) ? + Vector2.Normalize(GetEdgeNormal(rightEdge) + GetEdgeNormal(edge, cell)) : + Vector2.Normalize(rightEdge.Center - edge.point2); + } + for (int i = 0; i < 2; i++) + { + Vector2[] verts = new Vector2[3]; + VertexPositionTexture[] vertPos = new VertexPositionTexture[3]; + + + if (i==0) + { + verts[0] = edge.point1; + verts[1] = edge.point2; + verts[2] = edge.point1 + leftNormal * wallThickness; + + vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), Vector2.Zero); + vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); + vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(0, 0.5f)); + } + else + { + verts[0] = edge.point1 + leftNormal * wallThickness; + verts[1] = edge.point2; + verts[2] = edge.point2 + rightNormal * wallThickness; + + vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), new Vector2(0.0f, 0.5f)); + vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); + vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(1.0f, 0.5f)); + } + + var comparer = new CompareCCW((verts[0] + verts[1] + verts[2]) / 3.0f); + Array.Sort(verts, vertPos, comparer); + + for (int j = 0; j<3; j++) + { + verticeList.Add(vertPos[j]); + } + } + } + } + + return verticeList; + } + + private Vector2 GetEdgeNormal(GraphEdge edge, VoronoiCell cell = null) + { + if (cell == null) cell = edge.AdjacentCell(null); + if (cell == null) return Vector2.UnitX; + + CompareCCW compare = new CompareCCW(cell.Center); + if (compare.Compare(edge.point1, edge.point2) == -1) + { + var temp = edge.point1; + edge.point1 = edge.point2; + edge.point2 = temp; + } + + Vector2 normal = Vector2.Zero; + + normal = Vector2.Normalize(edge.point2 - edge.point1); + Vector2 diffToCell = Vector2.Normalize(cell.Center - edge.point2); + + normal = new Vector2(-normal.Y, normal.X); + + if (Vector2.Dot(normal, diffToCell) < 0) + { + normal = -normal; + } + + return normal; + } + //public void SetPosition(Vector2 pos) //{ // Vector2 amount = pos - Position; diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index 3ae18a0ac..6ff978245 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -27,7 +27,7 @@ namespace Barotrauma basicEffect.VertexColorEnabled = false; basicEffect.TextureEnabled = true; - basicEffect.Texture = TextureLoader.FromFile("Content/Map/iceSurface.png"); + basicEffect.Texture = TextureLoader.FromFile("Content/Map/iceWall.png"); } this.level = level; @@ -73,12 +73,12 @@ namespace Barotrauma { for (int i = 0; i < 2; i++) { - basicEffect.World = Matrix.CreateTranslation( - new Vector3(-Submarine.Loaded.Position + level.WrappingWalls[side, i].Offset, 0.0f)) * - cam.ShaderTransform * - Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; + // basicEffect.World = Matrix.CreateTranslation( + // new Vector3(-Submarine.Loaded.Position + level.WrappingWalls[side, i].Offset, 0.0f)) * + // cam.ShaderTransform * + // Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; - basicEffect.CurrentTechnique.Passes[0].Apply(); + // basicEffect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleList, diff --git a/Subsurface/Source/Map/Levels/VoronoiElements.cs b/Subsurface/Source/Map/Levels/VoronoiElements.cs index adf3f7832..529e21749 100644 --- a/Subsurface/Source/Map/Levels/VoronoiElements.cs +++ b/Subsurface/Source/Map/Levels/VoronoiElements.cs @@ -180,6 +180,11 @@ namespace Voronoi2 public bool isSolid; + public Vector2 Center + { + get { return (point1 + point2) / 2.0f; } + } + public VoronoiCell AdjacentCell(VoronoiCell cell) { if (cell1==cell) diff --git a/Subsurface/Source/Map/Levels/WrappingWall.cs b/Subsurface/Source/Map/Levels/WrappingWall.cs index 65314d417..21a5b5a2c 100644 --- a/Subsurface/Source/Map/Levels/WrappingWall.cs +++ b/Subsurface/Source/Map/Levels/WrappingWall.cs @@ -95,8 +95,15 @@ namespace Barotrauma vertices[3] = vertices[0] + Vector2.UnitY * wallSectionSize.Y; VoronoiCell wallCell = new VoronoiCell(vertices); + wallCell.edges[0].cell1 = wallCell; wallCell.edges[1].cell1 = wallCell; + wallCell.edges[2].cell1 = wallCell; wallCell.edges[3].cell1 = wallCell; + + wallCell.edges[0].isSolid = true; + wallCell.edges[2].isSolid = true; + + if (i > 1) { wallCell.edges[1].cell2 = cells[i - 2]; diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index 2e2133d85..0ccb93247 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -249,7 +249,7 @@ namespace Barotrauma.Lights if (!Enabled) return; CachedShadow cachedShadow = null; - if (cachedShadows.TryGetValue(light, out cachedShadow)) + if (cachedShadows.TryGetValue(light, out cachedShadow) && false) { if (light.Position == cachedShadow.LightPos || Vector2.DistanceSquared(light.WorldPosition, cachedShadow.LightPos) < 1.0f) @@ -269,9 +269,15 @@ namespace Barotrauma.Lights } else { - CalculateShadowVertices(light.Position, los); - cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.WorldPosition); - cachedShadows.Add(light, cachedShadow); + Vector2 lightPos = light.WorldPosition; + if (light.Submarine!=null && parentEntity != null && parentEntity.Submarine == light.Submarine) + { + lightPos = light.Position; + } + + CalculateShadowVertices(lightPos, los); + // cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.WorldPosition); + // cachedShadows.Add(light, cachedShadow); } DrawShadows(graphicsDevice, cam, transform, los); diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index 4cc6b6d3d..e2234977e 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -128,7 +128,7 @@ namespace Barotrauma.Lights //draw the light shape //where Alpha is 0, nothing will be written - spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, Matrix.CreateTranslation(new Vector3(Submarine.Loaded.DrawPosition.X, -Submarine.Loaded.DrawPosition.Y, 0.0f)) * cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, cam.Transform); light.Draw(spriteBatch); spriteBatch.End(); } diff --git a/Subsurface/Source/Map/Lights/LightSource.cs b/Subsurface/Source/Map/Lights/LightSource.cs index 70382be4e..b3818648f 100644 --- a/Subsurface/Source/Map/Lights/LightSource.cs +++ b/Subsurface/Source/Map/Lights/LightSource.cs @@ -101,7 +101,7 @@ namespace Barotrauma.Lights { Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2); float scale = range / (lightTexture.Width / 2.0f); - spriteBatch.Draw(lightTexture, new Vector2(Position.X, -Position.Y), null, color, 0, center, scale, SpriteEffects.None, 1); + spriteBatch.Draw(lightTexture, new Vector2(WorldPosition.X, -WorldPosition.Y), null, color, 0, center, scale, SpriteEffects.None, 1); } public void Remove() diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index b1842622d..4698ce31a 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -154,7 +154,7 @@ namespace Barotrauma public virtual bool Contains(Vector2 position) { - return (Submarine.RectContains(rect, position)); + return (Submarine.RectContains(WorldRect, position)); } protected void InsertToList() diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index dc9902dd1..c31e1168e 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -431,7 +431,7 @@ namespace Barotrauma if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return new AttackResult(0.0f, 0.0f); if (!prefab.HasBody || prefab.IsPlatform) return new AttackResult(0.0f, 0.0f); - Vector2 transformedPos = ConvertUnits.ToDisplayUnits(position); + Vector2 transformedPos = position; if (Submarine != null) transformedPos -= Submarine.Position; int i = FindSectionIndex(transformedPos); diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index d5d4d6f2f..0d265c30e 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -101,7 +101,7 @@ namespace Barotrauma public override Vector2 Position { - get { return subBody.Position - HiddenSubPosition; } + get { return subBody==null ? Vector2.Zero : subBody.Position - HiddenSubPosition; } } public new Vector2 DrawPosition @@ -616,7 +616,6 @@ namespace Barotrauma XDocument doc = OpenDoc(filePath); if (doc == null) return; - subBody = new SubmarineBody(this); foreach (XElement element in doc.Root.Elements()) { @@ -650,6 +649,7 @@ namespace Barotrauma } + subBody = new SubmarineBody(this); subBody.SetPosition(HiddenSubPosition); loaded = this; diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index 14e34f442..57dc36047 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -225,7 +225,7 @@ namespace Barotrauma if (body.LinearVelocity.LengthSquared() > 0.000001f) { - float dragCoefficient = 0.00001f; + float dragCoefficient = 0.01f; float speedLength = (body.LinearVelocity == Vector2.Zero) ? 0.0f : body.LinearVelocity.Length(); float drag = speedLength * speedLength * dragCoefficient * mass; @@ -259,9 +259,9 @@ namespace Barotrauma float neutralPercentage = 0.07f; float buoyancy = Math.Max(neutralPercentage - waterPercentage, -neutralPercentage*2.0f); - buoyancy *= mass * 30.0f; + buoyancy *= mass; - return new Vector2(0.0f, buoyancy); + return new Vector2(0.0f, buoyancy*10.0f); } public void ApplyForce(Vector2 force) @@ -417,6 +417,7 @@ namespace Barotrauma Vector2 lastContactPoint = worldPoints[0]; + normal = Vector2.Normalize(ConvertUnits.ToDisplayUnits(body.Position) - cell.Center); float impact = Vector2.Dot(Velocity, -normal); diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 6de856274..adab499a0 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -84,18 +84,20 @@ namespace Barotrauma { if (!editing && !GameMain.DebugDraw) return; - Point pos = new Point((int)Position.X, (int)Position.Y); + Rectangle drawRect = + Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); + Color clr = (isSelected) ? Color.Red : Color.LightGreen; - GUI.DrawRectangle(spriteBatch, new Rectangle(pos.X - rect.Width / 2, -pos.Y - rect.Height / 2, rect.Width, rect.Height), clr, true); + GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), clr, true); //spriteBatch.DrawString(GUI.SmallFont, Position.ToString(), new Vector2(Position.X, -Position.Y), Color.White); foreach (MapEntity e in linkedTo) { GUI.DrawLine(spriteBatch, - new Vector2(pos.X, -pos.Y), - new Vector2(e.Position.X + e.Rect.Width / 2, -e.Position.Y + e.Rect.Height / 2), + new Vector2(drawRect.X, -drawRect.Y), + new Vector2(e.DrawPosition.X, -e.DrawPosition.Y), Color.Green); } } diff --git a/Subsurface/Source/Particles/Particle.cs b/Subsurface/Source/Particles/Particle.cs index 0c07c275b..6481ef1e3 100644 --- a/Subsurface/Source/Particles/Particle.cs +++ b/Subsurface/Source/Particles/Particle.cs @@ -74,6 +74,7 @@ namespace Barotrauma.Particles spriteIndex = Rand.Int(prefab.Sprites.Count); currentHull = Hull.FindHull(position, hullGuess); + if (currentHull != null && currentHull.Submarine != null) speed += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity); //if (currentHull == null) position = Submarine.Loaded == null ? position : position + Submarine.Loaded.Position; this.position = position; diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 1c5900610..ed662959f 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -234,6 +234,12 @@ namespace Barotrauma spriteBatch.End(); + if (GameMain.GameSession != null && GameMain.GameSession.Level != null) + { + GameMain.GameSession.Level.Render(graphics, cam); + //GameMain.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); + } + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, @@ -325,12 +331,6 @@ namespace Barotrauma Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform); - if (GameMain.GameSession != null && GameMain.GameSession.Level != null) - { - GameMain.GameSession.Level.Render(graphics, cam); - //GameMain.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); - } - //---------------------------------------------------------------------------------------- //3. draw the sections of the map that are on top of the water //---------------------------------------------------------------------------------------- diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 4039fad10..219e9b7f6 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -103,7 +103,7 @@ namespace Barotrauma if (volume <= 0.0f) return -1; - alSourceId = SoundManager.Play(this, relativePos, volume); + alSourceId = SoundManager.Play(this, relativePos/100.0f, volume); return alSourceId; @@ -112,16 +112,16 @@ namespace Barotrauma //return UpdatePosition(newIndex, position, range, volume); } - public int Play(float volume, float range, Body body) - { - //Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); - //bodyPosition.Y = -bodyPosition.Y; + //public int Play(float volume, float range, Body body) + //{ + // //Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); + // //bodyPosition.Y = -bodyPosition.Y; - alSourceId = Play(volume, range, ConvertUnits.ToDisplayUnits(body.Position)); + // alSourceId = Play(volume, range, ConvertUnits.ToDisplayUnits(body.Position)); - return alSourceId; - } + // return alSourceId; + //} private float GetVolume(Vector2 relativePosition, float range, float baseVolume) { @@ -198,7 +198,7 @@ namespace Barotrauma return sourceIndex; } - return SoundManager.Loop(this, sourceIndex, relativePos, volume); + return SoundManager.Loop(this, sourceIndex, relativePos/100.0f, volume); } diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs index 96255625a..05d088ac5 100644 --- a/Subsurface/Source/Sounds/SoundPlayer.cs +++ b/Subsurface/Source/Sounds/SoundPlayer.cs @@ -76,10 +76,8 @@ namespace Barotrauma startDrone = Sound.Load("Content/Sounds/startDrone.ogg", false); startDrone.Play(); - yield return CoroutineStatus.Running; - waterAmbiences[0] = Sound.Load("Content/Sounds/Water/WaterAmbience1.ogg", false); yield return CoroutineStatus.Running; waterAmbiences[1] = Sound.Load("Content/Sounds/Water/WaterAmbience2.ogg", false); @@ -276,9 +274,9 @@ namespace Barotrauma } } - public static void PlayDamageSound(DamageSoundType damageType, float damage, Body body) + public static void PlayDamageSound(DamageSoundType damageType, float damage, PhysicsBody body) { - Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); + Vector2 bodyPosition = body.DrawPosition; bodyPosition.Y = -bodyPosition.Y; PlayDamageSound(damageType, damage, bodyPosition); diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index b46cddf37..1f2135e57 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -247,6 +247,11 @@ namespace Barotrauma this.center = center; } public int Compare(Vector2 a, Vector2 b) + { + return Compare(a, b, center); + } + + public static int Compare(Vector2 a, Vector2 b, Vector2 center) { if (a.X - center.X >= 0 && b.X - center.X < 0) return -1; if (a.X - center.X < 0 && b.X - center.X >= 0) return 1; diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 2bde0e29a..aa65a3a5f 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ