Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

monster and hero death now handled right after damage dealt

  • Loading branch information...
commit 540f1f25a01ffded5df2e2043f082835b2f52aee 1 parent 34135ef
@Mikolaj Mikolaj authored
Showing with 16 additions and 18 deletions.
  1. +16 −13 src/Actions.hs
  2. +0 −5 src/Turn.hs
View
29 src/Actions.hs
@@ -758,28 +758,31 @@ actorAttackActor source target =
-- damage the target
newHp = mhp tm - 3 - sword
killed = newHp <= 0
- if killed
- then do
- -- grant an immediate move to die; TODO: instead kill the actor
- -- right here, but carefully, because monsters and heroes have different
- -- ways of disappearing and for heroes it may end the game
- updateActor target $ \ m -> m { mhp = 0, mtime = 0 }
- -- place the actor's possessions on the map
- dropItemsAt (mitems tm) (mloc tm)
- else
- updateActor target $ \ m -> m { mhp = newHp }
- -- determine how the hero perceives the event; TODO: we have to be more
- -- precise and treat cases where two monsters fight, but only one is visible
- let combatVerb = if killed && target /= APlayer then "kill" else "hit"
+ -- determine how the hero perceives the event; TODO: we have to be more
+ -- precise and treat cases where two monsters fight,
+ -- but only one is visible; TODO: if 2 heroes hit a monster,
+ -- still only one of them should kill it
+ combatVerb = if killed && target /= APlayer then "kill" else "hit"
swordMsg = if sword == 0 then "" else
" with a (+" ++ show sword ++ ") sword" -- TODO: generate proper message
combatMsg = subjectVerbMObject state sm combatVerb tm swordMsg
+ updateActor target $ \ m -> m { mhp = newHp }
per <- currentPerception
let perceived = mloc sm `S.member` pvisible per
messageAdd $
if perceived
then combatMsg
else "You hear some noises."
+ when killed $ do
+ -- place the actor's possessions on the map
+ dropItemsAt (mitems tm) (mloc tm)
+ -- clean bodies up
+ case target of
+ APlayer ->
+ checkPartyDeath -- kills heroes and checks game over
+ AMonster n ->
+ let upd l = L.take n l ++ L.drop (n + 1) l
+ in modify (updateLevel (updateMonsters upd))
-- | Generate a monster, possibly.
generateMonster :: Action ()
View
5 src/Turn.hs
@@ -61,7 +61,6 @@ handle =
state <- get
let ptime = mtime (splayer state) -- time of hero's next move
let time = stime state -- current game time
- checkPartyDeath -- any hero can die even if it's not the player's turn
regenerate APlayer -- heroes regenerate even if outside the player's turn
debug $ "handle: time check. ptime = " ++ show ptime ++ ", time = " ++ show time
if ptime > time
@@ -90,10 +89,6 @@ handleMonsters =
(m@(Monster { mtime = mt }) : ms)
| mt > time -> -- no monster is ready for another move
nextMove
- | mhp m <= 0 -> -- the monster dies
- do
- modify (updateLevel (updateMonsters (const ms)))
- handleMonsters
| otherwise -> -- monster m should move; we temporarily remove m from the level
-- TODO: removal isn't nice. Actor numbers currently change during
-- a move. This could be cleaned up.
Please sign in to comment.
Something went wrong with that request. Please try again.