Permalink
Browse files

abort some actions with an empty message

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...
1 parent 4543a7f commit 3cd423e9fa120519f69319359ff35a02f4b8a3c1 @Mikolaj Mikolaj committed Apr 18, 2011
Showing with 16 additions and 18 deletions.
  1. +10 −12 src/Action.hs
  2. +6 −6 src/Actions.hs
View
@@ -150,19 +150,18 @@ debug x = return () -- liftIO $ hPutStrLn stderr x
-- | Print the given message, then abort.
abortWith :: Message -> Action a
-abortWith msg =
- do
- messageWipeAndSet msg
- display
- abort
+abortWith msg = do
+ messageWipeAndSet msg
+ display
+ abort
neverMind :: Bool -> Action a
neverMind b = abortIfWith b "never mind"
-- | Abort, and print the given message if the condition is true.
abortIfWith :: Bool -> Message -> Action a
-abortIfWith True = abortWith
-abortIfWith False = const abort
+abortIfWith True msg = abortWith msg
+abortIfWith False _ = abortWith ""
-- | Print message, await confirmation. Return value indicates
-- if the player tried to abort/escape.
@@ -178,11 +177,10 @@ messageMore msg = resetMessage >> messageMoreConfirm False msg >> return ()
-- | Print a yes/no question and return the player's answer.
messageYesNo :: Message -> Action Bool
-messageYesNo msg =
- do
- messageWipeAndSet (msg ++ yesno)
- displayBW -- turn player's attention to the choice
- session getYesNo
+messageYesNo msg = do
+ messageWipeAndSet (msg ++ yesno)
+ displayBW -- turn player's attention to the choice
+ session getYesNo
-- | Print a message and an overlay, await confirmation. Return value
-- indicates if the player tried to abort/escape.
View
@@ -184,7 +184,7 @@ continueRun dir =
exit _ = False
let hop t
| monstersVisible || heroThere
- || newsReported || itemsHere || exit t = abort
+ || newsReported || itemsHere || exit t = abortWith msg
hop Corridor =
-- in corridors, explore all corners and stop at all crossings
-- TODO: even in corridors, stop if you run past an exit (rare)
@@ -199,16 +199,16 @@ continueRun dir =
case L.filter (\ x -> not $ diagonal x) ns of
[ortoDir]
| allCloseTo ortoDir -> run ortoDir
- _ -> abort
+ _ -> abortWith msg
hop _ -- outside corridors, never change direction
- | not dirOK = abort
+ | not dirOK = abortWith msg
hop _ =
let ns = L.filter (\ x -> x /= dir && distance (neg dir, x) > 1) moves
ls = L.map (loc `shift`) ns
as = L.filter (\ x -> accessible lmap loc x
|| openable 1 lmap x) ls
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)
ifRunning :: (Dir -> Action a) -> Action a -> Action a
@@ -525,7 +525,7 @@ moveOrAttack allowAttacks autoOpen actor dir
actorRunActor actor target
when (actor == pl) $
messageAdd $ lookAt False True state lmap tloc ""
- else abort
+ else abortWith ""
Nothing ->
if accessible lmap sloc tloc then do
-- perform the move
@@ -540,7 +540,7 @@ moveOrAttack allowAttacks autoOpen actor dir
else if autoOpen then
-- try to open a door
actorOpenClose actor False True dir
- else abort
+ else abortWith ""
-- | Resolves the result of an actor moving into another. Usually this
-- involves melee attack, but with two heroes it just changes focus.

0 comments on commit 3cd423e

Please sign in to comment.