Permalink
Browse files

target is now an actor, not a number; close #34 (yet again)

  • Loading branch information...
1 parent 50f88bf commit 8937a50cf64f821195d8384504aae351e4393509 @Mikolaj Mikolaj committed Mar 13, 2011
Showing with 21 additions and 15 deletions.
  1. +16 −8 src/Actions.hs
  2. +5 −7 src/Monster.hs
View
24 src/Actions.hs
@@ -81,9 +81,13 @@ endTargeting accept = do
when (not accept) $ do
ploc <- gets (mloc . getPlayerBody)
modify (updateCursor (\ c -> c { clocation = ploc }))
+ state <- get
let verb = "target"
targetMsg = case target of
- TEnemy i -> objectMovable (mtype (monsters !! i))
+ TEnemy a ->
+ case findActorAnyLevel a state of
+ Just (_, m) -> objectMovable (mtype m)
+ Nothing -> "a long gone adversary"
TLoc loc -> "location " ++ show loc
TCursor -> "current cursor position continuously"
end = if accept then "." else "!"
@@ -522,14 +526,14 @@ targetMonster = do
target <- gets (mtarget . getPlayerBody)
level <- gets slevel
let i1 = case target of
- TEnemy i -> i + 1
+ TEnemy (AMonster i) -> i + 1
_ -> 0
ms = L.zip (lmonsters level) [0..]
(lt, gt) = L.splitAt i1 ms
lf = L.filter (\ (m, _) -> S.member (mloc m) (pvisible per)) (gt ++ lt)
tgt = case lf of
[] -> target -- no monsters in sight, stick to last target
- (_, ni) : _ -> TEnemy ni -- pick the next (or first) monster
+ (_, ni) : _ -> TEnemy (AMonster ni) -- pick the next monster
updatePlayerBody (\ p -> p { mtarget = tgt })
setCursor tgt
@@ -542,11 +546,15 @@ targetToLoc state per =
in case target of
TLoc loc -> loc
TCursor -> cloc
- TEnemy i ->
- let loc = mloc $ lmonsters (slevel state) !! i
- in if S.member loc (pvisible per)
- then loc
- else cloc -- monster invisible, keep the cursor position
+ TEnemy a ->
+ case findActorAnyLevel a state of
+ Just (_, m) ->
+ let loc = mloc m
+ in if S.member loc (pvisible per)
+ then loc
+ else cloc -- target invisible, keep the cursor position
+ Nothing ->
+ cloc -- target dead, keep the cursor position
-- | Set, activate and display cursor information.
setCursor :: Target -> Action ()
View
12 src/Monster.hs
@@ -4,6 +4,7 @@ import Data.Char
import Data.Binary
import Control.Monad
+import Actor
import Geometry
import Display
import Item
@@ -90,16 +91,13 @@ instance Binary MovableType where
_ -> fail "no parse (MovableType)"
data Target =
- TEnemy Int -- ^ fire at a monster (or a hero) with the given number
- -- TODO: what is the monster's number?
- -- (can't be position of monster on lmonsters.
- -- because monster death invalidates that)
- | TLoc Loc -- ^ fire at a given location
- | TCursor -- ^ fire at the current position of the cursor; the default
+ TEnemy Actor -- ^ fire at the actor (a monster or a hero)
+ | TLoc Loc -- ^ fire at a given location
+ | TCursor -- ^ fire at the current position of the cursor; the default
deriving (Show, Eq)
instance Binary Target where
- put (TEnemy n) = putWord8 0 >> put n
+ put (TEnemy a) = putWord8 0 >> put a
put (TLoc loc) = putWord8 1 >> put loc
put TCursor = putWord8 2
get = do

0 comments on commit 8937a50

Please sign in to comment.