diff --git a/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs b/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs index 46750381b..5a830c98d 100644 --- a/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs +++ b/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs @@ -63,12 +63,7 @@ namespace FarseerPhysics.Collision.Shapes { ShapeType = ShapeType.Chain; _radius = Settings.PolygonRadius; - - if (!(vertices != null && vertices.Count >= 2)) - { - int lkmsdgkldf = 1; - } - + Debug.Assert(vertices != null && vertices.Count >= 2); Debug.Assert(vertices[0] != vertices[vertices.Count - 1]); // FPE. See http://www.box2d.org/forum/viewtopic.php?f=4&t=7973&p=35363 diff --git a/Subsurface/Source/Characters/AI/CrewCommander.cs b/Subsurface/Source/Characters/AI/CrewCommander.cs index cb1acd72c..446a2ac6e 100644 --- a/Subsurface/Source/Characters/AI/CrewCommander.cs +++ b/Subsurface/Source/Characters/AI/CrewCommander.cs @@ -1,10 +1,7 @@ -using Barotrauma.Items.Components; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { @@ -137,7 +134,7 @@ namespace Barotrauma List prevCharacterFrames = new List(); foreach (GUIComponent child in frame.children) { - if (child.UserData as Character == null) continue; + if (!(child.UserData is Character)) continue; prevCharacterFrames.Add(child); } @@ -155,8 +152,6 @@ namespace Barotrauma int spacing = 5; - int rows = (int)Math.Ceiling((double)aliveCharacters.Count / charactersPerRow); - int i = 0; foreach (Character character in aliveCharacters) { @@ -164,7 +159,7 @@ namespace Barotrauma //if (i >= aliveCharacters.Count - charactersPerRow && aliveCharacters.Count % charactersPerRow > 0) rowCharacterCount = aliveCharacters.Count % charactersPerRow; // rowCharacterCount = Math.Min(rowCharacterCount, aliveCharacters.Count - i); - int startX = (int)-(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2; + int startX = -(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2; int x = startX + (150 + spacing) * (i % Math.Min(charactersPerRow, aliveCharacters.Count)); @@ -229,7 +224,6 @@ namespace Barotrauma { Order order = userData as Order; - List selectedCharacters = new List(); foreach (GUIComponent child in frame.children) { var characterButton = child as GUIButton; @@ -258,7 +252,7 @@ namespace Barotrauma var humanAi = character.AIController as HumanAIController; if (humanAi == null) return; - var existingOrder = characterFrame.children.Find(c => c.UserData as Order != null); + var existingOrder = characterFrame.children.Find(c => c.UserData is Order); if (existingOrder != null) characterFrame.RemoveChild(existingOrder); var orderFrame = new GUIFrame(new Rectangle(-5, characterFrame.Rect.Height, characterFrame.Rect.Width, 30 + order.Options.Length * 15), null, characterFrame); diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 7d02affb6..45c7b5a04 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -71,7 +71,7 @@ namespace Barotrauma targetMemories = new Dictionary(); XDocument doc = ToolBox.TryLoadXml(file); - if (doc == null) return; + if (doc == null || doc.Root == null) return; XElement aiElement = doc.Root.Element("ai"); if (aiElement == null) return; @@ -474,7 +474,7 @@ namespace Barotrauma } else if (closestStructure!=null) { - valueModifier = valueModifier / (closestStructure as IDamageable).Health; + valueModifier = valueModifier / ((IDamageable)closestStructure).Health; } else { diff --git a/Subsurface/Source/Characters/AI/HumanAIController.cs b/Subsurface/Source/Characters/AI/HumanAIController.cs index 8cd603126..238c63ca8 100644 --- a/Subsurface/Source/Characters/AI/HumanAIController.cs +++ b/Subsurface/Source/Characters/AI/HumanAIController.cs @@ -1,9 +1,5 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs b/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs index 3c9c41aee..f84ef8287 100644 --- a/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs +++ b/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.Xna.Framework; -using FarseerPhysics; using Barotrauma.Items.Components; namespace Barotrauma diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveCombat.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveCombat.cs index ec5711587..5d4cf2216 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveCombat.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveCombat.cs @@ -66,7 +66,7 @@ namespace Barotrauma } var pickedBody = Submarine.PickBody(character.SimPosition, enemy.SimPosition, ignoredBodies); - if (pickedBody != null && pickedBody.UserData as Limb == null) return; + if (pickedBody != null && !(pickedBody.UserData is Limb)) return; weapon.Use(deltaTime, character); } diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs index a0a7684af..78d4e87df 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs @@ -1,9 +1,6 @@ -using Barotrauma.Items.Components; -using Microsoft.Xna.Framework; -using System; +using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { @@ -59,10 +56,6 @@ namespace Barotrauma } else { - - - var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager; - Hull bestHull = null; float bestValue = currenthullSafety; @@ -75,7 +68,7 @@ namespace Barotrauma hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X- hull.Position.X)); hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.Y - hull.Position.Y)*2.0f); - if (bestHull==null || hullValue > bestValue) + if (bestHull == null || hullValue > bestValue) { bestHull = hull; bestValue = hullValue; diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFixLeaks.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFixLeaks.cs index 4e9f5404e..6bdb9860d 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFixLeaks.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFixLeaks.cs @@ -1,8 +1,6 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs index 379135caf..4571f2baa 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs @@ -2,9 +2,6 @@ using FarseerPhysics; using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs index b6342db9c..fb0c165f6 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs @@ -1,8 +1,6 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { @@ -119,7 +117,7 @@ namespace Barotrauma public override bool IsDuplicate(AIObjective otherObjective) { - return (otherObjective as AIObjectiveIdle != null); + return (otherObjective is AIObjectiveIdle); } } } diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs index 2d3f81dd7..04cb4c11b 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs @@ -1,8 +1,5 @@ -using Barotrauma.Items.Components; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Characters/AI/Order.cs b/Subsurface/Source/Characters/AI/Order.cs index 552284b43..be888bbb2 100644 --- a/Subsurface/Source/Characters/AI/Order.cs +++ b/Subsurface/Source/Characters/AI/Order.cs @@ -35,7 +35,7 @@ namespace Barotrauma PrefabList = new List(); XDocument doc = ToolBox.TryLoadXml(ConfigFile); - if (doc == null) return; + if (doc == null || doc.Root == null) return; foreach (XElement orderElement in doc.Root.Elements()) { diff --git a/Subsurface/Source/Characters/AI/PathFinder.cs b/Subsurface/Source/Characters/AI/PathFinder.cs index 8f0c0d99a..b561d6697 100644 --- a/Subsurface/Source/Characters/AI/PathFinder.cs +++ b/Subsurface/Source/Characters/AI/PathFinder.cs @@ -1,5 +1,4 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System.Collections.Generic; using System.Linq; @@ -80,7 +79,7 @@ namespace Barotrauma public delegate float? GetNodePenaltyHandler(PathNode node, PathNode prevNode); public GetNodePenaltyHandler GetNodePenalty; - List nodes; + private List nodes; private bool insideSubmarine; @@ -181,12 +180,13 @@ namespace Barotrauma endNode = node; if (startNode != null) break; } + } - if (startNode==null || endNode==null) - { - DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints"); - return new SteeringPath(); - } + + if (startNode == null || endNode == null) + { + DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints"); + return new SteeringPath(); } return FindPath(startNode, endNode); diff --git a/Subsurface/Source/Characters/AI/SteeringManager.cs b/Subsurface/Source/Characters/AI/SteeringManager.cs index e61202d60..dcab0d911 100644 --- a/Subsurface/Source/Characters/AI/SteeringManager.cs +++ b/Subsurface/Source/Characters/AI/SteeringManager.cs @@ -151,7 +151,7 @@ namespace Barotrauma } else if (closestBody.UserData is Item) { - Item item = closestBody.UserData as Item; + Item item = (Item)closestBody.UserData; avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition); } else diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index 902aa7e06..f05b937cd 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -747,12 +747,13 @@ namespace Barotrauma torso.body.ApplyForce((climbForce * 40.0f + subSpeed*50.0f) * torso.Mass); head.body.SmoothRotate(0.0f); - Rectangle trigger = character.SelectedConstruction.Prefab.Triggers.FirstOrDefault(); - if (trigger == null) + if (!character.SelectedConstruction.Prefab.Triggers.Any()) { character.SelectedConstruction = null; return; } + + Rectangle trigger = character.SelectedConstruction.Prefab.Triggers.FirstOrDefault(); trigger = character.SelectedConstruction.TransformTrigger(trigger); bool notClimbing = false; diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index d6c3ba420..11851c8ed 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -301,7 +301,7 @@ namespace Barotrauma { Structure structure = f2.Body.UserData as Structure; - if (f2.Body.UserData as Submarine != null && character.Submarine == f2.Body.UserData as Submarine) return false; + if (f2.Body.UserData is Submarine && character.Submarine == (Submarine)f2.Body.UserData) return false; //always collides with bodies other than structures if (structure == null) @@ -385,7 +385,7 @@ namespace Barotrauma avgVelocity = avgVelocity / Limbs.Count(); - if (character.Submarine == null && f2.Body.UserData is Submarine) avgVelocity -= (f2.Body.UserData as Submarine).Velocity; + if (character.Submarine == null && f2.Body.UserData is Submarine) avgVelocity -= ((Submarine)f2.Body.UserData).Velocity; float impact = Vector2.Dot(avgVelocity, -normal); diff --git a/Subsurface/Source/Characters/Attack.cs b/Subsurface/Source/Characters/Attack.cs index 489dae066..5ed3af6b0 100644 --- a/Subsurface/Source/Characters/Attack.cs +++ b/Subsurface/Source/Characters/Attack.cs @@ -128,19 +128,6 @@ namespace Barotrauma public AttackResult DoDamage(IDamageable attacker, IDamageable target, Vector2 worldPosition, float deltaTime, bool playSound = true) { - float damageAmount = 0.0f; - //DamageSoundType damageSoundType = DamageSoundType.None; - - if (target as Character == null) - { - damageAmount = structureDamage; - - } - else - { - damageAmount = damage; - } - if (particleEmitterPrefab != null) { particleEmitterPrefab.Emit(worldPosition); diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreaturePrefab.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreaturePrefab.cs index 1d0de283a..6dd2dad53 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreaturePrefab.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundCreaturePrefab.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Linq; +using System.Xml.Linq; namespace Barotrauma { diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs index 54f5f8264..7767e727e 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Linq; namespace Barotrauma diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index ee77fdbff..139bc8a1a 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -365,11 +365,6 @@ namespace Barotrauma public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath); public OnDeathHandler OnDeath; - public static Character Create(string file, Vector2 position) - { - return Create(file, position, null); - } - public static Character Create(CharacterInfo characterInfo, Vector2 position, bool isNetworkPlayer = false, bool hasAi=true) { return Create(characterInfo.File, position, characterInfo, isNetworkPlayer, hasAi); @@ -387,23 +382,18 @@ namespace Barotrauma return enemyCharacter; } - else + + if (hasAi && !isNetworkPlayer) { - if (hasAi && !isNetworkPlayer) - { - var character = new AICharacter(file, position, characterInfo, isNetworkPlayer); - var ai = new HumanAIController(character); - character.SetAI(ai); + var character = new AICharacter(file, position, characterInfo, isNetworkPlayer); + var ai = new HumanAIController(character); + character.SetAI(ai); - return character; + return character; - } - else - { - - return new Character(file, position, characterInfo, isNetworkPlayer); - } } + + return new Character(file, position, characterInfo, isNetworkPlayer); } protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false) diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index dbde15c26..cc13ef6d8 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -187,7 +187,7 @@ namespace Barotrauma public GUIFrame CreateInfoFrame(GUIFrame frame) { - GUIImage image = new GUIImage(new Rectangle(0,0,30,30), HeadSprite, Alignment.TopLeft, frame); + new GUIImage(new Rectangle(0,0,30,30), HeadSprite, Alignment.TopLeft, frame); SpriteFont font = frame.Rect.Width<280 ? GUI.SmallFont : GUI.Font; diff --git a/Subsurface/Source/Characters/DelayedEffect.cs b/Subsurface/Source/Characters/DelayedEffect.cs index b0935fd78..195cab43c 100644 --- a/Subsurface/Source/Characters/DelayedEffect.cs +++ b/Subsurface/Source/Characters/DelayedEffect.cs @@ -1,5 +1,4 @@ -using Microsoft.Xna.Framework; -using System.Collections.Generic; +using System.Collections.Generic; using System.Xml.Linq; namespace Barotrauma diff --git a/Subsurface/Source/Characters/Jobs/Job.cs b/Subsurface/Source/Characters/Jobs/Job.cs index 6908e1223..c34b91089 100644 --- a/Subsurface/Source/Characters/Jobs/Job.cs +++ b/Subsurface/Source/Characters/Jobs/Job.cs @@ -1,8 +1,5 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; using System.Xml.Linq; namespace Barotrauma @@ -10,7 +7,7 @@ namespace Barotrauma class Job { - private JobPrefab prefab; + private readonly JobPrefab prefab; private Dictionary skills; diff --git a/Subsurface/Source/Characters/Jobs/JobPrefab.cs b/Subsurface/Source/Characters/Jobs/JobPrefab.cs index aee18aac6..58b4f1452 100644 --- a/Subsurface/Source/Characters/Jobs/JobPrefab.cs +++ b/Subsurface/Source/Characters/Jobs/JobPrefab.cs @@ -160,7 +160,7 @@ namespace Barotrauma foreach (string filePath in filePaths) { XDocument doc = ToolBox.TryLoadXml(filePath); - if (doc == null) return; + if (doc == null || doc.Root == null) return; foreach (XElement element in doc.Root.Elements()) { diff --git a/Subsurface/Source/Characters/Jobs/SkillPrefab.cs b/Subsurface/Source/Characters/Jobs/SkillPrefab.cs index b89ba9583..2f2e4ff6a 100644 --- a/Subsurface/Source/Characters/Jobs/SkillPrefab.cs +++ b/Subsurface/Source/Characters/Jobs/SkillPrefab.cs @@ -1,17 +1,13 @@ using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Linq; namespace Barotrauma { class SkillPrefab { - string name; + private string name; - string description; + private string description; private Vector2 levelRange; diff --git a/Subsurface/Source/Characters/StatusEffect.cs b/Subsurface/Source/Characters/StatusEffect.cs index 48b95af00..ea15a4e0d 100644 --- a/Subsurface/Source/Characters/StatusEffect.cs +++ b/Subsurface/Source/Characters/StatusEffect.cs @@ -1,5 +1,4 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -274,20 +273,20 @@ namespace Barotrauma Type type = value.GetType(); if (type == typeof(float) || - (type == typeof(int) && property.GetValue().GetType() == typeof(float))) + (type == typeof(int) && property.GetValue() is float)) { float floatValue = Convert.ToSingle(value) * deltaTime; if (!setValue) floatValue += (float)property.GetValue(); property.TrySetValue(floatValue); } - else if (type == typeof(int) && value.GetType()==typeof(int)) + else if (type == typeof(int) && value is int) { int intValue = (int)((int)value * deltaTime); if (!setValue) intValue += (int)property.GetValue(); property.TrySetValue(intValue); } - else if (type == typeof(bool) && value.GetType() == typeof(bool)) + else if (type == typeof(bool) && value is bool) { property.TrySetValue((bool)value); } diff --git a/Subsurface/Source/CoroutineManager.cs b/Subsurface/Source/CoroutineManager.cs index 2fb853b17..c57fa7f75 100644 --- a/Subsurface/Source/CoroutineManager.cs +++ b/Subsurface/Source/CoroutineManager.cs @@ -1,8 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { @@ -14,7 +12,7 @@ namespace Barotrauma // Keeps track of all running coroutines, and runs them till the end. static class CoroutineManager { - static List> Coroutines = new List>(); + static readonly List> Coroutines = new List>(); public static float DeltaTime; diff --git a/Subsurface/Source/Events/ArtifactEvent.cs b/Subsurface/Source/Events/ArtifactEvent.cs index 1f0521abf..966d95126 100644 --- a/Subsurface/Source/Events/ArtifactEvent.cs +++ b/Subsurface/Source/Events/ArtifactEvent.cs @@ -1,9 +1,4 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Microsoft.Xna.Framework; using System.Xml.Linq; namespace Barotrauma diff --git a/Subsurface/Source/Events/MonsterEvent.cs b/Subsurface/Source/Events/MonsterEvent.cs index 5ff7d7286..72efb309f 100644 --- a/Subsurface/Source/Events/MonsterEvent.cs +++ b/Subsurface/Source/Events/MonsterEvent.cs @@ -36,7 +36,7 @@ namespace Barotrauma int amount = Rand.Range(minAmount, maxAmount, false); - monsters = new AICharacter[amount]; + monsters = new Character[amount]; for (int i = 0; i < amount; i++) { @@ -64,14 +64,14 @@ namespace Barotrauma if (isFinished) return; bool monstersDead = true; - for (int i = 0; i < monsters.Length; i++) + foreach (Character monster in monsters) { - if (monsters[i].IsDead) continue; + if (monster.IsDead) continue; - if (!isStarted && Vector2.Distance(monsters[i].WorldPosition, Submarine.Loaded.WorldPosition) < 5000.0f) isStarted = true; + if (!isStarted && Vector2.Distance(monster.WorldPosition, Submarine.Loaded.WorldPosition) < 5000.0f) isStarted = true; monstersDead = false; - break; + break; } if (monstersDead) Finished(); diff --git a/Subsurface/Source/Events/ScriptedEvent.cs b/Subsurface/Source/Events/ScriptedEvent.cs index 47bfe6a1f..f7485e102 100644 --- a/Subsurface/Source/Events/ScriptedEvent.cs +++ b/Subsurface/Source/Events/ScriptedEvent.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Xml.Linq; diff --git a/Subsurface/Source/Events/TaskManager.cs b/Subsurface/Source/Events/TaskManager.cs index 2f37db9fe..fc2437108 100644 --- a/Subsurface/Source/Events/TaskManager.cs +++ b/Subsurface/Source/Events/TaskManager.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using System; +using System.Linq; namespace Barotrauma { @@ -22,11 +21,7 @@ namespace Barotrauma { get { - foreach (Task task in tasks) - { - if (task.Priority >= CriticalPriority) return true; - } - return false; + return tasks.Any(task => task.Priority >= CriticalPriority); } } diff --git a/Subsurface/Source/GUI/ComponentStyle.cs b/Subsurface/Source/GUI/ComponentStyle.cs index c5bd4e340..4f6a73b1a 100644 --- a/Subsurface/Source/GUI/ComponentStyle.cs +++ b/Subsurface/Source/GUI/ComponentStyle.cs @@ -1,8 +1,5 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Linq; namespace Barotrauma diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index 63570b380..14d7e483b 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -57,9 +57,9 @@ namespace Barotrauma public static void Init(ContentManager content) { - GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content); - GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", content); - GUI.LargeFont = ToolBox.TryLoadFont("LargeFont", content); + Font = ToolBox.TryLoadFont("SpriteFont1", content); + SmallFont = ToolBox.TryLoadFont("SmallFont", content); + LargeFont = ToolBox.TryLoadFont("LargeFont", content); cursor = new Sprite("Content/UI/cursor.png", Vector2.Zero); } @@ -104,7 +104,7 @@ namespace Barotrauma pauseMenu = new GUIFrame(new Rectangle(0, 0, 200, 300), null, Alignment.Center, Style); int y = 0; - var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, GUI.Style, pauseMenu); + var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, Style, pauseMenu); button.OnClicked = TogglePauseMenu; y += 60; @@ -114,7 +114,7 @@ namespace Barotrauma SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode; if (spMode != null) { - button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, GUI.Style, pauseMenu); + button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, Style, pauseMenu); button.OnClicked += TogglePauseMenu; button.OnClicked += GameMain.GameSession.LoadPrevious; @@ -127,7 +127,7 @@ namespace Barotrauma SinglePlayerMode spMode = GameMain.GameSession.gameMode as SinglePlayerMode; if (spMode != null) { - button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, GUI.Style, pauseMenu); + button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, Style, pauseMenu); button.OnClicked += QuitClicked; button.OnClicked += TogglePauseMenu; button.UserData = "save"; @@ -137,7 +137,7 @@ namespace Barotrauma } - button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.Style, pauseMenu); + button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, Style, pauseMenu); button.OnClicked += QuitClicked; button.OnClicked += TogglePauseMenu; } @@ -193,7 +193,7 @@ namespace Barotrauma public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color? backgroundColor=null, int backgroundPadding=0, SpriteFont font = null) { - if (font == null) font = GUI.Font; + if (font == null) font = Font; if (backgroundColor != null) { Vector2 textSize = font.MeasureString(text); diff --git a/Subsurface/Source/GUI/GUIFrame.cs b/Subsurface/Source/GUI/GUIFrame.cs index 5489e5aa4..c3adb43db 100644 --- a/Subsurface/Source/GUI/GUIFrame.cs +++ b/Subsurface/Source/GUI/GUIFrame.cs @@ -1,5 +1,4 @@ using Microsoft.Xna.Framework; -using System; using System.Linq; namespace Barotrauma @@ -23,8 +22,8 @@ namespace Barotrauma this.rect = rect; this.alignment = alignment; - - if (color!=null) this.color = (Color)color; + + if (color != null) this.color = (Color)color; if (parent != null) { diff --git a/Subsurface/Source/GUI/GUIMessage.cs b/Subsurface/Source/GUI/GUIMessage.cs index a07fa6cb2..017985208 100644 --- a/Subsurface/Source/GUI/GUIMessage.cs +++ b/Subsurface/Source/GUI/GUIMessage.cs @@ -1,20 +1,15 @@ using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { class GUIMessage { - ColoredText coloredText; - Vector2 pos; + private ColoredText coloredText; + private Vector2 pos; - float lifeTime; - - Vector2 size; + private float lifeTime; + private Vector2 size; public string Text { diff --git a/Subsurface/Source/GUI/GUIStyle.cs b/Subsurface/Source/GUI/GUIStyle.cs index f66c9c22b..1a9878454 100644 --- a/Subsurface/Source/GUI/GUIStyle.cs +++ b/Subsurface/Source/GUI/GUIStyle.cs @@ -1,5 +1,4 @@ using System.Xml.Linq; -using Microsoft.Xna.Framework; using System; using System.Collections.Generic; @@ -22,24 +21,6 @@ namespace Barotrauma return; } - //smallPadding = ToolBox.GetAttributeVector4(doc.Root, "smallpadding", Vector4.Zero); - //largePadding = ToolBox.GetAttributeVector4(doc.Root, "largepadding", Vector4.Zero); - - //Vector4 colorVector = ToolBox.GetAttributeVector4(doc.Root, "backgroundcolor", new Vector4(0.0f,0.0f,0.0f,1.0f)); - //backGroundColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W); - - //colorVector = ToolBox.GetAttributeVector4(doc.Root, "foregroundcolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); - //foreGroundColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W); - - //colorVector = ToolBox.GetAttributeVector4(doc.Root, "textcolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); - //textColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W); - - //colorVector = ToolBox.GetAttributeVector4(doc.Root, "hovercolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); - //hoverColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W); - - //colorVector = ToolBox.GetAttributeVector4(doc.Root, "selectedcolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); - //selectedColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W); - foreach (XElement subElement in doc.Root.Elements()) { GUIComponentStyle componentStyle = new GUIComponentStyle(subElement); diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index cff620746..39628a0a6 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -93,7 +93,7 @@ namespace Barotrauma { } - protected override void UpdateDimensions(GUIComponent parent) + protected override void UpdateDimensions(GUIComponent parent = null) { base.UpdateDimensions(parent); diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 297048611..b7bcbf4c9 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -24,7 +24,7 @@ namespace Barotrauma public static bool WindowActive { - get { return Instance == null ? true : GameMain.Instance.IsActive; } + get { return Instance != null && Instance.IsActive; } } public static bool DebugDraw; diff --git a/Subsurface/Source/GameSession/CargoManager.cs b/Subsurface/Source/GameSession/CargoManager.cs index 0f6dea546..d15c43551 100644 --- a/Subsurface/Source/GameSession/CargoManager.cs +++ b/Subsurface/Source/GameSession/CargoManager.cs @@ -1,8 +1,5 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/GameSession/GameModes/GameMode.cs b/Subsurface/Source/GameSession/GameModes/GameMode.cs index 617252b6c..7396a875a 100644 --- a/Subsurface/Source/GameSession/GameModes/GameMode.cs +++ b/Subsurface/Source/GameSession/GameModes/GameMode.cs @@ -1,8 +1,6 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; -using System.Reflection; namespace Barotrauma { diff --git a/Subsurface/Source/GameSession/GameModes/TraitorMode.cs b/Subsurface/Source/GameSession/GameModes/TraitorMode.cs index d2b60febc..7051902a5 100644 --- a/Subsurface/Source/GameSession/GameModes/TraitorMode.cs +++ b/Subsurface/Source/GameSession/GameModes/TraitorMode.cs @@ -1,8 +1,5 @@ -using System; -using System.Linq; -using Barotrauma.Networking; +using Barotrauma.Networking; using System.Collections.Generic; -using Microsoft.Xna.Framework; namespace Barotrauma { diff --git a/Subsurface/Source/GameSession/GameModes/Tutorials/EditorTutorial.cs b/Subsurface/Source/GameSession/GameModes/Tutorials/EditorTutorial.cs index 04b8154a6..e3f24c938 100644 --- a/Subsurface/Source/GameSession/GameModes/Tutorials/EditorTutorial.cs +++ b/Subsurface/Source/GameSession/GameModes/Tutorials/EditorTutorial.cs @@ -1,8 +1,4 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace Barotrauma.Tutorials { diff --git a/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialMode.cs b/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialMode.cs index 9a3c417c9..0188fd925 100644 --- a/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialMode.cs +++ b/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialMode.cs @@ -1,11 +1,4 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Barotrauma.Items.Components; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Microsoft.Xna.Framework.Graphics; using Barotrauma.Tutorials; namespace Barotrauma diff --git a/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialType.cs b/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialType.cs index 4754708c9..8ccf26db4 100644 --- a/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialType.cs +++ b/Subsurface/Source/GameSession/GameModes/Tutorials/TutorialType.cs @@ -1,9 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma.Tutorials { diff --git a/Subsurface/Source/GameSession/InfoTextManager.cs b/Subsurface/Source/GameSession/InfoTextManager.cs index fceb62e5a..38aceb7fb 100644 --- a/Subsurface/Source/GameSession/InfoTextManager.cs +++ b/Subsurface/Source/GameSession/InfoTextManager.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Xml.Linq; namespace Barotrauma @@ -23,7 +21,7 @@ namespace Barotrauma infoTexts = new Dictionary>(); XDocument doc = ToolBox.TryLoadXml(file); - if (doc == null) return; + if (doc == null || doc.Root == null) return; foreach (XElement subElement in doc.Root.Elements()) { diff --git a/Subsurface/Source/GameSession/ShiftSummary.cs b/Subsurface/Source/GameSession/ShiftSummary.cs index d8a773423..1575a2c13 100644 --- a/Subsurface/Source/GameSession/ShiftSummary.cs +++ b/Subsurface/Source/GameSession/ShiftSummary.cs @@ -1,30 +1,10 @@ using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; -using System.Xml.Linq; namespace Barotrauma { class ShiftSummary { - //class Casualty - //{ - // public readonly CharacterInfo character; - // public readonly CauseOfDeath causeOfDeath; - - // public readonly string description; - - // public Casualty(CharacterInfo characterInfo, CauseOfDeath causeOfDeath, string description) - // { - // this.character = characterInfo; - // this.causeOfDeath = causeOfDeath; - // this.description = description; - // } - //} - private Location startLocation, endLocation; private GameSession gameSession; @@ -51,7 +31,7 @@ namespace Barotrauma { bool singleplayer = GameMain.NetworkMember == null; - bool gameOver = !gameSession.CrewManager.characters.Any(c => !c.IsDead); + bool gameOver = gameSession.CrewManager.characters.All(c => c.IsDead); bool progress = Submarine.Loaded.AtEndPosition; GUIFrame frame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.8f); diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 942c41c08..82646c61e 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -98,8 +98,10 @@ namespace Barotrauma /// /// If there is room, puts the item in the inventory and returns true, otherwise returns false /// - public override bool TryPutItem(Item item, List allowedSlots, bool createNetworkEvent = true) + public override bool TryPutItem(Item item, List allowedSlots = null, bool createNetworkEvent = true) { + if (allowedSlots == null) return false; + //try to place the item in LimBlot.Any slot if that's allowed if (allowedSlots.Contains(LimbSlot.Any)) { @@ -159,11 +161,8 @@ namespace Barotrauma bool combined = false; if (Items[index].Combine(item)) { - if (Items[index]==null) - { - System.Diagnostics.Debug.Assert(false); - return false; - } + System.Diagnostics.Debug.Assert(Items[index] != null); + Inventory otherInventory = Items[index].ParentInventory; if (otherInventory != null && otherInventory.Owner!=null && createNetworkEvent) { diff --git a/Subsurface/Source/Items/Components/Holdable/Propulsion.cs b/Subsurface/Source/Items/Components/Holdable/Propulsion.cs index 2a2435e52..a19dba2ef 100644 --- a/Subsurface/Source/Items/Components/Holdable/Propulsion.cs +++ b/Subsurface/Source/Items/Components/Holdable/Propulsion.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Xml.Linq; -using FarseerPhysics; -using FarseerPhysics.Dynamics; +using System.Xml.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Barotrauma.Particles; @@ -95,23 +91,8 @@ namespace Barotrauma.Items.Components return true; } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { - if (!IsActive) return; - - //Vector2 particleSpeed = new Vector2( - // (float)Math.Cos(item.body.Rotation), - // (float)Math.Sin(item.body.Rotation)) *item.body.Dir * 0.1f; - - - - - //Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position); - //Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition); - //endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2)); - - //GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f); - IsActive = false; } diff --git a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs index bbe19d9d5..de93cab60 100644 --- a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs @@ -105,7 +105,7 @@ namespace Barotrauma.Items.Components item.body.ApplyLinearImpulse( new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -50.0f); - projectileComponent.ignoredBodies = limbBodies; + projectileComponent.IgnoredBodies = limbBodies; item.RemoveContained(projectile); diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 5f0b0fa17..0b6ee0ff6 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -10,13 +10,13 @@ namespace Barotrauma.Items.Components { class RepairTool : ItemComponent { - List fixableEntities; + private List fixableEntities; - float range; + private float range; - Vector2 pickedPosition; + private Vector2 pickedPosition; - Vector2 barrelPos; + private Vector2 barrelPos; private string particles; diff --git a/Subsurface/Source/Items/Components/Holdable/Throwable.cs b/Subsurface/Source/Items/Components/Holdable/Throwable.cs index 48bbc0c3d..0b173ac95 100644 --- a/Subsurface/Source/Items/Components/Holdable/Throwable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Throwable.cs @@ -1,5 +1,4 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System.Xml.Linq; namespace Barotrauma.Items.Components diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index d39882f6c..43884d32a 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -301,7 +301,7 @@ namespace Barotrauma.Items.Components soundList.Add(itemSound); break; default: - ItemComponent ic = ItemComponent.Load(subElement, item, item.ConfigFile, false); + ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) break; ic.Parent = this; diff --git a/Subsurface/Source/Items/Components/ItemContainer.cs b/Subsurface/Source/Items/Components/ItemContainer.cs index fd9d3fdf9..e4607e27f 100644 --- a/Subsurface/Source/Items/Components/ItemContainer.cs +++ b/Subsurface/Source/Items/Components/ItemContainer.cs @@ -152,9 +152,9 @@ namespace Barotrauma.Items.Components } } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { - base.Draw(spriteBatch); + base.Draw(spriteBatch, editing); if (hideItems || (item.body != null && !item.body.Enabled)) return; diff --git a/Subsurface/Source/Items/Components/Ladder.cs b/Subsurface/Source/Items/Components/Ladder.cs index 3cbf1a47b..8347857a2 100644 --- a/Subsurface/Source/Items/Components/Ladder.cs +++ b/Subsurface/Source/Items/Components/Ladder.cs @@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components { } - public override bool Select(Character character = null) + public override bool Select(Character character) { if (character == null) return false; diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs index dc8f4afb9..2efa92e1a 100644 --- a/Subsurface/Source/Items/Components/Machines/Controller.cs +++ b/Subsurface/Source/Items/Components/Machines/Controller.cs @@ -215,7 +215,7 @@ namespace Barotrauma.Items.Components character.AnimController.Anim = AnimController.Animation.None; } - public override bool Select(Character activator = null) + public override bool Select(Character activator) { if (activator == null) return false; diff --git a/Subsurface/Source/Items/Components/Machines/Deconstructor.cs b/Subsurface/Source/Items/Components/Machines/Deconstructor.cs index 674eb491b..18784a4ca 100644 --- a/Subsurface/Source/Items/Components/Machines/Deconstructor.cs +++ b/Subsurface/Source/Items/Components/Machines/Deconstructor.cs @@ -117,7 +117,7 @@ namespace Barotrauma.Items.Components } else { - if (!container.Inventory.Items.Any(i => i != null)) return; + if (container.Inventory.Items.All(i => i == null)) return; activateButton.Text = "Cancel"; } diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index f4b279a0f..75338d2e1 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -90,7 +90,7 @@ namespace Barotrauma.Items.Components for (int i = 0; i < 5; i++) { - var bubbles = GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition - (Vector2.UnitX * item.Rect.Width/2), + GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition - (Vector2.UnitX * item.Rect.Width/2), -currForce / 5.0f + new Vector2(Rand.Range(-100.0f, 100.0f), Rand.Range(-50f, 50f)), 0.0f, item.CurrentHull); } diff --git a/Subsurface/Source/Items/Components/Machines/Fabricator.cs b/Subsurface/Source/Items/Components/Machines/Fabricator.cs index 6d08d117d..db5486383 100644 --- a/Subsurface/Source/Items/Components/Machines/Fabricator.cs +++ b/Subsurface/Source/Items/Components/Machines/Fabricator.cs @@ -150,7 +150,7 @@ namespace Barotrauma.Items.Components } text += "Required time: " + targetItem.RequiredTime + " s"; - GUITextBlock textBlock = new GUITextBlock( + new GUITextBlock( new Rectangle(0, 50, 0, 25), text, Color.Transparent, Color.White, diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index 95bbff2dd..4031b6e40 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -153,7 +153,6 @@ namespace Barotrauma.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; int x = GuiFrame.Rect.X; int y = GuiFrame.Rect.Y; diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index 83523e688..d0a66de69 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -94,19 +94,14 @@ namespace Barotrauma.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - int x = GuiFrame.Rect.X; - int y = GuiFrame.Rect.Y; GuiFrame.Update(1.0f / 60.0f); GuiFrame.Draw(spriteBatch); if (voltage < minVoltage) return; - int radius = GuiFrame.Rect.Height / 2 - 30; DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); - - //voltage = 0.0f; } private List radarBlips; @@ -202,20 +197,15 @@ namespace Barotrauma.Items.Components 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) { - float limbSize = limb.Mass; - for (int i = 0; i<=limb.Mass/100.0f; i++) { var blip = new RadarBlip(limb.WorldPosition+Rand.Vector(limb.Mass/10.0f), 1.0f); radarBlips.Add(blip); } - - } } } diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 72df6207e..3c4fab541 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -379,12 +379,12 @@ namespace Barotrauma.Items.Components public override bool Pick(Character picker) { - return (picker != null); + return picker != null; } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { - base.Draw(spriteBatch); + base.Draw(spriteBatch, editing); GUI.DrawRectangle(spriteBatch, new Vector2(item.Rect.X + item.Rect.Width / 2 - 6, -item.Rect.Y + 29), diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index bf88d5be3..d017e0972 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -224,9 +224,9 @@ namespace Barotrauma.Items.Components //if (connection.IsPower) voltage = power; } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { - base.Draw(spriteBatch); + base.Draw(spriteBatch, editing); GUI.DrawRectangle(spriteBatch, new Vector2(item.DrawPosition.X- 4, -item.DrawPosition.Y), diff --git a/Subsurface/Source/Items/Components/Power/Powered.cs b/Subsurface/Source/Items/Components/Power/Powered.cs index c6056c8b4..5c0ec5002 100644 --- a/Subsurface/Source/Items/Components/Power/Powered.cs +++ b/Subsurface/Source/Items/Components/Power/Powered.cs @@ -1,6 +1,4 @@ using System; -using System.Globalization; -using System.IO; using System.Xml.Linq; namespace Barotrauma.Items.Components @@ -85,7 +83,7 @@ namespace Barotrauma.Items.Components } } - public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0) { if (currPowerConsumption == 0.0f) voltage = 0.0f; if (connection.IsPower) voltage = power; diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index c9a59de0a..4e271594e 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Xml.Linq; using FarseerPhysics; using FarseerPhysics.Dynamics; @@ -18,9 +17,9 @@ namespace Barotrauma.Items.Components private PrismaticJoint stickJoint; private Body stickTarget; - Attack attack; + private Attack attack; - public List ignoredBodies; + public List IgnoredBodies; public Character User; @@ -48,7 +47,7 @@ namespace Barotrauma.Items.Components public Projectile(Item item, XElement element) : base (item, element) { - ignoredBodies = new List(); + IgnoredBodies = new List(); //launchImpulse = ToolBox.GetAttributeFloat(element, "launchimpulse", 10.0f); //characterUsable = ToolBox.GetAttributeBool(element, "characterusable", false); @@ -65,24 +64,10 @@ namespace Barotrauma.Items.Components //doesStick = ToolBox.GetAttributeBool(element, "doesstick", false); } - //public override void ConstructionActivate(Construction c, Vector2 modifier) - //{ - // for (int i = 0; i < item.linkedTo.Count; i++) - // item.linkedTo[i].RemoveLinked((MapEntity)item); - // item.linkedTo.Clear(); - - // ApplyStatusEffects(StatusEffect.Type.OnUse, 1.0f, null); - - // Launch(modifier+Vector2.Normalize(modifier)*launchImpulse); - - //} - public override bool Use(float deltaTime, Character character = null) { if (character != null && !characterUsable) return false; - //ApplyStatusEffects(ActionType.OnUse, 1.0f, Character); - Launch(new Vector2( (float)Math.Cos(item.body.Rotation), (float)Math.Sin(item.body.Rotation)) * launchImpulse * item.body.Mass); @@ -103,26 +88,25 @@ namespace Barotrauma.Items.Components item.Drop(); - if (stickJoint != null && doesStick) - { - if (stickTarget != null) - { - try - { - item.body.FarseerBody.RestoreCollisionWith(stickTarget); - } - catch (Exception e) - { -#if DEBUG - DebugConsole.ThrowError("Failed to restore collision with stickTarget", e); -#endif - } + if (stickJoint == null || !doesStick) return; - stickTarget = null; + if (stickTarget != null) + { + try + { + item.body.FarseerBody.RestoreCollisionWith(stickTarget); } - GameMain.World.RemoveJoint(stickJoint); - stickJoint = null; + catch (Exception e) + { +#if DEBUG + DebugConsole.ThrowError("Failed to restore collision with stickTarget", e); +#endif + } + + stickTarget = null; } + GameMain.World.RemoveJoint(stickJoint); + stickJoint = null; } public override void Update(float deltaTime, Camera cam) @@ -160,7 +144,7 @@ namespace Barotrauma.Items.Components private bool OnProjectileCollision(Fixture f1, Fixture f2, Contact contact) { - if (ignoredBodies.Contains(f2.Body)) return false; + if (IgnoredBodies.Contains(f2.Body)) return false; AttackResult attackResult = new AttackResult(0.0f, 0.0f); if (attack != null) @@ -185,7 +169,7 @@ namespace Barotrauma.Items.Components item.body.CollisionCategories = Physics.CollisionMisc; item.body.CollidesWith = Physics.CollisionWall | Physics.CollisionLevel; - ignoredBodies.Clear(); + IgnoredBodies.Clear(); f2.Body.ApplyLinearImpulse(item.body.LinearVelocity * item.body.Mass); @@ -220,9 +204,7 @@ namespace Barotrauma.Items.Components } } - return (f2.CollisionCategories != Physics.CollisionCharacter); - - //return false; + return f2.CollisionCategories != Physics.CollisionCharacter; } private bool StickToTarget(Body targetBody, Vector2 axis) diff --git a/Subsurface/Source/Items/Components/Rope.cs b/Subsurface/Source/Items/Components/Rope.cs index 8ea0a5328..baaf352b5 100644 --- a/Subsurface/Source/Items/Components/Rope.cs +++ b/Subsurface/Source/Items/Components/Rope.cs @@ -239,9 +239,9 @@ namespace Barotrauma.Items.Components } } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { - base.Draw(spriteBatch); + base.Draw(spriteBatch, editing); if (!IsActive) return; diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index 30a21a9d8..0b1c251a8 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -1,9 +1,6 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; using Barotrauma.Lights; using System; -using System.IO; using System.Xml.Linq; namespace Barotrauma.Items.Components @@ -135,16 +132,7 @@ namespace Barotrauma.Items.Components voltage = 0.0f; } - - public override void Draw(SpriteBatch spriteBatch, bool editing) - { - if (!editing) return; - - //Vector2 center = new Vector2(item.Rect.Center.X, -item.Rect.Y + item.Rect.Height/2.0f); - - //GUI.DrawLine(spriteBatch, center - Vector2.One * range, center + Vector2.One * range, lightColor); - } - + protected override void RemoveComponentSpecific() { base.RemoveComponentSpecific(); diff --git a/Subsurface/Source/Items/Components/Signal/RelayComponent.cs b/Subsurface/Source/Items/Components/Signal/RelayComponent.cs index 950ddd41a..ae4bd5489 100644 --- a/Subsurface/Source/Items/Components/Signal/RelayComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/RelayComponent.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Linq; +using System.Xml.Linq; namespace Barotrauma.Items.Components { diff --git a/Subsurface/Source/Items/Components/Signal/SignalCheckComponent.cs b/Subsurface/Source/Items/Components/Signal/SignalCheckComponent.cs index 617846d07..11e31d43a 100644 --- a/Subsurface/Source/Items/Components/Signal/SignalCheckComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/SignalCheckComponent.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Linq; +using System.Xml.Linq; namespace Barotrauma.Items.Components { diff --git a/Subsurface/Source/Items/Components/Signal/WifiComponent.cs b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs index 067c6fcbd..263a59616 100644 --- a/Subsurface/Source/Items/Components/Signal/WifiComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs @@ -1,5 +1,4 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; using System.Xml.Linq; diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index 8cf31b3d5..606ce8b26 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero)); } - public override void Draw(SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y); if (item.Submarine != null) drawPos += item.Submarine.DrawPosition; @@ -270,7 +270,7 @@ namespace Barotrauma.Items.Components if (Math.Abs(MathUtils.GetShortestAngle(enemyAngle, turretAngle)) > 0.01f) return false; var pickedBody = Submarine.PickBody(ConvertUnits.ToSimUnits(item.WorldPosition), closestEnemy.SimPosition, null); - if (pickedBody != null && pickedBody.UserData as Limb == null) return false; + if (pickedBody != null && !(pickedBody.UserData is Limb)) return false; if (objective.Option.ToLower()=="fire at will") Use(deltaTime, character); diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index ba090f4d4..0cc646934 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -363,8 +363,8 @@ namespace Barotrauma { if (sendingTime < lastUpdate) return; - List newItemIDs = new List(); - List droppedItems = new List(); + //List newItemIDs = new List(); + //List droppedItems = new List(); List prevItems = new List(Items); for (int i = 0; i < capacity; i++) @@ -389,15 +389,22 @@ namespace Barotrauma var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); if (sender != null && sender.Character != null) { - foreach (Item item in droppedItems) - { - GameServer.Log(sender.Character + " removed " + item.Name + " from " + Owner.ToString(), Color.Orange); - } - foreach (Item item in Items) { - if (item == null || prevItems.Contains(item)) continue; - GameServer.Log(sender.Character + " placed " + item.Name + " in " + Owner.ToString(), Color.Orange); + if (item == null) continue; + if (!prevItems.Contains(item)) + { + GameServer.Log(sender.Character + " placed " + item.Name + " in " + Owner, Color.Orange); + } + } + + foreach (Item item in prevItems) + { + if (item == null) continue; + if (!Items.Contains(item)) + { + GameServer.Log(sender.Character + " removed " + item.Name + " from " + Owner.ToString(), Color.Orange); + } } } } diff --git a/Subsurface/Source/Items/ItemSpawner.cs b/Subsurface/Source/Items/ItemSpawner.cs index 4dea7017d..73a53a293 100644 --- a/Subsurface/Source/Items/ItemSpawner.cs +++ b/Subsurface/Source/Items/ItemSpawner.cs @@ -1,14 +1,12 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Barotrauma { class ItemSpawner { - private Queue> spawnQueue; + private readonly Queue> spawnQueue; public ItemSpawner() { @@ -68,7 +66,7 @@ namespace Barotrauma { var item = new Item(itemInfo.First, Vector2.Zero, null); - var inventory = itemInfo.Second as Inventory; + var inventory = (Inventory)itemInfo.Second; inventory.TryPutItem(item, null, false); items.Add(item); @@ -138,7 +136,7 @@ namespace Barotrauma class ItemRemover { - private Queue removeQueue; + private readonly Queue removeQueue; public ItemRemover() { @@ -191,7 +189,7 @@ namespace Barotrauma ushort itemId = message.ReadUInt16(); var item = MapEntity.FindEntityByID(itemId); - if (item == null || item as Item != null) continue; + if (item == null || item is Item) continue; item.Remove(); } diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index ed6ae9701..0bf66e201 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -1,6 +1,4 @@ - -using FarseerPhysics; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Barotrauma.Lights; using System; using System.Collections.Generic; diff --git a/Subsurface/Source/Map/FireSource.cs b/Subsurface/Source/Map/FireSource.cs index 218cf4709..4b7e9f104 100644 --- a/Subsurface/Source/Map/FireSource.cs +++ b/Subsurface/Source/Map/FireSource.cs @@ -165,8 +165,6 @@ namespace Barotrauma for (int i = 0; i < count; i++ ) { - float normalizedPos = 0.5f-(i / count); - Vector2 spawnPos = new Vector2(WorldPosition.X + Rand.Range(0.0f, size.X), Rand.Range(WorldPosition.Y - size.Y, WorldPosition.Y) + 10.0f); Vector2 speed = new Vector2((spawnPos.X - (WorldPosition.X + size.X / 2.0f)), (float)Math.Sqrt(size.X) * Rand.Range(10.0f, 15.0f) * growModifier); diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index 34e8df21a..272ca3a74 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -115,7 +115,7 @@ namespace Barotrauma public static void UpdateHulls() { - foreach (Gap g in Gap.GapList) + foreach (Gap g in GapList) { g.FindHulls(); } diff --git a/Subsurface/Source/Map/Levels/WaterRenderer.cs b/Subsurface/Source/Map/Levels/WaterRenderer.cs index fe7fe7389..828255172 100644 --- a/Subsurface/Source/Map/Levels/WaterRenderer.cs +++ b/Subsurface/Source/Map/Levels/WaterRenderer.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index b20520ad0..433daa49b 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -112,21 +112,16 @@ namespace Barotrauma.Lights private void CalculateDimensions() { - Vector2 center = Vector2.Zero; - float? minX = null, minY = null, maxX = null, maxY = null; for (int i = 0; i < vertices.Length; i++) { - center += vertices[i]; - if (minX == null || vertices[i].X < minX) minX = vertices[i].X; if (minY == null || vertices[i].Y < minY) minY = vertices[i].Y; if (maxX == null || vertices[i].X > maxX) maxX = vertices[i].X; if (maxY == null || vertices[i].Y > minY) maxY = vertices[i].Y; } - center /= vertices.Length; boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)); } diff --git a/Subsurface/Source/Map/Map/Location.cs b/Subsurface/Source/Map/Map/Location.cs index f12e51c4f..6b40a79b2 100644 --- a/Subsurface/Source/Map/Map/Location.cs +++ b/Subsurface/Source/Map/Map/Location.cs @@ -1,8 +1,5 @@ using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 250b51729..b195d2c94 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -151,11 +151,11 @@ namespace Barotrauma protected bool ResizeHorizontal { - get { return prefab == null ? false : prefab.ResizeHorizontal; } + get { return prefab != null && prefab.ResizeHorizontal; } } protected bool ResizeVertical { - get { return prefab == null ? false : prefab.ResizeVertical; } + get { return prefab != null && prefab.ResizeVertical; } } public virtual string Name diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs index 793e4e3bc..7c75a84a1 100644 --- a/Subsurface/Source/Map/StructurePrefab.cs +++ b/Subsurface/Source/Map/StructurePrefab.cs @@ -1,9 +1,7 @@ using System; -using System.Diagnostics; using System.Xml.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System.Collections.Generic; namespace Barotrauma @@ -13,17 +11,17 @@ namespace Barotrauma //public static List list = new List(); //does the structure have a physics body - bool hasBody; + private bool hasBody; - bool castShadow; + private bool castShadow; - bool isPlatform; - Direction stairDirection; + private bool isPlatform; + private Direction stairDirection; - float maxHealth; + private float maxHealth; //default size - Vector2 size; + private Vector2 size; public bool HasBody { @@ -55,7 +53,7 @@ namespace Barotrauma foreach (string filePath in filePaths) { XDocument doc = ToolBox.TryLoadXml(filePath); - if (doc == null) return; + if (doc == null || doc.Root == null) return; foreach (XElement el in doc.Root.Elements()) { diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index c1a88ce94..48827f087 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -165,7 +165,7 @@ namespace Barotrauma public bool AtDamageDepth { - get { return subBody == null ? false : subBody.AtDamageDepth; } + get { return subBody != null && subBody.AtDamageDepth; } } public override string ToString() diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 13d850e65..a61415ffe 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -310,7 +310,7 @@ namespace Barotrauma if (hull.Rect.Width stairList = new List(); - foreach (MapEntity me in MapEntity.mapEntityList) + foreach (MapEntity me in mapEntityList) { Structure stairs = me as Structure; if (stairs == null) continue; @@ -439,8 +439,7 @@ namespace Barotrauma ladderPoints[0] = new WayPoint(new Vector2(item.Rect.Center.X, item.Rect.Y - item.Rect.Height + heightFromFloor), SpawnType.Path, Submarine.Loaded); ladderPoints[1] = new WayPoint(new Vector2(item.Rect.Center.X, item.Rect.Y-1.0f), SpawnType.Path, Submarine.Loaded); - - + WayPoint prevPoint = ladderPoints[0]; Vector2 prevPos = prevPoint.SimPosition; @@ -457,7 +456,7 @@ namespace Barotrauma if (pickedBody.UserData is Item) { - var door = (pickedBody.UserData as Item).GetComponent(); + var door = ((Item)pickedBody.UserData).GetComponent(); if (door != null) { WayPoint newPoint = new WayPoint(door.Item.Position, SpawnType.Path, Submarine.Loaded); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 32de5c2bf..c03cfac7c 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -128,7 +128,7 @@ namespace Barotrauma.Networking GUIMessageBox upnpBox = new GUIMessageBox("Please wait...", "Attempting UPnP port forwarding", new string[] {"Cancel"} ); upnpBox.Buttons[0].OnClicked = upnpBox.Close; - DateTime upnpTimeout = DateTime.Now + new TimeSpan(0,0,5); + //DateTime upnpTimeout = DateTime.Now + new TimeSpan(0,0,5); while (server.UPnP.Status == UPnPStatus.Discovering && GUIMessageBox.VisibleBox == upnpBox)// && upnpTimeout>DateTime.Now) { diff --git a/Subsurface/Source/Networking/GameServerSettings.cs b/Subsurface/Source/Networking/GameServerSettings.cs index efa8d83c8..5723ee376 100644 --- a/Subsurface/Source/Networking/GameServerSettings.cs +++ b/Subsurface/Source/Networking/GameServerSettings.cs @@ -53,7 +53,7 @@ namespace Barotrauma.Networking public bool AutoRestart { - get { return (ConnectedClients.Count == 0) ? false : autoRestart; } + get { return (ConnectedClients.Count != 0) && autoRestart; } set { autoRestart = value; diff --git a/Subsurface/Source/Networking/NetBufferExtensions.cs b/Subsurface/Source/Networking/NetBufferExtensions.cs index b328e20a5..0e407cc0c 100644 --- a/Subsurface/Source/Networking/NetBufferExtensions.cs +++ b/Subsurface/Source/Networking/NetBufferExtensions.cs @@ -1,7 +1,4 @@ -using Lidgren.Network; -using System; - -namespace Barotrauma.Networking +namespace Barotrauma.Networking { static class NetBufferExtensions { diff --git a/Subsurface/Source/Networking/NetConfig.cs b/Subsurface/Source/Networking/NetConfig.cs index ba50cc10b..655f77b69 100644 --- a/Subsurface/Source/Networking/NetConfig.cs +++ b/Subsurface/Source/Networking/NetConfig.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Barotrauma.Networking +namespace Barotrauma.Networking { static class NetConfig { diff --git a/Subsurface/Source/Networking/NetworkEvent.cs b/Subsurface/Source/Networking/NetworkEvent.cs index 889fbea3e..c95070695 100644 --- a/Subsurface/Source/Networking/NetworkEvent.cs +++ b/Subsurface/Source/Networking/NetworkEvent.cs @@ -109,7 +109,7 @@ namespace Barotrauma.Networking public NetworkEvent(NetworkEventType type, ushort id, bool allowClientSend, object data = null) { - if (!allowClientSend && GameMain.Server != null) return; + if (!allowClientSend && GameMain.Server == null) return; eventType = type; @@ -168,7 +168,7 @@ namespace Barotrauma.Networking try { - NetworkEvent.ReadData(message, sendingTime, resend); + ReadData(message, sendingTime, resend); } catch { diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index aef024fc3..5e2331dda 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; namespace Barotrauma.Networking { @@ -19,12 +18,12 @@ namespace Barotrauma.Networking private GUIListBox listBox; - private Queue lines; + private readonly Queue lines; public int LinesPerFile { get { return linesPerFile; } - set { linesPerFile = Math.Max(10, linesPerFile); } + set { linesPerFile = Math.Max(value, 10); } } public ServerLog(string serverName) diff --git a/Subsurface/Source/Particles/ParticleManager.cs b/Subsurface/Source/Particles/ParticleManager.cs index 455b62834..9759587c1 100644 --- a/Subsurface/Source/Particles/ParticleManager.cs +++ b/Subsurface/Source/Particles/ParticleManager.cs @@ -32,7 +32,7 @@ namespace Barotrauma.Particles particles = new Particle[MaxParticles]; XDocument doc = ToolBox.TryLoadXml(configFile); - if (doc == null) return; + if (doc == null || doc.Root == null) return; prefabs = new Dictionary(); diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 0160487b4..2eb6d1839 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -206,12 +206,7 @@ namespace Barotrauma { var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c); - //GUITextBlock textBlock = new GUITextBlock( - // new Rectangle(0, 0, 0, 25), - // c.Name + " (" + c.Job.Name + ")", GUI.Style, hireList); - //textBlock.UserData = c; - - var textBlock = new GUITextBlock( + new GUITextBlock( new Rectangle(0, 0, 0, 25), c.Salary.ToString(), null, null, @@ -475,7 +470,7 @@ namespace Barotrauma GUIComponent prevInfoFrame = null; foreach (GUIComponent child in bottomPanel[selectedRightPanel].children) { - if (child.UserData as CharacterInfo == null) continue; + if (!(child.UserData is CharacterInfo)) continue; prevInfoFrame = child; } diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index f50db9418..94d87f5a0 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -208,16 +208,13 @@ namespace Barotrauma otherButton.Selected = false; } - if (Screen.Selected != this) Select(); + if (Selected != this) Select(); return true; } public void SelectTab(Tab tab) { - int oldTab = selectedTab; - - if (GameMain.Config.UnsavedSettings) { var applyBox = new GUIMessageBox("Apply changes?", "Do you want to apply the settings or discard the changes?", diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index e5ba845ef..08d357dfb 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -246,7 +246,7 @@ namespace Barotrauma //traitor probability ------------------------------------------------------------------ - var traitorText = new GUITextBlock(new Rectangle(columnX, 180, 20, 20), "Traitors:", GUI.Style, infoFrame); + new GUITextBlock(new Rectangle(columnX, 180, 20, 20), "Traitors:", GUI.Style, infoFrame); traitorProbabilityButtons = new GUIButton[2]; @@ -1000,7 +1000,7 @@ namespace Barotrauma //msg.Write(durationBar.BarScroll); msg.Write(LevelSeed); - msg.Write(GameMain.Server == null ? false : GameMain.Server.AutoRestart); + msg.Write(GameMain.Server != null && GameMain.Server.AutoRestart); msg.Write(GameMain.Server == null ? 0.0f : GameMain.Server.AutoRestartTimer); msg.Write((byte)(playerList.CountChildren)); diff --git a/Subsurface/Source/Screens/Screen.cs b/Subsurface/Source/Screens/Screen.cs index efe49daef..d0b70ef8d 100644 --- a/Subsurface/Source/Screens/Screen.cs +++ b/Subsurface/Source/Screens/Screen.cs @@ -45,11 +45,10 @@ namespace Barotrauma private IEnumerable UpdateColorFade(Color from, Color to, float duration) { - while (Screen.Selected != this) + while (Selected != this) { yield return CoroutineStatus.Running; } - float timer = 0.0f; diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index a49a11579..8b9d4cbb8 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -1,12 +1,7 @@ using System; -using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Barotrauma.Networking; -using FarseerPhysics; -using FarseerPhysics.Factories; -using FarseerPhysics.Dynamics; -using System.IO; using System.Collections.Generic; using RestSharp; diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 11a18e4ea..80a073bc9 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics; using Microsoft.Xna.Framework; using OpenTK.Audio.OpenAL; using OpenTK.Audio; @@ -12,22 +11,14 @@ namespace Barotrauma.Sounds { public const int DefaultSourceCount = 16; - private static List alSources = new List(); - private static int[] alBuffers = new int[DefaultSourceCount]; + private static readonly List alSources = new List(); + private static readonly int[] alBuffers = new int[DefaultSourceCount]; private static int lowpassFilterId; + + private static AudioContext AC; - //private static float overrideLowPassGain; - - //public static float OverrideLowPassGain - //{ - // get { return overrideLowPassGain; } - // set { overrideLowPassGain = MathHelper.Clamp(overrideLowPassGain, 0.0f, 1.0f); } - //} - - static AudioContext AC; - - public static OggStreamer oggStreamer; - public static OggStream oggStream; + private static OggStreamer oggStreamer; + private static OggStream oggStream; public static float MasterVolume = 1.0f; diff --git a/Subsurface/Source/Utils/MTRandom.cs b/Subsurface/Source/Utils/MTRandom.cs index 730562993..e4606fdb7 100644 --- a/Subsurface/Source/Utils/MTRandom.cs +++ b/Subsurface/Source/Utils/MTRandom.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Utils/Rand.cs b/Subsurface/Source/Utils/Rand.cs index 75d477487..49df98208 100644 --- a/Subsurface/Source/Utils/Rand.cs +++ b/Subsurface/Source/Utils/Rand.cs @@ -1,9 +1,5 @@ -using Lidgren.Network; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Barotrauma { diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs index 7f4990037..cd6903cd3 100644 --- a/Subsurface/Source/Utils/SaveUtil.cs +++ b/Subsurface/Source/Utils/SaveUtil.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Linq; using System.Text; using System.Xml.Linq; diff --git a/Subsurface/Source/Utils/TextureLoader.cs b/Subsurface/Source/Utils/TextureLoader.cs index 1081ccad5..d1de3c787 100644 --- a/Subsurface/Source/Utils/TextureLoader.cs +++ b/Subsurface/Source/Utils/TextureLoader.cs @@ -1,10 +1,7 @@ -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; +using System.IO; using Microsoft.Xna.Framework.Graphics; using Color = Microsoft.Xna.Framework.Color; using System; -using Microsoft.Xna.Framework; namespace Barotrauma {