LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Server.Fov

Contents

- Perception cache
- Data used in FOV computation and cached to speed it up
- Operations
- Internal operations

Description

Field Of View scanning.

See https://github.com/LambdaHack/LambdaHack/wiki/Fov-and-los for discussion.

Synopsis

- data FovValid a
  - = FovValid a
  - | FovInvalid
- type PerValidFid = EnumMap FactionId (EnumMap LevelId Bool)
- newtype PerReachable = PerReachable {
  - preachable :: EnumSet Point
  }
- data CacheBeforeLucid = CacheBeforeLucid {
  - creachable :: PerReachable
  - cnocto :: PerVisible
  - csmell :: PerSmelled
  }
- type PerActor = EnumMap ActorId (FovValid CacheBeforeLucid)
- data PerceptionCache = PerceptionCache {
  - ptotal :: FovValid CacheBeforeLucid
  - perActor :: PerActor
  }
- type PerCacheLid = EnumMap LevelId PerceptionCache
- type PerCacheFid = EnumMap FactionId PerCacheLid
- newtype FovShine = FovShine {
  - fovShine :: EnumMap Point Int
  }
- newtype FovLucid = FovLucid {
  - fovLucid :: EnumSet Point
  }
- type FovLucidLid = EnumMap LevelId (FovValid FovLucid)
- newtype FovClear = FovClear {
  - fovClear :: Array Bool
  }
- type FovClearLid = EnumMap LevelId FovClear
- newtype FovLit = FovLit {
  - fovLit :: EnumSet Point
  }
- type FovLitLid = EnumMap LevelId FovLit
- perceptionFromPTotal :: FactionId -> LevelId -> FovLucid -> CacheBeforeLucid -> State -> Perception
- perActorFromLevel :: PerActor -> (ActorId -> Actor) -> ActorMaxSkills -> FovClear -> PerActor
- boundSightByCalm :: Int -> Int64 -> Int
- totalFromPerActor :: PerActor -> CacheBeforeLucid
- lucidFromLevel :: FovClearLid -> FovLitLid -> State -> LevelId -> Level -> FovLucid
- perFidInDungeon :: State -> (FovLitLid, FovClearLid, FovLucidLid, PerValidFid, PerCacheFid, PerFid)
- perceptionFromPTotalNoStash :: FovLucid -> CacheBeforeLucid -> Perception
- cacheBeforeLucidFromActor :: FovClear -> Actor -> Skills -> CacheBeforeLucid
- shineFromLevel :: State -> LevelId -> Level -> FovShine
- floorLightSources :: DiscoveryAspect -> Level -> [(Point, Int)]
- lucidFromItems :: FovClear -> [(Point, Int)] -> [FovLucid]
- litFromLevel :: COps -> Level -> FovLit
- litInDungeon :: State -> FovLitLid
- clearFromLevel :: COps -> Level -> FovClear
- clearInDungeon :: State -> FovClearLid
- lucidInDungeon :: FovClearLid -> FovLitLid -> State -> FovLucidLid
- perLidFromFaction :: FovLucidLid -> FovClearLid -> FactionId -> State -> (PerLid, PerCacheLid)
- perceptionCacheFromLevel :: FovClearLid -> FactionId -> LevelId -> State -> PerceptionCache
- type Matrix = (Int, Int, Int, Int)
- fullscan :: Int -> Point -> FovClear -> EnumSet Point

# Perception cache

data FovValid a Source #

Constructors

FovValid a |
FovInvalid |

#### Instances

Instances details

Show a => Show (FovValid a) Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> FovValid a -> ShowS Source # show :: FovValid a -> String Source # showList :: [FovValid a] -> ShowS Source #
Eq a => Eq (FovValid a) Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: FovValid a -> FovValid a -> Bool Source # (/=) :: FovValid a -> FovValid a -> Bool Source #

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

Main perception validity map, for all factions.

The inner type is not a set, due to an unbenchmarked theory that a constant shape map is faster.

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 |

Fields

- preachable :: EnumSet Point

#### Instances

Instances details

Show PerReachable Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> PerReachable -> ShowS Source # show :: PerReachable -> String Source # showList :: [PerReachable] -> ShowS Source #
Eq PerReachable Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: PerReachable -> PerReachable -> Bool Source # (/=) :: PerReachable -> PerReachable -> Bool Source #

data CacheBeforeLucid Source #

Constructors

CacheBeforeLucid |

Fields

- creachable :: PerReachable
- cnocto :: PerVisible
- csmell :: PerSmelled

#### Instances

Instances details

Show CacheBeforeLucid Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> CacheBeforeLucid -> ShowS Source # show :: CacheBeforeLucid -> String Source # showList :: [CacheBeforeLucid] -> ShowS Source #
Eq CacheBeforeLucid Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: CacheBeforeLucid -> CacheBeforeLucid -> Bool Source # (/=) :: CacheBeforeLucid -> CacheBeforeLucid -> Bool Source #

type PerActor = EnumMap ActorId (FovValid CacheBeforeLucid) Source #

data PerceptionCache Source #

Constructors

PerceptionCache |

Fields

- ptotal :: FovValid CacheBeforeLucid
- perActor :: PerActor

#### Instances

Instances details

Show PerceptionCache Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> PerceptionCache -> ShowS Source # show :: PerceptionCache -> String Source # showList :: [PerceptionCache] -> ShowS Source #
Eq PerceptionCache Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: PerceptionCache -> PerceptionCache -> Bool Source # (/=) :: PerceptionCache -> PerceptionCache -> Bool Source #

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

Constructors

FovShine |

Fields

- fovShine :: EnumMap Point Int

#### Instances

Instances details

Show FovShine Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> FovShine -> ShowS Source # show :: FovShine -> String Source # showList :: [FovShine] -> ShowS Source #
Eq FovShine Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: FovShine -> FovShine -> Bool Source # (/=) :: FovShine -> FovShine -> Bool Source #

newtype FovLucid Source #

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

Constructors

FovLucid |

Fields

- fovLucid :: EnumSet Point

#### Instances

Instances details

Show FovLucid Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> FovLucid -> ShowS Source # show :: FovLucid -> String Source # showList :: [FovLucid] -> ShowS Source #
Eq FovLucid Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: FovLucid -> FovLucid -> Bool Source # (/=) :: FovLucid -> FovLucid -> Bool Source #

type FovLucidLid = EnumMap LevelId (FovValid FovLucid) Source #

newtype FovClear Source #

Level positions that pass through light and vision.

Constructors

FovClear |

Fields

- fovClear :: Array Bool

#### Instances

Instances details

Show FovClear Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> FovClear -> ShowS Source # show :: FovClear -> String Source # showList :: [FovClear] -> ShowS Source #
Eq FovClear Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: FovClear -> FovClear -> Bool Source # (/=) :: FovClear -> FovClear -> Bool Source #

type FovClearLid = EnumMap LevelId FovClear Source #

newtype FovLit Source #

Level positions with tiles that have ambient light.

Constructors

FovLit |

Fields

- fovLit :: EnumSet Point

#### Instances

Instances details

Show FovLit Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods showsPrec :: Int -> FovLit -> ShowS Source # show :: FovLit -> String Source # showList :: [FovLit] -> ShowS Source #
Eq FovLit Source # |
Instance details Defined in Game.LambdaHack.Server.Fov Methods (==) :: FovLit -> FovLit -> Bool Source # (/=) :: FovLit -> FovLit -> Bool Source #

type FovLitLid = EnumMap LevelId FovLit Source #

# Operations

perceptionFromPTotal :: FactionId -> LevelId -> FovLucid -> CacheBeforeLucid -> State -> 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).

perActorFromLevel :: PerActor -> (ActorId -> Actor) -> ActorMaxSkills -> FovClear -> PerActor Source #

boundSightByCalm :: Int -> Int64 -> Int Source #

totalFromPerActor :: PerActor -> CacheBeforeLucid Source #

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

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

cacheBeforeLucidFromActor :: FovClear -> Actor -> Skills -> 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.

shineFromLevel :: State -> LevelId -> Level -> FovShine Source #

floorLightSources :: DiscoveryAspect -> Level -> [(Point, Int)] Source #

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

litFromLevel :: COps -> Level -> FovLit Source #

litInDungeon :: State -> FovLitLid Source #

clearFromLevel :: COps -> Level -> FovClear Source #

clearInDungeon :: State -> FovClearLid Source #

lucidInDungeon :: FovClearLid -> FovLitLid -> State -> FovLucidLid Source #

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

Calculate perception of a faction.

perceptionCacheFromLevel :: FovClearLid -> FactionId -> LevelId -> State -> PerceptionCache Source #

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

fullscan Source #

Arguments

:: Int | scanning radius
-> Point | position of the spectator
-> FovClear | the array with clear positions
-> EnumSet Point |

Perform a full scan for a given position. Returns the positions that are currently in the field of view. The actor's own position is considred in his field of view.