Permalink
Browse files

helper functions for actors

  • Loading branch information...
Mikolaj committed Mar 22, 2011
1 parent 41800b4 commit 23ad4e255043ec9e4db78735190d51e380f3f71e
Showing with 15 additions and 9 deletions.
  1. +8 −9 src/Actions.hs
  2. +7 −0 src/Movable.hs
View
@@ -894,8 +894,7 @@ actorAttackActor source target = do
actorDamageActor :: Actor -> Actor -> Int -> String -> Action ()
actorDamageActor source target damage weaponMsg =
do
- let isTgtHero = case target of AHero _ -> True ; _ -> False
- when isTgtHero $ do
+ when (isAHero target) $ do
-- Focus on the attacked hero.
b <- selectPlayer target
-- Extra prompt, in case many heroes attacked in one turn.
@@ -938,13 +937,13 @@ actorRunActor source target = do
updateAnyActor target $ \ m -> m { mloc = sloc }
if source == pl
then stopRunning -- do not switch positions repeatedly
- else case (source, target) of
- (AMonster _, AHero _) -> do
- -- A hero is run over by an enemy monster; focus on the hero.
- b <- selectPlayer target
- -- Extra prompt, in case many heroes disturbed in one turn.
- when b $ messageAddMore >> return ()
- _ -> return ()
+ else if isAMonster source && isAHero target
+ then do
+ -- A hero is run over by an enemy monster; focus on the hero.
+ b <- selectPlayer target
+ -- Extra prompt, in case many heroes disturbed in one turn.
+ when b $ messageAddMore >> return ()
+ else return ()
advanceTime source
-- | Generate a monster, possibly.
View
@@ -52,6 +52,13 @@ data Actor = AHero Int -- ^ hero index (on the lheroes intmap)
| AMonster Int -- ^ monster index (on the lmonsters intmap)
deriving (Show, Eq)
+isAHero :: Actor -> Bool
+isAHero (AHero _) = True
+isAHero (AMonster _) = False
+
+isAMonster :: Actor -> Bool
+isAMonster = not . isAHero
+
instance Binary Actor where
put (AHero n) = putWord8 0 >> put n
put (AMonster n) = putWord8 1 >> put n

0 comments on commit 23ad4e2

Please sign in to comment.