Make grass block vision

This commit is contained in:
Peter Stockings
2026-01-05 21:32:18 +11:00
parent 39528d297e
commit a01d4abdf7
4 changed files with 18 additions and 8 deletions

View File

@@ -82,8 +82,8 @@ describe('Combat Simulation', () => {
const player = world.actors.get(1);
expect(player!.pos).toEqual({ x: 4, y: 3 });
// Tile should effectively be destroyed (turned to empty/1)
expect(world.tiles[grassIdx]).toBe(1); // TileType.EMPTY
// Tile should effectively be destroyed (turned to saplings/2)
expect(world.tiles[grassIdx]).toBe(2); // TileType.GRASS_SAPLINGS
});
});

View File

@@ -1,7 +1,7 @@
import type { World, EntityId, Action, SimEvent, Actor, CombatantActor, CollectibleActor, ActorType } from "../../core/types";
import { isBlocked, inBounds, isWall, tryDestructTile } from "../world/world-logic";
import { isDestructibleByWalk } from "../../core/terrain";
import { isBlocked, inBounds, tryDestructTile } from "../world/world-logic";
import { isDestructibleByWalk, blocksSight } from "../../core/terrain";
import { findPathAStar } from "../world/pathfinding";
import { GAME_CONFIG } from "../../core/config/GameConfig";
import { type EntityManager } from "../EntityManager";
@@ -240,9 +240,11 @@ function canEnemySeePlayer(w: World, enemy: CombatantActor, player: CombatantAct
const viewRadius = 8; // Enemy vision range
let canSee = false;
const fov = new FOV.PreciseShadowcasting((x: number, y: number) => {
if (!inBounds(w, x, y)) return false;
return !isWall(w, x, y);
const idx = y * w.width + x;
return !blocksSight(w.tiles[idx]);
});
fov.compute(enemy.pos.x, enemy.pos.y, viewRadius, (x: number, y: number) => {