import { Hex, Vector2 } from "../../Util/index.js";
export class SimActionMoveEnemies {
    execute(simMain) {
        const simLevel = simMain.currentLevel;
        const deadEnemies = [];
        simLevel.simEnemies.forEach((simEnemy, idx) => {
            if (simEnemy.dead)
                deadEnemies.push(idx);
        });
        for (const idx of deadEnemies) {
            simLevel.simEnemies.splice(idx, 1);
        }
        for (const simEnemy of simLevel.simEnemies) {
            const duration = simEnemy.speed / simMain.gdRoot.simulation.stepsPerSecond;
            const t = (simLevel.currentStep - simEnemy.currentPathStep) * duration;
            const path2 = simLevel.simCells[simEnemy.path[simEnemy.currentPathIndex + 1]];
            if (!path2) {
                simEnemy.dead = true;
                return;
            }
            const hex2 = path2.hex;
            const pos1 = simEnemy.currentPathPosition;
            const pos2 = Hex.toWorld(hex2);
            simEnemy.position = Vector2.lerp(pos1, pos2, t);
            if (t >= 1) {
                simEnemy.currentPathIndex += 1;
                simEnemy.currentPathStep = simLevel.currentStep;
                simEnemy.onPathUpdated();
            }
        }
    }
}
//# sourceMappingURL=SimActionMoveEnemies.js.map