diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 32f66f85..04bf1dcc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,15 +1,23 @@ SneakyTactician + [Version 0.0.0.6] + ### GUI + *Stone is now rendered + ### API + *Stone is now generated in world + *Abstracted pathfinding so that we can support any algorithm with a little tweaking/a bridge between how each algorithm stores the path found + *Pathfinding now forbides living creatures from moving on tiles with marble. + ### Tweaks + *Ordering a unit now clears previous orders + ### Bugs + * [Version 0.0.0.5] ### GUI *Living creatures are now being rendered *Living creatures can now be individually selected and order to a location - #### API - * - ### Bugs - *Main menu fails to show when pressing escape (Issue #11) + *Discovered that main menu fails to show when pressing escape (Issue #11) [Version 0.0.0.4] ### GUI diff --git a/EarthWithMagic.sln b/EarthWithMagic.sln index 7aaf2e6a..34c9d180 100644 --- a/EarthWithMagic.sln +++ b/EarthWithMagic.sln @@ -13,8 +13,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicalLifeAPI", "MagicalLi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicalLifeSettings", "MagicalLifeSettings\MagicalLifeSettings.csproj", "{76B12B63-DF5D-40FD-8E90-03395095DD71}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicalLifeAPITests", "MagicalLifeAPITests\MagicalLifeAPITests.csproj", "{565125B9-D61B-49B4-9DBB-39CBF2D77882}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicalLifeGUIWindows", "MagicalLifeGUIWindows\MagicalLifeGUIWindows.csproj", "{9096A50A-058B-40F4-80A7-3C4D8725B658}" EndProject Global @@ -41,14 +39,6 @@ Global {76B12B63-DF5D-40FD-8E90-03395095DD71}.Release|Any CPU.Build.0 = Release|Any CPU {76B12B63-DF5D-40FD-8E90-03395095DD71}.Release|x86.ActiveCfg = Release|Any CPU {76B12B63-DF5D-40FD-8E90-03395095DD71}.Release|x86.Build.0 = Release|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Debug|Any CPU.Build.0 = Debug|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Debug|x86.ActiveCfg = Debug|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Debug|x86.Build.0 = Debug|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Release|Any CPU.ActiveCfg = Release|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Release|Any CPU.Build.0 = Release|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Release|x86.ActiveCfg = Release|Any CPU - {565125B9-D61B-49B4-9DBB-39CBF2D77882}.Release|x86.Build.0 = Release|Any CPU {9096A50A-058B-40F4-80A7-3C4D8725B658}.Debug|Any CPU.ActiveCfg = Debug|x86 {9096A50A-058B-40F4-80A7-3C4D8725B658}.Debug|x86.ActiveCfg = Debug|x86 {9096A50A-058B-40F4-80A7-3C4D8725B658}.Debug|x86.Build.0 = Debug|x86 diff --git a/MagicalLifeAPI/DataTypes/Point3D.cs b/MagicalLifeAPI/DataTypes/Point3D.cs deleted file mode 100644 index 82471a24..00000000 --- a/MagicalLifeAPI/DataTypes/Point3D.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; - -namespace MagicalLifeAPI.DataTypes -{ - /// - /// A 3 dimensional point class. - /// - public class Point3D : Object - { - public int X { get; set; } - public int Y { get; set; } - public int Z { get; set; } - - public Point3D(int x, int y, int z) - { - this.X = x; - this.Y = y; - this.Z = z; - } - - public Point3D(string str) - { - string[] delimiter = new string[] { ", " }; - string[] numbers = str.Split(delimiter, 3, StringSplitOptions.RemoveEmptyEntries); - - int.TryParse(numbers[0], out int x); - int.TryParse(numbers[1], out int y); - int.TryParse(numbers[2], out int z); - - this.X = x; - this.Y = y; - this.Z = z; - } - - public override string ToString() - { - return this.X.ToString() + ", " + this.Y.ToString() + ", " + this.Z.ToString(); - } - } -} \ No newline at end of file diff --git a/MagicalLifeAPI/Entities/Entity Factory/HumanFactory.cs b/MagicalLifeAPI/Entities/Entity Factory/HumanFactory.cs index c56fea7c..e6bc0714 100644 --- a/MagicalLifeAPI/Entities/Entity Factory/HumanFactory.cs +++ b/MagicalLifeAPI/Entities/Entity Factory/HumanFactory.cs @@ -1,6 +1,7 @@ using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.Entities.Humanoid; using MagicalLifeAPI.Util; +using Microsoft.Xna.Framework; namespace MagicalLifeAPI.Entities.Entity_Factory { @@ -22,18 +23,18 @@ public class HumanFactory /// /// The fastest a human could possibly be without starting down a class path. /// - private readonly int MaxHumanMovement = 50; + private readonly int MaxHumanMovement = 2; /// /// The slowest a human could possibly be without some significant injuries. /// - private readonly int MinHumanMovement = 25; + private readonly int MinHumanMovement = 1; /// /// Returns a fully generated human character. /// /// - public Human GenerateHuman(Point3D location) + public Human GenerateHuman(Point location) { int health = StaticRandom.Rand(this.MinHumanHealthPerLevel, this.MaxHumanHealthPerLevel + 1); int movement = StaticRandom.Rand(this.MinHumanMovement, this.MaxHumanMovement + 1); diff --git a/MagicalLifeAPI/Entities/Eventing/LivingEventArg.cs b/MagicalLifeAPI/Entities/Eventing/LivingEventArg.cs index fa20cb51..12c22913 100644 --- a/MagicalLifeAPI/Entities/Eventing/LivingEventArg.cs +++ b/MagicalLifeAPI/Entities/Eventing/LivingEventArg.cs @@ -14,13 +14,13 @@ public class LivingEventArg { public Living Living { get; set; } - public Point3D Location { get; private set; } + public Microsoft.Xna.Framework.Point Location { get; private set; } /// /// Constructs a . /// /// - public LivingEventArg(Living living, Point3D location) + public LivingEventArg(Living living, Microsoft.Xna.Framework.Point location) { this.Living = living; this.Location = location; diff --git a/MagicalLifeAPI/Entities/Humanoid/Human.cs b/MagicalLifeAPI/Entities/Humanoid/Human.cs index 7a772e1f..633f4d79 100644 --- a/MagicalLifeAPI/Entities/Humanoid/Human.cs +++ b/MagicalLifeAPI/Entities/Humanoid/Human.cs @@ -1,5 +1,6 @@ using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.GUI; +using Microsoft.Xna.Framework; namespace MagicalLifeAPI.Entities.Humanoid { @@ -8,7 +9,7 @@ namespace MagicalLifeAPI.Entities.Humanoid /// public class Human : Living { - public Human(int health, int movementSpeed, Point3D location) : base(health, movementSpeed, location) + public Human(int health, int movementSpeed, Point location) : base(health, movementSpeed, location) { } diff --git a/MagicalLifeAPI/Entities/Living.cs b/MagicalLifeAPI/Entities/Living.cs index 3e2626da..d141287a 100644 --- a/MagicalLifeAPI/Entities/Living.cs +++ b/MagicalLifeAPI/Entities/Living.cs @@ -1,10 +1,11 @@ -using DijkstraAlgorithm.Pathing; -using MagicalLifeAPI.DataTypes; +using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.Entities.Eventing; using MagicalLifeAPI.Entities.Movement; using MagicalLifeAPI.Entities.Util; using MagicalLifeAPI.GUI; +using MagicalLifeAPI.Pathfinding; using MagicalLifeAPI.Universal; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; @@ -18,7 +19,7 @@ public abstract class Living : Selectable /// /// A queue that holds the queued movement steps up for this living creature. /// - public Queue QueuedMovement { get; set; } = new Queue(); + public Queue QueuedMovement { get; set; } = new Queue(); /// /// How many hit points this creature has. @@ -45,7 +46,7 @@ public abstract class Living : Selectable /// /// /// - protected Living(int health, int movementSpeed, Point3D location) + protected Living(int health, int movementSpeed, Point location) { this.Health = new Util.Attribute(health); this.MovementSpeed = new Util.Attribute(movementSpeed); diff --git a/MagicalLifeAPI/Entities/Movement/EntityWorldMovement.cs b/MagicalLifeAPI/Entities/Movement/EntityWorldMovement.cs index 363193d5..ef5cc689 100644 --- a/MagicalLifeAPI/Entities/Movement/EntityWorldMovement.cs +++ b/MagicalLifeAPI/Entities/Movement/EntityWorldMovement.cs @@ -1,5 +1,5 @@ -using DijkstraAlgorithm.Pathing; -using MagicalLifeAPI.Entities.Util.Modifier_Remove_Conditions; +using MagicalLifeAPI.Entities.Util.Modifier_Remove_Conditions; +using MagicalLifeAPI.Pathfinding; using MagicalLifeAPI.World; using System; using System.Collections.Generic; @@ -17,17 +17,17 @@ public static class EntityWorldMovement /// public static void MoveEntity(ref Living entity) { - Queue path = entity.QueuedMovement; + Queue path = entity.QueuedMovement; while (entity.MovementSpeed.GetValue() > 0 && path.Count > 0) { - PathSegment destination = path.Dequeue(); - Tile sourceTile = WorldUtil.GetTileByID(World.World.mainWorld.Tiles, destination.Origin.Id); - Tile destinationTile = WorldUtil.GetTileByID(World.World.mainWorld.Tiles, destination.Destination.Id); + PathLink section = path.Dequeue(); + Tile sourceTile = World.World.mainWorld.Tiles[section.Origin.X, section.Origin.Y]; + Tile destinationTile = World.World.mainWorld.Tiles[section.Destination.X, section.Destination.Y]; string modifierReason = "Moved onto a " + destinationTile.GetName() + " tile"; - entity.MovementSpeed.AddModifier(new Tuple(-1 * destinationTile.MovementCost, new TimeRemoveCondition(1), modifierReason)); - World.World.mainWorld.Tiles[sourceTile.Location.X, sourceTile.Location.Y, sourceTile.Location.Z].Living = null; + entity.MovementSpeed.AddModifier(new Tuple(-1 * destinationTile.MovementCost, new TimeRemoveCondition(1), modifierReason)); + World.World.mainWorld.Tiles[sourceTile.Location.X, sourceTile.Location.Y].Living = null; entity.MapLocation = destinationTile.Location; - World.World.mainWorld.Tiles[destinationTile.Location.X, destinationTile.Location.Y, destinationTile.Location.Z].Living = entity; + World.World.mainWorld.Tiles[destinationTile.Location.X, destinationTile.Location.Y].Living = entity; } } diff --git a/MagicalLifeAPI/Entities/Movement/StandardPathFinder.cs b/MagicalLifeAPI/Entities/Movement/StandardPathFinder.cs deleted file mode 100644 index 10c8141d..00000000 --- a/MagicalLifeAPI/Entities/Movement/StandardPathFinder.cs +++ /dev/null @@ -1,179 +0,0 @@ -using DijkstraAlgorithm.Graphing; -using DijkstraAlgorithm.Pathing; -using MagicalLifeAPI.World; -using System.Linq; - -namespace MagicalLifeAPI.Entities.Movement -{ - /// - /// A class that handles the construction of the graph used to do optimal pathfinding. - /// - public static class StandardPathFinder - { - /// - /// Holds data that describes which tiles connect to which tiles. - /// This graph contains data used to pathfind for the standard movement. - /// - private static GraphBuilder tileConnectionGraph = new GraphBuilder(); - - private static Graph builtGraph; - - /// - /// Used to determine the fastest route between two points. - /// - private static PathFinder pathFinder; - - /// - /// Returns the fastest route between the source and destination tiles. - /// - /// - /// - /// - public static Path GetFastestPath(Tile source, Tile destination) - { - Path path = pathFinder.FindShortestPath( - StandardPathFinder.builtGraph.Nodes.Single(node => node.Id == source.Location.ToString()), - StandardPathFinder.builtGraph.Nodes.Single(node => node.Id == destination.Location.ToString())); - return path; - } - - /// - /// Populates the with data. - /// This should be called once after the world is generated. - /// - /// - public static void BuildPathGraph(World.World world) - { - StandardPathFinder.AddNodes(world); - StandardPathFinder.AddLinkes(world); - StandardPathFinder.builtGraph = StandardPathFinder.tileConnectionGraph.Build(); - StandardPathFinder.pathFinder = new PathFinder(StandardPathFinder.builtGraph); - } - - /// - /// Creates connections between tiles in the . - /// - /// - private static void AddLinkes(World.World world) - { - Tile[,,] tiles = world.Tiles; - int xSize = tiles.GetLength(0); - int ySize = tiles.GetLength(1); - int zSize = tiles.GetLength(2); - - int x = 0; - int y = 0; - int z = 0; - - //Iterate over each row. - for (int i = 0; i < xSize; i++) - { - //Iterate over each column - for (int ii = 0; ii < ySize; ii++) - { - //Iterate over the depth of each tile in the z axis. - for (int iii = 0; iii < zSize; iii++) - { - //Each tile can be accessed by the xyz coordinates from this inner loop properly. - StandardPathFinder.AddNeighborLink(1, 0, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(-1, 0, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(0, 1, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(0, -1, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(1, 1, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(1, -1, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(-1, 1, 0, tiles, tiles[x, y, z]); - StandardPathFinder.AddNeighborLink(-1, -1, 0, tiles, tiles[x, y, z]); - z++; - } - y++; - z = 0; - } - y = 0; - x++; - } - } - - /// - /// Adds a link to a neighboring tile if the tile exists/is in bounds. - /// - /// - /// - /// - /// - /// - private static void AddNeighborLink(int xChange, int yChange, int zChange, Tile[,,] tiles, Tile source) - { - int x = (int)source.Location.X; - int y = (int)source.Location.Y; - int z = (int)source.Location.Z; - - if (x + xChange > -1 && x + xChange < tiles.GetLength(0)) - { - x += xChange; - } - else - { - //The neighboring tile didn't exist. - return; - } - - if (y + yChange > -1 && y + yChange < tiles.GetLength(1)) - { - y += yChange; - } - else - { - //The neighboring tile didn't exist. - return; - } - - if (z + zChange > -1 && z + zChange < tiles.GetLength(2)) - { - z += zChange; - } - else - { - //The neighboring tile didn't exist. - return; - } - - StandardPathFinder.tileConnectionGraph.AddLink(source.Location.ToString(), tiles[x, y, z].Location.ToString(), 101 - tiles[x, y, z].MovementCost); - } - - /// - /// Adds tiles as nodes into the . - /// - /// - private static void AddNodes(World.World world) - { - Tile[,,] tiles = world.Tiles; - int xSize = tiles.GetLength(0); - int ySize = tiles.GetLength(1); - int zSize = tiles.GetLength(2); - - int x = 0; - int y = 0; - int z = 0; - - //Iterate over each row. - for (int i = 0; i < xSize; i++) - { - //Iterate over each column - for (int ii = 0; ii < ySize; ii++) - { - //Iterate over the depth of each tile in the z axis. - for (int iii = 0; iii < zSize; iii++) - { - //Each tile can be accessed by the xyz coordinates from this inner loop properly. - StandardPathFinder.tileConnectionGraph.AddNode(tiles[x, y, z].Location.ToString()); - z++; - } - y++; - z = 0; - } - y = 0; - x++; - } - } - } -} \ No newline at end of file diff --git a/MagicalLifeAPI/Entities/Util/Attribute.cs b/MagicalLifeAPI/Entities/Util/Attribute.cs index 7fbda99c..1e271c5f 100644 --- a/MagicalLifeAPI/Entities/Util/Attribute.cs +++ b/MagicalLifeAPI/Entities/Util/Attribute.cs @@ -13,8 +13,8 @@ public Attribute() private void World_TurnEnd(object sender, World.WorldEventArgs e) { - List> remove = new List>(); - foreach (Tuple item in this.Modifiers) + List> remove = new List>(); + foreach (Tuple item in this.Modifiers) { if (item.Item2.WearOff()) { @@ -22,7 +22,7 @@ private void World_TurnEnd(object sender, World.WorldEventArgs e) } } - foreach (Tuple item in remove) + foreach (Tuple item in remove) { this.Modifiers.Remove(item); } @@ -30,13 +30,13 @@ private void World_TurnEnd(object sender, World.WorldEventArgs e) public Attribute(int value) : this() { - this.AddModifier(new Tuple(value, new NeverRemoveCondition(), "Base value")); + this.AddModifier(new Tuple(value, new NeverRemoveCondition(), "Base value")); } - public Int64 GetValue() + public Int32 GetValue() { - Int64 ret = 0; - foreach (Tuple item in this.Modifiers) + Int32 ret = 0; + foreach (Tuple item in this.Modifiers) { ret += item.Item1; } @@ -47,13 +47,13 @@ public Int64 GetValue() /// The int value is applied to the value of this attribute, while the is used to determine if the modifier will wear off. /// The string value is a display message/reason as to why the modifier was applied. /// - public List> Modifiers { get; private set; } = new List>(); + public List> Modifiers { get; private set; } = new List>(); /// /// Adds a modifier to the modifiers list. /// /// - public void AddModifier(Tuple modifier) + public void AddModifier(Tuple modifier) { this.Modifiers.Add(modifier); } diff --git a/MagicalLifeAPI/GUI/HasTexture.cs b/MagicalLifeAPI/GUI/HasTexture.cs new file mode 100644 index 00000000..68d12b57 --- /dev/null +++ b/MagicalLifeAPI/GUI/HasTexture.cs @@ -0,0 +1,30 @@ +using MagicalLifeAPI.Universal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.GUI +{ + /// + /// Any class that inherits from this has a texture. + /// + public class HasTexture : Unique + { + /// + /// The index of the texture in our asset manager. + /// + public int TextureIndex { get; set; } + + public HasTexture(int textureIndex) + { + this.TextureIndex = textureIndex; + } + + public HasTexture() + { + + } + } +} diff --git a/MagicalLifeAPI/GUI/ISelectable.cs b/MagicalLifeAPI/GUI/ISelectable.cs index 81fe3e76..b4d77be1 100644 --- a/MagicalLifeAPI/GUI/ISelectable.cs +++ b/MagicalLifeAPI/GUI/ISelectable.cs @@ -1,5 +1,6 @@ using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.Universal; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -24,6 +25,6 @@ public abstract class Selectable : Unique /// /// The location of this selectable in game object. /// - public Point3D MapLocation { get; set; } + public Point MapLocation { get; set; } } } diff --git a/MagicalLifeAPI/MagicalLifeAPI.csproj b/MagicalLifeAPI/MagicalLifeAPI.csproj index 7a6ab555..72ac6ea0 100644 --- a/MagicalLifeAPI/MagicalLifeAPI.csproj +++ b/MagicalLifeAPI/MagicalLifeAPI.csproj @@ -12,6 +12,8 @@ v4.7.1 512 + + true @@ -31,8 +33,9 @@ 4 - - ..\Libs\DijkstraAlgorithm.dll + + ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + True ..\packages\MonoGame.Extended.1.0.617\lib\portable-net45+win8+wpa81\MonoGame.Extended.dll @@ -42,7 +45,10 @@ - ..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\RoyT.AStar.2.1.0\lib\netstandard1.0\RoyT.AStar.dll ..\packages\Serilog.2.6.0\lib\net46\Serilog.dll @@ -51,20 +57,120 @@ ..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll + + ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll + True + + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + True + + + ..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll + True + + + ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + True + + + ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + True + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + True + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + True + + + ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll + True + + + ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll + True + + + ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + True + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + True + + + + ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll + True + + + ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + + + ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll + True + + + ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll + True + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + True + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + + + ..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll + True + - + + ..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll + True + - @@ -73,12 +179,19 @@ - + + + + + + + + @@ -88,10 +201,13 @@ + + + @@ -110,4 +226,11 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/MagicalLifeAPI/Pathfinding/AStar/AStar.cs b/MagicalLifeAPI/Pathfinding/AStar/AStar.cs new file mode 100644 index 00000000..942b3786 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/AStar/AStar.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MagicalLifeAPI.Entities; +using MagicalLifeAPI.Filing.Logging; +using MagicalLifeAPI.World; +using Microsoft.Xna.Framework; +using RoyT.AStar; + +namespace MagicalLifeAPI.Pathfinding.AStar +{ + /// + /// Uses an A* algorithm. + /// + public class AStar : IPathFinder + { + private Grid Grid; + + public void AddConnections(Point location) + { + this.Grid.UnblockCell(new Position(location.X, location.Y)); + } + + public List GetRoute(World.World world, Living living, Point origin, Point destination) + { + MasterLog.DebugWriteLine("Finding route from: " + origin.ToString()); + MasterLog.DebugWriteLine("Finding route to: " + destination.ToString()); + Position[] path = this.Grid.GetPath(new Position(origin.X, origin.Y), new Position(destination.X, destination.Y)); + List ret = new List(); + + if (!world.Tiles[destination.X, destination.Y].IsWalkable) + { + throw new Exception("Destination not possible!"); + } + + if (path.Length < 1) + { + throw new Exception("Path not possible!"); + } + + int i = 0; + int length = path.Length - 1; + while (i != length) + { + if (!world.Tiles[path[i].X, path[i].Y].IsWalkable) + { + MasterLog.DebugWriteLine("Walking on unwalkable tile!"); + } + + ret.Add(new PathLink(new Point(path[i].X, path[i].Y), new Point(path[i + 1].X, path[i + 1].Y))); + i++; + } + + return ret; + } + + public void Initialize() + { + Tile[,] tiles = World.World.mainWorld.Tiles; + this.Grid = new Grid(tiles.GetLength(0), tiles.GetLength(1), 1); + + foreach (Tile item in tiles) + { + Position pos = new Position(item.Location.X, item.Location.Y); + + this.Grid.SetCellCost(pos, item.MovementCost); + if (!item.IsWalkable) + { + this.Grid.BlockCell(pos); + MasterLog.DebugWriteLine("Blocking tile: " + pos.ToString()); + } + } + } + + public void RemoveConnections(Point location) + { + this.Grid.BlockCell(new Position(location.X, location.Y)); + } + } +} diff --git a/MagicalLifeAPI/Pathfinding/Cost/CostRetriever.cs b/MagicalLifeAPI/Pathfinding/Cost/CostRetriever.cs new file mode 100644 index 00000000..3d5af660 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/Cost/CostRetriever.cs @@ -0,0 +1,50 @@ +using MagicalLifeAPI.Entities; +using MagicalLifeAPI.World; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.Pathfinding.Cost +{ + /// + /// Handles all rules involving the costs of moving between two tiles. + /// + public static class CostRetriever + { + /// + /// Contains all of the rules that collectively calculate the movement cost between two tiles. + /// + private static List MovementCostRules = new List(); + + public static void AddMovementCostRule(IAddMovementCost rule) + { + MovementCostRules.Add(rule); + } + + public static void RemoveMovementCostRule(IAddMovementCost rule) + { + MovementCostRules.Remove(rule); + } + + /// + /// Returns the total cost of moving between two tiles. + /// + /// + /// + /// The creature that would move between the two tiles. + /// If the return value is -1, then the end tile cannot be moved into. + public static int CalculateMovementCost(Tile start, Tile end, Living mover) + { + int total = 0; + + foreach (IAddMovementCost item in MovementCostRules) + { + total += item.GetMovementCost(start, end, mover); + } + + return total; + } + } +} diff --git a/MagicalLifeAPI/Pathfinding/Cost/IAddMovementCost.cs b/MagicalLifeAPI/Pathfinding/Cost/IAddMovementCost.cs new file mode 100644 index 00000000..9c874e26 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/Cost/IAddMovementCost.cs @@ -0,0 +1,26 @@ +using MagicalLifeAPI.Entities; +using MagicalLifeAPI.World; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.Pathfinding.Cost +{ + /// + /// Each implementer of this can add movement cost to the transition between two tiles. + /// The cost of many of these are used to determine the movement cost between moving between two tiles. + /// + public interface IAddMovementCost + { + /// + /// Returns the additional cost of the living creature moving between points 'a' and 'b' due to some rule this knows about. + /// + /// + /// + /// + /// + Int32 GetMovementCost(Tile start, Tile end, Living mover); + } +} diff --git a/MagicalLifeAPI/Pathfinding/Cost/StandardTileCost.cs b/MagicalLifeAPI/Pathfinding/Cost/StandardTileCost.cs new file mode 100644 index 00000000..2fc54a01 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/Cost/StandardTileCost.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MagicalLifeAPI.Entities; +using MagicalLifeAPI.World; + +namespace MagicalLifeAPI.Pathfinding.Cost +{ + /// + /// The normal cost for moving between tiles. No special rules here. + /// + public class StandardTileCost : IAddMovementCost + { + public int GetMovementCost(Tile start, Tile end, Living mover) + { + return end.MovementCost; + } + } +} diff --git a/MagicalLifeAPI/Pathfinding/IPathFinder.cs b/MagicalLifeAPI/Pathfinding/IPathFinder.cs new file mode 100644 index 00000000..5ab76c00 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/IPathFinder.cs @@ -0,0 +1,44 @@ +using MagicalLifeAPI.Entities; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.Pathfinding +{ + /// + /// All pathfinding algorithms must implement this. + /// + public interface IPathFinder + { + /// + /// Must get a valid path between the origin and the destination. + /// + /// The world with which the exists within. + /// The creature which will move between the two points. + /// The target location for the living to reach. + /// The starting point of the living. + /// + List GetRoute(World.World world, Living living, Point origin, Point destination); + + /// + /// Run whatever startup code you need to before being capable of world generating here. + /// + void Initialize(); + + /// + /// Removes all pathfindable links to the specified location. + /// + /// + void RemoveConnections(Point location); + + /// + /// Adds pathfindable links to the specified location. + /// + /// + + void AddConnections(Point location); + } +} diff --git a/MagicalLifeAPI/Pathfinding/MainPathFinder.cs b/MagicalLifeAPI/Pathfinding/MainPathFinder.cs new file mode 100644 index 00000000..3f7abb42 --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/MainPathFinder.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.Pathfinding +{ + /// + /// Handles who pathfinds. + /// + public static class MainPathFinder + { + /// + /// The pathfinder. + /// + public static IPathFinder PFinder = new AStar.AStar(); + } +} diff --git a/MagicalLifeAPI/Pathfinding/PathLink.cs b/MagicalLifeAPI/Pathfinding/PathLink.cs new file mode 100644 index 00000000..0166556d --- /dev/null +++ b/MagicalLifeAPI/Pathfinding/PathLink.cs @@ -0,0 +1,24 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.Pathfinding +{ + /// + /// Used to describe the steps a entity will take between two points for path finding. + /// + public class PathLink + { + public Point Origin; + public Point Destination; + + public PathLink(Point origin, Point destination) + { + this.Origin = origin; + this.Destination = destination; + } + } +} diff --git a/MagicalLifeAPI/World/Base/Resource.cs b/MagicalLifeAPI/World/Base/Resource.cs index d3111f9d..756de4a5 100644 --- a/MagicalLifeAPI/World/Base/Resource.cs +++ b/MagicalLifeAPI/World/Base/Resource.cs @@ -1,4 +1,5 @@ -using MagicalLifeAPI.Universal; +using MagicalLifeAPI.GUI; +using MagicalLifeAPI.Universal; namespace MagicalLifeAPI.World { @@ -6,8 +7,14 @@ namespace MagicalLifeAPI.World /// A base class for all resources. /// Resources in tiles are things such as minerals. /// - public abstract class Resource : Unique + public abstract class Resource : HasTexture { + public Resource(string name, int count) + { + this.Name = name; + this.Count = count; + } + /// /// The display name of the resource. /// @@ -16,6 +23,6 @@ public abstract class Resource : Unique /// /// How much of the resources is left. /// - public double Count { get; } + public int Count { get; } } } \ No newline at end of file diff --git a/MagicalLifeAPI/World/Base/Tile.cs b/MagicalLifeAPI/World/Base/Tile.cs index f0e24544..ac1cc68e 100644 --- a/MagicalLifeAPI/World/Base/Tile.cs +++ b/MagicalLifeAPI/World/Base/Tile.cs @@ -1,8 +1,10 @@ using MagicalLifeAPI.Asset; using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.Entities; +using MagicalLifeAPI.GUI; using MagicalLifeAPI.Universal; using MagicalLifeAPI.World.Base; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; @@ -11,14 +13,14 @@ namespace MagicalLifeAPI.World /// /// Every tile that implements this class must provide a parameterless version of itself for reflection purposes. That constructor will not be used during gameplay. /// - public abstract class Tile : Unique + public abstract class Tile : HasTexture { /// /// Initializes a new tile object. /// /// The 3D location of this tile in the map. /// This value is the movement cost of walking on this tile. It should be between 1 and 100 - protected Tile(Point3D location, int movementCost) + protected Tile(Point location, int movementCost) { this.Location = location; this.MovementCost = movementCost; @@ -33,10 +35,32 @@ protected Tile() { } + private bool isWalkable = true; + /// - /// The index of the texture in our asset manager. + /// If true, then the tile can be walked on by living. /// - public int TextureIndex { get; set; } + public bool IsWalkable + { + get + { + return this.isWalkable; + } + + set + { + if (value) + { + //Pathfinding.MainPathFinder.PFinder.AddConnections(this.Location); + } + else + { + //Pathfinding.MainPathFinder.PFinder.RemoveConnections(this.Location); + } + + this.isWalkable = value; + } + } /// /// Returns the name of the biome that this tile belongs to. @@ -67,14 +91,14 @@ public static Microsoft.Xna.Framework.Point GetTileSize() /// /// The resources that can be found in this tile. /// - public List Resources { get; set; } = new List(); + public Resource Resources { get; set; } public List Plants { get; set; } = new List(); /// /// The location of this tile in the tilemap. /// - public Point3D Location { get; protected set; } + public Point Location { get; protected set; } /// /// The entity that is in this tile. Is null if there is not an entity in this tile. @@ -86,6 +110,11 @@ public static Microsoft.Xna.Framework.Point GetTileSize() /// public static event EventHandler TileCreated; + /// + /// Raised whenever this specific tile is modified. + /// + public event EventHandler TileModified; //have this be used by the stone stuff so it can determine when to change what texture it is using. + /// /// Raises the world generated event. /// @@ -99,6 +128,15 @@ public static void TileCreatedHandler(TileEventArg e) } } + public void TileModifiedHandler(TileEventArg e) + { + EventHandler handler = TileModified; + if (handler != null) + { + handler(World.mainWorld, e); + } + } + public abstract string GetTextureName(); } } \ No newline at end of file diff --git a/MagicalLifeAPI/World/Resources/MarbleResource.cs b/MagicalLifeAPI/World/Resources/MarbleResource.cs new file mode 100644 index 00000000..0cb7ad3a --- /dev/null +++ b/MagicalLifeAPI/World/Resources/MarbleResource.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.World.Resources +{ + /// + /// Stone as a resource. + /// + public class MarbleResource : StoneBase + { + public MarbleResource(int count) : base("Marble", count) + { + } + + public override string GetConnectedFourTexture() + { + return "MarbleResourceConnected4"; + } + + public override string GetConnectedOneTexture() + { + return "MarbleResourceConnected1"; + } + + public override string GetConnectedThreeTexture() + { + return "MarbleResourceConnected3"; + } + + public override string GetConnectedTwoTexture() + { + return "MarbleResourceConnected2"; + } + + public override string GetUnconnectedTexture() + { + return "MarbleResourceUnconnected"; + } + } +} diff --git a/MagicalLifeAPI/World/Resources/StoneBase.cs b/MagicalLifeAPI/World/Resources/StoneBase.cs new file mode 100644 index 00000000..9fe4d4c1 --- /dev/null +++ b/MagicalLifeAPI/World/Resources/StoneBase.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.World.Resources +{ + /// + /// The base class for all stone-like resources. + /// + public abstract class StoneBase : Resource + { + public StoneBase(string name, int count) : base(name, count) + { + } + + /// + /// Gets the name of the texture to use when this stone is not adjacent to any other tile with a stone resource. + /// + /// + public abstract string GetUnconnectedTexture(); + + /// + /// Gets the name of the texture to use when this stone is connected to another stone. + /// + /// + public abstract string GetConnectedOneTexture(); + + /// + /// Gets the name of the texture to use when this stone is connected to two stone resources in adjacent tiles. + /// + /// + public abstract string GetConnectedTwoTexture(); + + /// + /// Gets the name of the texture to use when this stone is connected to three stone resources in adjacent tiles. + /// + /// + public abstract string GetConnectedThreeTexture(); + + /// + /// Gets the name of the texture to use when this stone is connected to four stone resources in adjacent tiles. + /// + /// + public abstract string GetConnectedFourTexture(); + } +} diff --git a/MagicalLifeAPI/World/Tiles/Dirt.cs b/MagicalLifeAPI/World/Tiles/Dirt.cs index f4918869..22639e7b 100644 --- a/MagicalLifeAPI/World/Tiles/Dirt.cs +++ b/MagicalLifeAPI/World/Tiles/Dirt.cs @@ -1,4 +1,5 @@ using MagicalLifeAPI.DataTypes; +using Microsoft.Xna.Framework; namespace MagicalLifeAPI.World.Tiles { @@ -7,7 +8,7 @@ namespace MagicalLifeAPI.World.Tiles /// public class Dirt : Tile { - public Dirt(Point3D location) : base(location, 10) + public Dirt(Point location) : base(location, 10) { //this.AdditionalMovementCost = 0; } @@ -23,8 +24,7 @@ public override string GetName() public override string GetTextureName() { - return "DirtTile"; - //return "TestTile.png"; + return "DirtFloor"; } } } \ No newline at end of file diff --git a/MagicalLifeAPI/World/World Generation/Generators/Dirtland.cs b/MagicalLifeAPI/World/World Generation/Generators/Dirtland.cs index d3f50bc6..10387383 100644 --- a/MagicalLifeAPI/World/World Generation/Generators/Dirtland.cs +++ b/MagicalLifeAPI/World/World Generation/Generators/Dirtland.cs @@ -2,6 +2,8 @@ using MagicalLifeAPI.Entities.Entity_Factory; using MagicalLifeAPI.Util; using MagicalLifeAPI.World.Tiles; +using Microsoft.Xna.Framework; +using System; namespace MagicalLifeAPI.World.World_Generation.Generators { @@ -10,13 +12,12 @@ namespace MagicalLifeAPI.World.World_Generation.Generators /// public class Dirtland : WorldGenerator { - public override string[,,] AssignBiomes(int xSize, int ySize, int zSize) + public override string[,] AssignBiomes(int xSize, int ySize, Random r) { - string[,,] ret = new string[xSize, ySize, zSize]; + string[,] ret = new string[xSize, ySize]; int x = 0; int y = 0; - int z = 0; //Iterate over each row. for (int i = 0; i < xSize; i++) @@ -24,17 +25,9 @@ public class Dirtland : WorldGenerator //Iterate over each column for (int ii = 0; ii < ySize; ii++) { - //Iterate over the depth of each tile in the z axis. - for (int iii = 0; iii < zSize; iii++) - { - //Each tile can be accessed by the xyz coordinates from this inner loop properly. - Dirt dirt = new Dirt(new Point3D(x, y, z)); - ret[x, y, z] = dirt.GetName(); - - z++; - } + Dirt dirt = new Dirt(new Point(x, y)); + ret[x, y] = dirt.GetName(); y++; - z = 0; } y = 0; x++; @@ -43,33 +36,29 @@ public class Dirtland : WorldGenerator return ret; } - public override Tile[,,] GenerateDetails(Tile[,,] map) + public override Tile[,] GenerateDetails(Tile[,] map, Random r) { int xSize = map.GetLength(0); int ySize = map.GetLength(1); - int zSize = map.GetLength(2); int x = StaticRandom.Rand(0, xSize); int y = StaticRandom.Rand(0, ySize); - int z = zSize - 1; HumanFactory hFactory = new HumanFactory(); - map[x, y, z].Living = (hFactory.GenerateHuman(new Point3D(x, y, z))); + map[x, y].Living = (hFactory.GenerateHuman(new Point(x, y))); return map; } - public override Tile[,,] GenerateLandType(string[,,] biomeMap) + public override Tile[,] GenerateLandType(string[,] biomeMap, Random r) { int xSize = biomeMap.GetLength(0); int ySize = biomeMap.GetLength(1); - int zSize = biomeMap.GetLength(2); int x = 0; int y = 0; - int z = 0; - Tile[,,] ret = new Tile[xSize, ySize, zSize]; + Tile[,] ret = new Tile[xSize, ySize]; //Iterate over each row. for (int i = 0; i < xSize; i++) @@ -77,15 +66,8 @@ public class Dirtland : WorldGenerator //Iterate over each column for (int ii = 0; ii < ySize; ii++) { - //Iterate over the depth of each tile in the z axis. - for (int iii = 0; iii < zSize; iii++) - { - //Each tile can be accessed by the xyz coordinates from this inner loop properly. - ret[x, y, z] = new Dirt(new Point3D(x, y, z)); - z++; - } + ret[x, y] = new Dirt(new Point(x, y)); y++; - z = 0; } y = 0; x++; @@ -94,17 +76,17 @@ public class Dirtland : WorldGenerator return ret; } - public override Tile[,,] GenerateMinerals(Tile[,,] map) + public override Tile[,] GenerateMinerals(Tile[,] map, Random r) { return map; } - public override Tile[,,] GenerateNaturalFeatures(Tile[,,] map) + public override Tile[,] GenerateNaturalFeatures(Tile[,] map, Random r) { return map; } - public override Tile[,,] GenerateVegetation(Tile[,,] map) + public override Tile[,] GenerateVegetation(Tile[,] map, Random r) { return map; } diff --git a/MagicalLifeAPI/World/World Generation/Generators/StoneSprinkle.cs b/MagicalLifeAPI/World/World Generation/Generators/StoneSprinkle.cs new file mode 100644 index 00000000..61ee4ed7 --- /dev/null +++ b/MagicalLifeAPI/World/World Generation/Generators/StoneSprinkle.cs @@ -0,0 +1,84 @@ +using MagicalLifeAPI.Entities.Entity_Factory; +using MagicalLifeAPI.Util; +using MagicalLifeAPI.World.Resources; +using MagicalLifeAPI.World.Tiles; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeAPI.World.World_Generation.Generators +{ + /// + /// A world generator that throws in a sprinkle of stone. + /// + public class StoneSprinkle : WorldGenerator + { + public override string[,] AssignBiomes(int xSize, int ySize, Random random) + { + string[,] ret = new string[xSize, ySize];//We don't need biomes right now + return ret; + } + + public override Tile[,] GenerateDetails(Tile[,] map, Random random) + { + int xSize = map.GetLength(0); + int ySize = map.GetLength(1); + + int x = StaticRandom.Rand(0, xSize); + int y = StaticRandom.Rand(0, ySize); + + HumanFactory hFactory = new HumanFactory(); + map[x, y].Living = (hFactory.GenerateHuman(new Point(x, y))); + + return map; + } + + public override Tile[,] GenerateLandType(string[,] biomeMap, Random random) + { + int x = 0; + int y = 0; + int xSize = biomeMap.GetLength(0); + int ySize = biomeMap.GetLength(1); + + Tile[,] tiles = new Tile[xSize, ySize]; + + while (x < xSize) + { + while (y < ySize) + { + Dirt dirt = new Dirt(new Point(x, y)); + + if (random.Next(4) == 2) + { + dirt.Resources = new MarbleResource(random.Next(25)); + dirt.IsWalkable = false; + } + tiles[x, y] = dirt; + y++; + } + x++; + y = 0; + } + + return tiles; + } + + public override Tile[,] GenerateMinerals(Tile[,] map, Random random) + { + return map; + } + + public override Tile[,] GenerateNaturalFeatures(Tile[,] map, Random random) + { + return map; + } + + public override Tile[,] GenerateVegetation(Tile[,] map, Random random) + { + return map; + } + } +} diff --git a/MagicalLifeAPI/World/World.cs b/MagicalLifeAPI/World/World.cs index 2c467d15..2a7b4396 100644 --- a/MagicalLifeAPI/World/World.cs +++ b/MagicalLifeAPI/World/World.cs @@ -1,5 +1,4 @@ -using DijkstraAlgorithm.Pathing; -using MagicalLifeAPI.DataTypes; +using MagicalLifeAPI.DataTypes; using MagicalLifeAPI.Entities; using MagicalLifeAPI.Entities.Movement; using MagicalLifeAPI.Filing.Logging; @@ -17,7 +16,7 @@ public class World : Unique /// /// A 3D array that holds every tile in the current world. /// - public Tile[,,] Tiles { get; private set; } + public Tile[,] Tiles { get; private set; } /// /// Raised when the world is finished generating for the first time. @@ -52,68 +51,18 @@ public World() /// /// /// - public static void Initialize(int width, int height, int depth, WorldGenerator generator) + public static void Initialize(int width, int height, WorldGenerator generator) { mainWorld = new World(); - mainWorld.Tiles = mainWorld.GenerateWorld(height, width, depth, generator); + mainWorld.Tiles = mainWorld.GenerateWorld(height, width, generator); WorldEventArgs worldEventArgs = new WorldEventArgs(mainWorld); mainWorld.WorldGeneratedHandler(worldEventArgs); - StandardPathFinder.BuildPathGraph(mainWorld); + Pathfinding.MainPathFinder.PFinder.Initialize(); World.TurnStartHandler(new WorldEventArgs(mainWorld)); } - //private static void TestMove() - //{ - // Living found = TestFindEntity(mainWorld.Tiles).Living; - // Tile start = TestFindEntity(mainWorld.Tiles); - - // Point3D des = new Point3D(10, 2, 1); - // if (start.Location != des && found.QueuedMovement.Count == 0) - // { - // Path pth = StandardPathFinder.GetFastestPath(start, mainWorld.Tiles[10, 2, 0]); - - // Extensions.EnqueueCollection(found.QueuedMovement, pth.Segments); - // EntityWorldMovement.MoveEntity(ref found); - // } - //} - - private static Tile TestFindEntity(Tile[,,] tiles) - { - int xSize = tiles.GetLength(0); - int ySize = tiles.GetLength(1); - int zSize = tiles.GetLength(2); - - int x = 0; - int y = 0; - int z = 0; - - //Iterate over each row. - for (int i = 0; i < xSize; i++) - { - //Iterate over each column - for (int ii = 0; ii < ySize; ii++) - { - //Iterate over the depth of each tile in the z axis. - for (int iii = 0; iii < zSize; iii++) - { - //Each tile can be accessed by the xyz coordinates from this inner loop properly. - if (tiles[x, y, z].Living != null) - { - return tiles[x, y, z]; - } - z++; - } - y++; - z = 0; - } - y = 0; - x++; - } - return null; - } - /// /// Actually handles generating the world. /// @@ -122,15 +71,16 @@ private static Tile TestFindEntity(Tile[,,] tiles) /// /// /// - private Tile[,,] GenerateWorld(int height, int width, int depth, WorldGenerator generator) + private Tile[,] GenerateWorld(int height, int width, WorldGenerator generator) { - string[,,] stage1 = generator.AssignBiomes(height, width, depth); - Tile[,,] stage2 = generator.GenerateLandType(stage1); - - stage2 = generator.GenerateNaturalFeatures(stage2); - stage2 = generator.GenerateMinerals(stage2); - stage2 = generator.GenerateVegetation(stage2); - stage2 = generator.GenerateDetails(stage2); + Random r = new Random(); + string[,] stage1 = generator.AssignBiomes(height, width, r); + Tile[,] stage2 = generator.GenerateLandType(stage1, r); + + stage2 = generator.GenerateNaturalFeatures(stage2, r); + stage2 = generator.GenerateMinerals(stage2, r); + stage2 = generator.GenerateVegetation(stage2, r); + stage2 = generator.GenerateDetails(stage2, r); return stage2; } diff --git a/MagicalLifeAPI/World/WorldGenerator.cs b/MagicalLifeAPI/World/WorldGenerator.cs index e45af1a6..536c6fa2 100644 --- a/MagicalLifeAPI/World/WorldGenerator.cs +++ b/MagicalLifeAPI/World/WorldGenerator.cs @@ -1,4 +1,5 @@ using MagicalLifeAPI.Universal; +using System; namespace MagicalLifeAPI.World { @@ -14,41 +15,41 @@ public abstract class WorldGenerator : Unique /// /// /// - public abstract string[,,] AssignBiomes(int xSize, int ySize, int zSize); + public abstract string[,] AssignBiomes(int xSize, int ySize, Random random); /// /// Generates things such as rock, dirt, grassland, and sand for each and every tile. /// /// /// - public abstract Tile[,,] GenerateLandType(string[,,] biomeMap); + public abstract Tile[,] GenerateLandType(string[,] biomeMap, Random random); /// /// Generates things such as rivers and caves. /// /// /// - public abstract Tile[,,] GenerateNaturalFeatures(Tile[,,] map); + public abstract Tile[,] GenerateNaturalFeatures(Tile[,] map, Random random); /// /// Generates minerals in the world. /// /// /// - public abstract Tile[,,] GenerateMinerals(Tile[,,] map); + public abstract Tile[,] GenerateMinerals(Tile[,] map, Random random); /// /// Generates vegetation in the world. /// /// /// - public abstract Tile[,,] GenerateVegetation(Tile[,,] map); + public abstract Tile[,] GenerateVegetation(Tile[,] map, Random random); /// /// Generates any other details not done in previous phases. /// /// /// - public abstract Tile[,,] GenerateDetails(Tile[,,] map); + public abstract Tile[,] GenerateDetails(Tile[,] map, Random random); } } \ No newline at end of file diff --git a/MagicalLifeAPI/World/WorldUtil.cs b/MagicalLifeAPI/World/WorldUtil.cs index 9e613ec4..44c8009d 100644 --- a/MagicalLifeAPI/World/WorldUtil.cs +++ b/MagicalLifeAPI/World/WorldUtil.cs @@ -1,4 +1,6 @@ using MagicalLifeAPI.DataTypes; +using Microsoft.Xna.Framework; +using System.Collections.Generic; using System.Diagnostics; namespace MagicalLifeAPI.World @@ -15,10 +17,64 @@ public static class WorldUtil /// /// /// - public static Tile GetTileByID(Tile[,,] tiles, string str) + public static Tile GetTileByID(Tile[,] tiles, string str) { - Point3D point = new Point3D(str); - return tiles[point.X, point.Y, point.Z]; + int x = 0; + int y = 0; + + string xstr = str; + xstr = xstr.Replace("{X:", ""); + xstr = xstr.Replace(" Y:", ", "); + xstr = xstr.Replace("}", ""); + + string[] splits = xstr.Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries); + x = int.Parse(splits[0]); + y = int.Parse(splits[1]); + + return tiles[x, y]; + } + + /// + /// Returns all the tiles that neighbor the specified tile. + /// + /// + public static List GetNeighboringTiles(Point tileLocation) + { + List neighborCandidates = new List(); + List neighbors = new List(); + + neighborCandidates.Add(new Point(tileLocation.X + 1, tileLocation.Y)); + neighborCandidates.Add(new Point(tileLocation.X - 1, tileLocation.Y)); + neighborCandidates.Add(new Point(tileLocation.X, tileLocation.Y + 1)); + neighborCandidates.Add(new Point(tileLocation.X, tileLocation.Y - 1)); + neighborCandidates.Add(new Point(tileLocation.X + 1, tileLocation.Y + 1)); + neighborCandidates.Add(new Point(tileLocation.X + 1, tileLocation.Y - 1)); + neighborCandidates.Add(new Point(tileLocation.X - 1, tileLocation.Y + 1)); + neighborCandidates.Add(new Point(tileLocation.X - 1, tileLocation.Y - 1)); + + foreach (Point item in neighborCandidates) + { + if (DoesTileExist(item)) + { + neighbors.Add(item); + } + } + + return neighbors; + } + + /// + /// Determines if the specified location is actually a tile in the current map. + /// + /// + /// + public static bool DoesTileExist(Point tileLocation) + { + int x = tileLocation.X; + int y = tileLocation.Y; + Tile[,] tiles = World.mainWorld.Tiles; + + return x > -1 && x < tiles.GetLength(0) && y > -1 && y < tiles.GetLength(1); } } } \ No newline at end of file diff --git a/MagicalLifeAPI/packages.config b/MagicalLifeAPI/packages.config index 1d067c4e..ea27f590 100644 --- a/MagicalLifeAPI/packages.config +++ b/MagicalLifeAPI/packages.config @@ -1,8 +1,56 @@  + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MagicalLifeAPITests/Entities/Humanoid/HumanTests.cs b/MagicalLifeAPITests/Entities/Humanoid/HumanTests.cs index a2f3c399..6f4faa9a 100644 --- a/MagicalLifeAPITests/Entities/Humanoid/HumanTests.cs +++ b/MagicalLifeAPITests/Entities/Humanoid/HumanTests.cs @@ -8,7 +8,7 @@ public class HumanTests [TestMethod()] public void HumanTest() { - Human human = new Human(10, 10, new DataTypes.Point3D(0, 0, 0)); + Human human = new Human(10, 10, new Point(0, 0)); Assert.IsNotNull(human); } } diff --git a/MagicalLifeGUIWindows/Content/Content.mgcb b/MagicalLifeGUIWindows/Content/Content.mgcb index 0148c996..6132eeaf 100644 --- a/MagicalLifeGUIWindows/Content/Content.mgcb +++ b/MagicalLifeGUIWindows/Content/Content.mgcb @@ -26,7 +26,7 @@ /processorParam:TextureFormat=Color /build:Basic Human.png -#begin DirtTile.png +#begin EndTurnButtonState1.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -36,9 +36,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:DirtTile.png +/build:EndTurnButtonState1.png -#begin EndTurnButtonState1.png +#begin EndTurnButtonState2.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -48,9 +48,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:EndTurnButtonState1.png +/build:EndTurnButtonState2.png -#begin EndTurnButtonState2.png +#begin TestTile.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -60,9 +60,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:EndTurnButtonState2.png +/build:TestTile.png -#begin GraniteTile.png +#begin MenuButton.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -72,9 +72,16 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:GraniteTile.png +/build:MenuButton.png -#begin GrassTile.png +#begin MainMenuFont24x.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:MainMenuFont24x.spritefont + +#begin MenuBackground.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -84,9 +91,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:GrassTile.png +/build:MenuBackground.png -#begin MarbleTile.png +#begin CursorCarrot.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -96,9 +103,16 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:MarbleTile.png +/build:CursorCarrot.png -#begin TestTile.png +#begin MainMenuFont12x.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:MainMenuFont12x.spritefont + +#begin InputBox100x50.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -108,9 +122,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:TestTile.png +/build:InputBox100x50.png -#begin MenuButton.png +#begin DirtFloor.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -120,16 +134,21 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:MenuButton.png +/build:DirtFloor.png -#begin MainMenuFont24x.spritefont -/importer:FontDescriptionImporter -/processor:FontDescriptionProcessor +#begin GraniteFloor.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False /processorParam:PremultiplyAlpha=True -/processorParam:TextureFormat=Compressed -/build:MainMenuFont24x.spritefont +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:GraniteFloor.png -#begin MenuBackground.png +#begin GrassFloor.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -139,9 +158,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:MenuBackground.png +/build:GrassFloor.png -#begin CursorCarrot.png +#begin MarbleFloor.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -151,16 +170,21 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:CursorCarrot.png +/build:MarbleFloor.png -#begin MainMenuFont12x.spritefont -/importer:FontDescriptionImporter -/processor:FontDescriptionProcessor +#begin MarbleResourceUnconnected.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False /processorParam:PremultiplyAlpha=True -/processorParam:TextureFormat=Compressed -/build:MainMenuFont12x.spritefont +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:MarbleResourceUnconnected.png -#begin InputBox100x50.png +#begin MarbleResourceConnected1.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -170,5 +194,41 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:InputBox100x50.png +/build:MarbleResourceConnected1.png + +#begin MarbleResourceConnected2.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:MarbleResourceConnected2.png + +#begin MarbleResourceConnected3.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:MarbleResourceConnected3.png + +#begin MarbleResourceConnected4.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:MarbleResourceConnected4.png diff --git a/MagicalLifeGUIWindows/Content/DirtTile.png b/MagicalLifeGUIWindows/Content/DirtFloor.png similarity index 100% rename from MagicalLifeGUIWindows/Content/DirtTile.png rename to MagicalLifeGUIWindows/Content/DirtFloor.png diff --git a/MagicalLifeGUIWindows/Content/GraniteTile.png b/MagicalLifeGUIWindows/Content/GraniteFloor.png similarity index 100% rename from MagicalLifeGUIWindows/Content/GraniteTile.png rename to MagicalLifeGUIWindows/Content/GraniteFloor.png diff --git a/MagicalLifeGUIWindows/Content/GrassTile.png b/MagicalLifeGUIWindows/Content/GrassFloor.png similarity index 100% rename from MagicalLifeGUIWindows/Content/GrassTile.png rename to MagicalLifeGUIWindows/Content/GrassFloor.png diff --git a/MagicalLifeGUIWindows/Content/MarbleTile.png b/MagicalLifeGUIWindows/Content/MarbleFloor.png similarity index 100% rename from MagicalLifeGUIWindows/Content/MarbleTile.png rename to MagicalLifeGUIWindows/Content/MarbleFloor.png diff --git a/MagicalLifeGUIWindows/Content/MarbleResourceConnected1.png b/MagicalLifeGUIWindows/Content/MarbleResourceConnected1.png new file mode 100644 index 00000000..e94a509f Binary files /dev/null and b/MagicalLifeGUIWindows/Content/MarbleResourceConnected1.png differ diff --git a/MagicalLifeGUIWindows/Content/MarbleResourceConnected2.png b/MagicalLifeGUIWindows/Content/MarbleResourceConnected2.png new file mode 100644 index 00000000..bec81cf3 Binary files /dev/null and b/MagicalLifeGUIWindows/Content/MarbleResourceConnected2.png differ diff --git a/MagicalLifeGUIWindows/Content/MarbleResourceConnected3.png b/MagicalLifeGUIWindows/Content/MarbleResourceConnected3.png new file mode 100644 index 00000000..3e127c0a Binary files /dev/null and b/MagicalLifeGUIWindows/Content/MarbleResourceConnected3.png differ diff --git a/MagicalLifeGUIWindows/Content/MarbleResourceConnected4.png b/MagicalLifeGUIWindows/Content/MarbleResourceConnected4.png new file mode 100644 index 00000000..865e3e2c Binary files /dev/null and b/MagicalLifeGUIWindows/Content/MarbleResourceConnected4.png differ diff --git a/MagicalLifeGUIWindows/Content/MarbleResourceUnconnected.png b/MagicalLifeGUIWindows/Content/MarbleResourceUnconnected.png new file mode 100644 index 00000000..c349be57 Binary files /dev/null and b/MagicalLifeGUIWindows/Content/MarbleResourceUnconnected.png differ diff --git a/MagicalLifeGUIWindows/GUI/New World Menu/NewGameInputHandler.cs b/MagicalLifeGUIWindows/GUI/New World Menu/NewGameInputHandler.cs index 5c2a5ad1..55673fcf 100644 --- a/MagicalLifeGUIWindows/GUI/New World Menu/NewGameInputHandler.cs +++ b/MagicalLifeGUIWindows/GUI/New World Menu/NewGameInputHandler.cs @@ -24,12 +24,10 @@ public void StartNewGame() int length = -1; bool lengthSuccess = int.TryParse(NewWorldMenu.NewWorldMenuM.worldLength.Text, out length); - int depth = -1; - bool depthSuccess = int.TryParse(NewWorldMenu.NewWorldMenuM.worldDepth.Text, out depth); - - if (widthSuccess && lengthSuccess && depthSuccess && width > 0 && length > 0 && depth > 0) + if (widthSuccess && lengthSuccess && width > 0 && length > 0) { - World.Initialize(width, length, depth, new Dirtland()); + //World.Initialize(width, length, new Dirtland()); + World.Initialize(width, length, new StoneSprinkle()); } else { diff --git a/MagicalLifeGUIWindows/Input/History/HistoricalInput.cs b/MagicalLifeGUIWindows/Input/History/HistoricalInput.cs index 3a3c9155..6f04aa50 100644 --- a/MagicalLifeGUIWindows/Input/History/HistoricalInput.cs +++ b/MagicalLifeGUIWindows/Input/History/HistoricalInput.cs @@ -29,9 +29,9 @@ public class HistoricalInput /// /// The location of the tile that the order was to. /// - public Point3D OrderPoint { get; set; } + public Microsoft.Xna.Framework.Point OrderPoint { get; set; } - public HistoricalInput(Point3D point) + public HistoricalInput(Microsoft.Xna.Framework.Point point) { this.OrderedToTile = true; this.OrderPoint = point; diff --git a/MagicalLifeGUIWindows/Input/History/HistoricalInputFactory.cs b/MagicalLifeGUIWindows/Input/History/HistoricalInputFactory.cs index 9cc488a1..effc8bb8 100644 --- a/MagicalLifeGUIWindows/Input/History/HistoricalInputFactory.cs +++ b/MagicalLifeGUIWindows/Input/History/HistoricalInputFactory.cs @@ -31,8 +31,8 @@ public HistoricalInput Generate(InputEventArgs e) private HistoricalInput SingleSelect(InputEventArgs e) { - Point3D mapSpot = Util.GetMapLocation(e.MouseEventArgs.Position.X, e.MouseEventArgs.Position.Y); - Selectable select = World.mainWorld.Tiles[mapSpot.X, mapSpot.Y, mapSpot.Z].Living; + Point mapSpot = Util.GetMapLocation(e.MouseEventArgs.Position.X, e.MouseEventArgs.Position.Y); + Selectable select = World.mainWorld.Tiles[mapSpot.X, mapSpot.Y].Living; if (select != null) { @@ -83,7 +83,7 @@ private bool IsSelectableSelected(Selectable selectable) private HistoricalInput Order(InputEventArgs e) { Point screenLocation = e.MouseEventArgs.Position; - Point3D mapLocation = Util.GetMapLocation(screenLocation.X, screenLocation.Y); + Point mapLocation = Util.GetMapLocation(screenLocation.X, screenLocation.Y); return new HistoricalInput(mapLocation); } } diff --git a/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingBoundHandler.cs b/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingBoundHandler.cs index 37c20764..45af8859 100644 --- a/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingBoundHandler.cs +++ b/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingBoundHandler.cs @@ -70,7 +70,7 @@ private static void Living_LivingModified(object sender, MagicalLifeAPI.Entities /// /// /// - public static Rectangle GetBoundsForTile(Point3D location) + public static Rectangle GetBoundsForTile(Point location) { Point size = Tile.GetTileSize(); diff --git a/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingMoveOrderInputHandler.cs b/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingMoveOrderInputHandler.cs index 5ba998c3..4ecc4b21 100644 --- a/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingMoveOrderInputHandler.cs +++ b/MagicalLifeGUIWindows/Input/Specialized Handlers/LivingMoveOrderInputHandler.cs @@ -3,6 +3,7 @@ using MagicalLifeAPI.Entities; using MagicalLifeAPI.Entities.Movement; using MagicalLifeAPI.GUI; +using MagicalLifeAPI.Pathfinding; using MagicalLifeAPI.Util; using MagicalLifeAPI.World; using MagicalLifeGUIWindows.Input.History; @@ -40,20 +41,24 @@ private void InputHistory_InputAdded() } } - private void Move(Selectable selectable, Point3D target) + private void Move(Selectable selectable, Microsoft.Xna.Framework.Point target) { - switch (selectable) + if (World.mainWorld.Tiles[target.X, target.Y].IsWalkable) { - case Living living: + switch (selectable) + { + case Living living: - Point3D start = selectable.MapLocation; - if (start != target) - { - Path pth = StandardPathFinder.GetFastestPath(World.mainWorld.Tiles[start.X, start.Y, start.Z], World.mainWorld.Tiles[target.X, target.Y, target.Z]); + Microsoft.Xna.Framework.Point start = selectable.MapLocation; + if (start != target) + { + List pth = MainPathFinder.PFinder.GetRoute(World.mainWorld, living, World.mainWorld.Tiles[start.X, start.Y].Location, World.mainWorld.Tiles[target.X, target.Y].Location); - Extensions.EnqueueCollection(living.QueuedMovement, pth.Segments); - } - break; + living.QueuedMovement.Clear(); + Extensions.EnqueueCollection(living.QueuedMovement, pth); + } + break; + } } } @@ -64,8 +69,8 @@ private void Move(Selectable selectable, Point3D target) /// private Living GetLivingAtClick(MouseEventArgs e) { - Point3D tileLocation = Util.GetMapLocation(e.Position.X, e.Position.Y); - return World.mainWorld.Tiles[tileLocation.X, tileLocation.Y, tileLocation.Z].Living; + Microsoft.Xna.Framework.Point tileLocation = Util.GetMapLocation(e.Position.X, e.Position.Y); + return World.mainWorld.Tiles[tileLocation.X, tileLocation.Y].Living; } } } diff --git a/MagicalLifeGUIWindows/Load/TextureLoader.cs b/MagicalLifeGUIWindows/Load/TextureLoader.cs index c08412e8..1cab16b6 100644 --- a/MagicalLifeGUIWindows/Load/TextureLoader.cs +++ b/MagicalLifeGUIWindows/Load/TextureLoader.cs @@ -28,7 +28,7 @@ private int CalculateTotalJobs() { this.TexturesToLoad.Add("Basic Human"); this.TexturesToLoad.Add("CursorCarrot"); - this.TexturesToLoad.Add("DirtTile"); + this.TexturesToLoad.Add("DirtFloor"); this.TexturesToLoad.Add("EndTurnButtonState1"); this.TexturesToLoad.Add("EndTurnButtonState2"); this.TexturesToLoad.Add("MenuBackground"); @@ -36,6 +36,13 @@ private int CalculateTotalJobs() this.TexturesToLoad.Add("TestTile"); this.TexturesToLoad.Add("InputBox100x50"); + this.TexturesToLoad.Add("MarbleFloor"); + this.TexturesToLoad.Add("MarbleResourceUnconnected"); + this.TexturesToLoad.Add("MarbleResourceConnected1"); + this.TexturesToLoad.Add("MarbleResourceConnected2"); + this.TexturesToLoad.Add("MarbleResourceConnected3"); + this.TexturesToLoad.Add("MarbleResourceConnected4"); + return this.TexturesToLoad.Count; } diff --git a/MagicalLifeGUIWindows/MagicalLifeGUIWindows.csproj b/MagicalLifeGUIWindows/MagicalLifeGUIWindows.csproj index ff73d37d..9f0f8a7c 100644 --- a/MagicalLifeGUIWindows/MagicalLifeGUIWindows.csproj +++ b/MagicalLifeGUIWindows/MagicalLifeGUIWindows.csproj @@ -118,6 +118,7 @@ + diff --git a/MagicalLifeGUIWindows/Map/ConnectedTextureManager.cs b/MagicalLifeGUIWindows/Map/ConnectedTextureManager.cs new file mode 100644 index 00000000..8df73ee4 --- /dev/null +++ b/MagicalLifeGUIWindows/Map/ConnectedTextureManager.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicalLifeGUIWindows.Map +{ + /// + /// Used to update the connected textures of each in game object if it has them. + /// + public static class ConnectedTextureManager + { + } +} diff --git a/MagicalLifeGUIWindows/Map/RenderingData.cs b/MagicalLifeGUIWindows/Map/RenderingData.cs index 7e6934ca..5e18992c 100644 --- a/MagicalLifeGUIWindows/Map/RenderingData.cs +++ b/MagicalLifeGUIWindows/Map/RenderingData.cs @@ -39,7 +39,7 @@ private static void Tile_TileCreated(object sender, TileEventArg e) private static void AssignTextureIndex(Tile tile) { - Point3D location = tile.Location; + Microsoft.Xna.Framework.Point location = tile.Location; string textureName = tile.GetTextureName(); List textures = AssetManager.Textures; diff --git a/MagicalLifeGUIWindows/Rendering/Map/MapRenderer.cs b/MagicalLifeGUIWindows/Rendering/Map/MapRenderer.cs index 5a37b57c..85a9a20f 100644 --- a/MagicalLifeGUIWindows/Rendering/Map/MapRenderer.cs +++ b/MagicalLifeGUIWindows/Rendering/Map/MapRenderer.cs @@ -1,5 +1,6 @@ using MagicalLifeAPI.Asset; using MagicalLifeAPI.World; +using MagicalLifeAPI.World.Resources; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -21,27 +22,20 @@ public static class MapRenderer /// public static void DrawMap(ref SpriteBatch spBatch) { - Tile[,,] tiles = World.mainWorld.Tiles; + Tile[,] tiles = World.mainWorld.Tiles; int xSize = tiles.GetLength(0); int ySize = tiles.GetLength(1); - int zSize = tiles.GetLength(2); int x = 0; int y = 0; - int z = 0; while (x < xSize) { while (y < ySize) { - while (z < zSize) - { - Tile tile = tiles[x, y, z]; - Microsoft.Xna.Framework.Point start = new Microsoft.Xna.Framework.Point(RenderingPipe.tileSize.X * x, RenderingPipe.tileSize.Y * y); - DrawTile(tile, ref spBatch, start); - z++; - } - z = 0; + Tile tile = tiles[x, y]; + Microsoft.Xna.Framework.Point start = new Microsoft.Xna.Framework.Point(RenderingPipe.tileSize.X * x, RenderingPipe.tileSize.Y * y); + DrawTile(tile, ref spBatch, start); y++; } y = 0; @@ -57,11 +51,33 @@ private static void DrawTile(Tile tile, ref SpriteBatch spBatch, Point start) Microsoft.Xna.Framework.Rectangle target = new Microsoft.Xna.Framework.Rectangle(start, RenderingPipe.tileSize); spBatch.Draw(AssetManager.Textures[tile.TextureIndex], target, RenderingPipe.colorMask); + DrawStone(tile, ref spBatch, target); + if (tile.Living != null) { Texture2D livingTexture = AssetManager.Textures[AssetManager.GetTextureIndex(tile.Living.GetTextureName())]; spBatch.Draw(livingTexture, target, RenderingPipe.colorMask); } } + + /// + /// Draws stone if it is present in the tile. + /// + /// + /// + /// + private static void DrawStone(Tile tile, ref SpriteBatch spBatch, Rectangle target) + { + if (tile.Resources != null) + { + switch (tile.Resources) + { + case StoneBase stone: + Texture2D stoneTexture = AssetManager.Textures[AssetManager.GetTextureIndex(stone.GetUnconnectedTexture())]; + spBatch.Draw(stoneTexture, target, RenderingPipe.colorMask); + break; + } + } + } } } diff --git a/MagicalLifeGUIWindows/Rendering/RenderingPipe.cs b/MagicalLifeGUIWindows/Rendering/RenderingPipe.cs index da572da7..d2d52d77 100644 --- a/MagicalLifeGUIWindows/Rendering/RenderingPipe.cs +++ b/MagicalLifeGUIWindows/Rendering/RenderingPipe.cs @@ -51,7 +51,7 @@ public static class RenderingPipe /// public static void DrawScreen(ref SpriteBatch spBatch) { - MasterLog.DebugWriteLine("Rendering frame"); + //MasterLog.DebugWriteLine("Rendering frame"); if (World.mainWorld != null) { MapRenderer.DrawMap(ref spBatch); diff --git a/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResource.png b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResource.png new file mode 100644 index 00000000..c349be57 Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResource.png differ diff --git a/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected1.png b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected1.png new file mode 100644 index 00000000..e94a509f Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected1.png differ diff --git a/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected2.png b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected2.png new file mode 100644 index 00000000..bec81cf3 Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected2.png differ diff --git a/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected3.png b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected3.png new file mode 100644 index 00000000..3e127c0a Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected3.png differ diff --git a/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected4.png b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected4.png new file mode 100644 index 00000000..865e3e2c Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/Marble/MarbleResourceConnected4.png differ diff --git a/MagicalLifeGUIWindows/Resource/Texture/StoneFloor.png b/MagicalLifeGUIWindows/Resource/Texture/StoneFloor.png new file mode 100644 index 00000000..8913652c Binary files /dev/null and b/MagicalLifeGUIWindows/Resource/Texture/StoneFloor.png differ diff --git a/MagicalLifeGUIWindows/Util.cs b/MagicalLifeGUIWindows/Util.cs index 0f48da08..812b1b3e 100644 --- a/MagicalLifeGUIWindows/Util.cs +++ b/MagicalLifeGUIWindows/Util.cs @@ -20,7 +20,7 @@ public static class Util /// /// /// - public static Point3D GetMapLocation(int x, int y) + public static Point GetMapLocation(int x, int y) { int x2 = x + Rendering.RenderingPipe.XViewOffset; int y2 = y + Rendering.RenderingPipe.YViewOffset; @@ -29,7 +29,7 @@ public static Point3D GetMapLocation(int x, int y) x2 /= size.X; y2 /= size.Y; - return new Point3D(x2, y2, Rendering.RenderingPipe.ZLevel); + return new Point(x2, y2); } } }