diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 1d3b32f53..b4383195e 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -331,6 +331,16 @@ Designer PreserveNewest + + PreserveNewest + + + PreserveNewest + + + Designer + PreserveNewest + PreserveNewest @@ -397,6 +407,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Items/Artifacts/artifacts.xml b/Subsurface/Content/Items/Artifacts/artifacts.xml index 4936b5054..9b81e1a74 100644 --- a/Subsurface/Content/Items/Artifacts/artifacts.xml +++ b/Subsurface/Content/Items/Artifacts/artifacts.xml @@ -4,7 +4,7 @@ name="Skyholder Artifact" pickdistance="150"> - + @@ -23,7 +23,7 @@ name="Thermal Artifact" pickdistance="150"> - + @@ -45,7 +45,7 @@ name="Faraday Artifact" pickdistance="150"> - + diff --git a/Subsurface/Content/Items/Fabricators/fabricators.xml b/Subsurface/Content/Items/Fabricators/fabricators.xml index af44d57d9..7938b6278 100644 --- a/Subsurface/Content/Items/Fabricators/fabricators.xml +++ b/Subsurface/Content/Items/Fabricators/fabricators.xml @@ -16,10 +16,13 @@ + + + diff --git a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml index 1f7a57513..77ee846ef 100644 --- a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml +++ b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml @@ -8,7 +8,7 @@ - + diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index 3ef81e616..597b35ba8 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -57,6 +57,11 @@ pickdistance="150" price="200"> + + + + + @@ -71,6 +76,11 @@ pickdistance="150" spritecolor="0.5,0.0,0.0,1.0"> + + + + + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index 6682a8348..9009c0405 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -30,7 +30,7 @@ - + @@ -77,7 +77,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index 7adf39b6f..f77e5ead4 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -58,6 +58,7 @@ + @@ -88,5 +89,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Weapons/weapons.png b/Subsurface/Content/Items/Weapons/weapons.png index 398e17bd0..df643f1c7 100644 Binary files a/Subsurface/Content/Items/Weapons/weapons.png and b/Subsurface/Content/Items/Weapons/weapons.png differ diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index 29e8d4262..97cf6e072 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -102,7 +102,7 @@ - + diff --git a/Subsurface/Properties/AssemblyInfo.cs b/Subsurface/Properties/AssemblyInfo.cs index d8e05518c..47ffee42f 100644 --- a/Subsurface/Properties/AssemblyInfo.cs +++ b/Subsurface/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.3.1.0")] -[assembly: AssemblyFileVersion("0.3.1.0")] +[assembly: AssemblyVersion("0.3.1.1")] +[assembly: AssemblyFileVersion("0.3.1.1")] diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index a9b3c1157..e7b2e5813 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -789,6 +789,8 @@ namespace Barotrauma public override void DragCharacter(Character target) { + if (target == null) return; + Limb leftHand = GetLimb(LimbType.LeftHand); Limb rightHand = GetLimb(LimbType.RightHand); diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreature.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreature.cs index f29e89e99..c2abfce94 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreature.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreature.cs @@ -39,7 +39,7 @@ namespace Barotrauma public Vector2 SimPosition { - get { return position; } + get { return FarseerPhysics.ConvertUnits.ToSimUnits(position); } } public Vector2 Velocity @@ -81,29 +81,51 @@ namespace Barotrauma depth = MathHelper.Clamp(depth + velocity.Z * deltaTime, 0.0f, MaxDepth); checkWallsTimer -= deltaTime; - if (checkWallsTimer<=0.0f && Level.Loaded!=null) + if (checkWallsTimer <= 0.0f && Level.Loaded != null) { checkWallsTimer = CheckWallsInterval; obstacleDiff = Vector2.Zero; - - var cells = Level.Loaded.GetCells(position, 1); - if (cells.Count > 0) + if (position.Y > Level.Loaded.Size.Y) { - - foreach (Voronoi2.VoronoiCell cell in cells) - { - obstacleDiff += cell.Center - position; - } - - obstacleDiff = Vector2.Normalize(obstacleDiff) * prefab.Speed; + obstacleDiff = Vector2.UnitY; } - } + else if (position.Y < 0.0f) + { + obstacleDiff = -Vector2.UnitY; + } + else if (position.X < 0.0f) + { + obstacleDiff = Vector2.UnitX; + } + else if (position.X > Level.Loaded.Size.X) + { + obstacleDiff = -Vector2.UnitX; + } + else + { + var cells = Level.Loaded.GetCells(position, 1); + if (cells.Count > 0) + { + + foreach (Voronoi2.VoronoiCell cell in cells) + { + obstacleDiff += cell.Center - position; + } + obstacleDiff /= cells.Count; + + obstacleDiff = Vector2.Normalize(obstacleDiff) * prefab.Speed; + } + } + } + + + if (Swarm!=null) { Vector2 midPoint = Swarm.MidPoint(); - float midPointDist = Vector2.Distance(position, midPoint); + float midPointDist = Vector2.Distance(SimPosition, midPoint); if (midPointDist > Swarm.MaxDistance) { @@ -116,9 +138,12 @@ namespace Barotrauma steeringManager.SteeringWander(prefab.Speed); } + //Level.Loaded.Size + + if (obstacleDiff != Vector2.Zero) { - steeringManager.SteeringSeek(-obstacleDiff, prefab.Speed); + steeringManager.SteeringSeek(SimPosition-obstacleDiff, prefab.Speed*2.0f); } steeringManager.Update(prefab.Speed); diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 0f3ceae21..c32565245 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -918,10 +918,10 @@ namespace Barotrauma if (!(AnimController is FishAnimController)) { bool protectedFromPressure = PressureProtection > 0.0f; - - if (Submarine.Loaded!=null && Level.Loaded !=null) + + if (Submarine.Loaded != null && Level.Loaded != null) { - protectedFromPressure = protectedFromPressure && Position.Y > SubmarineBody.DamageDepth; + protectedFromPressure = protectedFromPressure && WorldPosition.Y > SubmarineBody.DamageDepth; } if (!protectedFromPressure && diff --git a/Subsurface/Source/Characters/Limb.cs b/Subsurface/Source/Characters/Limb.cs index fd0a25df7..d1e8b1684 100644 --- a/Subsurface/Source/Characters/Limb.cs +++ b/Subsurface/Source/Characters/Limb.cs @@ -532,6 +532,7 @@ namespace Barotrauma break; } } + spriteBatch.Draw( bodyShapeTexture, new Vector2(body.DrawPosition.X, -body.DrawPosition.Y), @@ -546,7 +547,14 @@ namespace Barotrauma { sprite.Remove(); body.Remove(); - if (hitSound!=null) hitSound.Remove(); + + if (bodyShapeTexture != null) + { + bodyShapeTexture.Dispose(); + } + + + if (hitSound != null) hitSound.Remove(); } } } diff --git a/Subsurface/Source/Events/Quests/MonsterQuest.cs b/Subsurface/Source/Events/Quests/MonsterQuest.cs index cba33be31..13581fe82 100644 --- a/Subsurface/Source/Events/Quests/MonsterQuest.cs +++ b/Subsurface/Source/Events/Quests/MonsterQuest.cs @@ -27,7 +27,7 @@ namespace Barotrauma public override void Start(Level level) { - Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)]; + Vector2 position = level.GetRandomInterestingPosition(monster.Mass > 500.0f, true); monster = Character.Create(monsterFile, position); monster.Enabled = false; diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index 8a9722687..225faeb1e 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -314,6 +314,7 @@ namespace Barotrauma characters.Clear(); listBox.ClearChildren(); + orderListBox.ClearChildren(); } public void Draw(SpriteBatch spriteBatch) diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index c1352485a..2cb8b51b2 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components [HasDefaultValue(false, true)] public bool Attached { - get { return attached; } + get { return attached && item.Inventory == null; } set { attached = value; } } @@ -101,7 +101,7 @@ namespace Barotrauma.Items.Components Msg = ""; } - if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen && Submarine.Loaded!=null)) Use(1.0f); + if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen && Submarine.Loaded!=null)) Use(1.0f); //holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f); @@ -259,12 +259,22 @@ namespace Barotrauma.Items.Components { //prevRequiredItems = new List(requiredItems); - if (attached) + if (Attached) { Use(1.0f); } else - { + { + if (item.Inventory!=null) + { + if (body != null) + { + item.body = body; + body.Enabled = false; + } + attached = false; + } + requiredItems.Clear(); Msg = ""; } diff --git a/Subsurface/Source/Items/Components/ItemContainer.cs b/Subsurface/Source/Items/Components/ItemContainer.cs index e0d1b4d2a..0f59ed56f 100644 --- a/Subsurface/Source/Items/Components/ItemContainer.cs +++ b/Subsurface/Source/Items/Components/ItemContainer.cs @@ -9,6 +9,8 @@ namespace Barotrauma.Items.Components { class ItemContainer : ItemComponent { + public const int MaxInventoryCount = 4; + List containableItems; public ItemInventory Inventory; diff --git a/Subsurface/Source/Items/Components/Machines/Fabricator.cs b/Subsurface/Source/Items/Components/Machines/Fabricator.cs index 1a4efc1d1..136c49bc5 100644 --- a/Subsurface/Source/Items/Components/Machines/Fabricator.cs +++ b/Subsurface/Source/Items/Components/Machines/Fabricator.cs @@ -301,6 +301,10 @@ namespace Barotrauma.Items.Components int itemIndex = fabricatedItem == null ? -1 : fabricableItems.IndexOf(fabricatedItem); message.WriteRangedInteger(-1, fabricableItems.Count-1, itemIndex); + + var containers = item.GetComponents(); + containers[0].Inventory.FillNetworkData(type, message, null); + containers[1].Inventory.FillNetworkData(type, message, null); return true; } @@ -311,6 +315,10 @@ namespace Barotrauma.Items.Components int itemIndex = message.ReadRangedInteger(-1, fabricableItems.Count-1); + var containers = item.GetComponents(); + containers[0].Inventory.ReadNetworkData(type, message, sendingTime); + containers[1].Inventory.ReadNetworkData(type, message, sendingTime); + if (itemIndex == -1) { CancelFabricating(); @@ -324,7 +332,6 @@ namespace Barotrauma.Items.Components SelectItem(null, fabricableItems[itemIndex]); StartFabricating(fabricableItems[itemIndex]); - timeUntilReady -= sendingTime - (float)Lidgren.Network.NetTime.Now; } lastNetworkUpdate = sendingTime; diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 3f94f2d36..c9a59de0a 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -177,6 +177,8 @@ namespace Barotrauma.Items.Components } } + ApplyStatusEffects(ActionType.OnUse, 1.0f, null); + item.body.FarseerBody.OnCollision -= OnProjectileCollision; item.body.FarseerBody.IsBullet = false; diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index d052165f2..ed9118b46 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -172,6 +172,8 @@ namespace Barotrauma.Items.Components projectile.body.ResetDynamics(); projectile.body.Enabled = true; projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation); + projectile.FindHull(); + projectile.Submarine = projectile.body.Submarine; projectiles[0].Use(deltaTime); projectiles[0].User = character; diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 727ae9e50..a9d2bcc10 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1370,9 +1370,16 @@ namespace Barotrauma message.Write(requirementIndex); break; case NetworkEventType.InventoryUpdate: - var itemContainer = GetComponent(); - if (itemContainer == null || itemContainer.Inventory == null) return false; - return itemContainer.Inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data); + var itemContainers = GetComponents(); + if (itemContainers == null || !itemContainers.Any()) return false; + + message.WriteRangedInteger(1, ItemContainer.MaxInventoryCount, itemContainers.Count); + foreach (ItemContainer container in itemContainers) + { + container.Inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data); + } + + return true; case NetworkEventType.ComponentUpdate: case NetworkEventType.ImportantComponentUpdate: @@ -1434,7 +1441,7 @@ namespace Barotrauma { case NetworkEventType.DropItem: Vector2 newSimPos = Vector2.Zero; - newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat()); + newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat()); SetTransform(newSimPos, body.Rotation); Drop(null, false); break; @@ -1443,15 +1450,20 @@ namespace Barotrauma byte requirementIndex = message.ReadByte(); data = requirementIndex; - if (requirementIndex>=FixRequirements.Count) return; + if (requirementIndex >= FixRequirements.Count) return; FixRequirements[requirementIndex].Fixed = true; break; case NetworkEventType.InventoryUpdate: + var itemContainers = GetComponents(); + if (itemContainers == null || !itemContainers.Any()) return; + + int containerCount = message.ReadRangedInteger(1, ItemContainer.MaxInventoryCount); + for (int i = 0; i < containerCount;i++ ) + { + itemContainers[i].Inventory.ReadNetworkData(type, message, sendingTime); + } - var itemContainer = GetComponent(); - if (itemContainer == null || itemContainer.Inventory == null) return; - itemContainer.Inventory.ReadNetworkData(NetworkEventType.DropItem, message, sendingTime); break; case NetworkEventType.ComponentUpdate: case NetworkEventType.ImportantComponentUpdate: diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index 329e3c5e8..9e5d4d8cc 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -41,10 +41,16 @@ namespace Barotrauma { GameMain.ParticleManager.CreateParticle("shockwave", worldPosition, Vector2.Zero, 0.0f, hull); + + } for (int i = 0; i < attack.Range * 0.1f; i++) { + Vector2 bubblePos = Rand.Vector(attack.Range * 0.5f); + GameMain.ParticleManager.CreateParticle("bubbles", worldPosition+bubblePos, + bubblePos, 0.0f, hull); + if (sparks) { GameMain.ParticleManager.CreateParticle("spark", worldPosition, @@ -75,16 +81,17 @@ namespace Barotrauma foreach (Character c in Character.CharacterList) { - float dist = Vector2.Distance(c.WorldPosition, worldPosition); - if (dist > attack.Range) continue; - - float distFactor = 1.0f - dist / attack.Range; foreach (Limb limb in c.AnimController.Limbs) { + float dist = Vector2.Distance(limb.WorldPosition, worldPosition); + + if (dist > attack.Range) continue; + + float distFactor = 1.0f - dist / attack.Range; + if (limb.WorldPosition == worldPosition) continue; - distFactor = 1.0f - Vector2.Distance(limb.WorldPosition, worldPosition)/attack.Range; c.AddDamage(limb.SimPosition, DamageType.None, attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index ab62b1e4e..5947c7ab6 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -407,7 +407,7 @@ namespace Barotrauma public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { - if (back) return; + //if (back) return; if (!ShowHulls && !GameMain.DebugDraw) return; diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index f91fa1cf8..530003b63 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -13,12 +13,25 @@ using Voronoi2; namespace Barotrauma { + class Level { public static Level Loaded { get { return loaded; } } + + struct InterestingPosition + { + public readonly Vector2 Position; + public readonly bool IsLarge; + + public InterestingPosition(Vector2 position, bool isLarge) + { + Position = position; + IsLarge = isLarge; + } + } static Level loaded; @@ -49,7 +62,7 @@ namespace Barotrauma private List bodies; - private List positionsOfInterest; + private List positionsOfInterest; public Vector2 StartPosition { @@ -65,12 +78,7 @@ namespace Barotrauma { get { return endPosition; } } - - public List PositionsOfInterest - { - get { return positionsOfInterest; } - } - + public WrappingWall[,] WrappingWalls { get { return wrappingWalls; } @@ -101,7 +109,7 @@ namespace Barotrauma this.Difficulty = difficulty; - positionsOfInterest = new List(); + positionsOfInterest = new List(); borders = new Rectangle(0, 0, width, height); } @@ -109,7 +117,7 @@ namespace Barotrauma public static Level CreateRandom(LocationConnection locationConnection) { string seed = locationConnection.Locations[0].Name + locationConnection.Locations[1].Name; - return new Level(seed, locationConnection.Difficulty, 100000, 40000, 2000); + return new Level(seed, locationConnection.Difficulty, 100000, 50000, 2000); } public static Level CreateRandom(string seed = "") @@ -118,7 +126,7 @@ namespace Barotrauma { seed = Rand.Range(0, int.MaxValue, false).ToString(); } - return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 40000, 2000); + return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 50000, 2000); } public void Generate(bool mirror=false) @@ -140,6 +148,63 @@ namespace Barotrauma Rand.SetSyncedSeed(ToolBox.StringToInt(seed)); + float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height); + + startPosition = new Vector2(minWidth * 2, borders.Height); + endPosition = new Vector2(borders.Width - minWidth * 2, borders.Height); + + + List pathNodes = new List(); + Rectangle pathBorders = borders;// new Rectangle((int)minWidth, (int)minWidth, borders.Width - (int)minWidth * 2, borders.Height - (int)minWidth); + pathBorders.Inflate(-minWidth*2, -minWidth*2); + + pathNodes.Add(startPosition); + //pathNodes.Add(new Vector2(minWidth * 3, Rand.Range(minWidth * 2, borders.Height - minWidth * 2, false))); + + for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(2000.0f, 10000.0f, false)) + { + pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false))); + + //if (x > borders.Center.X) + //{ + // positionsOfInterest.Add(pathNodes.Last()); + //} + } + + //pathNodes.Add(new Vector2(borders.Width - minWidth * 3, borders.Height / 2)); + pathNodes.Add(endPosition); + + int smallTunnelCount = 5; + + List> smallTunnels = new List>(); + + for (int i = 0; i < smallTunnelCount; i++) + { + var tunnelStartPos = pathNodes[Rand.Range(2, pathNodes.Count - 2, false)]; + tunnelStartPos.X = MathHelper.Clamp(tunnelStartPos.X, pathBorders.X, pathBorders.Right); + + float tunnelLength = Rand.Range(5000.0f, 10000.0f, false); + + var tunnelNodes = MathUtils.GenerateJaggedLine(tunnelStartPos, tunnelStartPos + Rand.Vector(tunnelLength,false) + Vector2.UnitY*5000.0f, 3, 1000.0f); + + List tunnel = new List(); + foreach (Vector2[] tunnelNode in tunnelNodes) + { + if (!pathBorders.Contains(tunnelNode[0])) break; + tunnel.Add(tunnelNode[0]); + } + + if (tunnel.Any()) + { + smallTunnels.Add(tunnel); + positionsOfInterest.Add(new InterestingPosition(tunnel.Last(), false)); + + if (tunnel.Count() > 4) positionsOfInterest.Add(new InterestingPosition(tunnel[tunnel.Count()/2], false)); + } + } + + + float siteVariance = siteInterval * 0.4f; for (int x = siteInterval / 2; x < borders.Width; x += siteInterval) { @@ -147,6 +212,13 @@ namespace Barotrauma { Vector2 site = new Vector2(x, y) + Rand.Vector(siteVariance, false); + if (smallTunnels.Any(t => t.Any(node => Vector2.Distance(node, site) < siteInterval))) + { + if (x < borders.Width - siteInterval) sites.Add(new Vector2(x, y) + Vector2.UnitX * siteInterval * 0.2f); + if (y < borders.Height - siteInterval) sites.Add(new Vector2(x, y) + Vector2.UnitY * siteInterval * 0.2f); + if (x < borders.Width - siteInterval && y < borders.Height - siteInterval) sites.Add(new Vector2(x, y) + Vector2.One * siteInterval * 0.2f); + } + if (mirror) site.X = borders.Width - site.X; sites.Add(site); @@ -205,68 +277,63 @@ namespace Barotrauma Debug.WriteLine("find cells: " + sw2.ElapsedMilliseconds + " ms"); sw2.Restart(); - float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height); - //generate a path from the left edge of the map to right edge - Rectangle pathBorders = new Rectangle( - borders.X + (int)minWidth * 2, borders.Y + (int)minWidth * 2, - borders.Right - (int)minWidth * 4, borders.Y + borders.Height - (int)minWidth * 4); - - List pathNodes = new List(); - - startPosition = new Vector2((int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false)); - endPosition = new Vector2(borders.Width - (int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false)); - - pathNodes.Add(new Vector2(startPosition.X, borders.Height)); - pathNodes.Add(startPosition); - pathNodes.Add(endPosition); - pathNodes.Add(new Vector2(endPosition.X, borders.Height)); - - if (mirror) - { - pathNodes.Reverse(); - } + //if (mirror) + //{ + // pathNodes.Reverse(); + //} List pathCells = GeneratePath(pathNodes, cells, pathBorders, minWidth, 0.3f, mirror, true); - //place some enemy spawnpoints at random points in the path - for (int i = 0; i <3 ; i++ ) + foreach (InterestingPosition positionOfInterest in positionsOfInterest) { - Vector2 position = pathCells[Rand.Range((int)(pathCells.Count * 0.5f), pathCells.Count - 2, false)].Center; - WayPoint wayPoint = new WayPoint(new Rectangle((int)position.X, (int)position.Y, 10, 10), null); + WayPoint wayPoint = new WayPoint(positionOfInterest.Position, SpawnType.Enemy, null); wayPoint.MoveWithLevel = true; - wayPoint.SpawnType = SpawnType.Enemy; } startPosition = pathCells[0].Center; endPosition = pathCells[pathCells.Count - 1].Center; - //generate a couple of random paths - for (int i = 0; i <= Rand.Range(1,4,false); i++) + foreach (List tunnel in smallTunnels) { - //pathBorders = new Rectangle( - //borders.X + siteInterval * 2, borders.Y - siteInterval * 2, - //borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2); + if (tunnel.Count<2) continue; - Vector2 start = pathCells[Rand.Range(1, pathCells.Count - 2,false)].Center; + var newPathCells = GeneratePath(tunnel, cells, pathBorders, 0.0f, 0.0f); - float x = pathBorders.X + Rand.Range(0, pathBorders.Right - pathBorders.X, false); - float y = pathBorders.Y + Rand.Range(0,pathBorders.Bottom - pathBorders.Y, false); - - if (mirror) x = borders.Width - x; - - Vector2 end = new Vector2(x, y); - - var newPathCells = GeneratePath(new List { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror); - - for (int n = 0; n < newPathCells.Count; n += 5) - { - positionsOfInterest.Add(newPathCells[n].Center); - } + //for (int n = 0; n < newPathCells.Count; n += 5) + //{ + // positionsOfInterest.Add(newPathCells[n].Center); + //} pathCells.AddRange(newPathCells); } + ////generate a couple of random paths + //for (int i = 0; i <= Rand.Range(1,4,false); i++) + //{ + // //pathBorders = new Rectangle( + // //borders.X + siteInterval * 2, borders.Y - siteInterval * 2, + // //borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2); + + // Vector2 start = pathCells[Rand.Range(1, pathCells.Count - 2,false)].Center; + + // float x = pathBorders.X + Rand.Range(0, pathBorders.Right - pathBorders.X, false); + // float y = pathBorders.Y + Rand.Range(0,pathBorders.Bottom - pathBorders.Y, false); + + // if (mirror) x = borders.Width - x; + + // Vector2 end = new Vector2(x, y); + + // var newPathCells = GeneratePath(new List { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror); + + // for (int n = 0; n < newPathCells.Count; n += 5) + // { + // positionsOfInterest.Add(newPathCells[n].Center); + // } + + // pathCells.AddRange(newPathCells); + //} + Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms"); sw2.Restart(); @@ -282,9 +349,9 @@ namespace Barotrauma cells = CleanCells(pathCells); - pathCells.AddRange(CreateBottomHoles(0.8f, new Rectangle( + pathCells.AddRange(CreateBottomHoles(Rand.Range(0.2f,0.8f, false), new Rectangle( (int)(borders.Width * 0.2f), 0, - (int)(borders.Width * 0.6f), (int)(borders.Height * 0.5f)))); + (int)(borders.Width * 0.6f), (int)(borders.Height * 0.3f)))); foreach (VoronoiCell cell in pathCells) { @@ -345,7 +412,11 @@ namespace Barotrauma ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f); ShaftBodies[i].BodyType = BodyType.Static; ShaftBodies[i].CollisionCategories = Physics.CollisionLevel; - ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits((i == 0) ? startPosition : endPosition), 0.0f); + + Vector2 shaftPos = (i == 0) ? startPosition : endPosition; + shaftPos.Y = borders.Height; + + ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits(shaftPos), 0.0f); bodies.Add(ShaftBodies[i]); } @@ -403,7 +474,9 @@ namespace Barotrauma VoronoiCell currentCell = targetCells[0]; pathCells.Add(currentCell); - int currentTargetIndex = 1; + int currentTargetIndex = 1; + + wanderAmount = 0.0f; do { @@ -416,7 +489,7 @@ namespace Barotrauma allowedEdges.Add(edge); } - + //steer towards target if (Rand.Range(0.0f, 1.0f, false) > wanderAmount || allowedEdges.Count == 0) { @@ -544,22 +617,31 @@ namespace Barotrauma minDistance *= 0.5f; do { - for (int x = -1; x <= 1; x++) - { - for (int y = -1; y <= 1; y++) - { - if (x == 0 && y == 0) continue; - Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance); + var closeCells = GetCells(position, 2); - int cellIndex = FindCellIndex(cornerPos); - if (cellIndex == -1) continue; - if (!tooCloseCells.Contains(cells[cellIndex])) - { - tooCloseCells.Add(cells[cellIndex]); - } - } + foreach (VoronoiCell cell in closeCells) + { + if (!cell.edges.Any(e => Vector2.Distance(position, e.point1) < minDistance || Vector2.Distance(position, e.point2) < minDistance)) continue; + + if (!tooCloseCells.Contains(cell)) tooCloseCells.Add(cell); } + //for (int x = -1; x <= 1; x++) + //{ + // for (int y = -1; y <= 1; y++) + // { + // if (x == 0 && y == 0) continue; + // Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance); + + // int cellIndex = FindCellIndex(cornerPos); + // if (cellIndex == -1) continue; + // if (!tooCloseCells.Contains(cells[cellIndex])) + // { + // tooCloseCells.Add(cells[cellIndex]); + // } + // } + //} + position += Vector2.Normalize(emptyCells[targetCellIndex].Center - position) * step; if (Vector2.Distance(emptyCells[targetCellIndex].Center, position) < step * 2.0f) targetCellIndex++; @@ -771,6 +853,15 @@ namespace Barotrauma } + if (!leftNormal.IsValid()) + { +#if DEBUG + DebugConsole.ThrowError("Invalid right normal"); +#endif + leftNormal = Vector2.UnitX; + } + + if (rightEdge == null) { rightNormal = GetEdgeNormal(edge, cell); @@ -782,6 +873,14 @@ namespace Barotrauma Vector2.Normalize(rightEdge.Center - edge.point2); } + if (!rightNormal.IsValid()) + { +#if DEBUG + DebugConsole.ThrowError("Invalid right normal"); +#endif + rightNormal = Vector2.UnitX; + } + @@ -856,6 +955,8 @@ namespace Barotrauma public Vector2 GetRandomItemPos(float offsetFromWall = 10.0f) { + if (!positionsOfInterest.Any()) return Size*0.5f; + Vector2 position = Vector2.Zero; offsetFromWall = ConvertUnits.ToSimUnits(offsetFromWall); @@ -863,7 +964,7 @@ namespace Barotrauma int tries = 0; do { - Vector2 startPos = ConvertUnits.ToSimUnits(PositionsOfInterest[Rand.Int(PositionsOfInterest.Count, false)]); + Vector2 startPos = ConvertUnits.ToSimUnits(positionsOfInterest[Rand.Int(positionsOfInterest.Count, false)].Position); Vector2 endPos = startPos - ConvertUnits.ToSimUnits(Vector2.UnitY * Size.Y); @@ -888,6 +989,23 @@ namespace Barotrauma return position; } + public Vector2 GetRandomInterestingPosition(bool requireSpace, bool useSyncedRand) + { + if (!positionsOfInterest.Any()) return Size * 0.5f; + + if (requireSpace) + { + var positionsWithSpace = positionsOfInterest.FindAll(p => p.IsLarge); + if (!positionsWithSpace.Any()) return Size * 0.5f; + + return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position; + } + else + { + return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position; + } + } + public void Update (float deltaTime) { if (Submarine.Loaded!=null) @@ -902,6 +1020,14 @@ namespace Barotrauma { if (renderer == null) return; renderer.Draw(spriteBatch); + + if (GameMain.DebugDraw) + { + foreach (InterestingPosition pos in positionsOfInterest) + { + GUI.DrawRectangle(spriteBatch, new Vector2(pos.Position.X-15.0f, -pos.Position.Y-15.0f), new Vector2(30.0f, 30.0f), Color.Gold, true); + } + } } public void DrawBack(SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundSpriteManager = null) @@ -934,10 +1060,14 @@ namespace Barotrauma } } + if (wrappingWalls == null) return cells; + for (int side = 0; side < 2; side++) { for (int n = 0; n < 2; n++) { + if (wrappingWalls[side, n] == null) continue; + if (Vector2.Distance(wrappingWalls[side, n].MidPos, pos) > WrappingWall.WallWidth) continue; foreach (VoronoiCell cell in wrappingWalls[side, n].Cells) @@ -1015,6 +1145,7 @@ namespace Barotrauma private void Unload() { + renderer.Dispose(); renderer = null; diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index 136fa9949..2cbd4fccf 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -144,7 +144,7 @@ namespace Barotrauma public void Draw(SpriteBatch spriteBatch) { - Vector2 pos = new Vector2(0.0f, -level.StartPosition.Y);// level.EndPosition; + Vector2 pos = new Vector2(0.0f, -level.Size.Y);// level.EndPosition; if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return; @@ -232,8 +232,8 @@ namespace Barotrauma protected virtual void Dispose(bool disposing) { - wallVertices.Dispose(); - bodyVertices.Dispose(); + if (wallVertices!=null) wallVertices.Dispose(); + if (bodyVertices != null) bodyVertices.Dispose(); } } diff --git a/Subsurface/Source/Map/Levels/WrappingWall.cs b/Subsurface/Source/Map/Levels/WrappingWall.cs index 43accf309..797a34bfb 100644 --- a/Subsurface/Source/Map/Levels/WrappingWall.cs +++ b/Subsurface/Source/Map/Levels/WrappingWall.cs @@ -198,8 +198,8 @@ namespace Barotrauma protected virtual void Dispose(bool disposing) { - wallVertices.Dispose(); - bodyVertices.Dispose(); + if (wallVertices!=null) wallVertices.Dispose(); + if (bodyVertices!=null) bodyVertices.Dispose(); } } } diff --git a/Subsurface/Source/Map/Map/Map.cs b/Subsurface/Source/Map/Map/Map.cs index 077b48cc6..4fc161460 100644 --- a/Subsurface/Source/Map/Map/Map.cs +++ b/Subsurface/Source/Map/Map/Map.cs @@ -176,7 +176,7 @@ namespace Barotrauma Vector2 start = connection.Locations[0].MapPosition; Vector2 end = connection.Locations[1].MapPosition; int generations = (int)(Math.Sqrt(Vector2.Distance(start, end) / 10.0f)); - connection.CrackSegments = GenerateCrack(start, end, generations); + connection.CrackSegments = MathUtils.GenerateJaggedLine(start, end, generations, 5.0f); } } @@ -200,39 +200,6 @@ namespace Barotrauma } } - private List GenerateCrack(Vector2 start, Vector2 end, int generations) - { - List segments = new List(); - - segments.Add(new Vector2[] {start, end}); - - float offsetAmount = 5.0f; - - for (int n = 0; n < generations; n++) - { - for (int i = 0; i < segments.Count; i++) - { - Vector2 startSegment = segments[i][0]; - Vector2 endSegment = segments[i][1]; - - segments.RemoveAt(i); - - Vector2 midPoint = (startSegment + endSegment) / 2.0f; - - Vector2 normal = Vector2.Normalize(endSegment - startSegment); - normal = new Vector2(-normal.Y, normal.X); - midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, false); - - segments.Insert(i, new Vector2[] { startSegment, midPoint }); - segments.Insert(i+1, new Vector2[] { midPoint, endSegment }); - - i++; - } - } - - return segments; - } - public void MoveToNextLocation() { currentLocation = selectedLocation; diff --git a/Subsurface/Source/Sprite.cs b/Subsurface/Source/Sprite.cs index cbc1ed45e..99038a9c9 100644 --- a/Subsurface/Source/Sprite.cs +++ b/Subsurface/Source/Sprite.cs @@ -68,7 +68,7 @@ namespace Barotrauma { file = ToolBox.GetAttributeString(element, "texture", ""); } - + if (file == "") { DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!"); diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index 781454bcf..ddba37391 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -242,6 +242,37 @@ namespace Barotrauma return triangles; } + + public static List GenerateJaggedLine(Vector2 start, Vector2 end, int generations, float offsetAmount) + { + List segments = new List(); + + segments.Add(new Vector2[] { start, end }); + + for (int n = 0; n < generations; n++) + { + for (int i = 0; i < segments.Count; i++) + { + Vector2 startSegment = segments[i][0]; + Vector2 endSegment = segments[i][1]; + + segments.RemoveAt(i); + + Vector2 midPoint = (startSegment + endSegment) / 2.0f; + + Vector2 normal = Vector2.Normalize(endSegment - startSegment); + normal = new Vector2(-normal.Y, normal.X); + midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, false); + + segments.Insert(i, new Vector2[] { startSegment, midPoint }); + segments.Insert(i + 1, new Vector2[] { midPoint, endSegment }); + + i++; + } + } + + return segments; + } } class CompareCCW : IComparer diff --git a/Subsurface/changelog.txt b/Subsurface/changelog.txt index 9aa4fb76a..811654252 100644 --- a/Subsurface/changelog.txt +++ b/Subsurface/changelog.txt @@ -1,3 +1,11 @@ +--------------------------------------------------------------------------------------------------------- +v0.3.1.1 +--------------------------------------------------------------------------------------------------------- + +- fixed a major bug that caused item/monster ID mismatches between the server and the clients, which +accounted for many of the monster/inventory/item syncing issues +- improved player position syncing + --------------------------------------------------------------------------------------------------------- v0.3.1.0 --------------------------------------------------------------------------------------------------------- diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index d7b626fe7..d098ef395 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ