diff --git a/Assets/_Project/Definitions/Enemies/10_Enemy_UndeadDrakeBone_Definition.asset b/Assets/_Project/Definitions/Enemies/10_Enemy_UndeadDrakeBone_Definition.asset index 31d1eec..e3c2ac8 100644 --- a/Assets/_Project/Definitions/Enemies/10_Enemy_UndeadDrakeBone_Definition.asset +++ b/Assets/_Project/Definitions/Enemies/10_Enemy_UndeadDrakeBone_Definition.asset @@ -16,6 +16,5 @@ MonoBehaviour: MaxHp: 800 MoveSpeed: 4 IsFlying: 1 - FlightHeight: 3 LivesCost: 1 EnemyPrefab: {fileID: 1455822126534880203, guid: 738e5730a03623540aa1513639d0baf8, type: 3} diff --git a/Assets/_Project/Scripts/Gameplay/EnemyDefinition.cs b/Assets/_Project/Scripts/Gameplay/EnemyDefinition.cs index 15f45f8..ae8bd5d 100644 --- a/Assets/_Project/Scripts/Gameplay/EnemyDefinition.cs +++ b/Assets/_Project/Scripts/Gameplay/EnemyDefinition.cs @@ -27,16 +27,12 @@ namespace TD.Gameplay [Tooltip("Movement speed in world units per second along the A* path.")] public float MoveSpeed = 3f; - [Tooltip("When true this enemy flies: it paths on the baked terrain grid, ignoring " + - "towers, so it soars directly over the maze instead of following it. " + - "Towers with GroundedOnly=true will not target it.")] + [Tooltip("When true this enemy flies over tower footprints. " + + "Towers with GroundedOnly=true will not target it. " + + "Flying enemies follow the same A* path but are not physically " + + "blocked by tower colliders (handled in EnemyMovement).")] public bool IsFlying; - [Tooltip("Height (world units) above the ground a flying enemy hovers, so it " + - "visually clears towers. Only used when IsFlying is true. Keep modest — " + - "tower targeting uses 3D range, so large values eat into effective range.")] - public float FlightHeight = 3f; - [Header("Costs")] [Tooltip("Number of lives deducted from the shared pool when this enemy " + "reaches the Goal. Boss enemies might cost 2 or more lives.")] diff --git a/Assets/_Project/Scripts/Gameplay/EnemyMovement.cs b/Assets/_Project/Scripts/Gameplay/EnemyMovement.cs index 86195c6..c575a65 100644 --- a/Assets/_Project/Scripts/Gameplay/EnemyMovement.cs +++ b/Assets/_Project/Scripts/Gameplay/EnemyMovement.cs @@ -53,16 +53,11 @@ namespace TD.Gameplay private float pendingMoveSpeed; private Vector2Int pendingSpawnerTile; private PlayerSlot pendingOwnerSlot; - private bool pendingIsFlying; private bool hasPendingInit; // ----- Server-local runtime state ------------------------------------- private float moveSpeed; - // When true this enemy flies: it paths on the baked terrain grid (ignoring - // towers) and never re-paths, since the baked grid doesn't change. Grounded - // enemies path on the runtime grid and re-path on every walkability change. - private bool isFlying; private List remainingPath = new List(); private PlayerSlot currentZone = PlayerSlot.None; // Zone the enemy was spawned in — i.e., which player "owns" this enemy as part @@ -112,13 +107,11 @@ namespace TD.Gameplay /// tiles sit inside SpawnerVolume, not PlayerZoneVolume, so /// their owner-grid entry is . /// - public void InitializeServer(float speed, Vector2Int spawnerTile, PlayerSlot ownerSlot, - bool flying) + public void InitializeServer(float speed, Vector2Int spawnerTile, PlayerSlot ownerSlot) { pendingMoveSpeed = speed; pendingSpawnerTile = spawnerTile; pendingOwnerSlot = ownerSlot; - pendingIsFlying = flying; hasPendingInit = true; } @@ -146,7 +139,6 @@ namespace TD.Gameplay } moveSpeed = pendingMoveSpeed; - isFlying = pendingIsFlying; // Resolve starting zone from the spawner tile. This is what the enemy // observes as "the zone I am currently in." For SpawnerVolume tiles that @@ -166,10 +158,8 @@ namespace TD.Gameplay // Compute the initial path from the spawn tile to the nearest goal. ComputeAndStorePath(pendingSpawnerTile); - // Recompute when a tower is placed or sold — grounded enemies only. - // Flyers path on the static baked grid, so tower changes can never affect - // their route; subscribing would just trigger needless recomputes. - if (!isFlying && PathfindingService.Instance != null) + // Recompute when a tower is placed or sold. + if (PathfindingService.Instance != null) PathfindingService.Instance.OnPathsInvalidated += RecomputePath; } @@ -293,7 +283,7 @@ namespace TD.Gameplay return; } - remainingPath = service.ComputePath(fromTile, ignoreTowers: isFlying); + remainingPath = service.ComputePath(fromTile); // Dedupe the "no path" log: only emit on the transition into stuck // state, not every frame a walkability change re-fires the recompute. diff --git a/Assets/_Project/Scripts/Gameplay/LevelLoader.cs b/Assets/_Project/Scripts/Gameplay/LevelLoader.cs index 3a29dfb..89c8f6b 100644 --- a/Assets/_Project/Scripts/Gameplay/LevelLoader.cs +++ b/Assets/_Project/Scripts/Gameplay/LevelLoader.cs @@ -316,23 +316,6 @@ namespace TD.Gameplay return runtimeWalkability[idx]; } - /// - /// True if is walkable in the BAKED terrain grid, ignoring - /// any runtime tower placement. Returns false for out-of-bounds tiles. - /// - /// - /// Flying enemies path against this grid so they soar over towers (which only - /// affect 's runtime grid) while still respecting - /// impassable terrain and map bounds. Because the baked grid never changes at - /// runtime, flying paths are computed once and never need invalidation. - /// - public bool IsBaseWalkable(Vector2Int tile) - { - if (level == null || level.WalkabilityGrid == null) return false; - if (!TryFlatIndex(tile, out int idx)) return false; - return level.WalkabilityGrid[idx]; - } - /// /// Placement state for . Returns /// for out-of-bounds tiles. diff --git a/Assets/_Project/Scripts/Gameplay/PathfindingService.cs b/Assets/_Project/Scripts/Gameplay/PathfindingService.cs index d6c99df..413f1f4 100644 --- a/Assets/_Project/Scripts/Gameplay/PathfindingService.cs +++ b/Assets/_Project/Scripts/Gameplay/PathfindingService.cs @@ -125,12 +125,7 @@ namespace TD.Gameplay /// is unavailable (should not occur — TowerPlacementManager guarantees a path /// always exists after any placement). /// - /// - /// When true, pathing uses the baked terrain grid - /// () instead of the runtime - /// tower-stamped grid, so the path soars over towers. Used by flying enemies. - /// - public List ComputePath(Vector2Int startTile, bool ignoreTowers = false) + public List ComputePath(Vector2Int startTile) { var loader = LevelLoader.Instance; if (loader == null || !loader.IsLoaded || goalTiles == null || goalTiles.Count == 0) @@ -145,31 +140,23 @@ namespace TD.Gameplay // that just became blocked). Nudge to the nearest walkable tile so // the enemy can resume routing instead of repeatedly failing. // Search outward in Chebyshev rings — closest 8-neighbor wins. - // (For flyers this nudge is effectively never needed — the baked grid - // doesn't change — but it's cheap and keeps the two paths uniform.) - if (!IsTileWalkable(loader, startTile, ignoreTowers)) + if (!loader.IsWalkable(startTile)) { - if (TryFindNearestWalkable(startTile, loader, maxRadius: 4, ignoreTowers, out var nudged)) + if (TryFindNearestWalkable(startTile, loader, maxRadius: 4, out var nudged)) startTile = nudged; else return new List(); } - return RunAStar(startTile, loader, ignoreTowers); + return RunAStar(startTile, loader); } - // Single seam for "is this tile traversable for this enemy kind": grounded - // enemies see the runtime grid (towers block them); flyers see only the baked - // terrain grid (towers are invisible to them). - private static bool IsTileWalkable(LevelLoader loader, Vector2Int tile, bool ignoreTowers) - => ignoreTowers ? loader.IsBaseWalkable(tile) : loader.IsWalkable(tile); - // Expanding ring search (Chebyshev / 8-connected) for the nearest // walkable tile around . Caps at maxRadius to // keep this O(maxRadius²) in the worst case. Used by ComputePath when // an enemy's start tile becomes non-walkable mid-flight. private static bool TryFindNearestWalkable(Vector2Int origin, LevelLoader loader, - int maxRadius, bool ignoreTowers, out Vector2Int found) + int maxRadius, out Vector2Int found) { for (int r = 1; r <= maxRadius; r++) { @@ -180,7 +167,7 @@ namespace TD.Gameplay // Only walk the OUTER ring at distance r (skip interior — already checked at smaller r). if (Mathf.Abs(dx) != r && Mathf.Abs(dy) != r) continue; var tile = new Vector2Int(origin.x + dx, origin.y + dy); - if (IsTileWalkable(loader, tile, ignoreTowers)) + if (loader.IsWalkable(tile)) { found = tile; return true; @@ -194,7 +181,7 @@ namespace TD.Gameplay // ----- A* implementation ------------------------------------------ - private List RunAStar(Vector2Int start, LevelLoader loader, bool ignoreTowers) + private List RunAStar(Vector2Int start, LevelLoader loader) { cameFrom.Clear(); gScore.Clear(); @@ -210,14 +197,14 @@ namespace TD.Gameplay if (goalTiles.Contains(current)) { var tilePath = ReconstructPath(start, current); - return SmoothPath(start, tilePath, loader, ignoreTowers); + return SmoothPath(start, tilePath, loader); } float currentG = gScore.TryGetValue(current, out float g) ? g : float.MaxValue; foreach (var neighbor in GridCoordinates.GetNeighbors8(current)) { - if (!IsTileWalkable(loader, neighbor, ignoreTowers)) continue; + if (!loader.IsWalkable(neighbor)) continue; // Corner-cut prevention: for a diagonal step, both cardinal // shoulder tiles must also be walkable. Otherwise enemies could @@ -227,8 +214,7 @@ namespace TD.Gameplay { GridCoordinates.GetCornerShoulders(current, neighbor, out var shoulderA, out var shoulderB); - if (!IsTileWalkable(loader, shoulderA, ignoreTowers) - || !IsTileWalkable(loader, shoulderB, ignoreTowers)) + if (!loader.IsWalkable(shoulderA) || !loader.IsWalkable(shoulderB)) continue; } @@ -319,7 +305,7 @@ namespace TD.Gameplay /// squeezes through a diagonal corner. /// private List SmoothPath(Vector2Int start, List path, - LevelLoader loader, bool ignoreTowers) + LevelLoader loader) { if (path.Count <= 1) return path; @@ -333,7 +319,7 @@ namespace TD.Gameplay int farthest = i; for (int j = path.Count - 1; j > i; j--) { - if (HasLineOfSight(anchor, path[j], loader, ignoreTowers)) + if (HasLineOfSight(anchor, path[j], loader)) { farthest = j; break; @@ -354,8 +340,7 @@ namespace TD.Gameplay /// crosses walkable tiles, with no diagonal corner-cuts. Used by /// to decide whether two waypoints can be collapsed. /// - private static bool HasLineOfSight(Vector2Int a, Vector2Int b, LevelLoader loader, - bool ignoreTowers) + private static bool HasLineOfSight(Vector2Int a, Vector2Int b, LevelLoader loader) { int x0 = a.x, y0 = a.y; int x1 = b.x, y1 = b.y; @@ -389,11 +374,11 @@ namespace TD.Gameplay // shoulder tiles (same rule A* uses). if (steppedX && steppedY) { - if (!IsTileWalkable(loader, new Vector2Int(x - sx, y), ignoreTowers)) return false; - if (!IsTileWalkable(loader, new Vector2Int(x, y - sy), ignoreTowers)) return false; + if (!loader.IsWalkable(new Vector2Int(x - sx, y))) return false; + if (!loader.IsWalkable(new Vector2Int(x, y - sy))) return false; } - if (!IsTileWalkable(loader, new Vector2Int(x, y), ignoreTowers)) return false; + if (!loader.IsWalkable(new Vector2Int(x, y))) return false; } return true; diff --git a/Assets/_Project/Scripts/Gameplay/WaveManager.cs b/Assets/_Project/Scripts/Gameplay/WaveManager.cs index 0f49bae..fe75618 100644 --- a/Assets/_Project/Scripts/Gameplay/WaveManager.cs +++ b/Assets/_Project/Scripts/Gameplay/WaveManager.cs @@ -455,12 +455,6 @@ namespace TD.Gameplay if (zHalfExtent > 0f) spawnPos.z += Random.Range(-zHalfExtent, zHalfExtent); - // Flying enemies spawn elevated so they visually soar over towers. The - // movement code preserves Y per-frame, so this height persists for the - // enemy's whole flight. NetworkTransform replicates the raised position. - if (def.IsFlying) - spawnPos.y += def.FlightHeight; - float yaw = facing switch { Direction.North => 0f, @@ -469,11 +463,7 @@ namespace TD.Gameplay Direction.West => 270f, _ => 0f, }; - - var go = Instantiate( - def.EnemyPrefab, - spawnPos, - Quaternion.Euler(0f, yaw, 0f)); + var go = Instantiate(def.EnemyPrefab, spawnPos, Quaternion.Euler(0f, yaw, 0f)); var health = go.GetComponent(); var movement = go.GetComponent(); @@ -487,7 +477,7 @@ namespace TD.Gameplay } health.InitializeServer(def.MaxHp, def.LivesCost, def.IsFlying, held); - movement.InitializeServer(def.MoveSpeed, spawnerTile, ownerSlot, def.IsFlying); + movement.InitializeServer(def.MoveSpeed, spawnerTile, ownerSlot); if (held) heldEnemies.Add(health); health.OnDied += HandleEnemyKilled;