From 15a31c52916e8540c55da6d405d3dec24a1020fb Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 22 Aug 2017 18:58:45 +0300 Subject: [PATCH] - The commonness of scripted events can be overridden for specific level types (e.g. some monsters can be set to spawn more frequently in specific types of levels). - The sub can be moved from location to another in the map view by double clicking in debug builds. - Level wall color can be changed in level generation parameters. - Fixed level geometry not being rendered if the ocean floor is visible (which isn't a problem in most level types, but there can be levels where the ocean floor is so close to the actual level that they can both be visible at the same time). - Background sprite scale is taken into account when calculating particle emitter positions. - Fixed limb lights being rendered even if the character is disabled. --- .../BackgroundSpriteManager.cs | 2 +- .../Source/Map/Levels/LevelRenderer.cs | 37 +++++++++++-------- .../Source/Map/Lights/LightManager.cs | 2 +- .../Source/Map/Lights/LightSource.cs | 2 + .../BarotraumaClient/Source/Map/Map/Map.cs | 15 ++++++-- .../Source/Characters/Character.cs | 6 +++ .../Source/Events/ScriptedEvent.cs | 21 ++++++++++- .../Source/Map/Levels/Level.cs | 17 ++++++--- .../Map/Levels/LevelGenerationParams.cs | 9 +++++ 9 files changed, 83 insertions(+), 28 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs b/Barotrauma/BarotraumaClient/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs index 8cef2d9b8..40f164564 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs @@ -255,7 +255,7 @@ namespace Barotrauma { if (s.Prefab.ParticleEmitterPrefab != null) { - Vector2 emitterPos = new Vector2(s.Prefab.EmitterPosition.X, s.Prefab.EmitterPosition.Y); + Vector2 emitterPos = new Vector2(s.Prefab.EmitterPosition.X, s.Prefab.EmitterPosition.Y) * s.Scale; if (s.Rotation != 0.0f || s.Prefab.SwingAmount != 0.0f) { diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs index 14e5de89d..c1be3e9da 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs @@ -261,14 +261,24 @@ namespace Barotrauma { if (wallVertices == null) return; + bool renderLevel = cam.WorldView.Y >= 0.0f; + bool renderSeaFloor = cam.WorldView.Y - cam.WorldView.Height < level.SeaFloorTopPos + 1024; + + if (!renderLevel && !renderSeaFloor) return; + wallEdgeEffect.World = cam.ShaderTransform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 100) * 0.5f; wallCenterEffect.World = wallEdgeEffect.World; - - //render the solid center of the wall cells + graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; wallCenterEffect.CurrentTechnique.Passes[0].Apply(); - if (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height < level.SeaFloorTopPos + 1024) + + if (renderLevel) + { + graphicsDevice.SetVertexBuffer(bodyVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f)); + } + if (renderSeaFloor) { foreach (LevelWall wall in level.ExtraWalls) { @@ -276,28 +286,23 @@ namespace Barotrauma graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wall.BodyVertices.VertexCount / 3.0f)); } } - else - { - graphicsDevice.SetVertexBuffer(bodyVertices); - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f)); - } - //render the edges of the wall cells wallEdgeEffect.CurrentTechnique.Passes[0].Apply(); - if (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height < level.SeaFloorTopPos + 1024) + if (renderLevel) + { + wallEdgeEffect.CurrentTechnique.Passes[0].Apply(); + graphicsDevice.SetVertexBuffer(wallVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f)); + } + if (renderSeaFloor) { foreach (LevelWall wall in level.ExtraWalls) { graphicsDevice.SetVertexBuffer(wall.WallVertices); graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wall.WallVertices.VertexCount / 3.0f)); } - } - else - { - graphicsDevice.SetVertexBuffer(wallVertices); - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f)); - } + } } public void Dispose() diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs index e1b24db9e..aded0f755 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs @@ -151,7 +151,7 @@ namespace Barotrauma.Lights foreach (LightSource light in lights) { - if (light.Color.A < 1 || light.Range < 1.0f || !light.CastShadows) continue; + if (light.Color.A < 1 || light.Range < 1.0f || !light.CastShadows || !light.Enabled) continue; if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue; light.Draw(spriteBatch, lightEffect, transform); diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs index 34e7c80c2..1da593c4e 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs @@ -116,6 +116,8 @@ namespace Barotrauma.Lights } } + public bool Enabled = true; + public LightSource (XElement element) : this(Vector2.Zero, 100.0f, Color.White, null) { diff --git a/Barotrauma/BarotraumaClient/Source/Map/Map/Map.cs b/Barotrauma/BarotraumaClient/Source/Map/Map/Map.cs index db4c64e19..05c6c2da4 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Map/Map.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Map/Map.cs @@ -49,6 +49,13 @@ namespace Barotrauma GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection); } } + +#if DEBUG + if (PlayerInput.DoubleClicked() && highlightedLocation != null) + { + currentLocation = highlightedLocation; + } +#endif } } @@ -116,9 +123,11 @@ namespace Barotrauma new Vector2(0, 30), SpriteEffects.None, 0.01f); } - //TODO: remove - Vector2 center = rectCenter + (connection.CenterPos + offset) * scale; - GUI.DrawString(spriteBatch, center, connection.Biome.Name, Color.White); + if (GameMain.DebugDraw) + { + Vector2 center = rectCenter + (connection.CenterPos + offset) * scale; + GUI.DrawString(spriteBatch, center, connection.Biome.Name, Color.White); + } } rect.Inflate(8, 8); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 8d3ecbe9d..1bf68ae3b 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -41,6 +41,12 @@ namespace Barotrauma { limb.body.Enabled = enabled; } +#if CLIENT + if (limb.LightSource != null) + { + limb.LightSource.Enabled = enabled; + } +#endif } AnimController.Collider.Enabled = value; } diff --git a/Barotrauma/BarotraumaShared/Source/Events/ScriptedEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ScriptedEvent.cs index a84c01fd6..20cd73150 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ScriptedEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ScriptedEvent.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Xml.Linq; @@ -14,7 +15,9 @@ namespace Barotrauma protected int difficulty; protected bool isFinished; - + + public Dictionary OverrideCommonness; + public string Name { get { return name; } @@ -65,6 +68,22 @@ namespace Barotrauma commonness = ToolBox.GetAttributeInt(element, "commonness", 1); MusicType = ToolBox.GetAttributeString(element, "musictype", "default"); + + OverrideCommonness = new Dictionary(); + + foreach (XElement subElement in element.Elements()) + { + switch (subElement.Name.ToString().ToLowerInvariant()) + { + case "overridecommonness": + string levelType = ToolBox.GetAttributeString(subElement, "leveltype", ""); + if (!OverrideCommonness.ContainsKey(levelType)) + { + OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1)); + } + break; + } + } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index 86dd29e4f..915ea3d47 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -71,10 +71,10 @@ namespace Barotrauma private List ruins; private Color backgroundColor; + private Color wallColor; private LevelGenerationParams generationParams; - public Vector2 StartPosition { get { return startPosition; } @@ -145,6 +145,11 @@ namespace Barotrauma { get { return backgroundColor; } } + + public Color WallColor + { + get { return wallColor; } + } public Level(string seed, float difficulty, LevelGenerationParams generationParams) { @@ -448,13 +453,13 @@ namespace Barotrauma cellGrid[x, y].Add(cell); } - + ruins = new List(); - for (int i = 0; i