LambdaHack- A game engine library for roguelike dungeon crawlers

Safe HaskellNone




Field Of View scanning.

See for discussion.


Perception cache

data FovValid a Source #


FovValid a 


Eq a => Eq (FovValid a) Source # 


(==) :: FovValid a -> FovValid a -> Bool #

(/=) :: FovValid a -> FovValid a -> Bool #

Show a => Show (FovValid a) Source # 


showsPrec :: Int -> FovValid a -> ShowS #

show :: FovValid a -> String #

showList :: [FovValid a] -> ShowS #

type PerValidFid = EnumMap FactionId (EnumMap LevelId Bool) Source #

Main perception validity map, for all factions.

newtype PerReachable Source #

Visually reachable positions (light passes through them to the actor). They need to be intersected with lucid positions to obtain visible positions.



type PerCacheLid = EnumMap LevelId PerceptionCache Source #

Server cache of perceptions of a single faction, indexed by level identifier.

type PerCacheFid = EnumMap FactionId PerCacheLid Source #

Server cache of perceptions, indexed by faction identifier.

Data used in FOV computation and cached to speed it up

newtype FovShine Source #

Map from level positions that currently hold item or actor(s) with shine to the maximum of radiuses of the shining lights.

Note that floor and (many projectile) actors light on a single tile should be additive for FovShine to be incrementally updated.

FovShine should not even be kept in StateServer, because it's cheap to compute, compared to FovLucid and invalidated almost as often (not invalidated only by UpdAlterTile).



newtype FovLucid Source #

Level positions with either ambient light or shining items or actors.



newtype FovClear Source #

Level positions that pass through light and vision.




newtype FovLit Source #

Level positions with tiles that have ambient light.






perceptionFromPTotal :: FovLucid -> CacheBeforeLucid -> Perception Source #

Compute positions visible (reachable and seen) by the party. A position is lucid, if it's lit by an ambient light or by a weak, portable light source, e.g,, carried by an actor. A reachable and lucid position is visible. Additionally, positions directly adjacent to an actor are assumed to be visible to him (through sound, touch, noctovision, whatever).

lucidFromLevel :: FovClearLid -> FovLitLid -> State -> LevelId -> Level -> FovLucid Source #

Update lights on the level. This is needed every (even enemy) actor move to show thrown torches. We need to update lights even if cmd doesn't change any perception, so that for next cmd that does, but doesn't change lights, and operates on the same level, the lights are up to date. We could make lights lazy to ensure no computation is wasted, but it's rare that cmd changed them, but not the perception (e.g., earthquake in an uninhabited corner of the active arena, but the we'd probably want some feedback, at least sound).

perFidInDungeon :: State -> (FovLitLid, FovClearLid, FovLucidLid, PerValidFid, PerCacheFid, PerFid) Source #

Calculate the perception and its caches for the whole dungeon.

Internal operations

cacheBeforeLucidFromActor :: FovClear -> Actor -> AspectRecord -> CacheBeforeLucid Source #

Compute positions reachable by the actor. Reachable are all fields on a visually unblocked path from the actor position. Also compute positions seen by noctovision and perceived by smell.

lucidFromItems :: FovClear -> [(Point, Int)] -> [FovLucid] Source #

Compute all dynamically lit positions on a level, whether lit by actors or shining floor items. Note that an actor can be blind, in which case he doesn't see his own light (but others, from his or other factions, possibly do).

perLidFromFaction :: FovLucidLid -> FovClearLid -> FactionId -> State -> (PerLid, PerCacheLid) Source #

Calculate perception of a faction.

type Matrix = (Int, Int, Int, Int) Source #

fullscan Source #


:: FovClear

the array with clear points

-> Int

scanning radius

-> Point

position of the spectator

-> EnumSet Point 

Perform a full scan for a given position. Returns the positions that are currently in the field of view. The Field of View algorithm to use is passed in the second argument. The actor's own position is considred reachable by him.