PathEarlCore 1.2.3
dotnet add package PathEarlCore --version 1.2.3
NuGet\Install-Package PathEarlCore -Version 1.2.3
<PackageReference Include="PathEarlCore" Version="1.2.3" />
<PackageVersion Include="PathEarlCore" Version="1.2.3" />
<PackageReference Include="PathEarlCore" />
paket add PathEarlCore --version 1.2.3
#r "nuget: PathEarlCore, 1.2.3"
#:package PathEarlCore@1.2.3
#addin nuget:?package=PathEarlCore&version=1.2.3
#tool nuget:?package=PathEarlCore&version=1.2.3
PathEarlCore
First, define a TileInfo (or use EmptyTileInfo if you have no tile types / features to worry about). The TileInfo defines whatever parameters a tile may have, for instance whether it HasMountain = true or TileType = "swamp", etc. See BasicTileInfo in UT_PathEarlScout for a thorough example.
public class TestTileInfo : ITileInfo
{
public bool IsForest = false;
public void Clear()
{
IsForest = false;
}
public static Func<TestTileInfo> Spawner = () =>
{
return new TestTileInfo();
};
}
Next, create a Map:
Map<TestTileInfo> map = new Map<TestTileInfo>(TestTileInfo.Spawner);
The GenerateGrid method builds out the base structure of the map:
// gaps can be used to create voids where there are no tiles
bool[,] gaps = new bool[30, 30];
gaps[5, 5] = true;
gaps[5, 6] = true;
// note that xdist/ydist are how far apart the rows/columns are in pathfinding cost
int[,] ids = map.GenerateGrid(30, 30, out TestTileInfo[,] infos, gaps, xdist: 1, ydist: 1, hex: true);
Note that you can also generate any arbitrary map rather than a grid by using the AddNode and AddConnection methods on map; see the GenerateGrid source for an example.
Each node has an id which is used to refer to it; the ids array that GenerateGrid produces gives a handy reference for the ids of all tiles in the grid.
You may add blocking (collision) to the map via the Block method:
map.Block(ids[12, 18], EMapLayer.Ground);
map.Block(ids[21, 21], EMapLayer.Sea);
If a layer is blocked on a tile, any unit with that blocking type cannot pass through it. There are six blocking layers by default, though their names are arbitrary.
You can adjust any tile parameters by accessing their info like so:
map.Info[ids[10,10]].IsForest = true;
You may define a travel cost function that makes traveling through certain tiles cost more than others:
Func<int, int, float, TestTileInfo, TestTileInfo, float> cost = (from, to, dist, fromInfo, toInfo) =>
{
// moving into forests costs an extra tile of movement
if (toInfo.IsForest)
return dist + 1;
return dist;
};
Finally, you can find a path with the Djikstra method:
int start = ids[2, 9];
int target = ids[24, 24];
// suggested that you persist one MapScratch and reuse it instead of making a new one each time
MapScratch<TestTileInfo> scratch = new MapScratch<TestTileInfo>();
List<int> pathIdsWalksFliesAndSwims = map.Djikstra(start, target, EMapLayer.None, scratch, cost);
List<int> pathIdsWalksAndSwims = map.Djikstra(start, target, EMapLayer.Ground, scratch, cost);
List<int> pathIdsWalks = map.Djikstra(start, target, EMapLayer.Ground | EMapLayer.Sea, scratch, cost);
The resultant list is the sequence of tiles (by their ids) that the unit will pass through. After a unit has moved, you can Unblock their old tile and Block their new tile so that other units cannot pass through them, if desired.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- RelaStructures (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on PathEarlCore:
| Package | Downloads |
|---|---|
|
PathEarlScout
Mapgen package. |
|
|
PathEarlViz
Visualization for PathEarlScout mapgen package. |
GitHub repositories
This package is not used by any popular GitHub repositories.