Bugfixy, odstranění nepoužívaných tříd CameraSystem a ITargetingEnemy, přidání dedikované třídy ReturnToMenuElement, předělání pathfinding algoritmu z DFS na BFS, přesun správy obtížnosti do abstraktní třídy Enemy, přidání scriptů pro kompilaci na aplikaci nevyžadující dotnet
This commit is contained in:
parent
ceac37920b
commit
e5d746d597
24 changed files with 258 additions and 138 deletions
|
|
@ -12,38 +12,62 @@ public class RoamingPathfinder : Pathfinder {
|
|||
public List<MapTile> TakenPath { get; } = new();
|
||||
|
||||
private Random random = new();
|
||||
|
||||
// private Queue<MapTile> tilesToCrawl = new();
|
||||
// private Dictionary<MapTile, int> distances = new();
|
||||
// private Func<TileConnector, MapTile, bool> defaultConnectorFilter;
|
||||
public RoamingPathfinder(Enemy enemy, int tolerance) : base(enemy) {
|
||||
this.tolerance = tolerance;
|
||||
}
|
||||
|
||||
protected Dictionary<MapTile, int> Crawl(MapTile tile) {
|
||||
Dictionary<MapTile, int> distances = new(){ [tile] = 0 };
|
||||
CrawlStep(tile, distances);
|
||||
protected Dictionary<MapTile, int> Search(MapTile startingTile) {
|
||||
Dictionary<MapTile, int> distances = new(){ [startingTile] = 0 };
|
||||
Queue<MapTile> tilesToSearch = new();
|
||||
tilesToSearch.Enqueue(startingTile);
|
||||
|
||||
while (tilesToSearch.Count > 0){
|
||||
MapTile currentTile = tilesToSearch.Dequeue();
|
||||
|
||||
List<MapTile> neighbours = GetNeighbours(currentTile,
|
||||
c =>
|
||||
AdditionalConnectorFilter(c) &&
|
||||
(!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||
(!distances.ContainsKey(c.OtherTile(currentTile)) || distances[c.OtherTile(currentTile)] > distances[currentTile] + c.Value),
|
||||
t =>
|
||||
AdditionalTileFilter(t) &&
|
||||
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
||||
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
||||
|
||||
neighbours.ForEach(t => {
|
||||
distances[t] = distances[currentTile] + currentTile.GetConnector(t)!.Value;
|
||||
tilesToSearch.Enqueue(t);
|
||||
});
|
||||
}
|
||||
|
||||
return distances;
|
||||
}
|
||||
|
||||
private void CrawlStep(MapTile tile, Dictionary<MapTile, int> distances) {
|
||||
List<MapTile> neighbours = GetNeighbours(tile,
|
||||
c =>
|
||||
AdditionalConnectorFilter(c) &&
|
||||
(!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||
tile != Enemy.Location &&
|
||||
(!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
|
||||
t =>
|
||||
AdditionalTileFilter(t) &&
|
||||
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
||||
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
||||
|
||||
neighbours.ForEach(t => distances[t] = distances[tile] + tile.GetConnector(t)!.Value);
|
||||
|
||||
if (neighbours.Count != 0){
|
||||
neighbours.ForEach(t => CrawlStep(t, distances));
|
||||
}
|
||||
}
|
||||
|
||||
// private void CrawlStep(MapTile tile) {
|
||||
// List<MapTile> neighbours = GetNeighbours(tile,
|
||||
// c =>
|
||||
// AdditionalConnectorFilter(c) &&
|
||||
// (!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||
// tile != Enemy.Location &&
|
||||
// (!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
|
||||
// t =>
|
||||
// AdditionalTileFilter(t) &&
|
||||
// (!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
||||
// Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
||||
//
|
||||
// neighbours.ForEach(t => distances[t] = distances[tile] + tile.GetConnector(t)!.Value);
|
||||
//
|
||||
// if (neighbours.Count != 0){
|
||||
// neighbours.ForEach(t => CrawlStep(t));
|
||||
// }
|
||||
// }
|
||||
|
||||
public override Decision DecideNext(MapTile goal) {
|
||||
Dictionary<MapTile, int> distances = Crawl(goal);
|
||||
Dictionary<MapTile, int> distances = Search(goal);
|
||||
|
||||
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
||||
c => AdditionalConnectorFilter(c) && !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue