Permalink
Browse files

simplify the Target type

  • Loading branch information...
1 parent 6572e30 commit b73debe5d84aeada7f3dce5f26f001a9b26dc58c @Mikolaj Mikolaj committed Mar 6, 2011
Showing with 9 additions and 17 deletions.
  1. +4 −6 src/Actions.hs
  2. +5 −11 src/Monster.hs
View
10 src/Actions.hs
@@ -493,14 +493,14 @@ targetFloor = do
TEnemy i -> do
let ms = lmonsters (slevel state)
t = if i >= L.length ms
- then TCurFloor -- the targeted monster is dead
+ then TCursor -- the targeted monster is dead
else TLoc $ mloc $ ms !! i
lk <- setLook t
doLook lk
_ ->
doLook lk -- stick to the previous floor target
Nothing -> do
- lk <- setLook TCurFloor
+ lk <- setLook TCursor
doLook lk
-- | Start the monster targetting mode. Cycle between monster targets.
@@ -514,7 +514,7 @@ targetMonster = do
let (i1, tgt) = case slook state of
Just (Look _ tgt@(TEnemy i) _) -> (i + 1, tgt)
Just (Look _ tgt _) -> (0, tgt)
- _ -> (0, TCurFloor)
+ _ -> (0, TCursor)
ms = L.zip (lmonsters (slevel state)) [0..]
(lt, gt) = L.splitAt i1 ms
lf = L.filter (\ (m, _) -> S.member (mloc m) (pvisible per)) (gt ++ lt)
@@ -533,9 +533,7 @@ targetToLoc (TEnemy i) s per =
then loc
else mloc (splayer s)
targetToLoc (TLoc loc) s _ = loc
-targetToLoc TClosest s _ = undefined -- TODO
-targetToLoc TShare s _ = undefined -- TODO
-targetToLoc TCurFloor s _ = mloc (splayer s)
+targetToLoc TCursor s _ = mloc (splayer s) -- TODO: when targeting cursor is permanently stored, use it instead
-- | Set look mode.
setLook :: Target -> Action Look
View
16 src/Monster.hs
@@ -20,7 +20,7 @@ heroHP config =
-- | Initial hero.
defaultHero :: Int -> Loc -> Int -> Hero
defaultHero n ploc hp =
- Monster (Hero n) hp hp Nothing TCurFloor ploc [] 'a' 10 0
+ Monster (Hero n) hp hp Nothing TCursor ploc [] 'a' 10 0
-- | The serial number of the hero. At this number he appears
-- in level hero intmaps. TODO: strengthen the type to avoid the error?
@@ -99,25 +99,19 @@ data Target =
-- (can't be position of monster on lmonsters.
-- because monster death invalidates that)
| TLoc Loc -- ^ fire at a location
- | TClosest -- ^ fire at the floor of the closest enemy
- | TShare -- ^ fire at the floor of the friends' closest nontrivial target
- | TCurFloor -- ^ fire at the current floor (under the actor), the default
+ | TCursor -- ^ fire at the floor under the last position of cursor
deriving (Show, Eq)
instance Binary Target where
put (TEnemy n) = putWord8 0 >> put n
put (TLoc loc) = putWord8 1 >> put loc
- put TClosest = putWord8 2
- put TShare = putWord8 3
- put TCurFloor = putWord8 4
+ put TCursor = putWord8 2
get = do
tag <- getWord8
case tag of
0 -> liftM TEnemy get
1 -> liftM TLoc get
- 2 -> return TClosest
- 3 -> return TShare
- 4 -> return TCurFloor
+ 2 -> return TCursor
_ -> fail "no parse (Target)"
isFloorTarget :: Target -> Bool
@@ -148,7 +142,7 @@ newMonster loc ftp =
-- move immediately after generation; this does not seem like
-- a bad idea, but it would certainly be "more correct" to set
-- the time to the creation time instead
- template tp hp loc s = Monster tp hp hp Nothing TCurFloor loc [] 'a' s 0
+ template tp hp loc s = Monster tp hp hp Nothing TCursor loc [] 'a' s 0
hps Eye = randomR (1,12) -- falls in 1--4 unarmed rounds
hps FastEye = randomR (1,6) -- 1--2

0 comments on commit b73debe

Please sign in to comment.