Permalink
Browse files

fix messages and removing items from a dead hero's inventory

  • Loading branch information...
Mikolaj committed Mar 31, 2011
1 parent e55bb95 commit a8a3c43704da2812dc47f833c5868c2c90ceed22
Showing with 23 additions and 16 deletions.
  1. +6 −2 src/EffectAction.hs
  2. +1 −1 src/Grammar.hs
  3. +16 −13 src/ItemAction.hs
View
@@ -40,6 +40,9 @@ import qualified Effect
-- | The source actor affects the target actor, with a given effect and power.
-- Both actors are on the current level and can be the same actor.
-- The bool result indicates if the actors identify the effect.
+-- TODO: separately define messages for the case when source == target
+-- and for the other case; then use the messages outside of effectToAction,
+-- depending on the returned bool, perception and identity of the actors.
effectToAction :: Effect.Effect -> Actor -> Actor -> Int -> String ->
Action Bool
effectToAction Effect.NoEffect source target power msg = do
@@ -55,7 +58,8 @@ effectToAction Effect.Heal source target power msg = do
let upd m = m { mhp = min (nhpMax (mkind m)) (mhp m + power) }
updateAnyActor target upd
pl <- gets splayer
- when (target == pl) $ messageAdd "You feel better." -- TODO: use msg, if perceived, etc. Eliminate "you" in singular, but keep it in plural.
+ when (target == pl) $
+ messageAdd $ subjectMovableVerb (mkind m) "feel" ++ " better."
return True
effectToAction (Effect.Wound nDm) source target power msg = do
n <- liftIO $ rndToIO $ rollDice nDm
@@ -74,7 +78,7 @@ effectToAction (Effect.Wound nDm) source target power msg = do
then return () -- Unseen monster quaffs a potion of wounding.
else messageAdd $
if source == target && target == pl
- then "You feel wounded."
+ then subjectMovableVerb (mkind tm) "feel" ++ " wounded."
else if not tvis
then "You hear some noises."
else if source == target || not svis
View
@@ -53,7 +53,7 @@ subjectVerbMObject m v o add =
objectMovable (mkind o) ++ add ++ "."
subjCompoundVerbIObj :: State -> Movable -> String -> String ->
- Item -> String -> String
+ Item -> String -> String
subjCompoundVerbIObj state m v p o add =
subjectMovable (mkind m) ++ " " ++
compoundVerbMovable (mkind m) v p ++ " " ++
View
@@ -44,9 +44,9 @@ inventory :: Action a
inventory = do
items <- gets (mitems . getPlayerBody)
if L.null items
- then abortWith "You are not carrying anything."
+ then abortWith "Not carrying anything."
else do
- displayItems "This is what you are carrying:" True items
+ displayItems "Carrying:" True items
session getConfirm
abortWith ""
@@ -71,7 +71,7 @@ applyGroupItem groupName verb = do
pbody <- gets getPlayerBody
is <- gets (mitems . getPlayerBody)
iOpt <- getGroupItem is groupName
- ("What to " ++ verb ++ "?") "in your inventory"
+ ("What to " ++ verb ++ "?") "in inventory"
case iOpt of
Just item@(Item { ikind = ik }) -> do
-- only one item consumed, even if several in inventory
@@ -82,7 +82,7 @@ applyGroupItem groupName verb = do
message (subjectVerbIObject state pbody v consumed "")
pl <- gets splayer
b <- itemEffectAction consumed pl pl
- when b $ removeFromInventory consumed
+ when b $ removeFromInventory consumed (mloc pbody)
Nothing -> neverMind True
playerAdvanceTime
@@ -97,15 +97,15 @@ zapGroupItem groupName verb = do
target <- gets (mtarget . getPlayerBody)
pl <- gets splayer
iOpt <- getGroupItem is groupName
- ("What to " ++ verb ++ "?") "in your inventory"
+ ("What to " ++ verb ++ "?") "in inventory"
case iOpt of
Just item@(Item { ikind = ik }) -> do
-- only one item consumed, even if several in inventory
let v = if ItemKind.jname (ItemKind.getIK ik) == groupName
then verb
else "furiously zap"
consumed = item { icount = 1 }
- removeFromInventory consumed
+ removeFromInventory consumed (mloc pbody)
case targetToLoc (ptvisible per) state of
Nothing -> abortWith "target invalid"
Just loc ->
@@ -144,18 +144,21 @@ dropItem = do
iOpt <- getAnyItem "What to drop?" items "inventory"
case iOpt of
Just i -> do
- removeFromInventory i
+ removeFromInventory i (mloc pbody)
message (subjectVerbIObject state pbody "drop" i "")
modify (updateLevel (dropItemsAt [i] ploc))
Nothing -> neverMind True
playerAdvanceTime
-- | Remove given item from the hero's inventory or floor.
-- TODO: this is subtly wrong: if identical items are on the floor and in
--- inventory, the floor one will be chosen, regardless of player intention..
-removeFromInventory :: Item -> Action ()
-removeFromInventory i = do
- ploc <- gets (mloc . getPlayerBody)
+-- inventory, the floor one will be chosen, regardless of player intention.
+-- TODO: right now it ugly hacks (with the ploc) around removing items
+-- of dead heros/monsters. The subtle incorrectness helps here a lot,
+-- because itmes of dead heroes land on the floor, so we used them up
+-- in inventory, but remove them after use from the floor.
+removeFromInventory :: Item -> Loc -> Action ()
+removeFromInventory i ploc = do
b <- removeFromLoc i ploc
when (not b) $
updatePlayerBody (\ p -> p { mitems = removeItemByLetter i (mitems p) })
@@ -200,7 +203,7 @@ actorPickupItem actor = do
-- add item to actor's inventory:
updateAnyActor actor $ \ m ->
m { mitems = nitems, mletter = maxLetter l (mletter body) }
- Nothing -> abortIfWith isPlayer "you cannot carry any more"
+ Nothing -> abortIfWith isPlayer "cannot carry any more"
advanceTime actor
pickupItem :: Action ()
@@ -252,7 +255,7 @@ getItem prompt p ptext is0 isn = do
in "[" ++ r ++ ", ?, *," ++ floorMsg ++ " RET, ESC]"
interact = do
when (L.null is0 && L.null tis) $
- abortWith "You are not carrying anything."
+ abortWith "Not carrying anything."
message (prompt ++ " " ++ choice)
display
session nextCommand >>= perform

0 comments on commit a8a3c43

Please sign in to comment.