diff --git a/Subsurface/Camera.cs b/Subsurface/Camera.cs index 11a260a4d..978c2d385 100644 --- a/Subsurface/Camera.cs +++ b/Subsurface/Camera.cs @@ -18,6 +18,12 @@ namespace Subsurface private Vector2 position; private float rotation; + public float Shake; + private Vector2 shakePosition; + private Vector2 shakeTargetPosition; + + + //the area of the world inside the camera view private Rectangle worldView; @@ -151,10 +157,10 @@ namespace Subsurface Vector2 moveCam = Vector2.Zero; if (targetPos == Vector2.Zero) { - if (Keyboard.GetState().IsKeyDown(Keys.Left)) moveCam.X -= moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.Right)) moveCam.X += moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.Down)) moveCam.Y -= moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.Up)) moveCam.Y += moveSpeed; + if (Keyboard.GetState().IsKeyDown(Keys.A)) moveCam.X -= moveSpeed; + if (Keyboard.GetState().IsKeyDown(Keys.D)) moveCam.X += moveSpeed; + if (Keyboard.GetState().IsKeyDown(Keys.S)) moveCam.Y -= moveSpeed; + if (Keyboard.GetState().IsKeyDown(Keys.W)) moveCam.Y += moveSpeed; Zoom = MathHelper.Clamp(Zoom + PlayerInput.ScrollWheelSpeed / 1000.0f, 0.1f, 2.0f); } @@ -177,7 +183,11 @@ namespace Subsurface moveCam = (targetPos + offset - position) / MoveSmoothness; } - Translate(moveCam*deltaTime*60.0f); + shakeTargetPosition = Rand.Vector(Shake); + shakePosition = Vector2.Lerp(shakePosition, shakeTargetPosition, 0.5f); + Shake = MathHelper.Lerp(Shake, 0.0f, 0.03f); + + Translate((moveCam+shakePosition)*deltaTime*60.0f); } public Vector2 Position diff --git a/Subsurface/Characters/Character.cs b/Subsurface/Characters/Character.cs index bbbcced1f..9c810492a 100644 --- a/Subsurface/Characters/Character.cs +++ b/Subsurface/Characters/Character.cs @@ -392,11 +392,6 @@ namespace Subsurface AnimController.FindHull(); - //if (info.ID >= 0) - //{ - // ID = info.ID; - //} - CharacterList.Add(this); } @@ -764,7 +759,7 @@ namespace Subsurface if (Controlled.Inventory != null) Controlled.Inventory.Draw(spriteBatch); - if (closestItem!=null) + if (closestItem != null && selectedConstruction==null) { Color color = Color.Orange; @@ -882,12 +877,12 @@ namespace Subsurface for (int i = 0; i < 10; i++) { - Particle p = Game1.particleManager.CreateParticle("waterblood", + Particle p = Game1.ParticleManager.CreateParticle("waterblood", torso.SimPosition + new Vector2(Rand.Range(-0.5f, 0.5f), Rand.Range(-0.5f, 0.5f)), Vector2.Zero); if (p!=null) p.Size *= 2.0f; - Game1.particleManager.CreateParticle("bubbles", + Game1.ParticleManager.CreateParticle("bubbles", torso.SimPosition, new Vector2(Rand.Range(-0.5f, 0.5f), Rand.Range(-1.0f,0.5f))); } @@ -1047,6 +1042,7 @@ namespace Subsurface if (Game1.Client != null && controlled == this) { Game1.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); + Game1.LightManager.LosEnabled = false; } return; } diff --git a/Subsurface/Characters/DelayedEffect.cs b/Subsurface/Characters/DelayedEffect.cs index 7010fbdd9..cec94dc09 100644 --- a/Subsurface/Characters/DelayedEffect.cs +++ b/Subsurface/Characters/DelayedEffect.cs @@ -12,7 +12,7 @@ namespace Subsurface private float timer; - private Vector2 position; + private Entity entity; private List targets; @@ -27,12 +27,12 @@ namespace Subsurface delay = ToolBox.GetAttributeFloat(element, "delay", 1.0f); } - public override void Apply(ActionType type, float deltaTime, Vector2 position, List targets) + public override void Apply(ActionType type, float deltaTime, Entity entity, List targets) { if (this.type != type) return; timer = delay; - this.position = position; + this.entity = entity; this.targets = targets; @@ -45,7 +45,7 @@ namespace Subsurface if (timer > 0.0f) return; - base.Apply(1.0f, position, targets); + base.Apply(1.0f, entity, targets); List.Remove(this); } diff --git a/Subsurface/Characters/FishAnimController.cs b/Subsurface/Characters/FishAnimController.cs index 8448ecefe..efc9059d1 100644 --- a/Subsurface/Characters/FishAnimController.cs +++ b/Subsurface/Characters/FishAnimController.cs @@ -210,7 +210,6 @@ namespace Subsurface Limb torso = GetLimb(LimbType.Torso); Limb head = GetLimb(LimbType.Head); - if (torso!=null) { colliderLimb = torso; @@ -223,7 +222,7 @@ namespace Subsurface colliderLimb = head; colliderHeight = HeadPosition; - colliderLimb.body.SmoothRotate(HeadAngle*Dir, 100.0f); + if (onGround) colliderLimb.body.SmoothRotate(HeadAngle*Dir, 100.0f); } Vector2 colliderPos = colliderLimb.SimPosition; @@ -269,18 +268,19 @@ namespace Subsurface onFloorTimer -= deltaTime; } + if (!onGround) return; + if (closestFraction == 1) //raycast didn't hit anything - floorY = (currentHull == null || onGround) ? -1000.0f : ConvertUnits.ToSimUnits(currentHull.Rect.Y - currentHull.Rect.Height); + floorY = (currentHull == null) ? -1000.0f : ConvertUnits.ToSimUnits(currentHull.Rect.Y - currentHull.Rect.Height); else floorY = rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction; - - if (Math.Abs(colliderPos.Y - floorY) targets = new List(); targets.Add(target); - if (this.type == type) Apply(deltaTime, position, targets); + if (this.type == type) Apply(deltaTime, entity, targets); } - public virtual void Apply(ActionType type, float deltaTime, Vector2 position, List targets) + public virtual void Apply(ActionType type, float deltaTime, Entity entity, List targets) { - if (this.type == type) Apply(deltaTime, position, targets); + if (this.type == type) Apply(deltaTime, entity, targets); } - - protected virtual void Apply(float deltaTime, Vector2 position, List targets) - { - if (explosion != null) explosion.Explode(position); - if (sound != null) sound.Play(1.0f, 1000.0f, position); + protected virtual void Apply(float deltaTime, Entity entity, List targets) + { + if (explosion != null) explosion.Explode(entity.SimPosition); + + if (sound != null) sound.Play(1.0f, 1000.0f, ConvertUnits.ToDisplayUnits(entity.SimPosition)); for (int i = 0; i < propertyNames.Count(); i++) { diff --git a/Subsurface/Content/Characters/Mantis/mantis.xml b/Subsurface/Content/Characters/Mantis/mantis.xml index bda79ebba..ec41ab048 100644 --- a/Subsurface/Content/Characters/Mantis/mantis.xml +++ b/Subsurface/Content/Characters/Mantis/mantis.xml @@ -3,10 +3,10 @@ - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + diff --git a/Subsurface/Content/Items/Artifacts/artifact.png b/Subsurface/Content/Items/Artifacts/artifact.png new file mode 100644 index 000000000..4d342d912 Binary files /dev/null and b/Subsurface/Content/Items/Artifacts/artifact.png differ diff --git a/Subsurface/Content/Items/Artifacts/artifacts.xml b/Subsurface/Content/Items/Artifacts/artifacts.xml new file mode 100644 index 000000000..7faf4744e --- /dev/null +++ b/Subsurface/Content/Items/Artifacts/artifacts.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Content/Items/Electricity/poweritems.xml b/Subsurface/Content/Items/Electricity/poweritems.xml index 63e6562fa..06b3c7c75 100644 --- a/Subsurface/Content/Items/Electricity/poweritems.xml +++ b/Subsurface/Content/Items/Electricity/poweritems.xml @@ -43,7 +43,6 @@ - - + \ No newline at end of file diff --git a/Subsurface/Content/Items/Electricity/signalitems.xml b/Subsurface/Content/Items/Electricity/signalitems.xml index 982f40afb..7bcb2e020 100644 --- a/Subsurface/Content/Items/Electricity/signalitems.xml +++ b/Subsurface/Content/Items/Electricity/signalitems.xml @@ -14,9 +14,8 @@ - + - @@ -33,13 +32,11 @@ - + - - - @@ -63,11 +60,10 @@ - - - + - + @@ -91,11 +87,10 @@ - - - + - + @@ -120,11 +115,9 @@ - - - + - + @@ -147,11 +140,10 @@ - - - + - + @@ -159,6 +151,33 @@ + + + + + + + + + + + + + + + + + + + + + - - - + - + diff --git a/Subsurface/Content/Items/Engine/engine.ogg b/Subsurface/Content/Items/Engine/engine.ogg new file mode 100644 index 000000000..26de42449 Binary files /dev/null and b/Subsurface/Content/Items/Engine/engine.ogg differ diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index e5041f479..1cf0af13f 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -10,6 +10,7 @@ + diff --git a/Subsurface/Content/Items/Medical/medical.xml b/Subsurface/Content/Items/Medical/medical.xml index 12e02440f..72f61bba5 100644 --- a/Subsurface/Content/Items/Medical/medical.xml +++ b/Subsurface/Content/Items/Medical/medical.xml @@ -1,17 +1,15 @@  - + - - - + @@ -21,13 +19,11 @@ Tags="smallitem" pickdistance="150"> - + - - - + diff --git a/Subsurface/Content/Items/OxygenGenerator/item.xml b/Subsurface/Content/Items/OxygenGenerator/item.xml deleted file mode 100644 index 8a70b26ee..000000000 --- a/Subsurface/Content/Items/OxygenGenerator/item.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.ogg b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.ogg new file mode 100644 index 000000000..7204e3243 Binary files /dev/null and b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.ogg differ diff --git a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml new file mode 100644 index 000000000..7d8abf383 --- /dev/null +++ b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Content/Items/Vent/vent.png b/Subsurface/Content/Items/OxygenGenerator/vent.png similarity index 100% rename from Subsurface/Content/Items/Vent/vent.png rename to Subsurface/Content/Items/OxygenGenerator/vent.png diff --git a/Subsurface/Content/Items/OxygenGenerator/ventilation.ogg b/Subsurface/Content/Items/OxygenGenerator/ventilation.ogg new file mode 100644 index 000000000..757ba23d4 Binary files /dev/null and b/Subsurface/Content/Items/OxygenGenerator/ventilation.ogg differ diff --git a/Subsurface/Content/Items/Pump/pump.ogg b/Subsurface/Content/Items/Pump/pump.ogg new file mode 100644 index 000000000..fcf6e055a Binary files /dev/null and b/Subsurface/Content/Items/Pump/pump.ogg differ diff --git a/Subsurface/Content/Items/Pump/pump.xml b/Subsurface/Content/Items/Pump/pump.xml index c38b83bc7..51baf8032 100644 --- a/Subsurface/Content/Items/Pump/pump.xml +++ b/Subsurface/Content/Items/Pump/pump.xml @@ -4,8 +4,11 @@ pickdistance="200"> - - + + + + + diff --git a/Subsurface/Content/Items/Reactor/explosion.ogg b/Subsurface/Content/Items/Reactor/explosion.ogg new file mode 100644 index 000000000..69cf8ceb0 Binary files /dev/null and b/Subsurface/Content/Items/Reactor/explosion.ogg differ diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index bd432f5cb..d2a637f34 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -21,10 +21,14 @@ - + - + + + + + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index 0adf38a60..cbb358e4b 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -11,7 +11,8 @@ - + @@ -34,8 +35,6 @@ - - @@ -52,7 +51,8 @@ - + @@ -68,8 +68,6 @@ - - @@ -85,8 +83,8 @@ - - + - + - - + - \ No newline at end of file diff --git a/Subsurface/Content/Items/Vent/item.xml b/Subsurface/Content/Items/Vent/item.xml deleted file mode 100644 index 454121c34..000000000 --- a/Subsurface/Content/Items/Vent/item.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Subsurface/Content/Items/Weapons/explosives.png b/Subsurface/Content/Items/Weapons/explosives.png new file mode 100644 index 000000000..3fcdcc650 Binary files /dev/null and b/Subsurface/Content/Items/Weapons/explosives.png differ diff --git a/Subsurface/Content/Items/Weapons/explosives.xml b/Subsurface/Content/Items/Weapons/explosives.xml new file mode 100644 index 000000000..94536c2d5 --- /dev/null +++ b/Subsurface/Content/Items/Weapons/explosives.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index f7df33e46..2aad02389 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -42,7 +42,6 @@ - - - + + diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index 0af72d864..d80f96b82 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -23,10 +23,8 @@ - + - - diff --git a/Subsurface/Content/Quests.xml b/Subsurface/Content/Quests.xml new file mode 100644 index 000000000..a2dd7e82c --- /dev/null +++ b/Subsurface/Content/Quests.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml index 7d65e512a..77d6fbc01 100644 --- a/Subsurface/Content/Sounds/sounds.xml +++ b/Subsurface/Content/Sounds/sounds.xml @@ -26,6 +26,9 @@ + + + diff --git a/Subsurface/DebugConsole.cs b/Subsurface/DebugConsole.cs index 4a643cf67..3a326162f 100644 --- a/Subsurface/DebugConsole.cs +++ b/Subsurface/DebugConsole.cs @@ -163,10 +163,10 @@ namespace Subsurface } break; - case "startserver": - if (Game1.Server==null) - Game1.NetworkMember = new GameServer(); - break; + //case "startserver": + // if (Game1.Server==null) + // Game1.NetworkMember = new GameServer(); + // break; case "kick": if (Game1.Server == null) break; Game1.Server.KickPlayer(commands[1]); @@ -219,10 +219,13 @@ namespace Subsurface it.Condition = 100.0f; } break; - case "fowenabled": - case "fow": - case "drawfow": - Game1.LightManager.FowEnabled = !Game1.LightManager.FowEnabled; + case "shake": + Game1.GameScreen.Cam.Shake = 10.0f; + break; + case "losenabled": + case "los": + case "drawlos": + Game1.LightManager.LosEnabled = !Game1.LightManager.LosEnabled; break; case "lighting": case "lightingenabled": diff --git a/Subsurface/Events/EventManager.cs b/Subsurface/Events/EventManager.cs deleted file mode 100644 index bf4a7fe7f..000000000 --- a/Subsurface/Events/EventManager.cs +++ /dev/null @@ -1,106 +0,0 @@ -//using Microsoft.Xna.Framework; -//using Microsoft.Xna.Framework.Graphics; -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; - -//namespace Subsurface -//{ -// static class EventManager -// { -// static Event activeEvent; - -// static GUIFrame infoPanel; - -// const int MaxPreviousEvents = 6; -// const float PreviouslyUsedWeight = 10.0f; - -// static List previousEvents = new List(); - -// public static Event ActiveEvent -// { -// get { return activeEvent; } -// } - -// public static void StartShift() -// { -// int eventCount = Event.list.Count(); - -// //create an array where the probability of an event being selected will be calculated -// float[] eventProbability = new float[eventCount]; - -// float probabilitySum = 0.0f; - -// for (int i = 0; i < eventCount; i++) -// { -// eventProbability[i] = Event.list[i].Commonness; - -// //if the event has been previously selected, it's less likely to be selected now -// int previousEventIndex = previousEvents.FindIndex(x => x == Event.list[i]); -// if (previousEventIndex>=0) -// { -// //how many shifts ago was the event last selected -// int eventDist = eventCount - previousEventIndex; - -// float weighting = (1.0f / eventDist) * PreviouslyUsedWeight; - -// eventProbability[i] *= weighting; -// } - -// probabilitySum += eventProbability[i]; -// } - -// float randomNumber = (float)Game1.random.NextDouble()*probabilitySum; - -// for (int i = 0; i < eventCount; i++) -// { -// if (randomNumber <= eventProbability[i]) -// { -// SelectEvent(Event.list[i]); -// return; -// } - -// randomNumber -= eventProbability[i]; -// } -// } - -// public static void SelectEvent(Event selectedEvent) -// { -// if (selectedEvent == null) return; - -// activeEvent = selectedEvent; -// previousEvents.Add(activeEvent); - -// activeEvent.Init(); -// } - -// public static void Update(GameTime gameTime) -// { -// if (activeEvent==null) return; -// activeEvent.Update(gameTime); -// } - -// public static void DrawInfo(SpriteBatch spriteBatch) -// { -// if (activeEvent==null || !activeEvent.IsStarted) return; - -// if (infoPanel == null) -// { -// infoPanel = new GUIFrame(new Rectangle(Game1.GraphicsWidth - 320, 20, 300, 100), Color.White * 0.8f); -// infoPanel.Padding = GUI.style.smallPadding; -// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 20), activeEvent.Name, Color.Transparent, Color.Black)); -// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 50), activeEvent.Description, Color.Transparent, Color.Black)); -// } - - -// //infoPanel.Draw(spriteBatch); -// } - -// public static void EventFinished(Event e) -// { -// if (e != activeEvent) return; -// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 80), "Finished!", Color.Transparent, Color.Black)); -// } -// } -//} diff --git a/Subsurface/Events/Quests/Quest.cs b/Subsurface/Events/Quests/Quest.cs new file mode 100644 index 000000000..73785e0d4 --- /dev/null +++ b/Subsurface/Events/Quests/Quest.cs @@ -0,0 +1,155 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface +{ + class Quest + { + private static List list = new List(); + + private static string configFile = "Content/Quests.xml"; + + private string name; + + private string description; + + protected bool completed; + + private string successMessage; + private string failureMessage; + + private int reward; + + public string Name + { + get { return name; } + } + + public string Description + { + get { return description; } + } + + public int Reward + { + get { return reward; } + } + + public bool Completed + { + get { return completed; } + } + + public virtual string RadarLabel + { + get { return ""; } + } + + public virtual Vector2 RadarPosition + { + get { return Vector2.Zero; } + } + + public Quest(XElement element) + { + name = ToolBox.GetAttributeString(element, "name", ""); + + description = ToolBox.GetAttributeString(element, "description", ""); + + reward = ToolBox.GetAttributeInt(element, "reward", 1); + + successMessage = ToolBox.GetAttributeString(element, "successmessage", ""); + failureMessage = ToolBox.GetAttributeString(element, "failuremessage", ""); + } + + public static Quest LoadRandom(Random rand) + { + XDocument doc = ToolBox.TryLoadXml(configFile); + if (doc == null) return null; + + int eventCount = doc.Root.Elements().Count(); + //int[] commonness = new int[eventCount]; + float[] eventProbability = new float[eventCount]; + + float probabilitySum = 0.0f; + + int i = 0; + foreach (XElement element in doc.Root.Elements()) + { + eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1); + + probabilitySum += eventProbability[i]; + + i++; + } + + float randomNumber = (float)rand.NextDouble() * probabilitySum; + + i = 0; + foreach (XElement element in doc.Root.Elements()) + { + if (randomNumber <= eventProbability[i]) + { + Type t; + string type = element.Name.ToString(); + + try + { + t = Type.GetType("Subsurface." + type + ", Subsurface", true, true); + if (t == null) + { + DebugConsole.ThrowError("Error in " + configFile + "! Could not find a quest class of the type ''" + type + "''."); + continue; + } + } + catch + { + DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''."); + continue; + } + + ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) }); + object instance = constructor.Invoke(new object[] { element }); + + return (Quest)instance; + } + + randomNumber -= eventProbability[i]; + i++; + } + + return null; + } + + public virtual void Start(Level level) + { + } + + /// + /// End the quest and give a reward if it was completed successfully + /// + /// whether the quest was completed or not + public virtual void End() + { + completed = true; + + GiveReward(); + } + + public void GiveReward() + { + var mode = Game1.GameSession.gameMode as SinglePlayerMode; + mode.Money += reward; + + if (!string.IsNullOrWhiteSpace(successMessage)) + { + new GUIMessageBox("Quest completed", successMessage); + } + } + } +} diff --git a/Subsurface/Events/Quests/SalvageQuest.cs b/Subsurface/Events/Quests/SalvageQuest.cs new file mode 100644 index 000000000..3cf40e609 --- /dev/null +++ b/Subsurface/Events/Quests/SalvageQuest.cs @@ -0,0 +1,64 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface +{ + class SalvageQuest : Quest + { + ItemPrefab itemPrefab; + + Item item; + + public override string RadarLabel + { + get + { + return "Infrasonic signal"; + } + } + + public override Vector2 RadarPosition + { + get + { + return item.Position; + } + } + + public SalvageQuest(XElement element) + : base(element) + { + string itemName = ToolBox.GetAttributeString(element, "itemname", ""); + + itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; + + if (itemPrefab == null) + { + DebugConsole.ThrowError("Error in salvagequest: couldn't find an item prefab with the name "+itemName); + } + } + + public override void Start(Level level) + { + Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count)]; + + item = new Item(itemPrefab, position+level.Position); + //item.MoveWithLevel = true; + } + + public override void End() + { + if (item.CurrentHull == null) return; + + item.Remove(); + + GiveReward(); + + completed = true; + } + } +} diff --git a/Subsurface/Events/ScriptedEvent.cs b/Subsurface/Events/ScriptedEvent.cs index eb7b56405..18575fc93 100644 --- a/Subsurface/Events/ScriptedEvent.cs +++ b/Subsurface/Events/ScriptedEvent.cs @@ -140,13 +140,13 @@ namespace Subsurface t = Type.GetType("Subsurface." + type + ", Subsurface", true, true); if (t == null) { - DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''."); + DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type ''" + type + "''."); continue; } } catch { - DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''."); + DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type ''" + type + "''."); continue; } diff --git a/Subsurface/GUI/GUI.cs b/Subsurface/GUI/GUI.cs index 3b8245e20..2144c7758 100644 --- a/Subsurface/GUI/GUI.cs +++ b/Subsurface/GUI/GUI.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using System; +using System.Collections.Generic; namespace Subsurface { @@ -15,55 +15,6 @@ namespace Subsurface BottomRight = (Bottom | Right), BottomLeft = (Bottom | Left), BottomCenter = (CenterX | Bottom) } - - class GUIMessage - { - ColoredText coloredText; - Vector2 pos; - - float lifeTime; - - Vector2 size; - - - public string Text - { - get { return coloredText.text; } - } - - public Color Color - { - get { return coloredText.color; } - } - - public Vector2 Pos - { - get { return pos; } - set { pos = value; } - } - - public Vector2 Size - { - get { return size; } - } - - - public float LifeTime - { - get { return lifeTime; } - set { lifeTime = value; } - } - - public GUIMessage(string text, Color color, Vector2 position, float lifeTime) - { - coloredText = new ColoredText(text, color); - pos = position; - this.lifeTime = lifeTime; - - size = GUI.Font.MeasureString(text); - } - } - class GUI { public static GUIStyle style; @@ -71,15 +22,19 @@ namespace Subsurface static Texture2D t; public static SpriteFont Font, SmallFont; - - private static GraphicsDevice graphicsDevice; - + private static GraphicsDevice graphicsDevice; private static List messages = new List(); - private static Sound[] sounds; + private static bool pauseMenuOpen; + private static GUIFrame pauseMenu; + + public static bool PauseMenuOpen + { + get { return pauseMenuOpen; } + } public static void LoadContent(GraphicsDevice graphics) { @@ -96,6 +51,51 @@ namespace Subsurface style = new GUIStyle("Content/UI/style.xml"); } + public static void TogglePauseMenu() + { + if (Screen.Selected == Game1.MainMenuScreen) return; + + TogglePauseMenu(null, null); + + if (pauseMenuOpen) + { + pauseMenu = new GUIFrame(new Rectangle(0,0,200,300), null, Alignment.Center, style); + + int y = 0; + var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, GUI.style, pauseMenu); + button.OnClicked = TogglePauseMenu; + + y += 60; + + if (Screen.Selected == Game1.GameScreen) + { + SinglePlayerMode spMode = Game1.GameSession.gameMode as SinglePlayerMode; + if (spMode!=null) + { + button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, GUI.style, pauseMenu); + button.OnClicked += TogglePauseMenu; + button.OnClicked += Game1.GameSession.LoadPrevious; + + y += 60; + } + } + + button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.style, pauseMenu); + + button.UserData = (int)MainMenuScreen.Tabs.Main; + button.OnClicked += Game1.MainMenuScreen.SelectTab; + button.OnClicked += TogglePauseMenu; + } + + } + + private static bool TogglePauseMenu(GUIButton button, object obj) + { + pauseMenuOpen = !pauseMenuOpen; + + return true; + } + public static void DrawLine(SpriteBatch sb, Vector2 start, Vector2 end, Color clr, float depth = 0.0f) { Vector2 edge = end - start; @@ -266,15 +266,18 @@ namespace Subsurface public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam) { spriteBatch.DrawString(Font, - "FPS: " + (int)Game1.FrameCounter.AverageFramesPerSecond - + " - Physics: " + Game1.World.UpdateTime - + " - bodies: " + Game1.World.BodyList.Count, + "FPS: " + (int)Game1.FrameCounter.AverageFramesPerSecond, new Vector2(10, 10), Color.White); - - spriteBatch.DrawString(Font, - "Camera pos: " + Game1.GameScreen.Cam.Position, - new Vector2(10, 30), Color.White); + if (Game1.DebugDraw) + { + spriteBatch.DrawString(Font, + "Physics: " + Game1.World.UpdateTime + + " - bodies: " + Game1.World.BodyList.Count + + "Camera pos: " + Game1.GameScreen.Cam.Position, + new Vector2(10, 30), Color.White); + } + if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam); if (Game1.NetworkMember != null) Game1.NetworkMember.Draw(spriteBatch); @@ -287,6 +290,11 @@ namespace Subsurface if (messageBox != null) messageBox.Draw(spriteBatch); } + if (pauseMenuOpen) + { + pauseMenu.Update(1.0f); + pauseMenu.Draw(spriteBatch); + } DebugConsole.Draw(spriteBatch); } diff --git a/Subsurface/GUI/GUIMessage.cs b/Subsurface/GUI/GUIMessage.cs new file mode 100644 index 000000000..532390eaf --- /dev/null +++ b/Subsurface/GUI/GUIMessage.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Subsurface +{ + class GUIMessage + { + ColoredText coloredText; + Vector2 pos; + + float lifeTime; + + Vector2 size; + + + public string Text + { + get { return coloredText.text; } + } + + public Color Color + { + get { return coloredText.color; } + } + + public Vector2 Pos + { + get { return pos; } + set { pos = value; } + } + + public Vector2 Size + { + get { return size; } + } + + + public float LifeTime + { + get { return lifeTime; } + set { lifeTime = value; } + } + + public GUIMessage(string text, Color color, Vector2 position, float lifeTime) + { + coloredText = new ColoredText(text, color); + pos = position; + this.lifeTime = lifeTime; + + size = GUI.Font.MeasureString(text); + } + } +} diff --git a/Subsurface/Game1.cs b/Subsurface/Game1.cs index 3f3288bea..3ffe5a805 100644 --- a/Subsurface/Game1.cs +++ b/Subsurface/Game1.cs @@ -9,6 +9,7 @@ using Subsurface.Networking; using Subsurface.Particles; using System.Collections; using System.Collections.Generic; +using Microsoft.Xna.Framework.Input; namespace Subsurface { @@ -46,7 +47,7 @@ namespace Subsurface public static NetworkMember NetworkMember; - public static ParticleManager particleManager; + public static ParticleManager ParticleManager; public static TextureLoader TextureLoader; @@ -210,7 +211,7 @@ namespace Subsurface EditCharacterScreen = new EditCharacterScreen(); yield return Status.Running; - particleManager = new ParticleManager("Content/Particles/prefabs.xml", Cam); + ParticleManager = new ParticleManager("Content/Particles/prefabs.xml", Cam); yield return Status.Running; GameMode.Init(); @@ -250,11 +251,11 @@ namespace Subsurface if (loadState >= 100.0f && !titleScreenOpen) { - //if (PlayerInput.KeyDown(Keys.Escape)) Quit(); + if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); DebugConsole.Update(this, (float)deltaTime); - if (!DebugConsole.IsOpen || NetworkMember != null) Screen.Selected.Update(deltaTime); + if ((!DebugConsole.IsOpen && !GUI.PauseMenuOpen) || NetworkMember != null) Screen.Selected.Update(deltaTime); GUI.Update((float)deltaTime); diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs index fe6bdea88..10470fb66 100644 --- a/Subsurface/GameSession/GameSession.cs +++ b/Subsurface/GameSession/GameSession.cs @@ -23,7 +23,7 @@ namespace Subsurface private GUIFrame guiRoot; //private GUIListBox chatBox; - private GUITextBox textBox; + //private GUITextBox textBox; private string savePath; @@ -44,8 +44,7 @@ namespace Subsurface return (mode == null) ? null : mode.map; } } - - + public Submarine Submarine { get { return submarine; } @@ -70,35 +69,8 @@ namespace Subsurface guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent); - //int width = 350, height = 100; - //if (Game1.NetworkMember!=null) - //{ - // chatBox = new GUIListBox(new Rectangle( - // Game1.GraphicsWidth - 20 - width, - // Game1.GraphicsHeight - 40 - 25 - height, - // width, height), - // Color.White * 0.5f, GUI.style, guiRoot); - - // textBox = new GUITextBox( - // new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25), - // Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, GUI.style, guiRoot); - // textBox.OnEnter = EnterChatMessage; - //} - this.gameMode = gameMode; - //if (gameMode != null && !gameMode.IsSinglePlayer) - //{ - // gameMode.Start(Game1.NetLobbyScreen.GameDuration); - //} - - //startTime = DateTime.Now; - //endTime = startTime + gameDuration; - this.submarine = selectedSub; - - //if (!save) return; - - //CreateSaveFile(selectedMapFile); } @@ -108,10 +80,6 @@ namespace Subsurface XDocument doc = ToolBox.TryLoadXml(filePath); if (doc == null) return; - //gameMode = GameModePreset.list.Find(gm => gm.Name == "Single Player").Instantiate(); - - //day = ToolBox.GetAttributeInt(doc.Root,"day",1); - foreach (XElement subElement in doc.Root.Elements()) { if (subElement.Name.ToString().ToLower() != "gamemode") continue; @@ -131,20 +99,22 @@ namespace Subsurface public void StartShift(TimeSpan duration, Level level, bool reloadSub = true) { - Game1.LightManager.FowEnabled = (Game1.Server==null); + Game1.LightManager.LosEnabled = (Game1.Server==null); this.level = level; if (reloadSub || Submarine.Loaded != submarine) submarine.Load(); - if (gameMode!=null) gameMode.Start(duration); - if (level != null) { level.Generate(submarine == null ? 100.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height)); submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f)); } + if (gameMode!=null) gameMode.Start(duration); + + + taskManager.StartShift(level); } @@ -177,85 +147,27 @@ namespace Subsurface public bool LoadPrevious(GUIButton button, object obj) { SaveUtil.LoadGame(savePath); + + Game1.LobbyScreen.Select(); + return true; } - //public bool EnterChatMessage(GUITextBox textBox, string message) - //{ - // if (string.IsNullOrWhiteSpace(message)) return false; - - // else if (Game1.NetworkMember != null) - // { - // Game1.NetworkMember.SendChatMessage(Game1.NetworkMember.Name + ": " + message); - // } - - // textBox.Deselect(); - - // return true; - //} - - //public void NewChatMessage(string text, Color color) - //{ - // GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), text, - - // ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, color, - // Alignment.Left, null, null, true); - - // msg.Padding = new Vector4(20.0f, 0, 0, 0); - // chatBox.AddChild(msg); - - // while (chatBox.CountChildren > 20) - // { - // chatBox.RemoveChild(chatBox.children.First()); - // } - //} - public void Update(float deltaTime) { taskManager.Update(deltaTime); - //if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks; - //endShiftButton.Enabled = true; guiRoot.Update(deltaTime); - - //endShiftButton.Update(deltaTime); - - //textBox.Update(deltaTime); if (gameMode != null) gameMode.Update(deltaTime); - - //double duration = (endTime - startTime).TotalSeconds; - //double elapsedTime = (DateTime.Now-startTime).TotalSeconds; - //timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0)); - - if (PlayerInput.KeyHit(Keys.Tab) && textBox!=null) - { - if (textBox.Selected) - { - textBox.Deselect(); - textBox.Text = ""; - } - else - { - textBox.Select(); - } - } } public void Draw(SpriteBatch spriteBatch) { guiRoot.Draw(spriteBatch); - //crewManager.Draw(spriteBatch); taskManager.Draw(spriteBatch); - if (gameMode!=null) gameMode.Draw(spriteBatch); - - //chatBox.Draw(spriteBatch); - //textBox.Draw(spriteBatch); - - //timerBar.Draw(spriteBatch); - - //if (Game1.Client == null) endShiftButton.Draw(spriteBatch); + if (gameMode != null) gameMode.Draw(spriteBatch); } public void Save(string filePath) @@ -265,10 +177,6 @@ namespace Subsurface ((SinglePlayerMode)gameMode).Save(doc.Root); - //doc.Root.Add(new XAttribute("day", day)); - - //crewManager.Save(doc.Root); - try { doc.Save(filePath); diff --git a/Subsurface/GameSession/SinglePlayerMode.cs b/Subsurface/GameSession/SinglePlayerMode.cs index d43ef6d5f..08797a086 100644 --- a/Subsurface/GameSession/SinglePlayerMode.cs +++ b/Subsurface/GameSession/SinglePlayerMode.cs @@ -18,6 +18,8 @@ namespace Subsurface private GUIButton endShiftButton; public readonly CargoManager CargoManager; + + private Quest quest; public Map map; @@ -26,6 +28,12 @@ namespace Subsurface private bool savedOnStart; + public int Money + { + get { return crewManager.Money; } + set { crewManager.Money = value; } + } + public SinglePlayerMode(GameModePreset preset) : base(preset) { @@ -78,13 +86,15 @@ namespace Subsurface public void GenerateMap(string seed) { - map = new Map(seed.GetHashCode(), 500); + map = new Map(seed, 500); } public override void Start(TimeSpan duration) { CargoManager.CreateItems(); + Game1.GameSession.Map.SelectedConnection.Quest.Start(Level.Loaded); + if (!savedOnStart) { SaveUtil.SaveGame(Game1.GameSession.SavePath); @@ -166,6 +176,8 @@ namespace Subsurface { base.End(endMessage); + quest.End(); + StringBuilder sb = new StringBuilder(); List casualties = crewManager.characters.FindAll(c => c.IsDead); @@ -208,9 +220,6 @@ namespace Subsurface Character.CharacterList[i].Remove(); } - - //SaveUtil.SaveGame(Game1.GameSession.SavePath); - Game1.GameSession.EndShift(""); } diff --git a/Subsurface/Items/CharacterInventory.cs b/Subsurface/Items/CharacterInventory.cs index d21c164e1..2469ad150 100644 --- a/Subsurface/Items/CharacterInventory.cs +++ b/Subsurface/Items/CharacterInventory.cs @@ -125,6 +125,8 @@ namespace Subsurface } } + if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent); + return false; } diff --git a/Subsurface/Items/Components/Container.cs b/Subsurface/Items/Components/Container.cs index 6d4bd415a..b30ac86be 100644 --- a/Subsurface/Items/Components/Container.cs +++ b/Subsurface/Items/Components/Container.cs @@ -132,8 +132,8 @@ namespace Subsurface.Items.Components foreach (StatusEffect effect in ri.statusEffects) { - if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, item.AllPropertyObjects); - if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, contained.AllPropertyObjects); + if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item, item.AllPropertyObjects); + if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item, contained.AllPropertyObjects); } contained.ApplyStatusEffects(ActionType.OnContained, deltaTime); diff --git a/Subsurface/Items/Components/Holdable/Holdable.cs b/Subsurface/Items/Components/Holdable/Holdable.cs index 483c61043..fa52fd17b 100644 --- a/Subsurface/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Items/Components/Holdable/Holdable.cs @@ -4,12 +4,12 @@ using Microsoft.Xna.Framework; namespace Subsurface.Items.Components { - class Holdable : ItemComponent + class Holdable : Pickable { //the position(s) in the item that the character grabs protected Vector2[] handlePos; - protected Character picker; + //protected Character picker; //the distance from the holding characters elbow to center of the physics body of the item protected Vector2 holdPos; @@ -154,6 +154,8 @@ namespace Subsurface.Items.Components public override bool Pick(Character picker) { + if (!base.Pick(picker)) return false; + if (!attachable) return false; //if (item.body==null) diff --git a/Subsurface/Items/Components/Holdable/Pickable.cs b/Subsurface/Items/Components/Holdable/Pickable.cs index f0f8017e2..634d8f07a 100644 --- a/Subsurface/Items/Components/Holdable/Pickable.cs +++ b/Subsurface/Items/Components/Holdable/Pickable.cs @@ -37,10 +37,6 @@ namespace Subsurface.Items.Components if (picker == null) return false; if (picker.Inventory == null) return false; - //this.picker = picker; - - - if (picker.Inventory.TryPutItem(item, allowedSlots)) { if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false; diff --git a/Subsurface/Items/Components/Holdable/RepairTool.cs b/Subsurface/Items/Components/Holdable/RepairTool.cs index 32711b03e..064377f7e 100644 --- a/Subsurface/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Items/Components/Holdable/RepairTool.cs @@ -151,7 +151,7 @@ namespace Subsurface.Items.Components foreach (StatusEffect effect in statusEffects) { //if (Array.IndexOf(effect.TargetNames, targetItem.Name) == -1) continue; - effect.Apply(ActionType.OnUse, deltaTime, item.SimPosition, targetItem.AllPropertyObjects); + effect.Apply(ActionType.OnUse, deltaTime, item, targetItem.AllPropertyObjects); //targetItem.ApplyStatusEffect(effect, ActionType.OnUse, deltaTime); } //ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ); @@ -182,7 +182,7 @@ namespace Subsurface.Items.Components (float)Math.Cos(item.body.Rotation), (float)Math.Sin(item.body.Rotation)) *item.body.Dir * 5.0f; - Game1.particleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed); + Game1.ParticleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed); //Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position); //Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition); diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index 3645951ac..c0322fe98 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -7,11 +7,10 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Subsurface.Networking; -using Subsurface.Items.Components; using System.IO; using System.Globalization; -namespace Subsurface +namespace Subsurface.Items.Components { class ItemSound { @@ -20,6 +19,8 @@ namespace Subsurface public string VolumeProperty; + public float VolumeMultiplier; + public readonly float Range; public ItemSound(Sound sound, ActionType type, float range) @@ -207,10 +208,10 @@ namespace Subsurface guiFrame = new GUIFrame( new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W), - new Color(color.X, color.Y, color.Z, color.W), alignment); + new Color(color.X, color.Y, color.Z, color.W), alignment, GUI.style); //guiFrame.Alpha = color.W; - break; + break; case "sound": string filePath = ToolBox.GetAttributeString(subElement, "file", ""); if (filePath=="") continue; @@ -236,6 +237,7 @@ namespace Subsurface float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); ItemSound itemSound = new ItemSound(sound, type, range); itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", ""); + itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f); sounds.Add(itemSound); break; } @@ -245,7 +247,7 @@ namespace Subsurface private ItemSound loopingSound; private int loopingSoundIndex; - public void PlaySound(ActionType type, float volume, Vector2 position, bool loop=false) + public void PlaySound(ActionType type, Vector2 position, bool loop=false) { ItemSound itemSound = null; if (!loop || !Sounds.SoundManager.IsPlaying(loopingSoundIndex)) @@ -254,19 +256,9 @@ namespace Subsurface if (matchingSounds.Count == 0) return; int index = Rand.Int(matchingSounds.Count); - itemSound = sounds[index]; + itemSound = matchingSounds[index]; - if (itemSound.VolumeProperty != "") - { - ObjectProperty op = null; - if (properties.TryGetValue(itemSound.VolumeProperty.ToLower(), out op)) - { - float newVolume = 0.0f; - float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume); - volume = MathHelper.Clamp(newVolume, 0.0f, 1.0f); - } - } if (loop) loopingSound = itemSound; } @@ -274,16 +266,33 @@ namespace Subsurface if (loop) { - //if (loopingSound != null && loopingSound.volumeProperty != "") volume = float.Parse(properties[loopingSound.volumeProperty].GetValue().ToString()); - loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, volume, position, loopingSound.Range); + loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range); } else { - - itemSound.Sound.Play(volume, itemSound.Range, position); + + itemSound.Sound.Play(GetSoundVolume(itemSound), itemSound.Range, position); } } + private float GetSoundVolume(ItemSound sound) + { + if (sound.VolumeProperty == "") return 1.0f; + + ObjectProperty op = null; + if (properties.TryGetValue(sound.VolumeProperty.ToLower(), out op)) + { + float newVolume = 0.0f; + float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume); + + newVolume *= sound.VolumeMultiplier; + + return MathHelper.Clamp(newVolume, 0.0f, 1.0f); + } + + return 0.0f; + } + public virtual void Move(Vector2 amount) { } /// a character has picked the item @@ -347,7 +356,17 @@ namespace Subsurface return false; } - public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) { } + public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) + { + + switch (connection.Name) + { + case "activate": + case "use": + item.Use(1.0f); + break; + } + } public virtual bool Combine(Item item) { @@ -459,12 +478,12 @@ namespace Subsurface } } - public void ApplyStatusEffects(ActionType type, float deltaTime, Vector2 position, IPropertyObject target) + public void ApplyStatusEffects(ActionType type, float deltaTime, IPropertyObject target) { foreach (StatusEffect effect in statusEffects) { if (effect.type != type) continue; - effect.Apply(type, deltaTime, position, target); + effect.Apply(type, deltaTime, item, target); } } @@ -569,7 +588,7 @@ namespace Subsurface ConstructorInfo constructor; try { - if (!t.IsSubclassOf(typeof(ItemComponent))) return null; + if (t!=typeof(ItemComponent) && !t.IsSubclassOf(typeof(ItemComponent))) return null; constructor = t.GetConstructor(new Type[] { typeof(Item), typeof(XElement) }); if (constructor == null) { diff --git a/Subsurface/Items/Components/Machines/Engine.cs b/Subsurface/Items/Components/Machines/Engine.cs index df26e4e05..3e7d1051a 100644 --- a/Subsurface/Items/Components/Machines/Engine.cs +++ b/Subsurface/Items/Components/Machines/Engine.cs @@ -50,7 +50,11 @@ namespace Subsurface.Items.Components : base(item, element) { isActive = true; + } + public float CurrentVolume + { + get { return Math.Abs((force / 100.0f) * (voltage / minVoltage)); } } public override void Update(float deltaTime, Camera cam) @@ -68,7 +72,7 @@ namespace Subsurface.Items.Components for (int i = 0; i < 5; i++) { - Game1.particleManager.CreateParticle("bubbles", item.SimPosition, + Game1.ParticleManager.CreateParticle("bubbles", item.SimPosition, -currForce/500.0f + new Vector2(Rand.Range(-1.0f, 1.0f), Rand.Range(-0.5f, 0.5f))); } } diff --git a/Subsurface/Items/Components/Machines/Pump.cs b/Subsurface/Items/Components/Machines/Pump.cs index 7e67133c3..154a73d1f 100644 --- a/Subsurface/Items/Components/Machines/Pump.cs +++ b/Subsurface/Items/Components/Machines/Pump.cs @@ -1,4 +1,6 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; using System.Collections.Specialized; using System.Globalization; using System.Xml.Linq; @@ -16,6 +18,16 @@ namespace Subsurface.Items.Components Hull hull1, hull2; + private float FlowPercentage + { + get { return flowPercentage; } + set + { + if (float.IsNaN(flowPercentage)) return; + flowPercentage = MathHelper.Clamp(value,-100.0f,100.0f); + } + } + [HasDefaultValue(100.0f, false)] public float MaxFlow { @@ -26,7 +38,7 @@ namespace Subsurface.Items.Components public Pump(Item item, XElement element) : base(item, element) { - //maxFlow = ToolBox.GetAttributeFloat(element, "maxflow", 100.0f); + flowPercentage = 100.0f; item.linkedTo.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { GetHulls(); }; @@ -34,7 +46,7 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { - currPowerConsumption = powerConsumption; + currPowerConsumption = powerConsumption * Math.Abs(flowPercentage / 100.0f); if (voltage < minVoltage) return; @@ -56,52 +68,17 @@ namespace Subsurface.Items.Components } hull1.Volume += deltaVolume; - if (hull2 != null) hull2.Volume -= deltaVolume; + if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f; + + if (hull2 != null) + { + hull2.Volume -= deltaVolume; + if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f; + } voltage = 0.0f; } - - //public override void DrawHUD(SpriteBatch spriteBatch, Character character) - //{ - // int width = 300, height = 200; - // int x = Game1.GraphicsWidth / 2 - width / 2; - // int y = Game1.GraphicsHeight / 2 - height / 2; - - // GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - - // spriteBatch.DrawString(GUI.font, "Pumping direction: " + ((flowIn) ? "in" : "out"), new Vector2(x + 30, y + 30), Color.White); - // if (GUI.DrawButton(spriteBatch, new Rectangle(x + 30, y + 50, 80, 40), "TOGGLE")) flowIn = !flowIn; - - // if (GUI.DrawButton(spriteBatch, new Rectangle(x + 30, y + 150, 100, 40), (isActive) ? "TURN OFF" : "TURN ON")) IsActive = !isActive; - - //} - - //public override bool Pick(Character activator = null) - //{ - // //isActive = !isActive; - - // hull1 = null; - // hull2 = null; - - // foreach (MapEntity e in item.linkedTo) - // { - // Hull hull = e as Hull; - // if (hull == null) continue; - - // if (hull1 == null) - // { - // hull1 = hull; - // } - // else if (hull2 == null && hull != hull1) - // { - // hull2 = hull; - // break; - // } - // } - - // return true; - //} - + private void GetHulls() { hull1 = null; @@ -124,34 +101,33 @@ namespace Subsurface.Items.Components } } - //public override void OnMapLoaded() - //{ - // hull1 = null; - // hull2 = null; + 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; - // foreach (MapEntity e in item.linkedTo) - // { - // Hull hull = e as Hull; - // if (hull == null) continue; + GuiFrame.Draw(spriteBatch); - // if (hull1 == null) - // { - // hull1 = hull; - // } - // else if (hull2 == null && hull != hull1) - // { - // hull2 = hull; - // break; - // } - // } - //} + if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 100, 40), ((isActive) ? "TURN OFF" : "TURN ON"))) + { + targetLevel = null; + isActive = !isActive; + } + + spriteBatch.DrawString(GUI.Font, "Flow percentage: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White); + + if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true)) FlowPercentage += 1.0f; + if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true)) FlowPercentage -= 1.0f; + + + item.NewComponentEvent(this, true); + } public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { base.ReceiveSignal(signal, connection, sender, power); - - isActive = true; - + if (connection.Name == "toggle") { isActive = !isActive; @@ -176,8 +152,6 @@ namespace Subsurface.Items.Components targetLevel = MathHelper.Clamp(tempTarget, 0.0f, 100.0f); } } - - } public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) @@ -193,13 +167,13 @@ namespace Subsurface.Items.Components try { - newFlow = MathHelper.Clamp(message.ReadFloat(), -100.0f, 100.0f); + newFlow = message.ReadFloat(); newActive = message.ReadBoolean(); } catch { return; } - flowPercentage = newFlow; + FlowPercentage = newFlow; isActive = newActive; } } diff --git a/Subsurface/Items/Components/Machines/Radar.cs b/Subsurface/Items/Components/Machines/Radar.cs index 23c451f52..0ae025f68 100644 --- a/Subsurface/Items/Components/Machines/Radar.cs +++ b/Subsurface/Items/Components/Machines/Radar.cs @@ -96,6 +96,7 @@ namespace Subsurface.Items.Components float scale = 0.015f; + float displayScale = ConvertUnits.ToDisplayUnits(scale); if (Level.Loaded != null) { @@ -109,12 +110,11 @@ namespace Subsurface.Items.Components center + (edges[i][1] - offset) * scale, Color.White); } - scale = ConvertUnits.ToDisplayUnits(scale); for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++) { - Vector2 start = Submarine.Loaded.HullVertices[i] * scale; + Vector2 start = Submarine.Loaded.HullVertices[i] * displayScale; start.Y = -start.Y; - Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale; + Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * displayScale; end.Y = -end.Y; GUI.DrawLine(spriteBatch, center + start, center + end, Color.White); @@ -127,7 +127,7 @@ namespace Subsurface.Items.Components if (c.SimPosition != Vector2.Zero && c.SimPosition.Length() < 7 * Level.GridCellWidth) { - int width = (int)Math.Min(c.Mass / 5, 30); + int width = (int)MathHelper.Clamp(c.Mass / 20, 1, 10); Vector2 pos = c.Position * scale; pos.Y = -pos.Y; @@ -141,6 +141,74 @@ namespace Subsurface.Items.Components { screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X); } + + //if (Level.Loaded != null) + //{ + + // for (int i = 0; i < 2; i++) + // { + // Vector2 targetPos = (i == 0) ? Level.Loaded.StartPosition : Level.Loaded.EndPosition; + // targetPos += Level.Loaded.Position; + + // float dist = targetPos.Length(); + + // targetPos.Y = -targetPos.Y; + // Vector2 markerPos = Vector2.Normalize(targetPos) * (rect.Width * 0.55f); + // markerPos += center; + + // GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen); + + // string label; + // if (Game1.GameSession.Map!=null) + // { + // label = (i == 0) ? Game1.GameSession.Map.CurrentLocation.Name : Game1.GameSession.Map.SelectedLocation.Name; + // } + // else + // { + // label = (i == 0) ? "Start" : "End"; + // } + + // spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen); + // spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); + // } + + DrawMarker(spriteBatch, + (Game1.GameSession.Map == null) ? "Start" : Game1.GameSession.Map.CurrentLocation.Name, + Level.Loaded.StartPosition + Level.Loaded.Position, center, (rect.Width * 0.55f)); + + DrawMarker(spriteBatch, + (Game1.GameSession.Map == null) ? "End" : Game1.GameSession.Map.SelectedLocation.Name, + Level.Loaded.EndPosition + Level.Loaded.Position, center, (rect.Width * 0.55f)); + + if (Game1.GameSession.Map != null && Game1.GameSession.Map.SelectedConnection.Quest!=null) + { + var quest = Game1.GameSession.Map.SelectedConnection.Quest; + + if (!string.IsNullOrWhiteSpace(quest.RadarLabel)) + { + DrawMarker(spriteBatch, + quest.RadarLabel, + quest.RadarPosition, center, (rect.Width * 0.55f)); + } + + + } + } + + private void DrawMarker(SpriteBatch spriteBatch, string label, Vector2 position, Vector2 center, float radius) + { + //position += Level.Loaded.Position; + + float dist = position.Length(); + + position.Y = -position.Y; + Vector2 markerPos = center + Vector2.Normalize(position) * radius; + + GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen); + + spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen); + spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); + } private void UpdateRendertarget() diff --git a/Subsurface/Items/Components/Machines/Reactor.cs b/Subsurface/Items/Components/Machines/Reactor.cs index 7166cd19f..0f8eae963 100644 --- a/Subsurface/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Items/Components/Machines/Reactor.cs @@ -101,6 +101,8 @@ namespace Subsurface.Items.Components meltDownTemp = 9000.0f; + shutDownTemp = 500.0f; + powerPerTemp = 1.0f; isActive = true; @@ -227,39 +229,14 @@ namespace Subsurface.Items.Components new RepairTask(item, 60.0f, "Reactor meltdown!"); item.Condition = 0.0f; - fissionRate = 0.0f; - coolingRate = 0.0f; + //fissionRate = 0.0f; + //coolingRate = 0.0f; - new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode(); - - //List structureList = new List(); - - //float dist = 600.0f; - //foreach (MapEntity entity in MapEntity.mapEntityList) - //{ - // Structure structure = entity as Structure; - // if (structure == null) continue; - - // if (structure.HasBody && Vector2.Distance(structure.Position, item.Position) 0.0f) structure.AddDamage(i, damage); - // } - //} - - //if (item.currentHull!=null) - //{ - // item.currentHull.WaveVel[item.currentHull.GetWaveIndex(item.SimPosition)] = 100.0f; - //} + //PlaySound(ActionType.OnFailure, item.Position); + //item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, null); + //new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode(); + if (item.ContainedItems!=null) { foreach (Item containedItem in item.ContainedItems) @@ -274,11 +251,7 @@ namespace Subsurface.Items.Components public override bool Pick(Character picker) { - if (picker == null) return false; - - //picker.SelectedConstruction = (picker.SelectedConstruction==item) ? null : item; - - return true; + return (picker != null); } public override void Draw(SpriteBatch spriteBatch, bool editing) @@ -331,10 +304,10 @@ namespace Subsurface.Items.Components y = y - 260; - spriteBatch.DrawString(GUI.Font, "Autotemp: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White); + spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White); if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 60, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON"))) autoTemp = !autoTemp; - spriteBatch.DrawString(GUI.Font, "Max temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White); + spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White); if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true)) shutDownTemp += 100.0f; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true)) shutDownTemp -= 100.0f; @@ -378,7 +351,7 @@ namespace Subsurface.Items.Components Vector2 lastPoint = new Vector2(x, y + height - (graph[graph.Count - 1] + (graph[graph.Count - 2] - graph[graph.Count - 1]) * xOffset) * yScale); - GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.Red); + GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.White); } public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage message) diff --git a/Subsurface/Items/Components/Machines/Steering.cs b/Subsurface/Items/Components/Machines/Steering.cs index 62753df99..7a2c6cb70 100644 --- a/Subsurface/Items/Components/Machines/Steering.cs +++ b/Subsurface/Items/Components/Machines/Steering.cs @@ -12,12 +12,33 @@ namespace Subsurface.Items.Components { class Steering : ItemComponent { - Vector2 currVelocity; - Vector2 targetVelocity; + private Vector2 currVelocity; + private Vector2 targetVelocity; - bool autoPilot; + private bool autoPilot; - SteeringPath steeringPath; + private SteeringPath steeringPath; + + private static PathFinder pathFinder; + + bool AutoPilot + { + get { return autoPilot; } + set + { + if (value == autoPilot) return; + + autoPilot = value; + + if (autoPilot) + { + if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false); + steeringPath = pathFinder.FindPath( + ConvertUnits.ToSimUnits(Level.Loaded.Position), + ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); + } + } + } private Vector2 TargetVelocity { @@ -43,18 +64,16 @@ namespace Subsurface.Items.Components public override void Update(float deltaTime, Camera cam) { base.Update(deltaTime, cam); - - - + if (autoPilot) { - if (steeringPath==null) - { - PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false); - steeringPath = pathFinder.FindPath( - ConvertUnits.ToSimUnits(Level.Loaded.StartPosition), - ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); - } + //if (steeringPath==null) + //{ + // PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false); + // steeringPath = pathFinder.FindPath( + // ConvertUnits.ToSimUnits(Level.Loaded.StartPosition), + // ConvertUnits.ToSimUnits(Level.Loaded.EndPosition)); + //} steeringPath.GetNode(Vector2.Zero, 20.0f); @@ -90,7 +109,7 @@ namespace Subsurface.Items.Components if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot")) { - autoPilot = !autoPilot; + AutoPilot = !AutoPilot; item.NewComponentEvent(this, true); } @@ -156,7 +175,7 @@ namespace Subsurface.Items.Components } TargetVelocity = newTargetVelocity; - autoPilot = newAutoPilot; + AutoPilot = newAutoPilot; } } } diff --git a/Subsurface/Items/Components/Power/PowerContainer.cs b/Subsurface/Items/Components/Power/PowerContainer.cs index e85e7b515..fad6745ff 100644 --- a/Subsurface/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Items/Components/Power/PowerContainer.cs @@ -7,9 +7,9 @@ namespace Subsurface.Items.Components { class PowerContainer : Powered { + //[power/min] float capacity; - //[power/min] float charge; //how fast the battery can be recharged @@ -21,12 +21,6 @@ namespace Subsurface.Items.Components float maxOutput; - //public override float Charge - //{ - // get { return charge; } - // set { Math.Max(Math.Min(charge = value, capacity), 0.0f); } - //} - [Editable, HasDefaultValue(10.0f, true)] public float MaxOutPut { @@ -46,13 +40,14 @@ namespace Subsurface.Items.Components } - [HasDefaultValue(10.0f, false)] + [HasDefaultValue(10.0f, false), Editable] public float Capacity { get { return capacity; } set { capacity = Math.Max(value,1.0f); } } + [HasDefaultValue(10.0f, false), Editable] public float RechargeSpeed { get { return rechargeSpeed; } @@ -63,7 +58,7 @@ namespace Subsurface.Items.Components } } - [HasDefaultValue(10.0f, false)] + [HasDefaultValue(10.0f, false), Editable] public float MaxRechargeSpeed { get { return maxRechargeSpeed; } diff --git a/Subsurface/Items/Components/Signal/Connection.cs b/Subsurface/Items/Components/Signal/Connection.cs index 2777872e4..43589f7d0 100644 --- a/Subsurface/Items/Components/Signal/Connection.cs +++ b/Subsurface/Items/Components/Signal/Connection.cs @@ -26,6 +26,8 @@ namespace Subsurface.Items.Components private static Item draggingConnected; + private List effects; + int[] wireId; public List Recipients @@ -67,21 +69,31 @@ namespace Subsurface.Items.Components IsOutput = (element.Name.ToString() == "output"); Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input"); + effects = new List(); + wireId = new int[MaxLinked]; foreach (XElement subElement in element.Elements()) { - int index = -1; - - for (int i = 0; i < MaxLinked; i++) + switch (subElement.Name.ToString().ToLower()) { - if (wireId[i]<1) index = i; + case "link": + int index = -1; + for (int i = 0; i < MaxLinked; i++) + { + if (wireId[i]<1) index = i; + } + if (index == -1) break; + + wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1); + + break; + + case "statuseffect": + effects.Add(StatusEffect.Load(subElement)); + break; } - if (index == -1) break; - - wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1); } - } public int FindEmptyIndex() @@ -149,6 +161,13 @@ namespace Subsurface.Items.Components { ic.ReceiveSignal(signal, recipient, sender, power); } + + foreach (StatusEffect effect in recipient.effects) + { + + //effect.Apply(ActionType.OnUse, 1.0f, recipient.item, recipient.item); + recipient.item.ApplyStatusEffect(effect, ActionType.OnUse, 1.0f); + } } } diff --git a/Subsurface/Items/Components/Signal/RegExFindComponent.cs b/Subsurface/Items/Components/Signal/RegExFindComponent.cs index c247038c1..28ea8b161 100644 --- a/Subsurface/Items/Components/Signal/RegExFindComponent.cs +++ b/Subsurface/Items/Components/Signal/RegExFindComponent.cs @@ -28,7 +28,7 @@ namespace Subsurface.Items.Components { } - public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) { switch (connection.Name) { diff --git a/Subsurface/Items/Components/Signal/SignalCheckComponent.cs b/Subsurface/Items/Components/Signal/SignalCheckComponent.cs new file mode 100644 index 000000000..0f282106a --- /dev/null +++ b/Subsurface/Items/Components/Signal/SignalCheckComponent.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface.Items.Components +{ + class SignalCheckComponent : ItemComponent + { + private string output; + + private string targetSignal; + + [InGameEditable, HasDefaultValue("1", true)] + public string Output + { + get { return output; } + set { output = value; } + } + + [InGameEditable, HasDefaultValue("", true)] + public string TargetSignal + { + get { return targetSignal; } + set { targetSignal = value; } + } + + public SignalCheckComponent(Item item, XElement element) + : base(item, element) + { + } + + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) + { + switch (connection.Name) + { + case "signal_in": + item.SendSignal((signal == targetSignal) ? output : "0", "signal_out"); + + break; + case "set_output": + output = signal; + break; + case "set_targetsignal": + targetSignal = signal; + break; + } + } + } +} diff --git a/Subsurface/Items/Components/Turret.cs b/Subsurface/Items/Components/Turret.cs index 04de70385..4a3ef3a9d 100644 --- a/Subsurface/Items/Components/Turret.cs +++ b/Subsurface/Items/Components/Turret.cs @@ -51,7 +51,7 @@ namespace Subsurface.Items.Components set { reloadTime = value; } } - [HasDefaultValue("0.0,0.0", true)] + [HasDefaultValue("0.0,0.0", true), Editable] public string RotationLimits { get diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index 9d8e4918e..0a880e508 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -17,7 +17,7 @@ namespace Subsurface public enum ActionType { - OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure + OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure, OnBroken } class Item : MapEntity, IDamageable, IPropertyObject @@ -69,8 +69,9 @@ namespace Subsurface float prev = condition; condition = MathHelper.Clamp(value, 0.0f, 100.0f); - if (condition==0.0f && prev>0.0f) + if (condition == 0.0f && prev>0.0f) { + ApplyStatusEffects(ActionType.OnBroken, 1.0f, null); foreach (FixRequirement req in FixRequirements) { req.Fixed = false; @@ -369,7 +370,7 @@ namespace Subsurface public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null) { - if (condition == 0.0f) return; + if (condition == 0.0f && effect.type != ActionType.OnBroken) return; bool hasTargets = (effect.TargetNames == null); @@ -424,7 +425,7 @@ namespace Subsurface // //container.ApplyStatusEffect(effect, type, deltaTime, container); //} - effect.Apply(type, deltaTime, SimPosition, targets); + effect.Apply(type, deltaTime, this, targets); } } @@ -446,7 +447,7 @@ namespace Subsurface { ic.Update(deltaTime, cam); - ic.PlaySound(ActionType.OnActive, 1.0f, Position, true); + ic.PlaySound(ActionType.OnActive, Position, true); ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null); } else @@ -596,8 +597,8 @@ namespace Subsurface requiredItemCount += ic.requiredItems.Count; } } - - editingHUD = new GUIFrame(new Rectangle(x, y, width, 110 + (editableProperties.Count()+requiredItemCount) * 30), Color.Black * 0.5f); + + editingHUD = new GUIFrame(new Rectangle(x, y, width, 110 + (editableProperties.Count() + requiredItemCount) * 30), Color.Black * 0.5f); editingHUD.Padding = new Vector4(10, 10, 0, 0); editingHUD.UserData = this; @@ -662,6 +663,7 @@ namespace Subsurface editingHUD = CreateEditingHUD(true); } + editingHUD.Update((float)Physics.step); editingHUD.Draw(spriteBatch); foreach (ItemComponent ic in components) @@ -764,7 +766,7 @@ namespace Subsurface if (tempRequiredSkill != null) requiredSkill = tempRequiredSkill; - if (!ic.HasRequiredItems(picker, picker == Character.Controlled) && !forcePick) continue; + if (!forcePick && !ic.HasRequiredItems(picker, picker == Character.Controlled)) continue; if ((ic.CanBePicked && ic.Pick(picker)) || (ic.CanBeSelected && ic.Select(picker))) { picked = true; @@ -805,7 +807,7 @@ namespace Subsurface if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; if (ic.Use(deltaTime, character)) { - ic.PlaySound(ActionType.OnUse, 1.0f, Position); + ic.PlaySound(ActionType.OnUse, Position); ic.ApplyStatusEffects(ActionType.OnUse, deltaTime, character); @@ -902,14 +904,19 @@ namespace Subsurface object prevValue = objectProperty.GetValue(); + textBox.Selected = false; + if (objectProperty.TrySetValue(text)) { textBox.Text = text; + + new NetworkEvent(NetworkEventType.UpdateProperty, ID, true, objectProperty.Name); + return true; } else { - if (prevValue!=null) + if (prevValue != null) { textBox.Text = prevValue.ToString(); } @@ -1075,6 +1082,42 @@ namespace Subsurface case NetworkEventType.UpdateComponent: message.Write((int)data); components[(int)data].FillNetworkData(type, message); + break; + case NetworkEventType.UpdateProperty: + var allProperties = GetProperties(); + + ObjectProperty objectProperty = allProperties.Find(op => op.Name == (string)data); + if (objectProperty != null) + { + message.Write((string)data); + object value = objectProperty.GetValue(); + if (value is string) + { + message.Write((byte)0); + message.Write((string)value); + } + else if (value is float) + { + message.Write((byte)1); + message.Write((float)value); + } + else if (value is int) + { + message.Write((byte)2); + message.Write((int)value); + } + else if (value is bool) + { + message.Write((byte)3); + message.Write((bool)value); + } + else + { + message.Write((byte)200); + } + } + + break; } } @@ -1093,6 +1136,47 @@ namespace Subsurface int componentIndex = message.ReadInt32(); if (componentIndex < 0 || componentIndex > components.Count - 1) return; components[componentIndex].ReadNetworkData(type, message); + break; + case NetworkEventType.UpdateProperty: + string propertyName = ""; + + try + { + propertyName = message.ReadString(); + } + catch + { + return; + } + + var allProperties = GetProperties(); + ObjectProperty property = allProperties.Find(op => op.Name == propertyName); + if (property == null) return; + + try + { + switch (message.ReadByte()) + { + case 0: + property.TrySetValue(message.ReadString()); + break; + case 1: + property.TrySetValue(message.ReadFloat()); + break; + case 2: + property.TrySetValue(message.ReadInt32()); + break; + case 3: + property.TrySetValue(message.ReadBoolean()); + break; + } + } + + catch + { + return; + } + break; } } diff --git a/Subsurface/Map/Explosion.cs b/Subsurface/Map/Explosion.cs index d0344c4f0..d8a9c085b 100644 --- a/Subsurface/Map/Explosion.cs +++ b/Subsurface/Map/Explosion.cs @@ -1,5 +1,6 @@ using FarseerPhysics; using Microsoft.Xna.Framework; +using Subsurface.Lights; using System; using System.Collections.Generic; using System.Xml.Linq; @@ -8,29 +9,34 @@ namespace Subsurface { class Explosion { - Vector2 position; + private Vector2 position; + private float range; + private float damage; + private float structureDamage; + private float stun; - float range; - float damage; - float structureDamage; - float stun; + private float force; - float force; + private LightSource light; - public Explosion(Vector2 position, float range, float damage, float structureDamage, float stun=0.0f, float force=0.0f) + public float CameraShake; + + public Explosion(Vector2 position, float range, float damage, float structureDamage, float stun = 0.0f, float force = 0.0f) { this.position = position; - this.range = Math.Max(range,1.0f); + this.range = Math.Max(range, 1.0f); this.damage = damage; this.structureDamage = structureDamage; this.stun = stun; this.force = force; + + CameraShake = range*10.0f; } public Explosion(XElement element) { - range = Math.Max(ToolBox.GetAttributeFloat(element, "range", 1.0f),1.0f); + range = Math.Max(ToolBox.GetAttributeFloat(element, "range", 1.0f), 1.0f); damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f); stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f); @@ -43,18 +49,25 @@ namespace Subsurface Explode(position); } - public void Explode(Vector2 position) + public void Explode(Vector2 simPosition) { - for (int i = 0; i0.0f) + light = new LightSource(displayPosition, displayRange, Color.LightYellow); + CoroutineManager.StartCoroutine(DimLight()); + + float cameraDist = Vector2.Distance(Game1.GameScreen.Cam.Position, displayPosition)/2.0f; + Game1.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist)/displayRange, 0.0f); + + if (structureDamage > 0.0f) { List structureList = new List(); @@ -84,7 +97,7 @@ namespace Subsurface foreach (Character c in Character.CharacterList) { - float dist = Vector2.Distance(c.SimPosition, position); + float dist = Vector2.Distance(c.SimPosition, simPosition); if (dist > range) continue; @@ -92,16 +105,36 @@ namespace Subsurface foreach (Limb limb in c.AnimController.limbs) { - distFactor = 1.0f - Vector2.Distance(limb.SimPosition, position)/range; + distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/range; c.AddDamage(limb.SimPosition, DamageType.None, damage / c.AnimController.limbs.Length * distFactor, 0.0f, stun * distFactor); if (force>0.0f) { - limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition-position)*distFactor*force); + limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force); } } } } + + private IEnumerable DimLight() + { + float currBrightness= 1.0f; + float startRange = light.Range; + + while (light.Color.A > 0.0f) + { + light.Color = new Color(light.Color.R, light.Color.G, light.Color.B, currBrightness); + light.Range = startRange * currBrightness; + + currBrightness -= 0.1f; + + yield return Status.Running; + } + + light.Remove(); + + yield return Status.Success; + } } } diff --git a/Subsurface/Map/Gap.cs b/Subsurface/Map/Gap.cs index a8c43e3e1..4a58ee403 100644 --- a/Subsurface/Map/Gap.cs +++ b/Subsurface/Map/Gap.cs @@ -249,12 +249,12 @@ namespace Subsurface { pos.Y = ConvertUnits.ToSimUnits(MathHelper.Clamp(lowerSurface, rect.Y-rect.Height, rect.Y)); - Game1.particleManager.CreateParticle("watersplash", + Game1.ParticleManager.CreateParticle("watersplash", new Vector2(pos.X, pos.Y - Rand.Range(0.0f, 0.1f)), new Vector2(flowForce.X * Rand.Range(0.005f, 0.007f), flowForce.Y * Rand.Range(0.005f, 0.007f))); pos.Y = ConvertUnits.ToSimUnits(Rand.Range(lowerSurface, rect.Y - rect.Height)); - Game1.particleManager.CreateParticle("bubbles", pos, flowForce / 200.0f); + Game1.ParticleManager.CreateParticle("bubbles", pos, flowForce / 200.0f); } else { @@ -262,12 +262,12 @@ namespace Subsurface for (int i = 0; i < rect.Width; i += (int)Rand.Range(80, 100)) { pos.X = ConvertUnits.ToSimUnits(Rand.Range(rect.X, rect.X+rect.Width)); - Subsurface.Particles.Particle splash = Game1.particleManager.CreateParticle("watersplash", pos, + Subsurface.Particles.Particle splash = Game1.ParticleManager.CreateParticle("watersplash", pos, new Vector2(flowForce.X * Rand.Range(0.005f, 0.008f), flowForce.Y * Rand.Range(0.005f, 0.008f))); if (splash!=null) splash.Size = splash.Size * MathHelper.Clamp(rect.Width / 50.0f, 0.8f, 4.0f); - Game1.particleManager.CreateParticle("bubbles", pos, flowForce / 200.0f); + Game1.ParticleManager.CreateParticle("bubbles", pos, flowForce / 200.0f); } } diff --git a/Subsurface/Map/Hull.cs b/Subsurface/Map/Hull.cs index 31ff18ca9..488a9f351 100644 --- a/Subsurface/Map/Hull.cs +++ b/Subsurface/Map/Hull.cs @@ -210,7 +210,7 @@ namespace Subsurface float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i])); if (maxDelta > Rand.Range(0.2f,10.0f)) { - Game1.particleManager.CreateParticle("mist", + Game1.ParticleManager.CreateParticle("mist", ConvertUnits.ToSimUnits(new Vector2(rect.X + WaveWidth * i,surface + waveY[i])), new Vector2(0.0f, -0.5f)); } diff --git a/Subsurface/Map/Levels/Level.cs b/Subsurface/Map/Levels/Level.cs index c950acf7d..bed8368ac 100644 --- a/Subsurface/Map/Levels/Level.cs +++ b/Subsurface/Map/Levels/Level.cs @@ -38,9 +38,9 @@ namespace Subsurface //List bodies; private List cells; - private BasicEffect basicEffect; + private static BasicEffect basicEffect; - private VertexPositionColor[] vertices; + private VertexPositionTexture[] vertices; private VertexBuffer vertexBuffer; private Vector2 startPosition; @@ -50,6 +50,8 @@ namespace Subsurface private List bodies = new List(); + private List positionsOfInterest; + public Vector2 StartPosition { get { return startPosition; } @@ -77,6 +79,11 @@ namespace Subsurface get { return ConvertUnits.ToDisplayUnits(cells[0].body.Position); } } + public List PositionsOfInterest + { + get { return positionsOfInterest; } + } + public string Seed { get { return seed; } @@ -92,12 +99,24 @@ namespace Subsurface { if (shaftTexture == null) shaftTexture = Game1.TextureLoader.FromFile("Content/Map/shaft.png"); + if (basicEffect==null) + { + + basicEffect = new BasicEffect(Game1.CurrGraphicsDevice); + basicEffect.VertexColorEnabled = false; + + basicEffect.TextureEnabled = true; + basicEffect.Texture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png"); + } + this.seed = seed; this.siteInterval = siteInterval; this.Difficulty = difficulty; + positionsOfInterest = new List(); + borders = new Rectangle(0, 0, width, height); } @@ -237,7 +256,7 @@ namespace Subsurface endPosition = pathCells[pathCells.Count - 1].Center; //generate a couple of random paths - for (int i = 0; i < rand.Next() % 3; i++) + for (int i = 0; i <= rand.Next() % 3; i++) { //pathBorders = new Rectangle( //borders.X + siteInterval * 2, borders.Y - siteInterval * 2, @@ -252,10 +271,14 @@ namespace Subsurface Vector2 end = new Vector2(x, y); - pathCells.AddRange - ( - GeneratePath(rand, new List { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror) - ); + var newPathCells = GeneratePath(rand, new List { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror); + + for (int n = 1; n < newPathCells.Count; n += 3) + { + positionsOfInterest.Add(newPathCells[n].Center); + } + + pathCells.AddRange(newPathCells); } Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms"); @@ -329,13 +352,9 @@ namespace Subsurface Debug.WriteLine("Generatelevel: " + sw2.ElapsedMilliseconds + " ms"); sw2.Restart(); - vertexBuffer = new VertexBuffer(Game1.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); - + vertexBuffer = new VertexBuffer(Game1.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); vertexBuffer.SetData(vertices); - basicEffect = new BasicEffect(Game1.CurrGraphicsDevice); - basicEffect.VertexColorEnabled = true; - if (mirror) { Vector2 temp = startPosition; @@ -555,7 +574,7 @@ int currentTargetIndex = 1; private void GeneratePolygons(List cells, List emptyCells) { - List verticeList = new List(); + List verticeList = new List(); //bodies = new List(); List tempVertices = new List(); @@ -593,7 +612,7 @@ int currentTargetIndex = 1; { foreach (Vector2 vertex in triangles[i]) { - verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n*30, (n * 60) % 255, (n * 90) % 255) * 0.5f)); + verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 0.0f), vertex/1000.0f)); } } @@ -775,31 +794,31 @@ int currentTargetIndex = 1; Vector2 observerPosition; public void SetObserverPosition(Vector2 position) { - observerPosition = position - this.Position; - int gridPosX = (int)Math.Floor(observerPosition.X / GridCellWidth); - int gridPosY = (int)Math.Floor(observerPosition.Y / GridCellWidth); - int searchOffset = 2; + //observerPosition = position - this.Position; + //int gridPosX = (int)Math.Floor(observerPosition.X / GridCellWidth); + //int gridPosY = (int)Math.Floor(observerPosition.Y / GridCellWidth); + //int searchOffset = 2; - int startX = Math.Max(gridPosX - searchOffset, 0); - int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); + //int startX = Math.Max(gridPosX - searchOffset, 0); + //int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); - int startY = Math.Max(gridPosY - searchOffset, 0); - int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); + //int startY = Math.Max(gridPosY - searchOffset, 0); + //int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); - for (int x = 0; x < cellGrid.GetLength(0); x++) - { - for (int y = 0; y < cellGrid.GetLength(1); y++) - { - for (int i = 0; i < cellGrid[x, y].Count; i++) - { - //foreach (Body b in cellGrid[x, y][i].bodies) - //{ - if (cellGrid[x, y][i].body == null) continue; - cellGrid[x, y][i].body.Enabled = true;// (x >= startX && x <= endX && y >= startY && y <= endY); - //} - } - } - } + //for (int x = 0; x < cellGrid.GetLength(0); x++) + //{ + // for (int y = 0; y < cellGrid.GetLength(1); y++) + // { + // for (int i = 0; i < cellGrid[x, y].Count; i++) + // { + // //foreach (Body b in cellGrid[x, y][i].bodies) + // //{ + // if (cellGrid[x, y][i].body == null) continue; + // cellGrid[x, y][i].body.Enabled = true;// (x >= startX && x <= endX && y >= startY && y <= endY); + // //} + // } + // } + //} } @@ -897,11 +916,12 @@ int currentTargetIndex = 1; basicEffect.World = Matrix.CreateTranslation(new Vector3(Position, 0.0f)) * cam.ShaderTransform * Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f; - - + basicEffect.CurrentTechnique.Passes[0].Apply(); - graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f)); + graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; + + graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f)); } private void Unload() diff --git a/Subsurface/Map/Lights/ConvexHull.cs b/Subsurface/Map/Lights/ConvexHull.cs index 58667dcdb..3e8adea71 100644 --- a/Subsurface/Map/Lights/ConvexHull.cs +++ b/Subsurface/Map/Lights/ConvexHull.cs @@ -8,7 +8,7 @@ namespace Subsurface.Lights class ConvexHull { public static List list = new List(); - static BasicEffect fowEffect; + static BasicEffect losEffect; static BasicEffect shadowEffect; private VertexPositionColor[] vertices; @@ -87,14 +87,14 @@ namespace Subsurface.Lights // } //} - public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool fow = true) + public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool los = true) { if (!Enabled) return; - if (fowEffect == null) + if (losEffect == null) { - fowEffect = new BasicEffect(graphicsDevice); - fowEffect.VertexColorEnabled = true; + losEffect = new BasicEffect(graphicsDevice); + losEffect.VertexColorEnabled = true; } if (shadowEffect==null) { @@ -140,7 +140,7 @@ namespace Subsurface.Lights VertexPositionTexture[] penumbraVertices = new VertexPositionTexture[6]; - if (fow) + if (los) { for (int n = 0; n < 4; n+=3) { @@ -162,26 +162,18 @@ namespace Subsurface.Lights vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f); vertexDir.Normalize(); penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000; - - if (i==0) - { - //penumbraVertices[n].Position -= normal*2.0f; - } - - if (fow) + + if (los) { penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f); } else { - penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f):Vector2.Zero; + penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero; } - - - //penumbraVertices[i+1].Color = Color.Black; } - if (n>0) + if (n > 0) { var temp = penumbraVertices[4]; penumbraVertices[4] = penumbraVertices[5]; @@ -210,12 +202,12 @@ namespace Subsurface.Lights //one vertex on the hull shadowVertices[svCount] = new VertexPositionColor(); - shadowVertices[svCount].Color = fow ? Color.Black : Color.Transparent; + shadowVertices[svCount].Color = los ? Color.Black : Color.Transparent; shadowVertices[svCount].Position = vertexPos; //one extruded by the light direction shadowVertices[svCount + 1] = new VertexPositionColor(); - shadowVertices[svCount + 1].Color = fow ? Color.Black : Color.Transparent; + shadowVertices[svCount + 1].Color = los ? Color.Black : Color.Transparent; Vector3 L2P = vertexPos - new Vector3(lightSourcePos, 0); L2P.Normalize(); shadowVertices[svCount + 1].Position = new Vector3(lightSourcePos, 0) + L2P * 9000; @@ -224,13 +216,13 @@ namespace Subsurface.Lights currentIndex = (currentIndex + 1) % primitiveCount; } - fowEffect.World = cam.ShaderTransform + losEffect.World = cam.ShaderTransform * Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f; - fowEffect.CurrentTechnique.Passes[0].Apply(); + losEffect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2); - if (fow) + if (los) { shadowEffect.World = cam.ShaderTransform * Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f; diff --git a/Subsurface/Map/Lights/LightManager.cs b/Subsurface/Map/Lights/LightManager.cs index bb5029f5f..466b9c9ca 100644 --- a/Subsurface/Map/Lights/LightManager.cs +++ b/Subsurface/Map/Lights/LightManager.cs @@ -16,7 +16,7 @@ namespace Subsurface.Lights private List lights; - public bool FowEnabled = true; + public bool LosEnabled = true; public bool LightingEnabled = true; @@ -54,9 +54,9 @@ namespace Subsurface.Lights lights.Remove(light); } - public void DrawFow(GraphicsDevice graphics, Camera cam, Vector2 pos) + public void DrawLOS(GraphicsDevice graphics, Camera cam, Vector2 pos) { - if (!FowEnabled) return; + if (!LosEnabled) return; foreach (ConvexHull convexHull in ConvexHull.list) { convexHull.DrawShadows(graphics, cam, pos); diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs index f923c26f0..6132317a4 100644 --- a/Subsurface/Map/Map.cs +++ b/Subsurface/Map/Map.cs @@ -19,7 +19,7 @@ namespace Subsurface private List connections; - private int seed; + private string seed; private int size; private static Sprite iceTexture; @@ -29,6 +29,8 @@ namespace Subsurface private Location currentLocation; private Location selectedLocation; + private LocationConnection selectedConnection; + public Location CurrentLocation { get { return currentLocation; } @@ -44,12 +46,17 @@ namespace Subsurface get { return selectedLocation; } } - public int Seed + public LocationConnection SelectedConnection + { + get { return selectedConnection; } + } + + public string Seed { get { return seed; } } - public Map(int seed, int size) + public Map(string seed, int size) { this.seed = seed; @@ -65,7 +72,7 @@ namespace Subsurface if (iceCraters == null) iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png"); if (iceCrack == null) iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png"); - Rand.SetSyncedSeed(this.seed); + Rand.SetSyncedSeed(this.seed.GetHashCode()); GenerateLocations(); @@ -288,9 +295,9 @@ namespace Subsurface if (PlayerInput.LeftButtonClicked()&& selectedLocation != highlightedLocation && highlightedLocation != null) { - //currentLocation = highlightedLocation; - Game1.LobbyScreen.SelectLocation(highlightedLocation, connection); - selectedLocation = highlightedLocation; + selectedConnection = connection; + selectedLocation = highlightedLocation; + Game1.LobbyScreen.SelectLocation(highlightedLocation, connection); } } @@ -368,14 +375,34 @@ namespace Subsurface private Level level; public float Difficulty; - + public List CrackSegments; + private int questsCompleted; + + private Quest quest; + public Quest Quest + { + get + { + if (quest==null || quest.Completed) + { + if (quest !=null && quest.Completed) questsCompleted++; + Random rand = new Random(GetHashCode() + questsCompleted); + quest = Quest.LoadRandom(rand); + } + + return quest; + } + } + + + public Location[] Locations { get { return locations; } } - + public Level Level { get { return level; } @@ -385,8 +412,8 @@ namespace Subsurface public LocationConnection(Location location1, Location location2) { locations = new Location[] { location1, location2 }; - //location1.connections.Add(this); - //location2.connections.Add(this); + + questsCompleted = 0; } public Location OtherLocation(Location location) diff --git a/Subsurface/Map/Structure.cs b/Subsurface/Map/Structure.cs index 3976ade8f..4b5f48f63 100644 --- a/Subsurface/Map/Structure.cs +++ b/Subsurface/Map/Structure.cs @@ -371,8 +371,6 @@ namespace Subsurface if (Game1.Client==null) SetDamage(sectionIndex, sections[sectionIndex].damage + damage); - - } public int FindSectionIndex(Vector2 pos) @@ -408,9 +406,9 @@ namespace Subsurface int i = FindSectionIndex(ConvertUnits.ToDisplayUnits(position)); if (i == -1) return new AttackResult(0.0f, 0.0f); - Game1.particleManager.CreateParticle("dustcloud", ConvertUnits.ToSimUnits(SectionPosition(i)), 0.0f, 0.0f); + Game1.ParticleManager.CreateParticle("dustcloud", ConvertUnits.ToSimUnits(SectionPosition(i)), 0.0f, 0.0f); - if (playSound) + if (playSound && !SectionHasHole(i)) { DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash; AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position); diff --git a/Subsurface/Map/Submarine.cs b/Subsurface/Map/Submarine.cs index 627b6052e..c376f2c51 100644 --- a/Subsurface/Map/Submarine.cs +++ b/Subsurface/Map/Submarine.cs @@ -8,6 +8,7 @@ using FarseerPhysics.Factories; using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Subsurface.Items.Components; using System; using System.Collections.Generic; using System.IO; diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs index ac21a7463..422ec8c7a 100644 --- a/Subsurface/Networking/GameClient.cs +++ b/Subsurface/Networking/GameClient.cs @@ -161,6 +161,10 @@ namespace Subsurface.Networking if (packetType == (byte)PacketTypes.LoggedIn) { myID = inc.ReadInt32(); + if (inc.ReadBoolean()) + { + new GUIMessageBox("Please wait", "A round is already running. You will have to wait for a new round to start."); + } Game1.NetLobbyScreen.ClearPlayers(); diff --git a/Subsurface/Networking/GameServer.cs b/Subsurface/Networking/GameServer.cs index 94d7b484b..6741c1fc2 100644 --- a/Subsurface/Networking/GameServer.cs +++ b/Subsurface/Networking/GameServer.cs @@ -19,16 +19,16 @@ namespace Subsurface.Networking Client myClient; - public GameServer() + public GameServer(string name, int port) { - var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 170-120, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD); + var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD); endRoundButton.OnClicked = EndButtonHit; - name = "Server"; + this.name = name; Config = new NetPeerConfiguration("subsurface"); - Config.Port = 14242; + Config.Port = port; //Config.SimulatedLoss = 0.2f; //Config.SimulatedMinimumLatency = 0.25f; @@ -215,6 +215,8 @@ namespace Subsurface.Networking outmsg.Write(sender.ID); + outmsg.Write(gameStarted); + //notify the client about other clients already logged in outmsg.Write((myClient == null) ? connectedClients.Count - 1 : connectedClients.Count); foreach (Client c in connectedClients) diff --git a/Subsurface/Networking/NetworkEvent.cs b/Subsurface/Networking/NetworkEvent.cs index 04a44a0c3..c7892d490 100644 --- a/Subsurface/Networking/NetworkEvent.cs +++ b/Subsurface/Networking/NetworkEvent.cs @@ -10,7 +10,8 @@ namespace Subsurface.Networking UpdateComponent = 2, DropItem = 3, InventoryUpdate = 4, - PickItem = 5 + PickItem = 5, + UpdateProperty = 6 } class NetworkEvent diff --git a/Subsurface/Screens/GameScreen.cs b/Subsurface/Screens/GameScreen.cs index a17b4a0ab..2e248c9ce 100644 --- a/Subsurface/Screens/GameScreen.cs +++ b/Subsurface/Screens/GameScreen.cs @@ -38,8 +38,6 @@ namespace Subsurface { base.Select(); - //if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero); - foreach (MapEntity entity in MapEntity.mapEntityList) entity.IsHighlighted = false; } @@ -73,10 +71,9 @@ namespace Subsurface Character.UpdateAll(cam, (float)deltaTime); - Game1.particleManager.Update((float)deltaTime); + Game1.ParticleManager.Update((float)deltaTime); StatusEffect.UpdateAll((float)deltaTime); - //Physics.updated = false; cam.MoveCamera((float)deltaTime); @@ -108,24 +105,15 @@ namespace Subsurface } - /// - /// This is called when the game should draw itself. - /// public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { //if (!Physics.updated) return; DrawMap(graphics, spriteBatch); - //---------------------------------------------------------------------------------------- - //2. draw the HUD on top of everything - //---------------------------------------------------------------------------------------- - spriteBatch.Begin(); if (Game1.GameSession != null) Game1.GameSession.Draw(spriteBatch); - //EventManager.DrawInfo(spriteBatch); - if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) { if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) @@ -215,7 +203,7 @@ namespace Subsurface BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); - Game1.particleManager.Draw(spriteBatch, true); + Game1.ParticleManager.Draw(spriteBatch, true); spriteBatch.End(); @@ -233,7 +221,7 @@ namespace Subsurface null, DepthStencilState.DepthRead, null, null, cam.Transform); - Game1.particleManager.Draw(spriteBatch, false); + Game1.ParticleManager.Draw(spriteBatch, false); spriteBatch.End(); graphics.SetRenderTarget(null); @@ -253,6 +241,12 @@ namespace Subsurface Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform); + if (Game1.GameSession != null && Game1.GameSession.Level != null) + { + Game1.GameSession.Level.Render(graphics, cam); + Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); + } + if (Game1.LightManager.LightingEnabled) { //multiply scene with lightmap @@ -264,7 +258,7 @@ namespace Subsurface //---------------------------------------------------------------------------------------- //3. draw the sections of the map that are on top of the water //---------------------------------------------------------------------------------------- - + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null, null, @@ -279,20 +273,10 @@ namespace Subsurface Game1.GameSession.Level.Draw(spriteBatch); //Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); } - + spriteBatch.End(); - if (Game1.GameSession != null && Game1.GameSession.Level != null) - { - Game1.GameSession.Level.Render(graphics, cam); - Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); - } - else if (Game1.Level != null) - { - Game1.Level.Render(graphics, cam); - } - - Game1.LightManager.DrawFow(graphics,cam,LightManager.ViewPos); + Game1.LightManager.DrawLOS(graphics, cam, LightManager.ViewPos); } } diff --git a/Subsurface/Screens/LobbyScreen.cs b/Subsurface/Screens/LobbyScreen.cs index 07cdfb0bc..bc87c436d 100644 --- a/Subsurface/Screens/LobbyScreen.cs +++ b/Subsurface/Screens/LobbyScreen.cs @@ -21,7 +21,7 @@ namespace Subsurface GUIListBox characterList; GUIListBox hireList; - GUIListBox selectedItemList; + GUIListBox selectedItemList, itemList; SinglePlayerMode gameMode; @@ -31,9 +31,9 @@ namespace Subsurface Level selectedLevel; - private string SelectedItemCost() + private string CostTextGetter() { - return selectedItemCost.ToString(); + return "Cost: "+selectedItemCost.ToString(); } private int selectedItemCost @@ -55,7 +55,7 @@ namespace Subsurface { Rectangle panelRect = new Rectangle( 40, 40, - (int)(Game1.GraphicsWidth * 0.3f) - 60, + 180, Game1.GraphicsHeight - 80); leftPanel = new GUIFrame(panelRect, GUI.style); @@ -122,14 +122,15 @@ namespace Subsurface rightPanel[(int)PanelTab.Store] = new GUIFrame(panelRect, GUI.style); selectedItemList = new GUIListBox(new Rectangle(0, 0, 300, 400), Color.White * 0.7f, GUI.style, rightPanel[(int)PanelTab.Store]); + selectedItemList.OnSelected = DeselectItem; - var costText = new GUITextBlock(new Rectangle(0, 0, 200, 25), "Cost: ", Color.Transparent, Color.White, Alignment.BottomLeft, GUI.style, rightPanel[(int)PanelTab.Store]); - costText.TextGetter = SelectedItemCost; + var costText = new GUITextBlock(new Rectangle(0, 0, 200, 25), "Cost: ", GUI.style, Alignment.BottomLeft, Alignment.TopLeft, rightPanel[(int)PanelTab.Store]); + costText.TextGetter = CostTextGetter; - buyButton = new GUIButton(new Rectangle(15, 0, 100, 25), "Buy", Alignment.Bottom, GUI.style, rightPanel[(int)PanelTab.Store]); + buyButton = new GUIButton(new Rectangle(150, 0, 100, 25), "Buy", Alignment.Bottom, GUI.style, rightPanel[(int)PanelTab.Store]); buyButton.OnClicked = BuyItems; - GUIListBox itemList = new GUIListBox(new Rectangle(0, 0, 300, 400), Color.White * 0.7f, Alignment.TopRight, GUI.style, rightPanel[(int)PanelTab.Store]); + itemList = new GUIListBox(new Rectangle(0, 0, 300, 400), Color.White * 0.7f, Alignment.TopRight, GUI.style, rightPanel[(int)PanelTab.Store]); itemList.OnSelected = SelectItem; foreach (MapEntityPrefab ep in MapEntityPrefab.list) @@ -196,10 +197,22 @@ namespace Subsurface if (locationPanel != null) rightPanel[(int)PanelTab.Map].RemoveChild(locationPanel); - locationPanel = new GUIFrame(new Rectangle(0, 0, rightPanel[(int)PanelTab.Map].Rect.Width / 2 - 40, 190), Color.Transparent, null, rightPanel[(int)PanelTab.Map]); + locationPanel = new GUIFrame(new Rectangle(0, 0, 200, 190), Color.Transparent, Alignment.TopRight, null, rightPanel[(int)PanelTab.Map]); locationPanel.UserData = "selectedlocation"; - new GUITextBlock(new Rectangle(0,0,100,20), location.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); + new GUITextBlock(new Rectangle(0,0,0,0), location.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); + + if (Game1.GameSession.Map.SelectedConnection != null && Game1.GameSession.Map.SelectedConnection.Quest != null) + { + var quest = Game1.GameSession.Map.SelectedConnection.Quest; + + new GUITextBlock(new Rectangle(0, 40, 0, 20), "Quest: "+quest.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); + + new GUITextBlock(new Rectangle(0, 60, 0, 20), "Reward: " + quest.Reward, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); + + new GUITextBlock(new Rectangle(0, 80, 0, 0), quest.Description, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel, true); + + } startButton.Enabled = true; @@ -257,7 +270,6 @@ namespace Subsurface private bool SelectItem(object obj) { MapEntityPrefab prefab = obj as MapEntityPrefab; - if (prefab == null) return false; CreateItemFrame(prefab, selectedItemList); @@ -267,6 +279,16 @@ namespace Subsurface return false; } + private bool DeselectItem(object obj) + { + MapEntityPrefab prefab = obj as MapEntityPrefab; + if (prefab == null) return false; + + selectedItemList.RemoveChild(selectedItemList.children.Find(c => c.UserData == obj)); + + return false; + } + private bool BuyItems(GUIButton button, object obj) { int cost = selectedItemCost; @@ -323,8 +345,8 @@ namespace Subsurface Game1.GameSession.Map.Draw(spriteBatch, new Rectangle( rightPanel[selectedRightPanel].Rect.X + 20, rightPanel[selectedRightPanel].Rect.Y + 20, - rightPanel[selectedRightPanel].Rect.Width - 40, - rightPanel[selectedRightPanel].Rect.Height - 150), 3.0f); + rightPanel[selectedRightPanel].Rect.Width - 250, + rightPanel[selectedRightPanel].Rect.Height - 40), 3.0f); } if (rightPanel[(int)selectedRightPanel].UserData as Location != Game1.GameSession.Map.CurrentLocation) diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs index c1fd544cc..b83d0ff7c 100644 --- a/Subsurface/Screens/MainMenu.cs +++ b/Subsurface/Screens/MainMenu.cs @@ -8,7 +8,7 @@ namespace Subsurface { class MainMenuScreen : Screen { - enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3 } + public enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3, HostServer = 4 } private GUIFrame[] menuTabs; private GUIListBox mapList; @@ -19,6 +19,8 @@ namespace Subsurface private GUITextBox nameBox, ipBox; + private GUITextBox serverNameBox, portBox; + private Game1 game; int selectedTab; @@ -50,7 +52,8 @@ namespace Subsurface button.OnClicked = SelectTab; button = new GUIButton(new Rectangle(0, 180, 0, 30), "Host Server", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]); - button.OnClicked = HostServerClicked; + button.UserData = (int)Tabs.HostServer; + button.OnClicked = SelectTab; //button.Enabled = false; button = new GUIButton(new Rectangle(0, 240, 0, 30), "Quit", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]); @@ -86,7 +89,7 @@ namespace Subsurface seedBox.Text = ToolBox.RandomSeed(8); - button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start",Alignment.BottomRight, GUI.style, menuTabs[(int)Tabs.NewGame]); + button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, GUI.style, menuTabs[(int)Tabs.NewGame]); button.OnClicked = StartGame; //---------------------------------------------------------------------- @@ -94,7 +97,7 @@ namespace Subsurface menuTabs[(int)Tabs.LoadGame] = new GUIFrame(panelRect, GUI.style); //menuTabs[(int)Tabs.LoadGame].Padding = GUI.style.smallPadding; - new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", Color.Transparent, Color.Black, Alignment.CenterX, null, menuTabs[(int)Tabs.LoadGame]); + new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.LoadGame]); if (!Directory.Exists(SaveUtil.SaveFolder)) { @@ -148,6 +151,22 @@ namespace Subsurface //---------------------------------------------------------------------- + menuTabs[(int)Tabs.HostServer] = new GUIFrame(panelRect, GUI.style); + //menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding; + + new GUITextBlock(new Rectangle(0, 0, 0, 30), "Host Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]); + + new GUITextBlock(new Rectangle(0, 30, 0, 30), "Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]); + serverNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.HostServer]); + + new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server port:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]); + portBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.HostServer]); + portBox.Text = NetworkMember.DefaultPort.ToString(); + + GUIButton hostButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.HostServer]); + hostButton.OnClicked = HostServerClicked; + + //---------------------------------------------------------------------- for (int i = 1; i < 4; i++ ) { button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menuTabs[i]); @@ -158,14 +177,28 @@ namespace Subsurface } - private bool SelectTab(GUIButton button, object obj) + public bool SelectTab(GUIButton button, object obj) { selectedTab = (int)obj; + + this.Select(); return true; } private bool HostServerClicked(GUIButton button, object obj) { + string name = serverNameBox.Text; + if (string.IsNullOrEmpty(name)) name = "Server"; + + int port; + if (!int.TryParse(portBox.Text, out port)) + { + DebugConsole.ThrowError("ERROR: "+portBox.Text+" is not a valid port. Using the default port "+NetworkMember.DefaultPort); + port = NetworkMember.DefaultPort; + } + + Game1.NetworkMember = new GameServer(name, port); + Game1.NetLobbyScreen.IsServer = true; Game1.NetLobbyScreen.Select(); return true; diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index c18d87205..517135fc2 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -148,12 +148,10 @@ namespace Subsurface public override void Select() { - Game1.LightManager.FowEnabled = false; + Game1.LightManager.LosEnabled = false; infoFrame.ClearChildren(); - if (IsServer && Game1.Server == null) Game1.NetworkMember = new GameServer(); - textBox.Select(); new GUITextBlock(new Rectangle(0, 110, 0, 30), "Selected submarine:", GUI.style, infoFrame); @@ -219,9 +217,9 @@ namespace Subsurface serverName.TextGetter = GetServerName; serverName.Enabled = Game1.Server != null; serverName.OnTextChanged = ChangeServerName; - ServerName = "Server"; - - var serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70),null,null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); + ServerName = (Game1.Server==null) ? "Server" : Game1.Server.Name; + + var serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); serverMessage.Enabled = Game1.Server != null; serverMessage.Wrap = true; serverMessage.TextGetter = GetServerMessage; @@ -264,14 +262,14 @@ namespace Subsurface new GUITextBlock(new Rectangle(x, 150, 200, 30), "Job preferences:", GUI.style, playerFrame); - jobList = new GUIListBox(new Rectangle(x, 180, 200, 0), GUI.style, playerFrame); + jobList = new GUIListBox(new Rectangle(x, 180, 150, 0), GUI.style, playerFrame); foreach (JobPrefab job in JobPrefab.List) { GUITextBlock jobText = new GUITextBlock(new Rectangle(0,0,0,20), job.Name, GUI.style, jobList); jobText.UserData = job; - GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 40, 0, 20, 20), "u", GUI.style, jobText); + GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 45, 0, 20, 20), "u", GUI.style, jobText); upButton.UserData = -1; upButton.OnClicked += ChangeJobPreference; @@ -639,11 +637,14 @@ namespace Subsurface textBlock.Text = client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")"); - if (clientID == Game1.Client.ID) + if (client.assignedJob==null || jobName != client.assignedJob.Name) { - Game1.Client.CharacterInfo.Job = new Job(client.assignedJob); - Game1.Client.CharacterInfo.Name = client.name; - UpdatePreviewPlayer(Game1.Client.CharacterInfo); + if (clientID == Game1.Client.ID) + { + Game1.Client.CharacterInfo.Job = new Job(client.assignedJob); + Game1.Client.CharacterInfo.Name = client.name; + UpdatePreviewPlayer(Game1.Client.CharacterInfo); + } } } } diff --git a/Subsurface/Screens/Screen.cs b/Subsurface/Screens/Screen.cs index 97132c386..36e95f6d3 100644 --- a/Subsurface/Screens/Screen.cs +++ b/Subsurface/Screens/Screen.cs @@ -17,7 +17,7 @@ namespace Subsurface public virtual void Select() { - if (selected != null) selected.Deselect(); + if (selected != null && selected!=this) selected.Deselect(); selected = this; } diff --git a/Subsurface/Sprite.cs b/Subsurface/Sprite.cs index 14713c10c..ab1b0a697 100644 --- a/Subsurface/Sprite.cs +++ b/Subsurface/Sprite.cs @@ -128,7 +128,7 @@ namespace Subsurface { this.texture = texture; - sourceRect = sourceRectangle ?? new Rectangle(1, 1, texture.Width, texture.Height); + sourceRect = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height); offset = newOffset ?? Vector2.Zero; @@ -148,7 +148,7 @@ namespace Subsurface file = newFile; texture = LoadTexture(file); - sourceRect = sourceRectangle ?? new Rectangle(1, 1, texture.Width, texture.Height); + sourceRect = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height); offset = newOffset ?? Vector2.Zero; diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 5fa1188b3..879ae2517 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -66,8 +66,12 @@ + + + + @@ -160,7 +164,6 @@ - @@ -280,6 +283,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -294,6 +303,13 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + Designer + PreserveNewest Designer @@ -526,7 +542,7 @@ PreserveNewest - + PreserveNewest @@ -569,11 +585,7 @@ PreserveNewest - - PreserveNewest - Designer - - + PreserveNewest @@ -646,6 +658,9 @@ PreserveNewest Designer + + PreserveNewest + PreserveNewest @@ -719,9 +734,24 @@ PreserveNewest + + PreserveNewest + PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index a39d015d8..5f42e4dee 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ