diff --git a/Assets/Scripts/Logic/Data/World/Barrack.cs b/Assets/Scripts/Logic/Data/World/Barrack.cs index 65b1c63cdd317ebc4ed967f1271eae807b11ef71..3dbd9d6147830e9ef4e1890d0de1812afca2af11 100644 --- a/Assets/Scripts/Logic/Data/World/Barrack.cs +++ b/Assets/Scripts/Logic/Data/World/Barrack.cs @@ -5,6 +5,9 @@ using Logic.Event.World.Barrack; using Logic.Event.World.Unit; namespace Logic.Data.World { +/// <summary> +/// Represents a barrack in the game. +/// </summary> public class Barrack : Building { #region Fields diff --git a/Assets/Scripts/Logic/Data/World/Building.cs b/Assets/Scripts/Logic/Data/World/Building.cs index 247648ea03e96c24e5f5a8b0189003620981860b..3ad85f6a6f529736b3ff67a561f878518192ce39 100644 --- a/Assets/Scripts/Logic/Data/World/Building.cs +++ b/Assets/Scripts/Logic/Data/World/Building.cs @@ -1,10 +1,18 @@ ďťżnamespace Logic.Data.World { - +/// <summary> +/// Abstract class of every building of the world +/// </summary> public abstract class Building : TileObject { + /// <summary> + /// Color of the owner's team + /// </summary> public Color OwnerColor { get; } //Color is saved instead of GameTeam because in order to create a GameTeam // a Castle needed, so a Castle mustn't require a GameTeam instance. + /// <summary> + /// Owner of the building. + /// </summary> public GameTeam Owner => World.Overview.GetTeam(OwnerColor); private protected Building(GameWorld world, TilePosition position, Color owner) @@ -12,5 +20,4 @@ public abstract class Building : TileObject { OwnerColor = owner; } } - } diff --git a/Assets/Scripts/Logic/Data/World/Castle.cs b/Assets/Scripts/Logic/Data/World/Castle.cs index 358209892932988205cb3f5daab0010a33c59bef..6c256f672b2cfecb46575b5a7896e642851c88ac 100644 --- a/Assets/Scripts/Logic/Data/World/Castle.cs +++ b/Assets/Scripts/Logic/Data/World/Castle.cs @@ -2,6 +2,9 @@ using Logic.Event.World.Castle; namespace Logic.Data.World { +/// <summary> +/// represents a castle in the game. +/// </summary> public class Castle : Building { #region Properties diff --git a/Assets/Scripts/Logic/Data/World/Dijkstra.cs b/Assets/Scripts/Logic/Data/World/Dijkstra.cs deleted file mode 100644 index 2b77bbda14c0c0c874c39ae416836e63dc0815f3..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Logic/Data/World/Dijkstra.cs +++ /dev/null @@ -1,18 +0,0 @@ -ďťżnamespace Logic.Data.World { -internal class Dijkstra { - public int D { get; set; } - public int Ox { get; } - public int Oy { get; } - public int Px { get; set; } - public int Py { get; set; } - public bool Queued { get; set; } - - public Dijkstra(int x, int y) { - D = int.MaxValue; - Ox = x; - Oy = y; - Px = -1; - Py = -1; - } -} -} diff --git a/Assets/Scripts/Logic/Data/World/Dijkstra.cs.meta b/Assets/Scripts/Logic/Data/World/Dijkstra.cs.meta deleted file mode 100644 index 7a413ca18d328f9971c2f5b6b399bec61396b2e5..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Logic/Data/World/Dijkstra.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -ďťżfileFormatVersion: 2 -guid: d6355afc4ea14c25b1aa45e6459ef6e6 -timeCreated: 1647607809 \ No newline at end of file diff --git a/Assets/Scripts/Logic/Data/World/GameWorld.cs b/Assets/Scripts/Logic/Data/World/GameWorld.cs index 5c83b46f81bb4cb9ac558aa24318b89a327f4172..b9ba5696b2d7fb378f5c03ccce5f8c1da304745f 100644 --- a/Assets/Scripts/Logic/Data/World/GameWorld.cs +++ b/Assets/Scripts/Logic/Data/World/GameWorld.cs @@ -5,6 +5,9 @@ using Logic.Event.World.Tower; using Logic.Event.World.Unit; namespace Logic.Data.World { +/// <summary> +/// Represents the world in which the game takes place. +/// </summary> public class GameWorld { #region Fields diff --git a/Assets/Scripts/Logic/Data/World/ITowerTypeData.cs b/Assets/Scripts/Logic/Data/World/ITowerTypeData.cs index 66f5ce6418c72830711b091876961b8857ef1795..ed0fb188299cde8cce4457669b70527db0b8fe0c 100644 --- a/Assets/Scripts/Logic/Data/World/ITowerTypeData.cs +++ b/Assets/Scripts/Logic/Data/World/ITowerTypeData.cs @@ -1,4 +1,7 @@ ďťżnamespace Logic.Data.World { +/// <summary> +/// Interface for the different types of <see cref="Tower"/>s +/// </summary> public interface ITowerTypeData { #region Properties @@ -33,7 +36,7 @@ public interface ITowerTypeData { public int DestroyRefund { get; } /// <summary> - /// Building cost of the tower type. + /// Upgrade cost of the tower type. /// </summary> public int UpgradeCost { get; } diff --git a/Assets/Scripts/Logic/Data/World/IUnitTypeData.cs b/Assets/Scripts/Logic/Data/World/IUnitTypeData.cs index ad997e8367bed57da0c981d3feaee123d0b462d4..33d0bf4c91716f08f80cea05d73cf3a215bbdb4a 100644 --- a/Assets/Scripts/Logic/Data/World/IUnitTypeData.cs +++ b/Assets/Scripts/Logic/Data/World/IUnitTypeData.cs @@ -1,4 +1,7 @@ ďťżnamespace Logic.Data.World { +/// <summary> +/// Interface for the different types of <see cref="Unit"/>s +/// </summary> public interface IUnitTypeData { #region Properties diff --git a/Assets/Scripts/Logic/Data/World/Obstacle.cs b/Assets/Scripts/Logic/Data/World/Obstacle.cs index ea5e03998e2ac55b3e63ee2493b334ba74ff7318..6b233f6bf788468dec0dfa6f962733306591d780 100644 --- a/Assets/Scripts/Logic/Data/World/Obstacle.cs +++ b/Assets/Scripts/Logic/Data/World/Obstacle.cs @@ -1,6 +1,13 @@ ďťżnamespace Logic.Data.World { - +/// <summary> +/// Represents an obstacle of the world. +/// </summary> public class Obstacle : TileObject { + /// <summary> + /// Creates an obstacle. + /// </summary> + /// <param name="world">The world in which it will be created.</param> + /// <param name="position">The position of the obstacle.</param> internal Obstacle(GameWorld world, TilePosition position) : base(world, position) {} } diff --git a/Assets/Scripts/Logic/Data/World/TileObject.cs b/Assets/Scripts/Logic/Data/World/TileObject.cs index ba3705e441607877fe88934d7b6397b400b6b070..60b88899fc7aef053737f407367d6aac2ec2d629 100644 --- a/Assets/Scripts/Logic/Data/World/TileObject.cs +++ b/Assets/Scripts/Logic/Data/World/TileObject.cs @@ -1,4 +1,7 @@ ďťżnamespace Logic.Data.World { +/// <summary> +/// Base class of every Building and obstacle of the world. +/// </summary> public abstract class TileObject { /// <summary> /// The world in which the TileObject is located. @@ -15,10 +18,6 @@ public abstract class TileObject { Position = position; } - /// <summary> - /// Formats the object for printing on screen. - /// </summary> - /// <returns>Printable format of the TileObject.</returns> public override string ToString() { return $"{GetType().Name}@{Position}"; } diff --git a/Assets/Scripts/Logic/Data/World/TilePosition.cs b/Assets/Scripts/Logic/Data/World/TilePosition.cs index 6e6077c248ebc2f5adbb072273c03f6a04c309ed..dc7ff13fb922e3459238ed5dc8180c044d4d2039 100644 --- a/Assets/Scripts/Logic/Data/World/TilePosition.cs +++ b/Assets/Scripts/Logic/Data/World/TilePosition.cs @@ -1,6 +1,9 @@ ďťżusing System; namespace Logic.Data.World { +/// <summary> +/// Represents a tile's position on the grid. +/// </summary> public readonly struct TilePosition { /// <summary> /// First coordinate of the position. @@ -92,10 +95,6 @@ public readonly struct TilePosition { return Added(-x, -y); } - /// <summary> - /// Formats the TilePosition for printing on screen. - /// </summary> - /// <returns>Printable format of the TilePosition.</returns> public override string ToString() { return $"({X};{Y})"; } diff --git a/Assets/Scripts/Logic/Data/World/Tower.cs b/Assets/Scripts/Logic/Data/World/Tower.cs index 31fe3fbbcc7bc91dafaad7326bf75086c6cab801..6556d478d60ae16e0f750dd91de6f2f786670669 100644 --- a/Assets/Scripts/Logic/Data/World/Tower.cs +++ b/Assets/Scripts/Logic/Data/World/Tower.cs @@ -3,6 +3,9 @@ using System.Linq; using Logic.Event.World.Tower; namespace Logic.Data.World { +/// <summary> +/// Represents a tower of the world. +/// </summary> public class Tower : Building { #region Properties @@ -107,7 +110,7 @@ public class Tower : Building { } /// <summary> - /// The tower at the target. + /// The tower shoots at the target. /// </summary> /// <exception cref="InvalidOperationException">If the tower has no targets or is on cooldown.</exception> internal void Shoot() { diff --git a/Assets/Scripts/Logic/Data/World/Unit.cs b/Assets/Scripts/Logic/Data/World/Unit.cs index dc52fe7c76da087347a11cd55e398dd5188779f0..788a83946434e16a1d3f80b9ed7ea8357c00c246 100644 --- a/Assets/Scripts/Logic/Data/World/Unit.cs +++ b/Assets/Scripts/Logic/Data/World/Unit.cs @@ -3,6 +3,9 @@ using System.Linq; using Logic.Event.World.Unit; namespace Logic.Data.World { +/// <summary> +/// Represents a unit of the world. +/// </summary> public class Unit { #region Fields diff --git a/Assets/Scripts/Logic/Data/World/Vector2.cs b/Assets/Scripts/Logic/Data/World/Vector2.cs index 7b6680fbb4c0c3404b53330986dd558fb6d12eb4..2a03742f0022b49039eff2ff74aa1bfbd6cc88f7 100644 --- a/Assets/Scripts/Logic/Data/World/Vector2.cs +++ b/Assets/Scripts/Logic/Data/World/Vector2.cs @@ -1,6 +1,10 @@ ďťżusing System; namespace Logic.Data.World { + +/// <summary> +/// Represents an indiscreet position in the world. +/// </summary> public readonly struct Vector2 { /// <summary> /// First coordinate of the vector. diff --git a/Assets/Scripts/Logic/Data/World/WorldGenerator.cs b/Assets/Scripts/Logic/Data/World/WorldGenerator.cs index 7e65c8f5ba4a3d3a9fc3fd0626969740e93810a1..148a03a73ebf713001a3d70ecd52bcb655df612a 100644 --- a/Assets/Scripts/Logic/Data/World/WorldGenerator.cs +++ b/Assets/Scripts/Logic/Data/World/WorldGenerator.cs @@ -3,7 +3,19 @@ using System.Collections.Generic; using System.Linq; namespace Logic.Data.World { +/// <summary> +/// Class for generating the world. +/// </summary> internal class WorldGenerator { + /// <summary> + /// Generates the world. + /// </summary> + /// <param name="seed">Seed for randomisation.</param> + /// <param name="width">The width of the world.</param> + /// <param name="height">The height of the world.</param> + /// <param name="generateObstacles">If false, obstacles won't be generated.</param> + /// <param name="constructors">The constructors for the TileObjects.</param> + /// <returns>The grid of the world.</returns> public static TileObject[,] GenerateGrid(int seed, int width, int height, bool generateObstacles, ITileObjectConstructors constructors) { WorldGenerator generator = new WorldGenerator(seed, width, height, generateObstacles, constructors); @@ -117,6 +129,9 @@ internal class WorldGenerator { } } + /// <summary> + /// Interface for constructing TileObjects during generation. + /// </summary> public interface ITileObjectConstructors { public Castle CreateCastle(TilePosition position, Color team); public Barrack CreateBarrack(TilePosition position, Color team); diff --git a/Assets/Scripts/Logic/Data/World/WorldNavigation.cs b/Assets/Scripts/Logic/Data/World/WorldNavigation.cs index f1aab0f1799dec8b28cc9dd4218b282bc5a8cee7..cf3a570454800affce7cd273d003ce2b9bd38014 100644 --- a/Assets/Scripts/Logic/Data/World/WorldNavigation.cs +++ b/Assets/Scripts/Logic/Data/World/WorldNavigation.cs @@ -3,21 +3,49 @@ using System.Collections.Generic; using System.Linq; namespace Logic.Data.World { +/// <summary> +/// Represents the navigation system of the world. +/// </summary> internal class WorldNavigation { private readonly TileObject[,] _grid; + /// <summary> + /// Creates a navigation system. + /// </summary> + /// <param name="grid">The worldgrid.</param> public WorldNavigation(TileObject[,] grid) { _grid = grid; } + /// <summary> + /// Checks if there's a path between two tiles. + /// </summary> + /// <param name="from">First tile's position.</param> + /// <param name="to">Second tile's position.</param> + /// <param name="blockedTiles">The tiles that are blocked.</param> + /// <returns>True if a path exists.</returns> public bool IsPositionReachable(TilePosition from, TilePosition to, ISet<TilePosition> blockedTiles) { - return GetReachablePositionSubset(from, new HashSet<TilePosition> { to }, blockedTiles).Any(); + return GetReachablePositionSubset(from, new HashSet<TilePosition> {to}, blockedTiles).Any(); } + /// <summary> + /// Checks if there's a path between two tiles. + /// </summary> + /// <param name="from">First tile's position.</param> + /// <param name="to">Second tile's position.</param> + /// <returns>True if a path exists.</returns> public bool IsPositionReachable(TilePosition from, TilePosition to) { - return GetReachablePositionSubset(from, new HashSet<TilePosition> { to }).Any(); + return GetReachablePositionSubset(from, new HashSet<TilePosition> {to}).Any(); } + /// <summary> + /// Finds all the reachable TilePosition from a TilePosition. + /// </summary> + /// <param name="from">The start of the pathfinding.</param> + /// <param name="to">Set containing the destination for the pathfinding. </param> + /// <param name="blockedTiles">The tiles that are blocked. </param> + /// <returns>The set of reachable positions.</returns> + /// <exception cref="ArgumentException">If 'to' is a blocked position.</exception> public ISet<TilePosition> GetReachablePositionSubset(TilePosition from, ISet<TilePosition> to, ISet<TilePosition> blockedTiles) { if (blockedTiles.Overlaps(to)) @@ -41,6 +69,12 @@ internal class WorldNavigation { return result; } + /// <summary> + /// Finds all the reachable TilePosition from a TilePosition. + /// </summary> + /// <param name="from">The start of the pathfinding.</param> + /// <param name="to">Set containing the destination for the pathfinding. </param> + /// <returns>The set of reachable positions.</returns> public ISet<TilePosition> GetReachablePositionSubset(TilePosition from, ISet<TilePosition> to) { Dijkstra[,] dGrid = RunDijkstra(from.X, from.Y, to); HashSet<TilePosition> result = new HashSet<TilePosition>(to); @@ -66,8 +100,8 @@ internal class WorldNavigation { queue.Add(dGrid[fromX, fromY]); dGrid[fromX, fromY].Queued = true; - int[] diffX = { 0, 0, -1, 1 }; - int[] diffY = { 1, -1, 0, 0 }; + int[] diffX = {0, 0, -1, 1}; + int[] diffY = {1, -1, 0, 0}; //Instead of removing from the queue, advance an index: this is faster. //The first element always has the least weight due to all edges having the same cost (1). @@ -101,11 +135,18 @@ internal class WorldNavigation { return dGrid; } + /// <summary> + /// Calculates the vectors from tile to tile in the path between two positions. + /// </summary> + /// <param name="from">The start if the path.</param> + /// <param name="to">The end of the path.</param> + /// <param name="colliderRadius">The colliderRadius of the object that travels on the path.</param> + /// <returns>The pathDelta vectors</returns> public List<Vector2> TryGetPathDeltas(Vector2 from, Vector2 to, float colliderRadius) { if (from.ToTilePosition().Equals(to.ToTilePosition())) return new List<Vector2>(); Dijkstra[,] dGrid = RunDijkstra((int) from.X, (int) from.Y, - new HashSet<TilePosition> { to.ToTilePosition() }); + new HashSet<TilePosition> {to.ToTilePosition()}); if (dGrid[(int) to.X, (int) to.Y].D == int.MaxValue) return null; List<Vector2> pathDeltas = new List<Vector2>(); @@ -127,5 +168,22 @@ internal class WorldNavigation { private class FillerTileObject : TileObject { public FillerTileObject(TilePosition position) : base(null, position) {} } + + private class Dijkstra { + public int D { get; set; } + public int Ox { get; } + public int Oy { get; } + public int Px { get; set; } + public int Py { get; set; } + public bool Queued { get; set; } + + public Dijkstra(int x, int y) { + D = int.MaxValue; + Ox = x; + Oy = y; + Px = -1; + Py = -1; + } + } } }