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

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Common.Level

Contents

- Dungeon
- The `Level` type and its components
- Component updates
- Level query
- Misc
- Internal operations

Description

Inhabited dungeon levels and the operations to query and change them as the game progresses.

Synopsis

- type Dungeon = EnumMap LevelId Level
- dungeonBounds :: Dungeon -> (LevelId, LevelId)
- ascendInBranch :: Dungeon -> Bool -> LevelId -> [LevelId]
- whereTo :: LevelId -> Point -> Bool -> Dungeon -> [(LevelId, Point)]
- type ItemFloor = EnumMap Point ItemBag
- type BigActorMap = EnumMap Point ActorId
- type ProjectileMap = EnumMap Point [ActorId]
- type TileMap = Array (ContentId TileKind)
- type SmellMap = EnumMap Point Time
- data Level = Level {
  - lkind :: ContentId CaveKind
  - ldepth :: AbsDepth
  - lfloor :: ItemFloor
  - lembed :: ItemFloor
  - lbig :: BigActorMap
  - lproj :: ProjectileMap
  - ltile :: TileMap
  - lentry :: EntryMap
  - larea :: Area
  - lsmell :: SmellMap
  - lstair :: ([Point], [Point])
  - lescape :: [Point]
  - lseen :: Int
  - lexpl :: Int
  - ltime :: Time
  - lnight :: Bool
  }
- updateFloor :: (ItemFloor -> ItemFloor) -> Level -> Level
- updateEmbed :: (ItemFloor -> ItemFloor) -> Level -> Level
- updateBigMap :: (BigActorMap -> BigActorMap) -> Level -> Level
- updateProjMap :: (ProjectileMap -> ProjectileMap) -> Level -> Level
- updateTile :: (TileMap -> TileMap) -> Level -> Level
- updateEntry :: (EntryMap -> EntryMap) -> Level -> Level
- updateSmell :: (SmellMap -> SmellMap) -> Level -> Level
- at :: Level -> Point -> ContentId TileKind
- posToBigLvl :: Point -> Level -> Maybe ActorId
- occupiedBigLvl :: Point -> Level -> Bool
- posToProjsLvl :: Point -> Level -> [ActorId]
- occupiedProjLvl :: Point -> Level -> Bool
- posToAidsLvl :: Point -> Level -> [ActorId]
- findPosTry :: Int -> Level -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> Rnd (Maybe Point)
- findPosTry2 :: Int -> Level -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> (Point -> ContentId TileKind -> Bool) -> [Point -> ContentId TileKind -> Bool] -> Rnd (Maybe Point)
- nearbyPassablePoints :: COps -> Level -> Point -> [Point]
- nearbyFreePoints :: COps -> Level -> (ContentId TileKind -> Bool) -> Point -> [Point]
- sortEmbeds :: COps -> ContentId TileKind -> [(ItemKind, (ItemId, ItemQuant))] -> [(ItemId, ItemQuant)]
- type EntryMap = EnumMap Point PlaceEntry
- assertSparseItems :: ItemFloor -> ItemFloor
- assertSparseProjectiles :: ProjectileMap -> ProjectileMap

# Dungeon

type Dungeon = EnumMap LevelId Level Source #

The complete dungeon is a map from level identifiers to levels.

dungeonBounds :: Dungeon -> (LevelId, LevelId) Source #

ascendInBranch :: Dungeon -> Bool -> LevelId -> [LevelId] Source #

Levels in the current branch, one level up (or down) from the current.

whereTo Source #

Arguments

:: LevelId | level of the stairs
-> Point | position of the stairs
-> Bool | optional forced direction
-> Dungeon | current game dungeon
-> [(LevelId, Point)] | possible destinations

Compute the level identifier and stair position on the new level, after a level change.

We assume there is never a staircase up and down at the same position.

# The `Level` type and its components

type ItemFloor = EnumMap Point ItemBag Source #

Items located on map tiles.

type BigActorMap = EnumMap Point ActorId Source #

Big actors located on map tiles.

type ProjectileMap = EnumMap Point [ActorId] Source #

Collections of projectiles located on map tiles.

type TileMap = Array (ContentId TileKind) Source #

Tile kinds on the map.

type SmellMap = EnumMap Point Time Source #

Current smell on map tiles.

data Level Source #

A view on single, inhabited dungeon level. Remembered fields carry a subset of the info in the client copies of levels.

Constructors

Level |

Fields

- lkind :: ContentId CaveKind

  the kind of cave the level is an instance of

- ldepth :: AbsDepth

  absolute depth of the level

- lfloor :: ItemFloor

  remembered items lying on the floor

- lembed :: ItemFloor

  remembered items embedded in the tile

- lbig :: BigActorMap

  seen big (non-projectile) actors at positions on the level; could be recomputed at resume, but small enough

- lproj :: ProjectileMap

  seen projectiles at positions on the level; could be recomputed at resume

- ltile :: TileMap

  remembered level map

- lentry :: EntryMap

  room entrances on the level

- larea :: Area

  area of the level

- lsmell :: SmellMap

  remembered smells on the level

- lstair :: ([Point], [Point])

  positions of (up, down) stairs

- lescape :: [Point]

  positions of IK.Escape tiles

- lseen :: Int

  currently remembered clear tiles

- lexpl :: Int

  total number of explorable tiles

- ltime :: Time

  local time on the level (possibly frozen)

- lnight :: Bool

  whether the level is covered in darkness

#### Instances

Instances details

Binary Level Source # |
Instance details Defined in Game.LambdaHack.Common.Level Methods put :: Level -> Put Source # get :: Get Level Source # putList :: [Level] -> Put Source #
Show Level Source # |
Instance details Defined in Game.LambdaHack.Common.Level Methods showsPrec :: Int -> Level -> ShowS Source # show :: Level -> String Source # showList :: [Level] -> ShowS Source #
Eq Level Source # |
Instance details Defined in Game.LambdaHack.Common.Level Methods (==) :: Level -> Level -> Bool Source # (/=) :: Level -> Level -> Bool Source #

# Component updates

updateFloor :: (ItemFloor -> ItemFloor) -> Level -> Level Source #

updateEmbed :: (ItemFloor -> ItemFloor) -> Level -> Level Source #

updateBigMap :: (BigActorMap -> BigActorMap) -> Level -> Level Source #

updateProjMap :: (ProjectileMap -> ProjectileMap) -> Level -> Level Source #

updateTile :: (TileMap -> TileMap) -> Level -> Level Source #

updateEntry :: (EntryMap -> EntryMap) -> Level -> Level Source #

updateSmell :: (SmellMap -> SmellMap) -> Level -> Level Source #

# Level query

at :: Level -> Point -> ContentId TileKind Source #

Query for tile kinds on the map.

posToBigLvl :: Point -> Level -> Maybe ActorId Source #

occupiedBigLvl :: Point -> Level -> Bool Source #

posToProjsLvl :: Point -> Level -> [ActorId] Source #

occupiedProjLvl :: Point -> Level -> Bool Source #

posToAidsLvl :: Point -> Level -> [ActorId] Source #

findPosTry Source #

Arguments

:: Int | the number of tries
-> Level | look up in this level
-> (Point -> ContentId TileKind -> Bool) | mandatory predicate
-> [Point -> ContentId TileKind -> Bool] | optional predicates
-> Rnd (Maybe Point) |

Try to find a random position on the map satisfying conjunction of the mandatory and an optional predicate. If the permitted number of attempts is not enough, try again the same number of times without the next optional predicate, and fall back to trying with only the mandatory predicate.

findPosTry2 Source #

Arguments

:: Int | the number of tries
-> Level | look up in this level
-> (Point -> ContentId TileKind -> Bool) | mandatory predicate
-> [Point -> ContentId TileKind -> Bool] | optional predicates
-> (Point -> ContentId TileKind -> Bool) | good to have pred.
-> [Point -> ContentId TileKind -> Bool] | worst case predicates
-> Rnd (Maybe Point) |

nearbyPassablePoints :: COps -> Level -> Point -> [Point] Source #

Generate a list of all passable points on (connected component of) the level in the order of path distance from the starting position (BFS). The starting position needn't be passable and is always included.

nearbyFreePoints :: COps -> Level -> (ContentId TileKind -> Bool) -> Point -> [Point] Source #

# Misc

sortEmbeds :: COps -> ContentId TileKind -> [(ItemKind, (ItemId, ItemQuant))] -> [(ItemId, ItemQuant)] Source #

# Internal operations

type EntryMap = EnumMap Point PlaceEntry Source #

Entries of places on the map.

assertSparseItems :: ItemFloor -> ItemFloor Source #

assertSparseProjectiles :: ProjectileMap -> ProjectileMap Source #