LambdaHack-0.2.6: A roguelike game engine in early and active development

Safe HaskellNone




Game action monad and basic building blocks for player and monster actions. Exports liftIO for injecting IO into the Action monad, but does not export the implementation of the Action monad. The liftIO and handlerToIO operations are used only in Action.hs.


Actions and basic operations

type ActionFun r aSource


 = Session

session setup data

-> DungeonPerception

cached perception

-> (State -> Diary -> a -> IO r)


-> (Msg -> IO r)

failure/reset continuation

-> State

current state

-> Diary

current diary

-> IO r 

The type of the function inside any action. (Separated from the Action type to document each argument with haddock.)

data Action a Source

Actions of player-controlled characters and of any other actors.

handlerToIO :: Session -> State -> Diary -> Action () -> IO ()Source

Run an action, with a given session, state and diary, in the IO monad.

withPerception :: Action () -> Action ()Source

Update the cached perception for the given computation.

getPerception :: Action PerceptionSource

Get the current perception.

Actions returning frames

type ActionFrame a = Action (a, [Maybe SingleFrame])Source

Actions and screen frames, including delays, resulting from performing the actions.

returnNoFrame :: a -> ActionFrame aSource

Return the value with an empty set of screen frames.

returnFrame :: SingleFrame -> ActionFrame ()Source

Return the trivial value with a single frame to show.

whenFrame :: Bool -> ActionFrame () -> ActionFrame ()Source

As the when monad operation, but on type ActionFrame ().

inFrame :: Action () -> ActionFrame ()Source

Inject action into actions with screen frames.

Game session and assessors to its components

data Session Source

The information that is constant across a playing session, including many consecutive games in a single session, but is completely disregarded and reset when a new playing session starts.




sfs :: FrontendSession

frontend session information

scops :: COps

game content

sbinding :: Binding (ActionFrame ())

binding of keys to commands

sorigConfig :: CP

config from the config file

getFrontendSession :: Action FrontendSessionSource

Get the frontend session.

getCOps :: Action COpsSource

Get the content operations.

getBinding :: Action (Binding (ActionFrame ()))Source

Get the key binding.

getOrigConfig :: Action CPSource

Get the config from the config file.

Various ways to abort action

abort :: Action aSource

Reset the state and resume from the last backup point, i.e., invoke the failure continuation.

abortWith :: Msg -> Action aSource

Abort with the given message.

abortIfWith :: Bool -> Msg -> Action aSource

Abort and print the given msg if the condition is true.

neverMind :: Bool -> Action aSource

Abort and conditionally print the fixed message.

Abort exception handlers

tryWith :: (Msg -> Action a) -> Action a -> Action aSource

Set the current exception handler. First argument is the handler, second is the computation the handler scopes over.

tryRepeatedlyWith :: (Msg -> Action ()) -> Action () -> Action ()Source

Take a handler and a computation. If the computation fails, the handler is invoked and then the computation is retried.

tryIgnore :: Action () -> Action ()Source

Try the given computation and silently catch failure.

Diary and report

getDiary :: Action DiarySource

Get the current diary.

msgAdd :: Msg -> Action ()Source

Add a message to the current report.

historyReset :: History -> Action ()Source

Wipe out and set a new value for the history.

msgReset :: Msg -> Action ()Source

Wipe out and set a new value for the current report.