Skip to content

Commit

Permalink
abort some actions with an empty message
Browse files Browse the repository at this point in the history
In this way, it's obvious when a move accomplished nothing, e.g.,
a diagonal move from a door after a few bumps into walls that left
searching messages on the screen.
  • Loading branch information
Mikolaj committed Apr 18, 2011
1 parent 4543a7f commit 3cd423e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
22 changes: 10 additions & 12 deletions src/Action.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -150,19 +150,18 @@ debug x = return () -- liftIO $ hPutStrLn stderr x


-- | Print the given message, then abort. -- | Print the given message, then abort.
abortWith :: Message -> Action a abortWith :: Message -> Action a
abortWith msg = abortWith msg = do
do messageWipeAndSet msg
messageWipeAndSet msg display
display abort
abort


neverMind :: Bool -> Action a neverMind :: Bool -> Action a
neverMind b = abortIfWith b "never mind" neverMind b = abortIfWith b "never mind"


-- | Abort, and print the given message if the condition is true. -- | Abort, and print the given message if the condition is true.
abortIfWith :: Bool -> Message -> Action a abortIfWith :: Bool -> Message -> Action a
abortIfWith True = abortWith abortIfWith True msg = abortWith msg
abortIfWith False = const abort abortIfWith False _ = abortWith ""


-- | Print message, await confirmation. Return value indicates -- | Print message, await confirmation. Return value indicates
-- if the player tried to abort/escape. -- if the player tried to abort/escape.
Expand All @@ -178,11 +177,10 @@ messageMore msg = resetMessage >> messageMoreConfirm False msg >> return ()


-- | Print a yes/no question and return the player's answer. -- | Print a yes/no question and return the player's answer.
messageYesNo :: Message -> Action Bool messageYesNo :: Message -> Action Bool
messageYesNo msg = messageYesNo msg = do
do messageWipeAndSet (msg ++ yesno)
messageWipeAndSet (msg ++ yesno) displayBW -- turn player's attention to the choice
displayBW -- turn player's attention to the choice session getYesNo
session getYesNo


-- | Print a message and an overlay, await confirmation. Return value -- | Print a message and an overlay, await confirmation. Return value
-- indicates if the player tried to abort/escape. -- indicates if the player tried to abort/escape.
Expand Down
12 changes: 6 additions & 6 deletions src/Actions.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ continueRun dir =
exit _ = False exit _ = False
let hop t let hop t
| monstersVisible || heroThere | monstersVisible || heroThere
|| newsReported || itemsHere || exit t = abort || newsReported || itemsHere || exit t = abortWith msg
hop Corridor = hop Corridor =
-- in corridors, explore all corners and stop at all crossings -- in corridors, explore all corners and stop at all crossings
-- TODO: even in corridors, stop if you run past an exit (rare) -- TODO: even in corridors, stop if you run past an exit (rare)
Expand All @@ -199,16 +199,16 @@ continueRun dir =
case L.filter (\ x -> not $ diagonal x) ns of case L.filter (\ x -> not $ diagonal x) ns of
[ortoDir] [ortoDir]
| allCloseTo ortoDir -> run ortoDir | allCloseTo ortoDir -> run ortoDir
_ -> abort _ -> abortWith msg
hop _ -- outside corridors, never change direction hop _ -- outside corridors, never change direction
| not dirOK = abort | not dirOK = abortWith msg
hop _ = hop _ =
let ns = L.filter (\ x -> x /= dir && distance (neg dir, x) > 1) moves let ns = L.filter (\ x -> x /= dir && distance (neg dir, x) > 1) moves
ls = L.map (loc `shift`) ns ls = L.map (loc `shift`) ns
as = L.filter (\ x -> accessible lmap loc x as = L.filter (\ x -> accessible lmap loc x
|| openable 1 lmap x) ls || openable 1 lmap x) ls
ts = L.map (tterrain . (lmap `at`)) as ts = L.map (tterrain . (lmap `at`)) as
in if L.any exit ts then abort else run dir in if L.any exit ts then abortWith msg else run dir
hop (tterrain t) hop (tterrain t)


ifRunning :: (Dir -> Action a) -> Action a -> Action a ifRunning :: (Dir -> Action a) -> Action a -> Action a
Expand Down Expand Up @@ -525,7 +525,7 @@ moveOrAttack allowAttacks autoOpen actor dir
actorRunActor actor target actorRunActor actor target
when (actor == pl) $ when (actor == pl) $
messageAdd $ lookAt False True state lmap tloc "" messageAdd $ lookAt False True state lmap tloc ""
else abort else abortWith ""
Nothing -> Nothing ->
if accessible lmap sloc tloc then do if accessible lmap sloc tloc then do
-- perform the move -- perform the move
Expand All @@ -540,7 +540,7 @@ moveOrAttack allowAttacks autoOpen actor dir
else if autoOpen then else if autoOpen then
-- try to open a door -- try to open a door
actorOpenClose actor False True dir actorOpenClose actor False True dir
else abort else abortWith ""


-- | Resolves the result of an actor moving into another. Usually this -- | Resolves the result of an actor moving into another. Usually this
-- involves melee attack, but with two heroes it just changes focus. -- involves melee attack, but with two heroes it just changes focus.
Expand Down

0 comments on commit 3cd423e

Please sign in to comment.