Skip to content

Commit

Permalink
helper functions for actors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Mar 22, 2011
1 parent 41800b4 commit 23ad4e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Actions.hs
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/Movable.hs
Expand Up @@ -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
Expand Down

0 comments on commit 23ad4e2

Please sign in to comment.