diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 95e215df9..370f034f5 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -91,11 +91,13 @@ + + @@ -288,6 +290,15 @@ Designer PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -333,6 +344,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -348,12 +362,18 @@ PreserveNewest + + PreserveNewest + PreserveNewest PreserveNewest + + PreserveNewest + PreserveNewest @@ -552,6 +572,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Characters/Coelanth/coelanth.xml b/Subsurface/Content/Characters/Coelanth/coelanth.xml index 0de557050..1f9407652 100644 --- a/Subsurface/Content/Characters/Coelanth/coelanth.xml +++ b/Subsurface/Content/Characters/Coelanth/coelanth.xml @@ -1,5 +1,5 @@  - + @@ -55,4 +55,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Subsurface/Content/Characters/Crawler/crawler.xml b/Subsurface/Content/Characters/Crawler/crawler.xml index 7d2b58e22..da7669615 100644 --- a/Subsurface/Content/Characters/Crawler/crawler.xml +++ b/Subsurface/Content/Characters/Crawler/crawler.xml @@ -1,5 +1,5 @@  - + @@ -77,5 +77,5 @@ - + diff --git a/Subsurface/Content/Characters/Human/damagedhead.png b/Subsurface/Content/Characters/Human/damagedhead.png new file mode 100644 index 000000000..d5f0c83a8 Binary files /dev/null and b/Subsurface/Content/Characters/Human/damagedhead.png differ diff --git a/Subsurface/Content/Characters/Human/damagedlegs.png b/Subsurface/Content/Characters/Human/damagedlegs.png new file mode 100644 index 000000000..ce67ed6f0 Binary files /dev/null and b/Subsurface/Content/Characters/Human/damagedlegs.png differ diff --git a/Subsurface/Content/Characters/Human/damagedtorso.png b/Subsurface/Content/Characters/Human/damagedtorso.png new file mode 100644 index 000000000..0117cd5a8 Binary files /dev/null and b/Subsurface/Content/Characters/Human/damagedtorso.png differ diff --git a/Subsurface/Content/Characters/Human/human.xml b/Subsurface/Content/Characters/Human/human.xml index 1494045b1..b94ee1a85 100644 --- a/Subsurface/Content/Characters/Human/human.xml +++ b/Subsurface/Content/Characters/Human/human.xml @@ -1,5 +1,5 @@  - + @@ -13,53 +13,66 @@ + + + + + + + + + + + + - + + @@ -88,5 +101,5 @@ - + diff --git a/Subsurface/Content/Characters/Mantis/mantis.xml b/Subsurface/Content/Characters/Mantis/mantis.xml index 1d1502524..e8657ac5b 100644 --- a/Subsurface/Content/Characters/Mantis/mantis.xml +++ b/Subsurface/Content/Characters/Mantis/mantis.xml @@ -1,5 +1,5 @@  - + @@ -88,5 +88,5 @@ - + diff --git a/Subsurface/Content/Characters/Moloch/moloch.xml b/Subsurface/Content/Characters/Moloch/moloch.xml index 18d51ad96..aa257707d 100644 --- a/Subsurface/Content/Characters/Moloch/moloch.xml +++ b/Subsurface/Content/Characters/Moloch/moloch.xml @@ -1,5 +1,5 @@  - + @@ -59,4 +59,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Subsurface/Content/Characters/Scorpion/scorpion.xml b/Subsurface/Content/Characters/Scorpion/scorpion.xml index f6b2ebf02..3629067c0 100644 --- a/Subsurface/Content/Characters/Scorpion/scorpion.xml +++ b/Subsurface/Content/Characters/Scorpion/scorpion.xml @@ -1,5 +1,5 @@  - + @@ -44,5 +44,5 @@ - + diff --git a/Subsurface/Content/Characters/TigerThresher/damagedtigerthresher.png b/Subsurface/Content/Characters/TigerThresher/damagedtigerthresher.png new file mode 100644 index 000000000..3e2fd7e63 Binary files /dev/null and b/Subsurface/Content/Characters/TigerThresher/damagedtigerthresher.png differ diff --git a/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml b/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml index c401e5d51..2429cba50 100644 --- a/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml +++ b/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml @@ -1,5 +1,5 @@  - + @@ -10,37 +10,44 @@ + - + + + + + + + @@ -64,4 +71,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Subsurface/Content/Items/Clothes/clothes.xml b/Subsurface/Content/Items/Clothes/clothes.xml index 9586f6b69..27f4328e0 100644 --- a/Subsurface/Content/Items/Clothes/clothes.xml +++ b/Subsurface/Content/Items/Clothes/clothes.xml @@ -4,7 +4,7 @@ pickdistance="150" tags="smallitem"> - + @@ -18,7 +18,7 @@ pickdistance="150" tags="smallitem"> - + @@ -38,7 +38,7 @@ pickdistance="150" tags="smallitem"> - + @@ -57,7 +57,7 @@ pickdistance="150" tags="smallitem"> - + @@ -73,7 +73,7 @@ pickdistance="150" tags="smallitem"> - + @@ -82,5 +82,28 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Clothes/engigear.png b/Subsurface/Content/Items/Clothes/engigear.png new file mode 100644 index 000000000..11ac9854a Binary files /dev/null and b/Subsurface/Content/Items/Clothes/engigear.png differ diff --git a/Subsurface/Content/Items/Electricity/signalcomp.png b/Subsurface/Content/Items/Electricity/signalcomp.png new file mode 100644 index 000000000..fa56f7a50 Binary files /dev/null and b/Subsurface/Content/Items/Electricity/signalcomp.png differ diff --git a/Subsurface/Content/Items/Electricity/signalitems.xml b/Subsurface/Content/Items/Electricity/signalitems.xml index a18e6ee2b..3949324cc 100644 --- a/Subsurface/Content/Items/Electricity/signalitems.xml +++ b/Subsurface/Content/Items/Electricity/signalitems.xml @@ -102,7 +102,7 @@ linkable="true" price="10"> - + @@ -129,7 +129,7 @@ linkable="true" price="10"> - + @@ -155,7 +155,7 @@ linkable="true" price="10"> - + @@ -182,11 +182,11 @@ linkable="true" price="10"> - + - + @@ -199,6 +199,30 @@ + + + + + + + + + + + + + + + + + + - + @@ -233,7 +257,7 @@ linkable="true" price="10"> - + @@ -258,7 +282,7 @@ linkable="true" price="20"> - + diff --git a/Subsurface/Content/Particles/ParticlePrefabs.xml b/Subsurface/Content/Particles/ParticlePrefabs.xml index 86b65da6a..e89939ca4 100644 --- a/Subsurface/Content/Particles/ParticlePrefabs.xml +++ b/Subsurface/Content/Particles/ParticlePrefabs.xml @@ -86,6 +86,7 @@ growtime ="0.1" deleteoncollision="true" rotatetodirection="true" + blendstate="additive" velocitychange="0.0, -5.0"> @@ -102,6 +103,35 @@ + + + + + + + + + @@ -123,6 +154,7 @@ colorchange="0.0, 0.0, 0.0, -4.0" lifetime="0.25" drawtarget="both" + blendstate="additive" velocitychange="0.0, 0.0"> @@ -134,6 +166,7 @@ colorchange="0.0, 0.0, 0.0, -4.0" lifetime="0.25" drawtarget="both" + blendstate="additive" velocitychange="0.0, 0.0"> diff --git a/Subsurface/Content/Particles/fire.png b/Subsurface/Content/Particles/fire.png new file mode 100644 index 000000000..4675dd8d1 Binary files /dev/null and b/Subsurface/Content/Particles/fire.png differ diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 9206871df..87ec7a3b8 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -37,13 +37,13 @@ namespace Barotrauma //the duration is determined by the attackDuration of the attacking limb private float attackTimer; - //a "cooldown time" after an attack during which the character doesn't try to attack again + //a "cooldown time" after an attack during which the Character doesn't try to attack again private float attackCoolDown; private float coolDownTimer; - //a point in a wall which the character is currently targeting + //a point in a wall which the Character is currently targeting private Vector2 wallAttackPos; - //the entity (a wall) which the character is targeting + //the entity (a wall) which the Character is targeting private IDamageable targetEntity; //the limb selected for the current attack @@ -226,7 +226,7 @@ namespace Barotrauma private void GetTargetEntity() { targetEntity = null; - //check if there's a wall between the target and the character + //check if there's a wall between the target and the Character Vector2 rayStart = Character.AnimController.Limbs[0].SimPosition; Vector2 rayEnd = selectedAiTarget.Position; Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd); @@ -313,7 +313,7 @@ namespace Barotrauma } else { - //limb.body.ApplyTorque(limb.Mass * -20.0f * character.animController.Dir * dir); + //limb.body.ApplyTorque(limb.Mass * -20.0f * Character.animController.Dir * dir); } Vector2 diff = attackPosition - limb.SimPosition; @@ -341,7 +341,7 @@ namespace Barotrauma } //goes through all the AItargets, evaluates how preferable it is to attack the target, - //whether the character can see/hear the target and chooses the most preferable target within + //whether the Character can see/hear the target and chooses the most preferable target within //sight/hearing range public void UpdateTargets(Character character) { @@ -370,7 +370,7 @@ namespace Barotrauma Character targetCharacter = target.Entity as Character; - //ignore the aitarget if it is the character itself + //ignore the aitarget if it is the Character itself if (targetCharacter == character) continue; if (targetCharacter!=null) @@ -381,7 +381,7 @@ namespace Barotrauma } else if (target.Entity!=null && attackRooms!=0.0f) { - //skip the target if it's the room the character is inside of + //skip the target if it's the room the Character is inside of if (character.AnimController.CurrentHull != null && character.AnimController.CurrentHull == target.Entity as Hull) continue; valueModifier = attackRooms; @@ -407,7 +407,7 @@ namespace Barotrauma //if (targetCharacter != null) //{ - // //if target is a character that isn't visible, ignore + // //if target is a Character that isn't visible, ignore // if (closestStructure != null) continue; // //prefer targets with low health @@ -542,11 +542,6 @@ namespace Barotrauma AiState newState = AiState.None; Vector2 newWallAttackPos = Vector2.Zero; float wanderAngle; - float updateTargetsTimer, raycastTimer, coolDownTimer; - - Vector2 newVelocity = Vector2.Zero; - - Vector2 targetPosition = Vector2.Zero; ushort targetID; @@ -590,10 +585,10 @@ namespace Barotrauma } } - //the "memory" of the character + //the "memory" of the Character //keeps track of how preferable it is to attack a specific target - //(if the character can't inflict much damage the target, the priority decreases - //and if the target attacks the character, the priority increases) + //(if the Character can't inflict much damage the target, the priority decreases + //and if the target attacks the Character, the priority increases) class AITargetMemory { //private AITarget target; diff --git a/Subsurface/Source/Characters/AI/PathFinder.cs b/Subsurface/Source/Characters/AI/PathFinder.cs index 3172407ab..692b83e3c 100644 --- a/Subsurface/Source/Characters/AI/PathFinder.cs +++ b/Subsurface/Source/Characters/AI/PathFinder.cs @@ -141,7 +141,7 @@ namespace Barotrauma if (startNode==null || endNode==null) { DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints"); - return new SteeringPath();; + return new SteeringPath(); } } diff --git a/Subsurface/Source/Characters/AnimController.cs b/Subsurface/Source/Characters/AnimController.cs index 326321440..2c6b911b6 100644 --- a/Subsurface/Source/Characters/AnimController.cs +++ b/Subsurface/Source/Characters/AnimController.cs @@ -17,7 +17,7 @@ namespace Barotrauma protected float walkSpeed, swimSpeed; - //how large impacts the character can take before being stunned + //how large impacts the Character can take before being stunned //protected float impactTolerance; protected float stunTimer; diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs index 0f6dbe27b..410b119c2 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs @@ -25,7 +25,7 @@ namespace Barotrauma prefabs = new List(); XDocument doc = ToolBox.TryLoadXml(configPath); - if (doc == null) return; + if (doc == null || doc.Root == null) return; foreach (XElement element in doc.Root.Elements()) { @@ -78,7 +78,7 @@ namespace Barotrauma } if (amount > 0) { - Swarm swarm = new Swarm(swarmMembers, prefab.SwarmRadius); + new Swarm(swarmMembers, prefab.SwarmRadius); } } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index c3a62accf..ab78afe27 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -5,12 +5,10 @@ using FarseerPhysics.Dynamics.Joints; using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Barotrauma.Networking; using Barotrauma.Particles; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Xml.Linq; @@ -27,7 +25,7 @@ namespace Barotrauma public static bool DisableControls; - //the character that the player is currently controlling + //the Character that the player is currently controlling private static Character controlled; public static Character Controlled @@ -43,7 +41,6 @@ namespace Barotrauma } public readonly bool IsNetworkPlayer; - private int importantUpdateTimer; private CharacterInventory inventory; @@ -116,7 +113,7 @@ namespace Barotrauma { get { - return (info != null && !string.IsNullOrWhiteSpace(info.Name)) ? info.Name : SpeciesName; + return info != null && !string.IsNullOrWhiteSpace(info.Name) ? info.Name : SpeciesName; } } @@ -334,7 +331,7 @@ namespace Barotrauma Info = characterInfo==null ? new CharacterInfo(file) : characterInfo; XDocument doc = ToolBox.TryLoadXml(file); - if (doc == null) return; + if (doc == null || doc.Root == null) return; SpeciesName = ToolBox.GetAttributeString(doc.Root, "name", "Unknown"); @@ -516,7 +513,7 @@ namespace Barotrauma if (IsKeyDown(InputType.Down)) targetMovement.Y -= 1.0f; //the vertical component is only used for falling through platforms and climbing ladders when not in water, - //so the movement can't be normalized or the character would walk slower when pressing down/up + //so the movement can't be normalized or the Character would walk slower when pressing down/up if (AnimController.InWater) { float length = targetMovement.Length(); @@ -693,7 +690,7 @@ namespace Barotrauma } /// - /// Control the character according to player input + /// Control the Character according to player input /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { @@ -753,7 +750,7 @@ namespace Barotrauma } - //find the closest item if selectkey has been hit, or if the character is being + //find the closest item if selectkey has been hit, or if the Character is being //controlled by the player (in order to highlight it) if (findClosestTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen) @@ -921,13 +918,13 @@ namespace Barotrauma aiTarget.SightRange = 0.0f; - //distance is approximated based on the mass of the character + //distance is approximated based on the mass of the Character //(which corresponds to size because all the characters have the same limb density) foreach (Limb limb in AnimController.Limbs) { aiTarget.SightRange += limb.Mass * 1000.0f; } - //the faster the character is moving, the easier it is to see it + //the faster the Character is moving, the easier it is to see it Limb torso = AnimController.GetLimb(LimbType.Torso); if (torso !=null) { @@ -1060,6 +1057,8 @@ namespace Barotrauma foreach (Limb limb in AnimController.Limbs) { + limb.AddDamage(limb.SimPosition, DamageType.Blunt, 500.0f, 0.0f, false); + Vector2 diff = centerOfMass - limb.SimPosition; if (diff == Vector2.Zero) continue; limb.body.ApplyLinearImpulse(diff * 10.0f); @@ -1138,7 +1137,7 @@ namespace Barotrauma if (GameMain.NetworkMember != null) { - //if the character is controlled by this client/server, let others know that the character has died + //if the Character is controlled by this client/server, let others know that the Character has died if (Character.controlled == this) { string chatMessage = "You have " + DeathMsg[(int)causeOfDeath] + "."; @@ -1149,12 +1148,12 @@ namespace Barotrauma new NetworkEvent(NetworkEventType.KillCharacter, ID, true, causeOfDeath); } - //if it's an ai character, only let the server kill it + //if it's an ai Character, only let the server kill it else if (GameMain.Server != null && this is AICharacter) { new NetworkEvent(NetworkEventType.KillCharacter, ID, true, causeOfDeath); } - //otherwise don't kill the character unless received a message about the character dying + //otherwise don't kill the Character unless received a message about the Character dying else if (!isNetworkMessage) { return; @@ -1350,9 +1349,9 @@ namespace Barotrauma case NetworkEventType.KillCharacter: if (GameMain.Server != null) { - Client sender =GameMain.Server.connectedClients.Find(c => c.Connection == message.SenderConnection); - if (sender ==null || sender.character != this) - throw new Exception("Received a KillCharacter message from someone else than the client controlling the character!"); + Client sender =GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); + if (sender ==null || sender.Character != this) + throw new Exception("Received a KillCharacter message from someone else than the client controlling the Character!"); } CauseOfDeath causeOfDeath = CauseOfDeath.Damage; @@ -1505,7 +1504,7 @@ namespace Barotrauma catch { - //failed to read position, character may be further than NetConfig.CharacterIgnoreDistance + //failed to read position, Character may be further than NetConfig.CharacterIgnoreDistance pos = SimPosition; } diff --git a/Subsurface/Source/Characters/CharacterHUD.cs b/Subsurface/Source/Characters/CharacterHUD.cs index b718da8cb..d57d1e94c 100644 --- a/Subsurface/Source/Characters/CharacterHUD.cs +++ b/Subsurface/Source/Characters/CharacterHUD.cs @@ -45,8 +45,6 @@ namespace Barotrauma if (character.Inventory != null) character.Inventory.DrawOwn(spriteBatch); - Color color = Color.Orange; - if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory!=null) { character.SelectedCharacter.Inventory.Draw(spriteBatch); diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index 1ee00a41e..297d8c7b5 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -274,7 +274,7 @@ namespace Barotrauma public virtual XElement Save(XElement parentElement) { - XElement charElement = new XElement("character"); + XElement charElement = new XElement("Character"); charElement.Add( new XAttribute("name", Name), diff --git a/Subsurface/Source/Characters/FishAnimController.cs b/Subsurface/Source/Characters/FishAnimController.cs index c27c42c37..333c27fb3 100644 --- a/Subsurface/Source/Characters/FishAnimController.cs +++ b/Subsurface/Source/Characters/FishAnimController.cs @@ -178,7 +178,7 @@ namespace Barotrauma //headMovement *= movement.Length(); //the movement angle is between direction of the head and the direction - //where the character is actually trying to go + //where the Character is actually trying to go //current * (float)alpha + previous * (1.0f - (float)alpha); diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index 8989b719d..23f622cc1 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -685,7 +685,7 @@ namespace Barotrauma leftLeg.body.ApplyTorque(Dir * -8.0f); rightLeg.body.ApplyTorque(Dir * -8.0f); - //apply forces to the head and the torso to move the character up/down + //apply forces to the head and the torso to move the Character up/down float movementFactor = (handPos.Y / stepHeight) * (float)Math.PI; movementFactor = 0.8f + (float)Math.Abs(Math.Sin(movementFactor)); @@ -727,7 +727,7 @@ namespace Barotrauma // Limb rightHand = GetLimb(LimbType.RightHand); // Limb head = GetLimb(LimbType.Head); - // Vector2 diff = Vector2.Normalize(character.CursorPosition - RefLimb.Position); + // Vector2 diff = Vector2.Normalize(Character.CursorPosition - RefLimb.Position); // rightHand.body.ApplyLinearImpulse(diff * 20.0f); // head.body.ApplyLinearImpulse(diff * 5.0f); @@ -863,8 +863,6 @@ namespace Barotrauma transformedHoldPos += Vector2.Transform(itemPos, torsoTransform); } - Vector2 bodyVelocity = torso.body.LinearVelocity / 60.0f; - item.body.ResetDynamics(); Vector2 currItemPos = (character.SelectedItems[0]==item) ? diff --git a/Subsurface/Source/Characters/Jobs/JobPrefab.cs b/Subsurface/Source/Characters/Jobs/JobPrefab.cs index 01a4c8600..677635c36 100644 --- a/Subsurface/Source/Characters/Jobs/JobPrefab.cs +++ b/Subsurface/Source/Characters/Jobs/JobPrefab.cs @@ -29,7 +29,7 @@ namespace Barotrauma private set; } - //names of the items the character spawns with + //names of the items the Character spawns with public List ItemNames; public List EquipItem; diff --git a/Subsurface/Source/Characters/Limb.cs b/Subsurface/Source/Characters/Limb.cs index 5c0abc64a..1a26e55b4 100644 --- a/Subsurface/Source/Characters/Limb.cs +++ b/Subsurface/Source/Characters/Limb.cs @@ -34,7 +34,7 @@ namespace Barotrauma protected readonly Vector2 stepOffset; - public Sprite sprite; + public Sprite sprite, damagedSprite; public bool inWater; @@ -50,6 +50,8 @@ namespace Barotrauma public readonly float impactTolerance; + private float damage; + private readonly Vector2 armorSector; private readonly float armorValue; @@ -142,7 +144,7 @@ namespace Barotrauma // set // { // damage = Math.Max(value, 0.0f); - // if (damage >=maxHealth) character.Kill(); + // if (damage >=maxHealth) Character.Kill(); // } //} @@ -246,7 +248,7 @@ namespace Barotrauma foreach (XElement subElement in element.Elements()) { - switch (subElement.Name.ToString()) + switch (subElement.Name.ToString().ToLower()) { case "sprite": string spritePath = subElement.Attribute("texture").Value; @@ -260,6 +262,18 @@ namespace Barotrauma sprite = new Sprite(subElement, "", spritePath); break; + case "damagedsprite": + string damagedSpritePath = subElement.Attribute("texture").Value; + + if (character.Info != null) + { + damagedSpritePath = damagedSpritePath.Replace("[GENDER]", (character.Info.Gender == Gender.Female) ? "f" : ""); + damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString()); + } + + + damagedSprite = new Sprite(subElement, "", damagedSpritePath); + break; case "attack": attack = new Attack(subElement); break; @@ -313,10 +327,9 @@ namespace Barotrauma damageSoundType = DamageSoundType.LimbArmor; amount = Math.Max(0.0f, amount - totalArmorValue); - bleedingAmount = Math.Max(0.0f, bleedingAmount - totalArmorValue); ; + bleedingAmount = Math.Max(0.0f, bleedingAmount - totalArmorValue); } - if (playSound) { SoundPlayer.PlayDamageSound(damageSoundType, amount, ConvertUnits.ToDisplayUnits(simPosition)); @@ -342,6 +355,9 @@ namespace Barotrauma GameMain.ParticleManager.CreateParticle("waterblood", Position, Vector2.Zero); } + damage += Math.Max(amount,bleedingAmount) / character.MaxHealth * 100.0f; + + return new AttackResult(amount, bleedingAmount, hitArmor); } @@ -362,6 +378,9 @@ namespace Barotrauma public void Update(float deltaTime) { + + if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f); + if (LinearVelocity.X>100.0f) { //DebugConsole.ThrowError("CHARACTER EXPLODED"); @@ -454,6 +473,19 @@ namespace Barotrauma 1.0f, spriteEffect, depth); } + if (damage>0.0f && damagedSprite!=null) + { + SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + float depth = sprite.Depth - 0.0000015f; + + damagedSprite.Draw(spriteBatch, + new Vector2(body.DrawPosition.X, -body.DrawPosition.Y), + color*Math.Min(damage/50.0f,1.0f), sprite.origin, + -body.DrawRotation, + 1.0f, spriteEffect, depth); + } + if (!GameMain.DebugDraw) return; if (pullJoint!=null) diff --git a/Subsurface/Source/Characters/Ragdoll.cs b/Subsurface/Source/Characters/Ragdoll.cs index 7e17cf90b..d22e94010 100644 --- a/Subsurface/Source/Characters/Ragdoll.cs +++ b/Subsurface/Source/Characters/Ragdoll.cs @@ -41,7 +41,7 @@ namespace Barotrauma private Vector2 targetMovement; //a movement vector that overrides targetmovement if trying to steer - //a character to the position sent by server in multiplayer mode + //a Character to the position sent by server in multiplayer mode protected Vector2 correctionMovement; protected float floorY; @@ -616,7 +616,7 @@ namespace Barotrauma { //create a splash particle - Barotrauma.Particles.Particle splash = GameMain.ParticleManager.CreateParticle("watersplash", + GameMain.ParticleManager.CreateParticle("watersplash", new Vector2(limb.Position.X, limbHull.Surface), new Vector2(0.0f, Math.Abs(-limb.LinearVelocity.Y * 10.0f)), 0.0f); @@ -633,7 +633,7 @@ namespace Barotrauma - //if the character dropped into water, create a wave + //if the Character dropped into water, create a wave if (limb.LinearVelocity.Y<0.0f) { //1.0 when the limb is parallel to the surface of the water diff --git a/Subsurface/Source/Characters/StatusEffect.cs b/Subsurface/Source/Characters/StatusEffect.cs index 384c431e9..53e537572 100644 --- a/Subsurface/Source/Characters/StatusEffect.cs +++ b/Subsurface/Source/Characters/StatusEffect.cs @@ -162,9 +162,9 @@ namespace Barotrauma } - //public virtual void Apply(ActionType type, float deltaTime, Item item, Character character = null) + //public virtual void Apply(ActionType type, float deltaTime, Item item, Character Character = null) //{ - // if (this.type == type) Apply(deltaTime, character, item); + // if (this.type == type) Apply(deltaTime, Character, item); //} private bool HasRequiredItems(Entity entity) @@ -225,7 +225,7 @@ namespace Barotrauma } } - //protected virtual void Apply(float deltaTime, Character character, Item item) + //protected virtual void Apply(float deltaTime, Character Character, Item item) //{ // if (explosion != null) explosion.Explode(item.SimPosition); @@ -235,7 +235,7 @@ namespace Barotrauma // { // ObjectProperty property; - // if (character!=null && character.properties.TryGetValue(propertyNames[i], out property)) + // if (Character!=null && Character.properties.TryGetValue(propertyNames[i], out property)) // { // ApplyToProperty(property, propertyEffects[i], deltaTime); // } diff --git a/Subsurface/Source/ContentPackage.cs b/Subsurface/Source/ContentPackage.cs index 826a376a7..d923e6a9c 100644 --- a/Subsurface/Source/ContentPackage.cs +++ b/Subsurface/Source/ContentPackage.cs @@ -130,8 +130,6 @@ namespace Barotrauma private void CalculateHash() { - StringBuilder sb = new StringBuilder(); - List hashes = new List(); //foreach (ContentFile file in files) diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 7502c5707..494f40452 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -167,8 +167,8 @@ namespace Barotrauma { SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode; if (mode == null) break; - mode.CrewManager.AddCharacter(Character.Controlled); - mode.CrewManager.SelectCharacter(null, Character.Controlled); + GameMain.GameSession.CrewManager.AddCharacter(Character.Controlled); + GameMain.GameSession.CrewManager.SelectCharacter(null, Character.Controlled); } } else @@ -232,10 +232,12 @@ namespace Barotrauma break; case "editwater": case "water": - if (GameMain.Client== null) - { - Hull.EditWater = !Hull.EditWater; - } + if (GameMain.Client == null) Hull.EditWater = !Hull.EditWater; + + break; + case "fire": + if (GameMain.Client == null) Hull.EditFire = !Hull.EditFire; + break; case "generatelevel": GameMain.Level = new Level("asdf", 50.0f, 500,500, 50); diff --git a/Subsurface/Source/EventInput/EventInput.cs b/Subsurface/Source/EventInput/EventInput.cs index d6818366e..e28362515 100644 --- a/Subsurface/Source/EventInput/EventInput.cs +++ b/Subsurface/Source/EventInput/EventInput.cs @@ -101,7 +101,7 @@ namespace EventInput public static class EventInput { /// - /// Event raised when a character has been entered. + /// Event raised when a Character has been entered. /// public static event CharEnteredHandler CharEntered; diff --git a/Subsurface/Source/Events/Task.cs b/Subsurface/Source/Events/Task.cs index acea30f10..f146a0475 100644 --- a/Subsurface/Source/Events/Task.cs +++ b/Subsurface/Source/Events/Task.cs @@ -41,9 +41,9 @@ namespace Barotrauma public Task(float priority, string name) { - if (GameMain.GameSession==null || GameMain.GameSession.taskManager == null) return; + if (GameMain.GameSession==null || GameMain.GameSession.TaskManager == null) return; - taskManager = GameMain.GameSession.taskManager; + taskManager = GameMain.GameSession.TaskManager; musicType = "repair"; this.priority = priority; this.name = name; diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index cf31ade77..427faf303 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -85,9 +85,9 @@ namespace Barotrauma if (textBlock.Text != "") { - //if you attempt to display a character that is not in your font + //if you attempt to display a Character that is not in your font //you will get an exception, so we filter the characters - //remove the filtering if you're using a default character in your spritefont + //remove the filtering if you're using a default Character in your spritefont String filtered = ""; foreach (char c in value) { diff --git a/Subsurface/Source/GameSession/CargoManager.cs b/Subsurface/Source/GameSession/CargoManager.cs index 9167814ed..3e106d654 100644 --- a/Subsurface/Source/GameSession/CargoManager.cs +++ b/Subsurface/Source/GameSession/CargoManager.cs @@ -32,7 +32,7 @@ namespace Barotrauma Hull cargoRoom = Hull.FindHull(wp.Position); - if (wp == null) + if (cargoRoom == null) { DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!"); return; @@ -44,7 +44,7 @@ namespace Barotrauma Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20), Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height + 20.0f, cargoRoom.Rect.Y)); - new Item(prefab as ItemPrefab, wp.Position); + new Item(prefab as ItemPrefab, position); } purchasedItems.Clear(); diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index 67cd1b81f..279260332 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -20,6 +20,10 @@ namespace Barotrauma private GUIFrame guiFrame; private GUIListBox listBox; + private bool crewFrameOpen; + private GUIButton crewButton; + protected GUIFrame crewFrame; + public int Money { @@ -34,10 +38,13 @@ namespace Barotrauma guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent); - listBox = new GUIListBox(new Rectangle(0, 0, 150, 0), Color.Transparent, null, guiFrame); + listBox = new GUIListBox(new Rectangle(0, 30, 150, 0), Color.Transparent, null, guiFrame); listBox.ScrollBarEnabled = false; listBox.OnSelected = SelectCharacter; + crewButton = new GUIButton(new Rectangle(0, 00, 100, 20), "Crew", GUI.Style, guiFrame); + crewButton.OnClicked = ToggleCrewFrame; + money = 10000; } @@ -100,6 +107,8 @@ namespace Barotrauma public void Update(float deltaTime) { guiFrame.Update(deltaTime); + + if (crewFrameOpen) crewFrame.Update(deltaTime); } public void KillCharacter(Character killedCharacter) @@ -113,6 +122,71 @@ namespace Barotrauma //} } + + public void CreateCrewFrame(List crew) + { + int width = 600, height = 400; + + crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); + crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + + GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame); + crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + crewList.OnSelected = SelectCrewCharacter; + + foreach (Character character in crew) + { + GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList); + frame.UserData = character; + frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); + frame.Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent; + frame.HoverColor = Color.LightGray * 0.5f; + frame.SelectedColor = Color.Gold * 0.5f; + + GUITextBlock textBlock = new GUITextBlock( + new Rectangle(40, 0, 0, 25), + character.Info.Name + " (" + character.Info.Job.Name + ")", + Color.Transparent, Color.White, + Alignment.Left, Alignment.Left, + null, frame); + textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); + + new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame); + } + + var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame); + closeButton.OnClicked = ToggleCrewFrame; + } + + protected virtual bool SelectCrewCharacter(GUIComponent component, object obj) + { + Character character = obj as Character; + if (character == null) return false; + + GUIComponent existingFrame = crewFrame.FindChild("selectedcharacter"); + if (existingFrame != null) crewFrame.RemoveChild(existingFrame); + + var previewPlayer = new GUIFrame( + new Rectangle(0, 0, 230, 300), + new Color(0.0f, 0.0f, 0.0f, 0.8f), Alignment.TopRight, GUI.Style, crewFrame); + previewPlayer.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); + previewPlayer.UserData = "selectedcharacter"; + + character.Info.CreateInfoFrame(previewPlayer); + + if (GameMain.NetworkMember != null) GameMain.NetworkMember.SelectCrewCharacter(component, obj); + + return true; + } + + private bool ToggleCrewFrame(GUIButton button, object obj) + { + if (crewFrame == null) CreateCrewFrame(characters); + + crewFrameOpen = !crewFrameOpen; + return true; + } + public void StartShift() { listBox.ClearChildren(); @@ -161,6 +235,8 @@ namespace Barotrauma public void Draw(SpriteBatch spriteBatch) { guiFrame.Draw(spriteBatch); + + if (crewFrameOpen) crewFrame.Draw(spriteBatch); } public void Save(XElement parentElement) diff --git a/Subsurface/Source/GameSession/GameModes/GameMode.cs b/Subsurface/Source/GameSession/GameModes/GameMode.cs index 02e207d05..169d28285 100644 --- a/Subsurface/Source/GameSession/GameModes/GameMode.cs +++ b/Subsurface/Source/GameSession/GameModes/GameMode.cs @@ -47,6 +47,11 @@ namespace Barotrauma get { return endMessage; } } + public GameModePreset Preset + { + get { return preset; } + } + public GameMode(GameModePreset preset) { this.preset = preset; diff --git a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs index 217b7e7a1..9b5e727af 100644 --- a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs @@ -12,7 +12,7 @@ namespace Barotrauma { //private const int StartCharacterAmount = 3; - public readonly CrewManager CrewManager; + //public readonly CrewManager CrewManager; //public readonly HireManager hireManager; private GUIButton endShiftButton; @@ -36,14 +36,18 @@ namespace Barotrauma public int Money { - get { return CrewManager.Money; } - set { CrewManager.Money = value; } + get { return GameMain.GameSession.CrewManager.Money; } + set { GameMain.GameSession.CrewManager.Money = value; } + } + + private CrewManager CrewManager + { + get { return GameMain.GameSession.CrewManager; } } public SinglePlayerMode(GameModePreset preset) : base(preset) { - CrewManager = new CrewManager(); CargoManager = new CargoManager(); @@ -86,7 +90,7 @@ namespace Barotrauma { if (subElement.Name.ToString().ToLower() != "crew") continue; - CrewManager = new CrewManager(subElement); + GameMain.GameSession.CrewManager = new CrewManager(subElement); } savedOnStart = true; diff --git a/Subsurface/Source/GameSession/GameModes/TutorialMode.cs b/Subsurface/Source/GameSession/GameModes/TutorialMode.cs index 80994a91a..415a456ac 100644 --- a/Subsurface/Source/GameSession/GameModes/TutorialMode.cs +++ b/Subsurface/Source/GameSession/GameModes/TutorialMode.cs @@ -23,7 +23,7 @@ namespace Barotrauma GameMain.GameSession.StartShift("tuto"); - GameMain.GameSession.taskManager.Tasks.Clear(); + GameMain.GameSession.TaskManager.Tasks.Clear(); GameMain.GameScreen.Select(); } @@ -255,7 +255,6 @@ namespace Barotrauma infoBox = CreateInfoFrame("You can see the equipped wire at the middle of the connection panel. Drag it to the power connector."); var steeringConnection = steering.Item.Connections.Find(c => c.Name.Contains("power")); - var junctionConnection = junctionBox.Item.Connections.Find(c => c.Name.Contains("power")); while (steeringConnection.Wires.FirstOrDefault(w => w != null) == null) { diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index 30d7433aa..ae784e255 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -12,23 +12,17 @@ namespace Barotrauma { class GameSession { - public readonly TaskManager taskManager; - - - //protected DateTime startTime; - //protected DateTime endTime; - - public readonly GameMode gameMode; + public readonly TaskManager TaskManager; + public readonly GameMode gameMode; + private GUIFrame guiRoot; - - //private GUIListBox chatBox; - //private GUITextBox textBox; - + private string saveFile; private Submarine submarine; + public CrewManager CrewManager; public Quest Quest { @@ -65,28 +59,29 @@ namespace Barotrauma get { return saveFile; } } - public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset) - :this(submarine, saveFile, gameModePreset.Instantiate()) + public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null) { + GameMain.GameSession = this; - } + CrewManager = new CrewManager(); - public GameSession(Submarine selectedSub, string saveFile, GameMode gameMode = null) - { - taskManager = new TaskManager(this); + TaskManager = new TaskManager(this); this.saveFile = saveFile; guiRoot = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsWidth), Color.Transparent); - this.gameMode = gameMode; - this.submarine = selectedSub; - + if (gameModePreset!=null) this.gameMode = gameModePreset.Instantiate(); + this.submarine = submarine; } - + public GameSession(Submarine selectedSub, string saveFile, string filePath) : this(selectedSub, saveFile) { + GameMain.GameSession = this; + + CrewManager = new CrewManager(); + XDocument doc = ToolBox.TryLoadXml(filePath); if (doc == null) return; @@ -131,7 +126,7 @@ namespace Barotrauma if (gameMode!=null) gameMode.Start(); - taskManager.StartShift(level); + TaskManager.StartShift(level); } public void EndShift(string endMessage) @@ -149,7 +144,7 @@ namespace Barotrauma GameMain.LobbyScreen.Select(); } - taskManager.EndShift(); + TaskManager.EndShift(); //gameMode.End(); //return true; @@ -158,9 +153,7 @@ namespace Barotrauma public void KillCharacter(Character character) { - SinglePlayerMode singlePlayerMode = gameMode as SinglePlayerMode; - if (singlePlayerMode == null) return; - singlePlayerMode.CrewManager.KillCharacter(character); + CrewManager.KillCharacter(character); } public bool LoadPrevious(GUIButton button, object obj) @@ -174,7 +167,7 @@ namespace Barotrauma public void Update(float deltaTime) { - taskManager.Update(deltaTime); + TaskManager.Update(deltaTime); guiRoot.Update(deltaTime); diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 922236ad0..23b0a0604 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -336,7 +336,7 @@ namespace Barotrauma.Items.Components } //opening a partially stuck door makes it less stuck - if (isOpen) stuck = MathHelper.Clamp(stuck-30.0f, 0.0f, 100.0f); ; + if (isOpen) stuck = MathHelper.Clamp(stuck-30.0f, 0.0f, 100.0f); } } } diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index 6b2087ac9..e381d9b36 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -7,7 +7,7 @@ namespace Barotrauma.Items.Components { class Holdable : Pickable { - //the position(s) in the item that the character grabs + //the position(s) in the item that the Character grabs protected Vector2[] handlePos; private List prevRequiredItems; @@ -24,7 +24,7 @@ namespace Barotrauma.Items.Components private bool attachable, attached, attachedByDefault; private PhysicsBody body; - //the angle in which the character holds the item + //the angle in which the Character holds the item protected float holdAngle; [HasDefaultValue(false, true)] diff --git a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs index 56d0b7f97..e4252a6cd 100644 --- a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -115,13 +115,11 @@ namespace Barotrauma.Items.Components AnimController ac = picker.AnimController; - Limb rightHand = ac.GetLimb(LimbType.RightHand); - if (!hitting) { if (picker.IsKeyDown(InputType.Aim)) { - hitPos = (float)System.Math.Min(hitPos+deltaTime*5.0f, MathHelper.Pi*0.7f); + hitPos = Math.Min(hitPos+deltaTime*5.0f, MathHelper.Pi*0.7f); ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.6f, -0.1f), new Vector2(-0.3f, 0.2f), false, hitPos); } diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index e7a9c7e5b..05d4f12bf 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -104,7 +104,7 @@ namespace Barotrauma.Items.Components if (character == null) return false; if (!character.IsKeyDown(InputType.Aim)) return false; - //if (DoesUseFail(character)) return false; + //if (DoesUseFail(Character)) return false; IsActive = true; @@ -181,7 +181,7 @@ namespace Barotrauma.Items.Components //ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ); } - //if (character.SecondaryKeyDown.State) + //if (Character.SecondaryKeyDown.State) //{ // IPropertyObject propertyObject = targetBody.UserData as IPropertyObject; // if (propertyObject!=null) ApplyStatusEffects(ActionType.OnUse, 1.0f, item.SimPosition, propertyObject); diff --git a/Subsurface/Source/Items/Components/Holdable/Throwable.cs b/Subsurface/Source/Items/Components/Holdable/Throwable.cs index 814fe1c2b..70d1eddf3 100644 --- a/Subsurface/Source/Items/Components/Holdable/Throwable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Throwable.cs @@ -30,18 +30,18 @@ namespace Barotrauma.Items.Components if (character == null) return false; if (!character.IsKeyDown(InputType.Aim) || throwing) return false; - //Vector2 diff = Vector2.Normalize(character.CursorPosition - character.AnimController.RefLimb.Position); + //Vector2 diff = Vector2.Normalize(Character.CursorPosition - Character.AnimController.RefLimb.Position); - //if (character.SelectedItems[1]==item) + //if (Character.SelectedItems[1]==item) //{ - // Limb leftHand = character.AnimController.GetLimb(LimbType.LeftHand); + // Limb leftHand = Character.AnimController.GetLimb(LimbType.LeftHand); // leftHand.body.ApplyLinearImpulse(diff * 20.0f); // leftHand.Disabled = true; //} - //if (character.SelectedItems[0] == item) + //if (Character.SelectedItems[0] == item) //{ - // Limb rightHand = character.AnimController.GetLimb(LimbType.RightHand); + // Limb rightHand = Character.AnimController.GetLimb(LimbType.RightHand); // rightHand.body.ApplyLinearImpulse(diff * 20.0f); // rightHand.Disabled = true; //} diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 15d47344d..d60813aaf 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -373,7 +373,7 @@ namespace Barotrauma.Items.Components public virtual void Move(Vector2 amount) { } - /// a character has picked the item + /// a Character has picked the item public virtual bool Pick(Character picker) { return false; @@ -384,7 +384,7 @@ namespace Barotrauma.Items.Components return CanBeSelected; } - /// a character has dropped the item + /// a Character has dropped the item public virtual void Drop(Character dropper) { } public virtual void Draw(SpriteBatch spriteBatch, bool editing = false) { } @@ -475,7 +475,7 @@ namespace Barotrauma.Items.Components } /// - /// Returns 0.0f-1.0f based on how well the character can use the itemcomponent + /// Returns 0.0f-1.0f based on how well the Character can use the itemcomponent /// /// 0.5f if all the skills meet the skill requirements exactly, 1.0f if they're way above and 0.0f if way less protected float DegreeOfSuccess(Character character) @@ -496,14 +496,14 @@ namespace Barotrauma.Items.Components return (average+100.0f)/2.0f; } - //public bool CheckFailure(Character character) + //public bool CheckFailure(Character Character) //{ // foreach (Skill skill in requiredSkills) // { - // int characterLevel = character.GetSkillLevel(skill.Name); + // int characterLevel = Character.GetSkillLevel(skill.Name); // if (characterLevel > skill.Level) continue; - // item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character); + // item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, Character); // //Item.ApplyStatusEffects(); // return true; diff --git a/Subsurface/Source/Items/Components/Label.cs b/Subsurface/Source/Items/Components/Label.cs index 97e086077..1bd5363ab 100644 --- a/Subsurface/Source/Items/Components/Label.cs +++ b/Subsurface/Source/Items/Components/Label.cs @@ -30,7 +30,7 @@ // } -// public override bool Select(Character character) +// public override bool Select(Character Character) // { // if (textBox == null) // { @@ -47,10 +47,10 @@ // textBox.Select(); -// return base.Select(character); +// return base.Select(Character); // } -// public override void DrawHUD(SpriteBatch spriteBatch, Character character) +// public override void DrawHUD(SpriteBatch spriteBatch, Character Character) // { // //isActive = true; // GuiFrame.Update((float)Physics.step); @@ -61,7 +61,7 @@ // //int y = Game1.GraphicsHeight / 2 - height / 2 - 50; // //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); -// if (!textBox.Selected) character.SelectedConstruction = null; +// if (!textBox.Selected) Character.SelectedConstruction = null; // } // private bool TextChanged(GUITextBox textBox, string text) diff --git a/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs b/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs index 791ad8373..3c9834d64 100644 --- a/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs +++ b/Subsurface/Source/Items/Components/Machines/OxygenGenerator.cs @@ -42,8 +42,7 @@ namespace Barotrauma.Items.Components ventList = new List(); - item.linkedTo.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { GetVents(); }; + item.linkedTo.CollectionChanged += delegate { GetVents(); }; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index e494a8a19..033db2468 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -78,9 +78,8 @@ namespace Barotrauma.Items.Components return (pingState > 1.0f); } - public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character) + 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; @@ -120,7 +119,6 @@ namespace Barotrauma.Items.Components if (Level.Loaded != null) { List cells = Level.Loaded.GetCells(-Level.Loaded.Position, 7); - Vector2 offset = Vector2.Zero; foreach (VoronoiCell cell in cells) { @@ -174,7 +172,6 @@ namespace Barotrauma.Items.Components end.Y = -end.Y; Vector2 diff = end - start; - Vector2 normalizedDiff = Vector2.Normalize(diff); for (float x = 0; x < diff.Length(); x+=4.0f ) { GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green); diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 22fdcfc64..9dbde12e1 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -141,7 +141,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/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index 68057f21e..3489cba01 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components { if (character != null && !characterUsable) return false; - //ApplyStatusEffects(ActionType.OnUse, 1.0f, character); + //ApplyStatusEffects(ActionType.OnUse, 1.0f, Character); Launch(new Vector2( (float)Math.Cos(item.body.Rotation), diff --git a/Subsurface/Source/Items/Components/Signal/Connection.cs b/Subsurface/Source/Items/Components/Signal/Connection.cs index 685197230..3b79d54c3 100644 --- a/Subsurface/Source/Items/Components/Signal/Connection.cs +++ b/Subsurface/Source/Items/Components/Signal/Connection.cs @@ -191,7 +191,7 @@ namespace Barotrauma.Items.Components bool mouseInRect = panelRect.Contains(PlayerInput.MousePosition); Wire equippedWire = null; - //if the character using the panel has a wire item equipped + //if the Character using the panel has a wire item equipped //and the wire hasn't been connected yet, draw it on the panel for (int i = 0; i < character.SelectedItems.Length; i++) { @@ -246,7 +246,7 @@ namespace Barotrauma.Items.Components } } - //if the character using the panel has a wire item equipped + //if the Character using the panel has a wire item equipped //and the wire hasn't been connected yet, draw it on the panel if (equippedWire!=null) { @@ -262,9 +262,9 @@ namespace Barotrauma.Items.Components } } - //for (int i = 0; i < character.SelectedItems.Length; i++ ) + //for (int i = 0; i < Character.SelectedItems.Length; i++ ) //{ - // Item selectedItem = character.SelectedItems[i]; + // Item selectedItem = Character.SelectedItems[i]; // if (selectedItem == null) continue; @@ -281,7 +281,7 @@ namespace Barotrauma.Items.Components if (!PlayerInput.LeftButtonDown()) { panel.Item.NewComponentEvent(panel, true, true); - //draggingConnected.Drop(character); + //draggingConnected.Drop(Character); draggingConnected = null; } } diff --git a/Subsurface/Source/Items/Components/Signal/WaterDetector.cs b/Subsurface/Source/Items/Components/Signal/WaterDetector.cs new file mode 100644 index 000000000..8aab2f40f --- /dev/null +++ b/Subsurface/Source/Items/Components/Signal/WaterDetector.cs @@ -0,0 +1,38 @@ +using System.Xml.Linq; + +namespace Barotrauma.Items.Components +{ + class WaterDetector : ItemComponent + { + private Hull hull; + + public WaterDetector(Item item, XElement element) + : base (item, element) + { + hull = Hull.FindHull(item.Position); + + IsActive = true; + } + + public override void OnMapLoaded() + { + hull = Hull.FindHull(item.Position); + } + + public override void Move(Microsoft.Xna.Framework.Vector2 amount) + { + hull = Hull.FindHull(item.Position); + } + + public override void Update(float deltaTime, Camera cam) + { + if (hull == null) return; + + float waterDepth = hull.Volume / hull.Size.X; + + bool underWater = (hull.Rect.Y-hull.Rect.Height + waterDepth)>item.Position.Y; + + item.SendSignal(underWater ? "1" : "0", "signal_out"); + } + } +} diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 12b5b14b1..bf47d2c0c 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -41,7 +41,7 @@ namespace Barotrauma.Items.Components public override void Move(Vector2 amount) { - amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); + //amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); //for (int i = 0; iPosition of the character doing the pick, only items that are close enough to this are checked + /// Position of the Character doing the pick, only items that are close enough to this are checked /// the item closest to pickPosition is returned /// If a hull is specified, only items within that hull are checked public static Item FindPickable(Vector2 position, Vector2 pickPosition, Hull hull = null, Item[] ignoredItems=null) @@ -1171,7 +1171,7 @@ namespace Barotrauma Item item = new Item(rect, ip); item.ID = (ushort)int.Parse(element.Attribute("ID").Value); - item.linkedToID = new List(); + item.linkedToID = new List(); foreach (XAttribute attribute in element.Attributes()) { @@ -1198,7 +1198,7 @@ namespace Barotrauma string[] linkedToIds = linkedToString.Split(','); for (int i = 0; i Triggers; public string ConfigFile diff --git a/Subsurface/Source/Map/FireSource.cs b/Subsurface/Source/Map/FireSource.cs new file mode 100644 index 000000000..723576e36 --- /dev/null +++ b/Subsurface/Source/Map/FireSource.cs @@ -0,0 +1,186 @@ +using Barotrauma.Lights; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Barotrauma +{ + class FireSource + { + const float OxygenConsumption = 10.0f; + const float GrowSpeed = 5.0f; + + Hull hull; + + LightSource lightSource; + + Vector2 position; + Vector2 size; + + public Vector2 Size + { + get { return size; } + } + + public FireSource(Vector2 position) + { + hull = Hull.FindHull(position); + if (hull == null) return; + + lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f)); + + hull.AddFireSource(this); + + this.position = position - new Vector2(-5.0f, 5.0f); + + this.position.Y = hull.Rect.Y - hull.Rect.Height; + + size = new Vector2(10.0f, 10.0f); + } + + private void LimitSize() + { + position.X = Math.Max(hull.Rect.X, position.X); + position.Y = Math.Min(hull.Rect.Y, position.Y); + + size.X = Math.Min(hull.Rect.Width - (position.X - hull.Rect.X), size.X); + size.Y = Math.Min(hull.Rect.Height - (hull.Rect.Y - position.Y), size.Y); + } + + public static void UpdateAll(List fireSources, float deltaTime) + { + for (int i = fireSources.Count - 1; i >= 0; i--) + { + fireSources[i].Update(deltaTime); + } + + //combine overlapping fires + for (int i = fireSources.Count - 1; i >= 0; i--) + { + for (int j = i-1; j>=0 ; j--) + { + if (!fireSources[i].CheckOverLap(fireSources[j])) continue; + + fireSources[j].position.X = Math.Min(fireSources[i].position.X, fireSources[j].position.X); + + fireSources[j].size.X = + Math.Max(fireSources[i].position.X + fireSources[i].size.X, fireSources[j].position.X + fireSources[j].size.X) + - fireSources[j].position.X; + + fireSources[i].Remove(); + } + } + } + + private bool CheckOverLap(FireSource fireSource) + { + return !(position.X > fireSource.position.X + fireSource.size.X && + position.X + size.X < fireSource.position.X); + + + } + + public void Update(float deltaTime) + { + float count = Rand.Range(0.0f, (float)Math.Sqrt(size.X)/2.0f); + + for (int i = 0; i < count; i++ ) + { + float normalizedPos = 0.5f-(i / count); + + Vector2 spawnPos = new Vector2(position.X + Rand.Range(0.0f, size.X), Rand.Range(position.Y - size.Y, position.Y)+10.0f); + + Vector2 speed = new Vector2((spawnPos.X - (position.X + size.X/2.0f)), (float)Math.Sqrt(size.X)*Rand.Range(10.0f,15.0f)); + + var particle = GameMain.ParticleManager.CreateParticle("flame", + spawnPos, speed, 0.0f, hull); + + if (particle == null) continue; + + if (Rand.Int(20) == 1) particle.OnChangeHull = OnChangeHull; + + + particle.Size *= MathHelper.Clamp(size.X/100.0f * (hull.Oxygen/hull.FullVolume), 0.5f, 4.0f); + } + + DamageCharacters(deltaTime); + + if (hull.Volume > 0.0f) Extinquish(deltaTime); + + lightSource.Range = Math.Max(size.X, size.Y)*Rand.Range(8.0f, 10.0f)/2.0f; + lightSource.Color = new Color(1.0f, 0.9f, 0.6f) * Rand.Range(0.8f, 1.0f); + + hull.Oxygen -= size.X*deltaTime*OxygenConsumption; + + float growModifier = hull.OxygenPercentage < 20.0f ? hull.OxygenPercentage/20.0f : 1.0f; + + position.X -= GrowSpeed * growModifier * 0.5f * deltaTime; + //position.Y += GrowSpeed*0.5f * deltaTime; + + size.X += GrowSpeed * growModifier * deltaTime; + //size.Y += GrowSpeed * deltaTime; + + LimitSize(); + } + + private void OnChangeHull(Vector2 pos, Hull particleHull) + { + if (particleHull == hull || particleHull==null) return; + + if (particleHull.FireSources.Find(fs => pos.X > fs.position.X && pos.X < fs.position.X+fs.size.X)!=null) return; + + new FireSource(new Vector2(pos.X, particleHull.Rect.Y-particleHull.Rect.Height + 5.0f)); + } + + private void DamageCharacters(float deltaTime) + { + foreach (Character c in Character.CharacterList) + { + if (c.AnimController.CurrentHull == null) continue; + + float range = (float)Math.Sqrt(size.X) * 10.0f; + if (c.Position.X < position.X - range || c.Position.X > position.X + size.X + range) continue; + if (c.Position.Y < position.Y - size.Y || c.Position.Y > hull.Rect.Y) continue; + + c.Health -= (float)Math.Sqrt(size.X) * deltaTime; + } + } + + private void Extinquish(float deltaTime) + { + float extinquishAmount = Math.Min(hull.Volume / 100.0f, size.X); + + float steamCount = Rand.Range(-5.0f, (float)Math.Sqrt(extinquishAmount)); + + for (int i = 0; i < steamCount; i++) + { + Vector2 spawnPos = new Vector2(position.X + size.X * (i / steamCount) + Rand.Range(-5.0f, 5.0f), Rand.Range(position.Y - size.Y, position.Y) + 10.0f); + + Vector2 speed = new Vector2((spawnPos.X - (position.X + size.X / 2.0f)), (float)Math.Sqrt(size.X) * Rand.Range(20.0f, 25.0f)); + + var particle = GameMain.ParticleManager.CreateParticle("steam", + spawnPos, speed, 0.0f, hull); + + if (particle == null) continue; + + particle.Size *= MathHelper.Clamp(size.X / 10.0f, 0.5f, 3.0f); + } + + position.X += extinquishAmount * 0.1f / 2.0f; + size.X -= extinquishAmount * 0.1f; + + hull.Volume -= extinquishAmount; + + if (size.X < 1.0f) Remove(); + } + + public void Remove() + { + lightSource.Remove(); + + hull.RemoveFire(this); + } + } +} diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index 5f45e58d1..83e05e1f0 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -609,7 +609,7 @@ namespace Barotrauma Gap g = new Gap(rect); g.ID = (ushort)int.Parse(element.Attribute("ID").Value); - g.linkedToID = new List(); + g.linkedToID = new List(); //int i = 0; //while (element.Attribute("linkedto" + i) != null) //{ diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 17447f643..3dcffaac1 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -15,9 +15,11 @@ namespace Barotrauma { public static List hullList = new List(); - public static bool EditWater; + public static bool EditWater, EditFire; public static WaterRenderer renderer; + + private List fireSources; public const float OxygenDistributionSpeed = 500.0f; public const float OxygenDetoriationSpeed = 0.3f; @@ -126,12 +128,19 @@ namespace Barotrauma get { return waveVel; } } + public List FireSources + { + get { return fireSources; } + } + public Hull(Rectangle rectangle) { rect = rectangle; OxygenPercentage = Rand.Range(90.0f, 100.0f, false); + fireSources = new List(); + properties = TypeDescriptor.GetProperties(GetType()) .Cast() .ToDictionary(pr => pr.Name); @@ -197,6 +206,11 @@ namespace Barotrauma hullList.Remove(this); } + public void AddFireSource(FireSource fireSource) + { + fireSources.Add(fireSource); + } + public override void Update(Camera cam, float deltaTime) { Oxygen -= OxygenDetoriationSpeed * deltaTime; @@ -217,7 +231,20 @@ namespace Barotrauma } } } + else if (EditFire) + { + Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); + if (Submarine.RectContains(rect, position)) + { + if (PlayerInput.LeftButtonClicked()) + { + new FireSource(position); + } + } + } + FireSource.UpdateAll(fireSources, deltaTime); + //update client hulls if the amount of water has changed by >10% if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f) { @@ -292,8 +319,11 @@ namespace Barotrauma LethalPressure += ( Submarine.Loaded!=null && Submarine.Loaded.AtDamageDepth) ? 100.0f*deltaTime : 10.0f * deltaTime; } + } - + public void RemoveFire(FireSource fire) + { + fireSources.Remove(fire); } public override void Draw(SpriteBatch spriteBatch, bool editing) @@ -441,6 +471,27 @@ namespace Barotrauma return null; } + public List FindGaps() + { + List gaps = new List(); + + foreach (Gap gap in Gap.GapList) + { + if (gap.Open < 0.01f) continue; + if (gap.linkedTo.Count == 0) continue; + + var gapHull = gap.linkedTo[0] as Hull; + if (gapHull == this) gaps.Add(gap); + + if (gap.linkedTo.Count < 2) continue; + + gapHull = gap.linkedTo[1] as Hull; + if (gapHull == this) gaps.Add(gap); + } + + return gaps; + } + public override XElement Save(XDocument doc) { XElement element = new XElement("Hull"); diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index e274d1197..95f3aa857 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -731,10 +731,8 @@ namespace Barotrauma // cell.body.SetTransform(cell.body.Position + simAmount, cell.body.Rotation); //} - int i = 0; foreach (Body body in bodies) { - i++; body.SetTransform(body.Position + simAmount, body.Rotation); } @@ -759,7 +757,6 @@ namespace Barotrauma Vector2 prevVelocity; public void Move(Vector2 amount) { - Vector2 velocity = amount; Vector2 simVelocity = ConvertUnits.ToSimUnits(amount / (float)Physics.step); foreach (Body body in bodies) diff --git a/Subsurface/Source/Map/Levels/VoronoiElements.cs b/Subsurface/Source/Map/Levels/VoronoiElements.cs index ec22a8f5c..adf3f7832 100644 --- a/Subsurface/Source/Map/Levels/VoronoiElements.cs +++ b/Subsurface/Source/Map/Levels/VoronoiElements.cs @@ -62,10 +62,6 @@ namespace Voronoi2 { public double x, y; - public Point () - { - } - public void setPoint ( double x, double y ) { this.x = x; diff --git a/Subsurface/Source/Map/LocationType.cs b/Subsurface/Source/Map/LocationType.cs index 9ac05b1ab..6f4960dab 100644 --- a/Subsurface/Source/Map/LocationType.cs +++ b/Subsurface/Source/Map/LocationType.cs @@ -54,7 +54,7 @@ namespace Barotrauma nameFormats = new List(); foreach (XAttribute nameFormat in element.Element("nameformats").Attributes()) { - nameFormats.Add(nameFormat.Value.ToString()); + nameFormats.Add(nameFormat.Value); } string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png"); diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index e3d109813..59f7a50f7 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -24,7 +24,7 @@ namespace Barotrauma protected static Vector2 startMovingPos = Vector2.Zero; - protected List linkedToID; + protected List linkedToID; //observable collection because some entities may need to be notified when the collection is modified public ObservableCollection linkedTo; diff --git a/Subsurface/Source/Map/WaterRenderer.cs b/Subsurface/Source/Map/WaterRenderer.cs index 7f05f52bb..fcbe29b14 100644 --- a/Subsurface/Source/Map/WaterRenderer.cs +++ b/Subsurface/Source/Map/WaterRenderer.cs @@ -35,7 +35,7 @@ namespace Barotrauma waterEffect.Parameters["xWaveWidth"].SetValue(0.05f); waterEffect.Parameters["xWaveHeight"].SetValue(0.05f); #if WINDOWS - waterEffect.Parameters["xTexture"].SetValue(waterTexture); + //waterEffect.Parameters["xTexture"].SetValue(waterTexture); #endif #if LINUX waterEffect.Parameters["xWaterBumpMap"].SetValue(waterTexture); diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index d86ad027b..b04631f1a 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -327,11 +327,11 @@ namespace Barotrauma w.assignedJob = JobPrefab.List.Find(jp => jp.Name.ToLower() == jobName); } - w.linkedToID = new List(); + w.linkedToID = new List(); int i = 0; while (element.Attribute("linkedto" + i) != null) { - w.linkedToID.Add(int.Parse(element.Attribute("linkedto" + i).Value)); + w.linkedToID.Add((ushort)int.Parse(element.Attribute("linkedto" + i).Value)); i += 1; } } diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 76cc24db5..4f7f772b2 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using Lidgren.Network; using Microsoft.Xna.Framework; using System.Collections.Generic; @@ -207,7 +206,7 @@ namespace Barotrauma.Networking if (packetType == (byte)PacketTypes.LoggedIn) { myID = inc.ReadInt32(); - bool gameStarted= inc.ReadBoolean(); + gameStarted = inc.ReadBoolean(); if (gameStarted && Screen.Selected != GameMain.GameScreen) { new GUIMessageBox("Please wait", "A round is already running. You will have to wait for a new round to start."); @@ -219,7 +218,7 @@ namespace Barotrauma.Networking { GameMain.NetLobbyScreen.Select(); - new GUIMessageBox("Connection timed out", "You were disconnected for too long and your character was deleted. Please wait for another round to start."); + new GUIMessageBox("Connection timed out", "You were disconnected for too long and your Character was deleted. Please wait for another round to start."); } GameMain.NetLobbyScreen.ClearPlayers(); @@ -428,7 +427,7 @@ namespace Barotrauma.Networking switch (packetType) { case (byte)PacketTypes.StartGame: - if (gameStarted) continue; + if (Screen.Selected == GameMain.GameScreen) continue; GameMain.ShowLoading(StartGame(inc), false); @@ -467,8 +466,8 @@ namespace Barotrauma.Networking if (!c.IsNetworkPlayer || !c.IsHumanoid || c.Info==null) continue; crew.Add(c); } - - CreateCrewFrame(crew); + + GameMain.GameSession.CrewManager.CreateCrewFrame(crew); break; @@ -532,7 +531,7 @@ namespace Barotrauma.Networking if (gameMode == null) { - DebugConsole.ThrowError("Game mode ''"+gameMode+"'' not found!"); + DebugConsole.ThrowError("Game mode ''" + modeName + "'' not found!"); yield return CoroutineStatus.Success; } @@ -576,7 +575,7 @@ namespace Barotrauma.Networking AddChatMessage("Press TAB to chat", ChatMessageType.Server); - CreateCrewFrame(crew); + GameMain.GameSession.CrewManager.CreateCrewFrame(crew); yield return CoroutineStatus.Success; } @@ -624,7 +623,7 @@ namespace Barotrauma.Networking myCharacter = null; foreach (Client c in otherClients) { - c.character = null; + c.Character = null; } yield return CoroutineStatus.Success; @@ -680,6 +679,16 @@ namespace Barotrauma.Networking } } + public bool SpectateClicked(GUIButton button, object userData) + { + NetOutgoingMessage msg = client.CreateMessage(); + msg.Write((byte)PacketTypes.Spectate); + + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + + return false; + } + public void SendCharacterData() { if (characterInfo == null) return; @@ -800,7 +809,7 @@ namespace Barotrauma.Networking int bitCount = Rand.Int(100); for (int i = 0; i connectedClients = new List(); + public List ConnectedClients = new List(); //for keeping track of disconnected clients in case the reconnect shortly after private List disconnectedClients = new List(); private NetStats netStats; + private int roundStartSeed; + //is the server running - bool started; + private bool started; private NetServer server; private NetPeerConfiguration config; @@ -131,7 +134,7 @@ namespace Barotrauma.Networking request.AddParameter("action", "addserver"); request.AddParameter("servername", name); request.AddParameter("serverport", Port); - request.AddParameter("playercount", PlayerCountToByte(connectedClients.Count, config.MaximumConnections)); + request.AddParameter("playercount", PlayerCountToByte(ConnectedClients.Count, config.MaximumConnections)); request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1); // execute the request @@ -143,7 +146,7 @@ namespace Barotrauma.Networking return; } - if (response!=null && !string.IsNullOrWhiteSpace(response.Content)) + if (response != null && !string.IsNullOrWhiteSpace(response.Content)) { DebugConsole.ThrowError("Error while connecting to master server (" +response.Content+")"); return; @@ -160,7 +163,7 @@ namespace Barotrauma.Networking var request = new RestRequest("masterserver.php", Method.GET); request.AddParameter("action", "refreshserver"); request.AddParameter("gamestarted", gameStarted ? 1 : 0); - request.AddParameter("playercount", PlayerCountToByte(connectedClients.Count, config.MaximumConnections)); + request.AddParameter("playercount", PlayerCountToByte(ConnectedClients.Count, config.MaximumConnections)); System.Diagnostics.Debug.WriteLine("refreshing master"); @@ -221,7 +224,7 @@ namespace Barotrauma.Networking //if all characters dead if (AutoRestart && - connectedClients.Find(c => c.character != null && !c.character.IsDead)==null && + ConnectedClients.Find(c => c.Character != null && !c.Character.IsDead)==null && (myCharacter == null || myCharacter.IsDead)) { EndButtonHit(null, null); @@ -229,7 +232,7 @@ namespace Barotrauma.Networking return; } } - else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0) + else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && ConnectedClients.Count>0) { AutoRestartTimer -= deltaTime; if (AutoRestartTimer < 0.0f) @@ -243,16 +246,16 @@ namespace Barotrauma.Networking disconnectedClients[i].deleteDisconnectedTimer -= deltaTime; if (disconnectedClients[i].deleteDisconnectedTimer > 0.0f) continue; - if (gameStarted && disconnectedClients[i].character!=null) + if (gameStarted && disconnectedClients[i].Character!=null) { - disconnectedClients[i].character.Remove(); - disconnectedClients[i].character = null; + disconnectedClients[i].Character.Remove(); + disconnectedClients[i].Character = null; } disconnectedClients.RemoveAt(i); } - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { c.ReliableChannel.Update(deltaTime); } @@ -283,7 +286,7 @@ namespace Barotrauma.Networking foreach (Character c in Character.CharacterList) { - if (c as AICharacter == null || c.IsDead) continue; + if (!(c is AICharacter) || c.IsDead) continue; if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; @@ -301,12 +304,10 @@ namespace Barotrauma.Networking updateTimer = DateTime.Now + updateInterval; } - if (registeredToMaster && refreshMasterTimer < DateTime.Now) - { - CoroutineManager.StartCoroutine(RefreshMaster()); + if (!registeredToMaster || refreshMasterTimer >= DateTime.Now) return; - refreshMasterTimer = DateTime.Now + refreshMasterInterval; - } + CoroutineManager.StartCoroutine(RefreshMaster()); + refreshMasterTimer = DateTime.Now + refreshMasterInterval; } private void SparseUpdate() @@ -315,7 +316,7 @@ namespace Barotrauma.Networking foreach (Character c in Character.CharacterList) { - if (c as AICharacter != null || c.IsDead) continue; + if (c is AICharacter || c.IsDead) continue; new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false); } @@ -325,8 +326,6 @@ namespace Barotrauma.Networking private void ReadMessage(NetIncomingMessage inc) { - NetOutgoingMessage outmsg; - switch (inc.MessageType) { case NetIncomingMessageType.ConnectionApproval: @@ -336,7 +335,7 @@ namespace Barotrauma.Networking Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status); if (inc.SenderConnection.Status == NetConnectionStatus.Connected) { - Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection); + Client sender = ConnectedClients.Find(x => x.Connection == inc.SenderConnection); if (sender == null) break; @@ -345,7 +344,7 @@ namespace Barotrauma.Networking DisconnectClient(sender, sender.name+" was unable to connect to the server (nonmatching game version)", "Version " + GameMain.Version + " required to connect to the server (Your version: " + sender.version + ")"); } - else if (connectedClients.Find(x => x.name == sender.name && x != sender)!=null) + else if (ConnectedClients.Find(x => x.name == sender.name && x != sender)!=null) { DisconnectClient(sender, sender.name + " was unable to connect to the server (name already in use)", "The name ''"+sender.name+"'' is already in use. Please choose another name."); @@ -357,19 +356,16 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen.AddPlayer(sender.name); // Notify the client that they have logged in - outmsg = server.CreateMessage(); + var outmsg = server.CreateMessage(); outmsg.Write((byte)PacketTypes.LoggedIn); - outmsg.Write(sender.ID); - outmsg.Write(gameStarted); - - outmsg.Write(gameStarted && sender.character!=null); + outmsg.Write(gameStarted && sender.Character!=null); //notify the client about other clients already logged in - outmsg.Write((characterInfo == null) ? connectedClients.Count - 1 : connectedClients.Count); - foreach (Client c in connectedClients) + outmsg.Write((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count); + foreach (Client c in ConnectedClients) { if (c.Connection == inc.SenderConnection) continue; outmsg.Write(c.name); @@ -401,7 +397,7 @@ namespace Barotrauma.Networking } else if (inc.SenderConnection.Status == NetConnectionStatus.Disconnected) { - var connectedClient = connectedClients.Find(c => c.Connection == inc.SenderConnection); + var connectedClient = ConnectedClients.Find(c => c.Connection == inc.SenderConnection); if (connectedClient != null && !disconnectedClients.Contains(connectedClient)) { connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime; @@ -415,7 +411,7 @@ namespace Barotrauma.Networking break; case NetIncomingMessageType.Data: - Client dataSender = connectedClients.Find(c => c.Connection == inc.SenderConnection); + Client dataSender = ConnectedClients.Find(c => c.Connection == inc.SenderConnection); if (dataSender == null) return; byte packetType = 0; @@ -428,13 +424,10 @@ namespace Barotrauma.Networking return; } - bool isReliable = false; if (packetType == (byte)PacketTypes.ReliableMessage) { if (!dataSender.ReliableChannel.CheckMessage(inc)) return; packetType = inc.ReadByte(); - - isReliable = true; } switch (packetType) @@ -443,33 +436,6 @@ namespace Barotrauma.Networking if (!gameStarted) break; NetworkEvent.ReadMessage(inc, true); - //List recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame); - //if (recipients.Count == 0) break; - - //if (isReliable) - //{ - // Debug.WriteLine("receiver reliable networkevent"); - // foreach (Client c in recipients) - // { - // var reliableMessage = c.ReliableChannel.CreateMessage(); - // inc.Position = 8+16; - // byte[] messageBytes = inc.ReadBytes(inc.LengthBytes-3); - // reliableMessage.InnerMessage.Write(messageBytes); - - // c.ReliableChannel.SendMessage(reliableMessage, c.Connection); - // } - //} - //else - //{ - // outmsg = server.CreateMessage(); - // outmsg.Write(inc); - - // List recipientConnections = new List(); - // foreach (Client c in recipients) recipientConnections.Add(c.Connection); - - // server.SendMessage(outmsg, recipientConnections, inc.DeliveryMethod, 0); - //} - break; case (byte)PacketTypes.Chatmessage: ChatMessageType messageType = (ChatMessageType)inc.ReadByte(); @@ -492,7 +458,14 @@ namespace Barotrauma.Networking dataSender.ReliableChannel.HandleLatestMessageID(inc); break; case (byte)PacketTypes.Vote: - Voting.RegisterVote(inc, connectedClients); + Voting.RegisterVote(inc, ConnectedClients); + break; + case (byte)PacketTypes.Spectate: + if (gameStarted) + { + var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset); + server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered); + } break; } break; @@ -515,7 +488,7 @@ namespace Barotrauma.Networking return; } - if (connectedClients.Find(c => c.Connection == inc.SenderConnection)!=null) + if (ConnectedClients.Find(c => c.Connection == inc.SenderConnection)!=null) { inc.SenderConnection.Deny("Connection error - already joined"); return; @@ -565,7 +538,7 @@ namespace Barotrauma.Networking DebugConsole.NewMessage(name + " couldn't join the server (wrong content package hash)", Color.Red); return; } - else if (connectedClients.Find(c => c.name.ToLower() == name.ToLower() && c.ID!=userID) != null) + else if (ConnectedClients.Find(c => c.name.ToLower() == name.ToLower() && c.ID!=userID) != null) { inc.SenderConnection.Deny("The name ''" + name + "'' is already in use. Please choose another name."); DebugConsole.NewMessage(name + " couldn't join the server (name already in use)", Color.Red); @@ -577,14 +550,14 @@ namespace Barotrauma.Networking //existing user re-joining if (userID > 0) { - Client existingClient = connectedClients.Find(c => c.ID == userID); + Client existingClient = ConnectedClients.Find(c => c.ID == userID); if (existingClient == null) { existingClient = disconnectedClients.Find(c => c.ID == userID); if (existingClient != null) { disconnectedClients.Remove(existingClient); - connectedClients.Add(existingClient); + ConnectedClients.Add(existingClient); UpdateCrewFrame(); } @@ -598,7 +571,7 @@ namespace Barotrauma.Networking } userID = Rand.Range(1, 1000000); - while (connectedClients.Find(c => c.ID == userID) != null) + while (ConnectedClients.Find(c => c.ID == userID) != null) { userID++; } @@ -607,7 +580,7 @@ namespace Barotrauma.Networking newClient.Connection = inc.SenderConnection; newClient.version = version; - connectedClients.Add(newClient); + ConnectedClients.Add(newClient); UpdateCrewFrame(); @@ -615,11 +588,11 @@ namespace Barotrauma.Networking } - private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection) + private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection = null) { List recipients = new List(); - foreach (Client client in connectedClients) + foreach (Client client in ConnectedClients) { if (client.Connection != excludedConnection) recipients.Add(client.Connection); } @@ -634,78 +607,10 @@ namespace Barotrauma.Networking { if (NetworkEvent.Events.Count == 0) return; - List recipients = connectedClients.FindAll(c => c.character != null); - - List recipientConnections = new List(); - foreach (Client c in recipients) - { - recipientConnections.Add(c.Connection); - } + List recipients = ConnectedClients.FindAll(c => c.Character != null); if (recipients.Count == 0) return; - //foreach (Client c in recipients) - //{ - - // for (int i = 0; i < 2; i++) - // { - // bool important = i == 0; - - // var events = NetworkEvent.Events.FindAll(e => e.IsImportant == important && e.SenderConnection != c.Connection); - // if (events.Count == 0) continue; - - // List msgBytes = new List(); - - // int totalLength = 1; - - // foreach (NetworkEvent unreliableEvent in events) - // { - // NetBuffer tempMessage = new NetBuffer();// server.CreateMessage(); - // if (!unreliableEvent.FillData(tempMessage)) continue; - // tempMessage.WritePadBits(); - - // tempMessage.Position = 0; - // msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes)); - - // //one extra byte for writing the length - // totalLength += 1 + tempMessage.LengthBytes; - // } - - // //NetOutgoingMessage combinedMessage = null; - // //reliableMessage = null; - // if (important) - // { - // ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage(); - - // reliableMessage.InnerMessage.Write((byte)msgBytes.Count); - // foreach (byte[] msgData in msgBytes) - // { - // if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)"); - - // reliableMessage.InnerMessage.Write((byte)msgData.Length); - // reliableMessage.InnerMessage.Write(msgData); - // } - - // c.ReliableChannel.SendMessage(reliableMessage, c.Connection); - // } - // else - // { - // var combinedMessage = server.CreateMessage(totalLength); - - // combinedMessage.Write((byte)msgBytes.Count); - // foreach (byte[] msgData in msgBytes) - // { - // if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)"); - - // combinedMessage.Write((byte)msgData.Length); - // combinedMessage.Write(msgData); - // } - - // server.SendMessage(combinedMessage, c.Connection, NetDeliveryMethod.Unreliable, 0); - // } - - // } - //} foreach (Client c in recipients) { var message = ComposeNetworkEventMessage(true, c.Connection); @@ -725,39 +630,6 @@ namespace Barotrauma.Networking } } - - - //foreach (NetworkEvent networkEvent in NetworkEvent.events) - //{ - // if (!networkEvent.IsImportant) co - // //if (!networkEvent.IsClient) continue; - - // if (!networkEvent.FillData(message)) - // { - // continue; - // } - - // //Entity e = Entity.FindEntityByID(networkEvent.ID); - // //if (e == null) continue; - // if (networkEvent.IsImportant) - // { - // foreach (Client c in recipients) - // { - // ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage(); - // message.Position = 0; - // reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes)); - - // c.ReliableChannel.SendMessage(reliableMessage, c.Connection); - // } - // } - // else - // { - // if (server.ConnectionsCount>0) - // { - // server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0); - // } - // } - //} NetworkEvent.Events.Clear(); } @@ -768,7 +640,7 @@ namespace Barotrauma.Networking if (Voting.AllowSubVoting) { - Voting.HighestVoted(VoteType.Sub, connectedClients); + selectedSub = Voting.HighestVoted(VoteType.Sub, ConnectedClients); if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub; } else @@ -793,22 +665,23 @@ namespace Barotrauma.Networking AssignJobs(); - //selectedMap.Load(); + roundStartSeed = DateTime.Now.Millisecond; + Rand.SetSyncedSeed(roundStartSeed); - int seed = DateTime.Now.Millisecond; - Rand.SetSyncedSeed(seed); - - GameModePreset selectedMode = Voting.HighestVoted(VoteType.Mode, connectedClients); + GameModePreset selectedMode = Voting.HighestVoted(VoteType.Mode, ConnectedClients); if (selectedMode==null) selectedMode=GameMain.NetLobbyScreen.SelectedMode; GameMain.GameSession = new GameSession(selectedSub, "", selectedMode); GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed); + var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset); + SendMessage(startMessage, NetDeliveryMethod.ReliableUnordered); + yield return CoroutineStatus.Running; List characterInfos = new List(); - foreach (Client client in connectedClients) + foreach (Client client in ConnectedClients) { client.inGame = true; @@ -829,11 +702,11 @@ namespace Barotrauma.Networking WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos); - for (int i = 0; i < connectedClients.Count; i++) + for (int i = 0; i < ConnectedClients.Count; i++) { - connectedClients[i].character = new Character( - connectedClients[i].characterInfo, assignedWayPoints[i], true); - connectedClients[i].character.GiveJobItems(assignedWayPoints[i]); + ConnectedClients[i].Character = new Character( + ConnectedClients[i].characterInfo, assignedWayPoints[i], true); + ConnectedClients[i].Character.GiveJobItems(assignedWayPoints[i]); } if (characterInfo != null) @@ -845,7 +718,23 @@ namespace Barotrauma.Networking } yield return CoroutineStatus.Running; + + UpdateCrewFrame(); + //give some time for the clients to load the map + yield return new WaitForSeconds(2.0f); + + gameStarted = true; + + GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; + + GameMain.GameScreen.Select(); + + yield return CoroutineStatus.Success; + } + + private NetOutgoingMessage CreateStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode) + { NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)PacketTypes.StartGame); @@ -860,11 +749,13 @@ namespace Barotrauma.Networking //msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes); - msg.Write((myCharacter == null) ? (byte)connectedClients.Count : (byte)(connectedClients.Count + 1)); - foreach (Client client in connectedClients) + List playingClients = ConnectedClients.FindAll(c => c.Character != null); + + msg.Write((myCharacter == null) ? (byte)playingClients.Count : (byte)(playingClients.Count + 1)); + foreach (Client client in playingClients) { msg.Write(client.ID); - WriteCharacterData(msg, client.character.Name, client.character); + WriteCharacterData(msg, client.Character.Name, client.Character); } if (myCharacter != null) @@ -873,21 +764,7 @@ namespace Barotrauma.Networking WriteCharacterData(msg, myCharacter.Info.Name, Character.Controlled); } - SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null); - - UpdateCrewFrame(); - - //give some time for the clients to load the map - yield return new WaitForSeconds(2.0f); - - gameStarted = true; - - GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; - - GameMain.GameScreen.Select(); - - yield return CoroutineStatus.Success; - + return msg; } private bool EndButtonHit(GUIButton button, object obj) @@ -909,7 +786,7 @@ namespace Barotrauma.Networking gameStarted = false; - if (connectedClients.Count > 0) + if (ConnectedClients.Count > 0) { NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)PacketTypes.EndGame); @@ -920,9 +797,9 @@ namespace Barotrauma.Networking server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0); } - foreach (Client client in connectedClients) + foreach (Client client in ConnectedClients) { - client.character = null; + client.Character = null; client.inGame = false; } } @@ -961,7 +838,7 @@ namespace Barotrauma.Networking private void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "") { - Client client = connectedClients.Find(x => x.Connection == senderConnection); + Client client = ConnectedClients.Find(x => x.Connection == senderConnection); if (client != null) DisconnectClient(client, msg, targetmsg); } @@ -969,18 +846,18 @@ namespace Barotrauma.Networking { if (client == null) return; - if (gameStarted && client.character != null) + if (gameStarted && client.Character != null) { if (GameMain.GameSession!=null && GameMain.GameSession.gameMode!=null) { TraitorMode traitorMode = GameMain.GameSession.gameMode as TraitorMode; if (traitorMode!=null) { - traitorMode.CharacterLeft(client.character); + traitorMode.CharacterLeft(client.Character); } } - client.character.ClearInputs(); + client.Character.ClearInputs(); } if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server"; @@ -991,7 +868,7 @@ namespace Barotrauma.Networking outmsg.Write(targetmsg); server.SendMessage(outmsg, client.Connection, NetDeliveryMethod.ReliableUnordered, 0); - connectedClients.Remove(client); + ConnectedClients.Remove(client); outmsg = server.CreateMessage(); outmsg.Write((byte)PacketTypes.PlayerLeft); @@ -1014,24 +891,24 @@ namespace Barotrauma.Networking { List crew = new List(); - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { - if (c.character == null || !c.inGame) continue; + if (c.Character == null || !c.inGame) continue; - crew.Add(c.character); + crew.Add(c.Character); } if (myCharacter != null) crew.Add(myCharacter); - CreateCrewFrame(crew); + if (GameMain.GameSession!=null) GameMain.GameSession.CrewManager.CreateCrewFrame(crew); } public void KickPlayer(string playerName, bool ban = false) { playerName = playerName.ToLower(); - Client client = connectedClients.Find( c => c.name.ToLower() == playerName || - (c.character != null && c.character.Name.ToLower() == playerName)); + Client client = ConnectedClients.Find( c => c.name.ToLower() == playerName || + (c.Character != null && c.Character.Name.ToLower() == playerName)); if (client == null) return; @@ -1056,10 +933,10 @@ namespace Barotrauma.Networking public void NewTraitor(out Character traitor, out Character target) { List characters = new List(); - foreach (Client client in connectedClients) + foreach (Client client in ConnectedClients) { - if (!client.inGame || client.character==null) continue; - characters.Add(client.character); + if (!client.inGame || client.Character==null) continue; + characters.Add(client.Character); } if (myCharacter!= null) characters.Add(myCharacter); @@ -1093,9 +970,9 @@ namespace Barotrauma.Networking } Client traitorClient = null; - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { - if (c.character != traitor) continue; + if (c.Character != traitor) continue; traitorClient = c; break; } @@ -1133,7 +1010,7 @@ namespace Barotrauma.Networking int resentMessages = 0; y += 110; - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { spriteBatch.DrawString(GUI.SmallFont, c.name + ":", new Vector2(x + 10, y), Color.White); spriteBatch.DrawString(GUI.SmallFont, "- avg roundtrip " + c.Connection.AverageRoundtripTime+" s", new Vector2(x + 20, y + 15), Color.White); @@ -1160,7 +1037,7 @@ namespace Barotrauma.Networking { NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)PacketTypes.VoteStatus); - Voting.WriteData(msg, connectedClients); + Voting.WriteData(msg, ConnectedClients); server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0); } @@ -1191,14 +1068,12 @@ namespace Barotrauma.Networking return true; } - protected override bool SelectCrewCharacter(GUIComponent component, object obj) + public override bool SelectCrewCharacter(GUIComponent component, object obj) { - base.SelectCrewCharacter(component, obj); - - var characterFrame = crewFrame.FindChild("selectedcharacter"); + var characterFrame = component.Parent.Parent.FindChild("selectedcharacter"); Character character = obj as Character; - if (obj == null) return false; + if (character == null) return false; if (character != myCharacter) { @@ -1225,9 +1100,9 @@ namespace Barotrauma.Networking List recipients = new List(); - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { - if (type!=ChatMessageType.Dead || (c.character != null && c.character.IsDead)) recipients.Add(c); + if (type!=ChatMessageType.Dead || (c.Character != null && c.Character.IsDead)) recipients.Add(c); } foreach (Client c in recipients) @@ -1271,7 +1146,7 @@ namespace Barotrauma.Networking if (jobPrefab != null) jobPreferences.Add(jobPrefab); } - foreach (Client c in connectedClients) + foreach (Client c in ConnectedClients) { if (c.Connection != message.SenderConnection) continue; @@ -1298,7 +1173,7 @@ namespace Barotrauma.Networking private void AssignJobs() { - List unassigned = new List(connectedClients); + List unassigned = new List(ConnectedClients); int[] assignedClientCount = new int[JobPrefab.List.Count]; @@ -1424,7 +1299,7 @@ namespace Barotrauma.Networking int bitCount = Rand.Int(100); for (int i = 0; i < bitCount; i++) { - msg.Write((Rand.Int(2) == 0) ? true : false); + msg.Write(Rand.Int(2) == 0); } SendMessage(msg, (Rand.Int(2) == 0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable, null); @@ -1442,7 +1317,7 @@ namespace Barotrauma.Networking public string name; public int ID; - public Character character; + public Character Character; public CharacterInfo characterInfo; public NetConnection Connection { get; set; } public string version; diff --git a/Subsurface/Source/Networking/GameServerSettings.cs b/Subsurface/Source/Networking/GameServerSettings.cs index 4081baf14..401c665a4 100644 --- a/Subsurface/Source/Networking/GameServerSettings.cs +++ b/Subsurface/Source/Networking/GameServerSettings.cs @@ -36,7 +36,7 @@ namespace Barotrauma.Networking public bool AutoRestart { - get { return (connectedClients.Count == 0) ? false : autoRestart; } + get { return (ConnectedClients.Count == 0) ? false : autoRestart; } set { autoRestart = value; diff --git a/Subsurface/Source/Networking/NetConfig.cs b/Subsurface/Source/Networking/NetConfig.cs index 969eaa0ca..ea298bca7 100644 --- a/Subsurface/Source/Networking/NetConfig.cs +++ b/Subsurface/Source/Networking/NetConfig.cs @@ -14,7 +14,7 @@ namespace Barotrauma.Networking public static string MasterServerUrl = GameMain.Config.MasterServerUrl; - //if a character is further than this from the sub, the server will ignore it + //if a Character is further than this from the sub, the server will ignore it //(in sim units) public const float CharacterIgnoreDistance = 100.0f; diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index e49ae368b..e8b967505 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -27,7 +27,9 @@ namespace Barotrauma.Networking Vote, VoteStatus, - ResendRequest, ReliableMessage, LatestMessageID + ResendRequest, ReliableMessage, LatestMessageID, + + Spectate } enum VoteType @@ -56,10 +58,6 @@ namespace Barotrauma.Networking public int Port; - private bool crewFrameOpen; - private GUIButton crewButton; - protected GUIFrame crewFrame; - protected bool gameStarted; protected Character myCharacter; @@ -117,8 +115,6 @@ namespace Barotrauma.Networking chatMsgBox.Font = GUI.SmallFont; chatMsgBox.OnEnterPressed = EnterChatMessage; - crewButton = new GUIButton(new Rectangle(chatBox.Rect.Right-80, chatBox.Rect.Y-30, 80, 20), "Crew", GUI.Style, inGameHUD); - crewButton.OnClicked = ToggleCrewFrame; Voting = new Voting(); } @@ -159,66 +155,6 @@ namespace Barotrauma.Networking } return message; - } - - protected void CreateCrewFrame(List crew) - { - int width = 600, height = 400; - - crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); - crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); - - GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame); - crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); - crewList.OnSelected = SelectCrewCharacter; - - foreach (Character character in crew) - { - GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList); - frame.UserData = character; - frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); - frame.Color = (myCharacter == character) ? Color.Gold * 0.2f : Color.Transparent; - frame.HoverColor = Color.LightGray * 0.5f; - frame.SelectedColor = Color.Gold * 0.5f; - - GUITextBlock textBlock = new GUITextBlock( - new Rectangle(40, 0, 0, 25), - character.Info.Name + " ("+character.Info.Job.Name+")", - Color.Transparent, Color.White, - Alignment.Left, Alignment.Left, - null, frame); - textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); - - new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame); - } - - var closeButton = new GUIButton(new Rectangle(0,0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame); - closeButton.OnClicked = ToggleCrewFrame; - } - - protected virtual bool SelectCrewCharacter(GUIComponent component, object obj) - { - Character character = obj as Character; - if (obj == null) return false; - - GUIComponent existingFrame = crewFrame.FindChild("selectedcharacter"); - if (existingFrame != null) crewFrame.RemoveChild(existingFrame); - - var previewPlayer = new GUIFrame( - new Rectangle(0,0, 230, 300), - new Color(0.0f, 0.0f, 0.0f, 0.8f), Alignment.TopRight, GUI.Style, crewFrame); - previewPlayer.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); - previewPlayer.UserData = "selectedcharacter"; - - var infoFrame = character.Info.CreateInfoFrame(previewPlayer); - - return true; - } - - private bool ToggleCrewFrame(GUIButton button, object obj) - { - crewFrameOpen = !crewFrameOpen; - return true; } public bool EnterChatMessage(GUITextBox textBox, string message) @@ -251,7 +187,6 @@ namespace Barotrauma.Networking //float prevScroll = chatBox.BarScroll; float prevSize = chatBox.BarSize; - float oldScroll = chatBox.BarScroll; msg.Padding = new Vector4(20, 0, 0, 0); chatBox.AddChild(msg); @@ -265,13 +200,13 @@ namespace Barotrauma.Networking public virtual void Update(float deltaTime) { - if (gameStarted) + if (gameStarted && Screen.Selected == GameMain.GameScreen) { inGameHUD.Update(deltaTime); - if (crewFrameOpen) crewFrame.Update(deltaTime); + //if (crewFrameOpen) crewFrame.Update(deltaTime); - if (Character.Controlled != null && Character.Controlled.IsDead) + if (Character.Controlled == null || Character.Controlled.IsDead) { GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; GameMain.LightManager.LosEnabled = false; @@ -294,11 +229,14 @@ namespace Barotrauma.Networking public virtual void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { - if (!gameStarted) return; + if (!gameStarted && Screen.Selected != GameMain.GameScreen) return; inGameHUD.Draw(spriteBatch); + } - if (crewFrameOpen) crewFrame.Draw(spriteBatch); + public virtual bool SelectCrewCharacter(GUIComponent component, object obj) + { + return false; } public virtual void Disconnect() { } diff --git a/Subsurface/Source/Particles/Particle.cs b/Subsurface/Source/Particles/Particle.cs index 75ea43ef8..0d9f15e22 100644 --- a/Subsurface/Source/Particles/Particle.cs +++ b/Subsurface/Source/Particles/Particle.cs @@ -10,6 +10,9 @@ namespace Barotrauma.Particles { private ParticlePrefab prefab; + public delegate void OnChangeHullHandler(Vector2 position, Hull currentHull); + public OnChangeHullHandler OnChangeHull; + private Vector2 position; private Vector2 prevPosition; @@ -26,6 +29,8 @@ namespace Barotrauma.Particles private Color color; private float alpha; + private int spriteIndex; + private float totalLifeTime; private float lifeTime; @@ -37,12 +42,17 @@ namespace Barotrauma.Particles private Hull currentHull; - private List hullLimits; + private List hullGaps; public ParticlePrefab.DrawTargetType DrawTarget { get { return prefab.DrawTarget; } } + + public ParticleBlendState BlendState + { + get { return prefab.BlendState; } + } public Vector2 Size { @@ -56,10 +66,12 @@ namespace Barotrauma.Particles set { velocityChange = value; } } - public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation) + public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null) { this.prefab = prefab; + spriteIndex = Rand.Int(prefab.Sprites.Count); + this.position = position; prevPosition = position; @@ -84,11 +96,15 @@ namespace Barotrauma.Particles velocityChange = prefab.VelocityChange; + OnChangeHull = null; + if (prefab.DeleteOnCollision || prefab.CollidesWithWalls) { - //currentHull = Hull.FindHull(position); - hullLimits = new List(); - hullLimits = FindLimits(position); + currentHull = Hull.FindHull(position, hullGuess); + + hullGaps = currentHull==null ? new List() : currentHull.FindGaps(); + //hullLimits = new List(); + //hullLimits = FindLimits(position); } if (prefab.RotateToDirection) @@ -99,55 +115,17 @@ namespace Barotrauma.Particles } } - private List FindLimits(Vector2 position) - { - List hullList = new List(); + //private List FindLimits(Vector2 position) + //{ + // List hullList = new List(); - currentHull = Hull.FindHull(position); - if (currentHull == null) return hullList; + // currentHull = Hull.FindHull(position); + // if (currentHull == null) return hullList; - hullList.Add(currentHull); - - return FindAdjacentHulls(hullList, currentHull, Math.Abs(velocity.X)>Math.Abs(velocity.Y)); - } + // hullList.Add(currentHull); - private List FindAdjacentHulls(List adjacentHulls, Hull currentHull, bool isHorizontal) - { - foreach (Gap gap in Gap.GapList) - { - if (gap.isHorizontal != isHorizontal) continue; - if (gap.Open < 0.01f) continue; - if (gap.linkedTo.Count==0) - { - continue; - } - else if (gap.linkedTo.Count==1) - { - if (!adjacentHulls.Contains(gap.linkedTo[0] as Hull)) - { - adjacentHulls.Add(gap.linkedTo[0] as Hull); - } - } - else if (gap.linkedTo[0] == currentHull && gap.linkedTo[1] != null) - { - if (!adjacentHulls.Contains(gap.linkedTo[1] as Hull)) - { - adjacentHulls.Add(gap.linkedTo[1] as Hull); - FindAdjacentHulls(adjacentHulls, gap.linkedTo[1] as Hull, isHorizontal); - } - } - else if (gap.linkedTo[1] == currentHull && gap.linkedTo[0] != null) - { - if (!adjacentHulls.Contains(gap.linkedTo[0] as Hull)) - { - adjacentHulls.Add(gap.linkedTo[0] as Hull); - FindAdjacentHulls(adjacentHulls, gap.linkedTo[0] as Hull, isHorizontal); - } - } - } - - return adjacentHulls; - } + // return FindAdjacentHulls(hullList, currentHull, Math.Abs(velocity.X) > Math.Abs(velocity.Y)); + //} public bool Update(float deltaTime) { @@ -182,24 +160,57 @@ namespace Barotrauma.Particles if ((prefab.DeleteOnCollision || prefab.CollidesWithWalls) && currentHull!=null) { - bool insideHull = false; - foreach (Hull hull in hullLimits) - { - if (!Submarine.RectContains(hull.Rect, position)) continue; + Vector2 edgePos = position + prefab.Sprites[spriteIndex].SourceRect.Width * Vector2.Normalize(velocity) * size.X; + //bool insideHull = false; + //foreach (Hull hull in hullLimits) + //{ + // if (!Submarine.RectContains(hull.Rect, edgePos)) continue; - insideHull = true; - break; - } + // insideHull = true; + // break; + //} - if (!insideHull) + if (!Submarine.RectContains(currentHull.Rect, edgePos)) { if (prefab.DeleteOnCollision) return false; - Hull prevHull = Hull.FindHull(prevPosition, hullLimits, currentHull); + bool gapFound = false; + foreach (Gap gap in hullGaps) + { + if (!gap.isHorizontal) + { + if (gap.Rect.X > position.X || gap.Rect.Right < position.X) continue; + if (Math.Sign(velocity.Y) != Math.Sign(gap.Rect.Y - position.Y)) continue; + } + else + { + if (gap.Rect.Y < position.Y || gap.Rect.Y - gap.Rect.Height > position.Y) continue; + if (Math.Sign(velocity.X) != Math.Sign(gap.Rect.X - position.X)) continue; + } - if (prevHull == null) return false; + //Rectangle enlargedRect = new Rectangle(gap.Rect.X - 10, gap.Rect.Y + 10, gap.Rect.Width + 20, gap.Rect.Height + 20); + //if (!Submarine.RectContains(enlargedRect, position)) continue; + gapFound = true; + } + + if (!gapFound) + { + + OnWallCollision(currentHull, edgePos); + } + else + { + currentHull = Hull.FindHull(position); + hullGaps = currentHull == null ? new List() : currentHull.FindGaps(); + + if (OnChangeHull != null) OnChangeHull(edgePos, currentHull); + + } + + //Hull prevHull = Hull.FindHull(prevPosition, hullLimits, currentHull); + + //if (prevHull == null) return false; - OnWallCollision(prevHull); } //if (position.Y < currentHull.Rect.Y-currentHull.Rect.Height) @@ -217,10 +228,10 @@ namespace Barotrauma.Particles return true; } - private void OnWallCollision(Hull prevHull) + private void OnWallCollision(Hull prevHull, Vector2 position) { - float restitution = 0.05f; - + float restitution = 0.5f; + if (position.Y < prevHull.Rect.Y - prevHull.Rect.Height) { position.Y = prevHull.Rect.Y - prevHull.Rect.Height + 1.0f; @@ -229,7 +240,8 @@ namespace Barotrauma.Particles else if (position.Y > prevHull.Rect.Y) { position.Y = prevHull.Rect.Y - 1.0f; - velocity.Y = -velocity.Y; + velocity.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X); + velocity.Y = -velocity.Y*0.1f; } if (position.X < prevHull.Rect.X) @@ -262,7 +274,9 @@ namespace Barotrauma.Particles } - prefab.Sprite.Draw(spriteBatch, drawPosition, color*alpha, prefab.Sprite.origin, drawRotation, drawSize, SpriteEffects.None, prefab.Sprite.Depth); + prefab.Sprites[spriteIndex].Draw(spriteBatch, drawPosition, color * alpha, + prefab.Sprites[spriteIndex].origin, drawRotation, + drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth); //spriteBatch.Draw( // prefab.sprite.Texture, diff --git a/Subsurface/Source/Particles/ParticleManager.cs b/Subsurface/Source/Particles/ParticleManager.cs index 750ccfdf1..04b2da216 100644 --- a/Subsurface/Source/Particles/ParticleManager.cs +++ b/Subsurface/Source/Particles/ParticleManager.cs @@ -7,9 +7,16 @@ using Microsoft.Xna.Framework.Graphics; namespace Barotrauma.Particles { + enum ParticleBlendState + { + AlphaBlend, Additive + } + class ParticleManager { public static int particleCount; + + private const int MaxOutOfViewDist = 500; private const int MaxParticles = 1500; private Particle[] particles; @@ -45,23 +52,23 @@ namespace Barotrauma.Particles return CreateParticle(prefabName, position, new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * speed, angle); } - public Particle CreateParticle(string prefabName, Vector2 position, Vector2 speed, float rotation=0.0f) + public Particle CreateParticle(string prefabName, Vector2 position, Vector2 speed, float rotation=0.0f, Hull hullGuess = null) { ParticlePrefab prefab = FindPrefab(prefabName); - return CreateParticle(prefab, position, speed, rotation); + return CreateParticle(prefab, position, speed, rotation, hullGuess); } - public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation=0.0f) + public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation = 0.0f, Hull hullGuess = null) { - if (!Submarine.RectContains(cam.WorldView, position)) return null; + if (!Submarine.RectContains(MathUtils.ExpandRect(cam.WorldView, MaxOutOfViewDist), position)) return null; //if (!cam.WorldView.Contains(position)) return null; if (particleCount >= MaxParticles) return null; if (particles[particleCount] == null) particles[particleCount] = new Particle(); - particles[particleCount].Init(prefab, position, speed, rotation); + particles[particleCount].Init(prefab, position, speed, rotation, hullGuess); particleCount++; @@ -100,12 +107,13 @@ namespace Barotrauma.Particles } } - public void Draw(SpriteBatch spriteBatch, bool inWater) + public void Draw(SpriteBatch spriteBatch, bool inWater, ParticleBlendState blendState) { ParticlePrefab.DrawTargetType drawTarget = inWater ? ParticlePrefab.DrawTargetType.Water : ParticlePrefab.DrawTargetType.Air; for (int i = 0; i < particleCount; i++) { + if (particles[i].BlendState != blendState) continue; if (!particles[i].DrawTarget.HasFlag(drawTarget)) continue; particles[i].Draw(spriteBatch); diff --git a/Subsurface/Source/Particles/ParticlePrefab.cs b/Subsurface/Source/Particles/ParticlePrefab.cs index d505b3131..04ceb3be2 100644 --- a/Subsurface/Source/Particles/ParticlePrefab.cs +++ b/Subsurface/Source/Particles/ParticlePrefab.cs @@ -1,6 +1,7 @@ using System.Xml.Linq; using Microsoft.Xna.Framework; using FarseerPhysics; +using System.Collections.Generic; namespace Barotrauma.Particles { @@ -10,7 +11,7 @@ namespace Barotrauma.Particles public readonly string Name; - public readonly Sprite Sprite; + public readonly List Sprites; public readonly float AngularVelocityMin, AngularVelocityMax; @@ -35,17 +36,21 @@ namespace Barotrauma.Particles public readonly DrawTargetType DrawTarget; + public readonly ParticleBlendState BlendState; + public readonly bool RotateToDirection; public ParticlePrefab(XElement element) { Name = element.Name.ToString(); + Sprites = new List(); + foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLower() != "sprite") continue; - Sprite = new Sprite(subElement); + Sprites.Add(new Sprite(subElement)); } if (element.Attribute("angularvelocity") == null) @@ -81,6 +86,10 @@ namespace Barotrauma.Particles SizeChangeMax = SizeChangeMin; } + var blendState = ToolBox.GetAttributeString(element, "blendstate", "alphablend"); + + BlendState = (blendState != "additive") ? ParticleBlendState.AlphaBlend : ParticleBlendState.Additive; + GrowTime = ToolBox.GetAttributeFloat(element, "growtime", 0.0f); if (element.Attribute("startrotation") == null) diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index 05a916536..1e42e05a9 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -41,7 +41,7 @@ namespace Barotrauma private float density; //the direction the item is facing (for example, a gun has to be - //flipped horizontally if the character holding it turns around) + //flipped horizontally if the Character holding it turns around) float dir; public Vector2 TargetPosition diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index a5d33222c..1c5214111 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -309,14 +309,14 @@ namespace Barotrauma { if (!oldKeyboardState.IsKeyUp(key)) continue; - char character = (char)key; + char Character = (char)key; if (keyboardState.IsKeyUp(Keys.LeftShift) && keyboardState.IsKeyUp(Keys.RightShift)) { - character = char.ToLower(character); + Character = char.ToLower(Character); } - EventInput.EventInput.OnCharEntered(character); + EventInput.EventInput.OnCharEntered(Character); } #endif diff --git a/Subsurface/Source/Properties.cs b/Subsurface/Source/Properties.cs index 21503aa68..a2fae550f 100644 --- a/Subsurface/Source/Properties.cs +++ b/Subsurface/Source/Properties.cs @@ -232,7 +232,7 @@ namespace Barotrauma { ObjectProperty property = null; if (!dictionary.TryGetValue(attribute.Name.ToString().ToLower(), out property)) continue; - if (property.Attributes.OfType().Count() == 0) continue; + if (!property.Attributes.OfType().Any()) continue; property.TrySetValue(attribute.Value); } diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 9214a425c..c354f30e2 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -14,7 +14,7 @@ namespace Barotrauma private GUIComponent[] GUItabs; private int selectedTab; - //a character used for picking up and manipulating items + //a Character used for picking up and manipulating items private Character dummyCharacter; private bool characterMode; diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 6cd0d8461..b8faa7b55 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -254,7 +254,7 @@ namespace Barotrauma BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); - GameMain.ParticleManager.Draw(spriteBatch, true); + GameMain.ParticleManager.Draw(spriteBatch, true, Particles.ParticleBlendState.AlphaBlend); spriteBatch.End(); @@ -271,10 +271,17 @@ namespace Barotrauma BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); - - GameMain.ParticleManager.Draw(spriteBatch, false); + GameMain.ParticleManager.Draw(spriteBatch, false, Particles.ParticleBlendState.AlphaBlend); spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, + BlendState.Additive, + null, DepthStencilState.DepthRead, null, null, + cam.Transform); + GameMain.ParticleManager.Draw(spriteBatch, false, Particles.ParticleBlendState.Additive); + spriteBatch.End(); + + graphics.SetRenderTarget(null); //---------------------------------------------------------------------------------------- diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index abddf7fbe..4d8e8edf6 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -54,6 +54,11 @@ namespace Barotrauma } } + private CrewManager CrewManager + { + get { return GameMain.GameSession.CrewManager; } + } + public LobbyScreen() { Rectangle panelRect = new Rectangle( @@ -68,7 +73,7 @@ namespace Barotrauma // save, Color.Transparent, Color.White, Alignment.Left, GUI.Style, leftPanel); GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 30, 0, 25), "", GUI.Style, - Alignment.TopCenter, Alignment.Top, leftPanel); + Alignment.TopLeft, Alignment.TopLeft, leftPanel); moneyText.TextGetter = GetMoney; GUIButton button = new GUIButton(new Rectangle(0, 70, 100, 30), "Map", null, Alignment.TopCenter, GUI.Style, leftPanel); @@ -234,7 +239,7 @@ namespace Barotrauma private void UpdateCharacterLists() { characterList.ClearChildren(); - foreach (CharacterInfo c in gameMode.CrewManager.characterInfos) + foreach (CharacterInfo c in CrewManager.characterInfos) { GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), @@ -291,7 +296,7 @@ namespace Barotrauma CreateItemFrame(prefab, selectedItemList); - buyButton.Enabled = gameMode.CrewManager.Money >= selectedItemCost; + buyButton.Enabled = CrewManager.Money >= selectedItemCost; return false; } @@ -310,9 +315,9 @@ namespace Barotrauma { int cost = selectedItemCost; - if (gameMode.CrewManager.Money < cost) return false; + if (CrewManager.Money < cost) return false; - gameMode.CrewManager.Money -= cost; + CrewManager.Money -= cost; for (int i = selectedItemList.children.Count-1; i>=0; i--) { @@ -345,7 +350,7 @@ namespace Barotrauma public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - if (characterList.CountChildren != gameMode.CrewManager.characterInfos.Count) + if (characterList.CountChildren != CrewManager.characterInfos.Count) { UpdateCharacterLists(); } @@ -406,7 +411,7 @@ namespace Barotrauma private string GetMoney() { - return "Money: " + ((GameMain.GameSession == null) ? "" : gameMode.CrewManager.Money.ToString()); + return "Money: " + ((GameMain.GameSession == null) ? "" : CrewManager.Money.ToString()); } private bool SelectCharacter(GUIComponent component, object selection) diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 24afdc285..a1f409a8e 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -129,7 +129,7 @@ namespace Barotrauma //server info panel ------------------------------------------------------------ infoFrame = new GUIFrame(new Rectangle(0, 0, (int)(panelRect.Width * 0.7f), (int)(panelRect.Height * 0.6f)), GUI.Style, menu); - infoFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); ; + infoFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); //chatbox ---------------------------------------------------------------------- GUIFrame chatFrame = new GUIFrame( @@ -295,8 +295,8 @@ namespace Barotrauma ServerName = (GameMain.Server==null) ? "Server" : GameMain.Server.Name; - infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton")); + infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton")); playerList.Parent.RemoveChild(playerList.Parent.children.Find(c => c.UserData as string == "banListButton")); @@ -313,15 +313,13 @@ namespace Barotrauma GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame); settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame; + settingsButton.CanBeSelected = false; settingsButton.UserData = "settingsButton"; var banListButton = new GUIButton(new Rectangle(0, 30, 100, 20), "Banned IPs", Alignment.BottomRight, GUI.Style, playerList.Parent); banListButton.OnClicked = GameMain.Server.BanList.ToggleBanFrame; banListButton.UserData = "banListButton"; - //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); - //modeList.OnSelected += GameMain.Server.UpdateNetLobby; - if (subList.CountChildren > 0 && subList.Selected == null) subList.Select(-1); if (GameModePreset.list.Count > 0 && modeList.Selected == null) modeList.Select(-1); @@ -337,8 +335,15 @@ namespace Barotrauma if (GameMain.Server.SubSelectionMode == SelectionMode.Random) subList.Select(Rand.Range(0,subList.CountChildren)); if (GameMain.Server.ModeSelectionMode == SelectionMode.Random) modeList.Select(Rand.Range(0, modeList.CountChildren)); } - else + else if (GameMain.Client != null) { + if (GameMain.Client.GameStarted) + { + GUIButton spectateButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Spectate", Alignment.BottomRight, GUI.Style, infoFrame); + spectateButton.OnClicked = GameMain.Client.SpectateClicked; + spectateButton.UserData = "spectateButton"; + } + UpdatePlayerFrame(GameMain.Client.CharacterInfo); } @@ -654,7 +659,6 @@ namespace Barotrauma public void NewChatMessage(string message, Color color) { float prevSize = chatBox.BarSize; - float oldScroll = chatBox.BarScroll; while (chatBox.CountChildren>20) { diff --git a/Subsurface/Source/Screens/NetLobbyVoting.cs b/Subsurface/Source/Screens/NetLobbyVoting.cs index ee3a3029f..6f6bee116 100644 --- a/Subsurface/Source/Screens/NetLobbyVoting.cs +++ b/Subsurface/Source/Screens/NetLobbyVoting.cs @@ -24,7 +24,7 @@ namespace Barotrauma if (GameMain.Server != null) { - UpdateVoteTexts(GameMain.Server.connectedClients, VoteType.Sub); + UpdateVoteTexts(GameMain.Server.ConnectedClients, VoteType.Sub); GameMain.Server.UpdateVoteStatus(); } else @@ -44,7 +44,7 @@ namespace Barotrauma GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes").Visible = value; if (GameMain.Server != null) { - UpdateVoteTexts(GameMain.Server.connectedClients, VoteType.Mode); + UpdateVoteTexts(GameMain.Server.ConnectedClients, VoteType.Mode); GameMain.Server.UpdateVoteStatus(); } else diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 20c7aa855..904219bc4 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -143,7 +143,7 @@ namespace Barotrauma if (string.IsNullOrWhiteSpace(masterServerData)) { - var nameText = new GUITextBlock(new Rectangle(0, 0, 0, 20), "Couldn't find any servers", GUI.Style, serverList); + new GUITextBlock(new Rectangle(0, 0, 0, 20), "Couldn't find any servers", GUI.Style, serverList); return; } diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs index ddef81f8a..7b9d21872 100644 --- a/Subsurface/Source/Sounds/SoundPlayer.cs +++ b/Subsurface/Source/Sounds/SoundPlayer.cs @@ -217,7 +217,7 @@ namespace Barotrauma Task criticalTask = null; if (GameMain.GameSession!=null) { - foreach (Task task in GameMain.GameSession.taskManager.Tasks) + foreach (Task task in GameMain.GameSession.TaskManager.Tasks) { if (!task.IsStarted) continue; if (criticalTask == null || task.Priority > criticalTask.Priority) diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index 645e46eb2..b46cddf37 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -42,6 +42,10 @@ namespace Barotrauma return (IsValid(vector.X) && IsValid(vector.Y)); } + public static Rectangle ExpandRect(Rectangle rect, int amount) + { + return new Rectangle(rect.X - amount, rect.Y + amount, rect.Width + amount * 2, rect.Height + amount * 2); + } public static int VectorOrientation(Vector2 p1, Vector2 p2, Vector2 p) { diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index 5afb9de85..1dc516a4a 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -179,7 +179,6 @@ namespace Barotrauma var attribute = element.Attribute(name); if (attribute == null) return defaultValue; - string val = attribute.Value.ToLower().Trim(); return GetAttributeBool(attribute, defaultValue); } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 37f70570d..09f6f31b2 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ