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

Safe HaskellSafe-Infered

Game.LambdaHack.Action

Contents

Description

Game action monad and basic building blocks for player and monster actions.

Synopsis

Actions and basic operations

type ActionFun r aSource

Arguments

 = Session

session setup data

-> DungeonPerception

cached perception

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

continuation

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

rndToAction :: Rnd a -> Action aSource

Invoke pseudo-random computation with the generator kept in the state.

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.

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 its accessors

data Session Source

The constant session information, not saved to the game save file.

Constructors

Session 

Fields

sfs :: FrontendSession

frontend session information

scops :: COps

game content

skeyb :: Binding (ActionFrame ())

binding of keys to commands

getCOps :: Action COpsSource

Get the content operations.

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

Get the key binding.

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.

tryWithFrame :: Action a -> ActionFrame a -> ActionFrame aSource

Set the current exception handler. Apart of executing it, draw and pass along a frame with the abort message, if any.

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.

tryIgnoreFrame :: ActionFrame () -> ActionFrame ()Source

Try the given computation and silently catch failure, returning empty set of screen frames.

Diary and report

getDiary :: Action DiarySource

Get the current diary.

msgAdd :: Msg -> Action ()Source

Add a message to the current report.

recordHistory :: Action ()Source

Store current report in the history and reset report.

Key input

getKeyCommand :: Maybe Bool -> Action (Key, Modifier)Source

Wait for a player command.

getKeyChoice :: [(Key, Modifier)] -> SingleFrame -> Action (Key, Modifier)Source

Wait for a player keypress.

getOverConfirm :: [SingleFrame] -> Action BoolSource

A series of confirmations for all overlays.

Display each frame and confirm

displayMore :: ColorMode -> Msg -> Action BoolSource

Display a msg with a more prompt. Return value indicates if the player tried to cancel/escape.

displayYesNo :: Msg -> Action BoolSource

Print a yes/no question and return the player's answer. Use black and white colours to turn player's attention to the choice.

displayOverAbort :: Msg -> [Overlay] -> Action ()Source

Print a msg and several overlays, one per page. All frames require confirmations. Raise abort if the players presses ESC.

Assorted frame operations

displayOverlays :: Msg -> [Overlay] -> ActionFrame ()Source

Print a msg and several overlays, one per page. The last frame does not expect a confirmation.

displayChoiceUI :: Msg -> [Overlay] -> [(Key, Modifier)] -> Action (Key, Modifier)Source

Print a prompt and an overlay and wait for a player keypress. If many overlays, scroll screenfuls with SPACE. Do not wrap screenfuls (in some menus ? cycles views, so the user can restart from the top).

displayFramePush :: Maybe SingleFrame -> Action ()Source

Push a frame or a single frame's worth of delay to the frame queue.

drawPrompt :: ColorMode -> Msg -> Action SingleFrameSource

Draw the current level. The prompt is displayed, but not added to history. The prompt is appended to the current message and only the first screenful of the resulting overlay is displayed.

Clip init operations

startClip :: Action () -> Action ()Source

Initialize perception, etc., display level and run the action.

remember :: Action ()Source

Update player memory.

rememberList :: [Point] -> Action ()Source

Update player at the given list of locations..

Assorted operations

getPerception :: Action PerceptionSource

Get the current perception.

updateAnyActor :: ActorId -> (Actor -> Actor) -> Action ()Source

Update actor stats. Works for actors on other levels, too.

updatePlayerBody :: (Actor -> Actor) -> Action ()Source

Update player-controlled actor stats.

Assorted primitives

currentDate :: Action ClockTimeSource

Obtains the current date and time.

saveGameBkp :: State -> Diary -> Action ()Source

Save the diary and a backup of the save game file, in case of crashes.

See saveGameBkp.

dumpCfg :: FilePath -> CP -> Action ()Source

Dumps the current configuration to a file.

See dump.

shutGame :: (Bool, Status) -> Action ()Source

End the game, shutting down the frontend. The boolean argument tells if ending screens should be shown, the other arguments describes the cause of shutdown.

debug :: String -> Action ()Source

Debugging.