fixed dynamic enemy pathfinding
This commit is contained in:
@@ -143,16 +143,31 @@ export class SimLevel {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const routeIdx in gdLevel.enemyRoutes) {
|
||||
const route = gdLevel.enemyRoutes[routeIdx];
|
||||
const enemySpawnHex = gdLevel.enemySpawns[route[0]];
|
||||
const enemySpawnCell = this.cells[this.getCellIndex(enemySpawnHex)];
|
||||
enemySpawnCell.pathsToTarget[routeIdx] = newRoutePaths[routeIdx];
|
||||
}
|
||||
|
||||
for (let idx in this.enemies) {
|
||||
const simEnemy = this.enemies[idx];
|
||||
const hex = Hex.fromWorld(simEnemy.position);
|
||||
const startIndex = this.getCellIndex(hex);
|
||||
const currentIndex = simEnemy.path[simEnemy.currentPathIndex];
|
||||
const nextIndex = simEnemy.path[simEnemy.currentPathIndex + 1];
|
||||
const nextCell = this.cells[nextIndex];
|
||||
const endIndex = this.getCellIndex(simEnemy.endHex);
|
||||
const path = PathFinding.bfs(this, startIndex, endIndex);
|
||||
let startIndex = nextCell.type != ECellType.Free ? currentIndex : nextIndex;
|
||||
let path = PathFinding.bfs(this, startIndex, endIndex);
|
||||
if (path == null) {
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
if (nextCell.type != ECellType.Free) {
|
||||
path = [nextIndex, ...path];
|
||||
}
|
||||
else {
|
||||
path = [currentIndex, ...path];
|
||||
}
|
||||
newEnemyPaths[idx] = path;
|
||||
}
|
||||
|
||||
@@ -160,15 +175,9 @@ export class SimLevel {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const routeIdx in gdLevel.enemyRoutes) {
|
||||
const route = gdLevel.enemyRoutes[routeIdx];
|
||||
const enemySpawnHex = gdLevel.enemySpawns[route[0]];
|
||||
const enemySpawnCell = this.cells[this.getCellIndex(enemySpawnHex)];
|
||||
enemySpawnCell.pathsToTarget[routeIdx] = newRoutePaths[routeIdx];
|
||||
}
|
||||
|
||||
this.enemies.forEach((simEnemy: SimEnemy, idx: number) => {
|
||||
simEnemy.path = newEnemyPaths[idx];
|
||||
const newPath = newEnemyPaths[idx];
|
||||
simEnemy.path = newPath;
|
||||
simEnemy.currentPathIndex = 0;
|
||||
simEnemy.onPathUpdated(this);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user