LambdaHack-0.6.1.0: A game engine library for roguelike dungeon crawlers

Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Server.Fov

Contents

Description

Field Of View scanning with a variety of algorithms. See https://github.com/LambdaHack/LambdaHack/wiki/Fov-and-los for discussion.

Synopsis

Perception cache

data FovValid a Source #

Constructors

FovValid !a 
FovInvalid 

Instances

Eq a => Eq (FovValid a) Source # 

Methods

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

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

Show a => Show (FovValid a) Source # 

Methods

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.

Constructors

PerReachable 

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: ActorAspect and FovShine shoudn't be in State, because on client they need to be updated every time an item discovery is made, unlike on the server, where it's much simpler and cheaper. BTW, 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).

Constructors

FovShine 

newtype FovLucid Source #

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

Constructors

FovLucid 

newtype FovClear Source #

Level positions that pass through light and vision.

Constructors

FovClear 

Fields

newtype FovLit Source #

Level positions with tiles that have ambient light.

Constructors

FovLit 

Fields

Instances

Update of invalidated Fov data

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 :: DiscoveryAspect -> ActorAspect -> 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).

Computation of initial perception and caches

perFidInDungeon :: DiscoveryAspect -> State -> (ActorAspect, 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.

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

Calculate perception of a faction.

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).

The actual Fov algorithm

fullscan Source #

Arguments

:: 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.