Adding flying functionality for enemies

This commit is contained in:
Matt F 2026-06-23 22:27:35 -07:00
parent 54f11d91ff
commit d685894878
6 changed files with 83 additions and 26 deletions

View file

@ -53,11 +53,16 @@ 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<Vector2Int> remainingPath = new List<Vector2Int>();
private PlayerSlot currentZone = PlayerSlot.None;
// Zone the enemy was spawned in — i.e., which player "owns" this enemy as part
@ -106,11 +111,13 @@ namespace TD.Gameplay
/// tiles sit inside <c>SpawnerVolume</c>, not <c>PlayerZoneVolume</c>, so
/// their owner-grid entry is <see cref="PlayerSlot.None"/>.
/// </summary>
public void InitializeServer(float speed, Vector2Int spawnerTile, PlayerSlot ownerSlot)
public void InitializeServer(float speed, Vector2Int spawnerTile, PlayerSlot ownerSlot,
bool flying)
{
pendingMoveSpeed = speed;
pendingSpawnerTile = spawnerTile;
pendingOwnerSlot = ownerSlot;
pendingIsFlying = flying;
hasPendingInit = true;
}
@ -137,6 +144,7 @@ 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
@ -156,8 +164,10 @@ 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.
if (PathfindingService.Instance != null)
// 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)
PathfindingService.Instance.OnPathsInvalidated += RecomputePath;
}
@ -280,7 +290,7 @@ namespace TD.Gameplay
return;
}
remainingPath = service.ComputePath(fromTile);
remainingPath = service.ComputePath(fromTile, ignoreTowers: isFlying);
// Dedupe the "no path" log: only emit on the transition into stuck
// state, not every frame a walkability change re-fires the recompute.