Last active
July 19, 2019 16:12
-
-
Save AG-Dan/7657547913f986cc4050053699fba661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Doorway GetNextDoorwayClosestToEndTile(Tile currentTile) | |
{ | |
// Loop through all active doorways for the tile we're currently in | |
foreach (var doorway in currentTile.Placement.UsedDoorways) | |
{ | |
var adjacentTile = doorway.ConnectedDoorway.Tile; // Get the tile connected by this doorway | |
if (currentTile.Placement.IsOnMainPath) | |
{ | |
// We're already on the main path | |
// If the adjacent tile is further along the main path than the current tile, it's closer to the goal | |
if (adjacentTile.Placement.NormalizedPathDepth > currentTile.Placement.NormalizedPathDepth) | |
return doorway; | |
} | |
else | |
{ | |
// We're on a branch | |
// If the adjacent tile is on the main path or it's closer to the beginning of the branch, it's closer to the goal | |
if (adjacentTile.Placement.IsOnMainPath || adjacentTile.Placement.NormalizedBranchDepth < currentTile.Placement.NormalizedBranchDepth) | |
return doorway; | |
} | |
} | |
throw new Exception("No closest tile found. This should never happen"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment