Browse files

prevent free monster moves after domination; second part

  • Loading branch information...
1 parent 4d00940 commit 8dabd75c7dd4a96e838127d09cde5999433da468 @Mikolaj Mikolaj committed Mar 29, 2011
Showing with 11 additions and 8 deletions.
  1. +0 −3 src/Actions.hs
  2. +5 −1 src/EffectAction.hs
  3. +6 −4 src/Turn.hs
View
3 src/Actions.hs
@@ -211,9 +211,6 @@ continueRun dir =
in if L.any exit ts then abort else run dir
hop (tterrain t)
-stopRunning :: Action ()
-stopRunning = updatePlayerBody (\ p -> p { mdir = Nothing })
-
ifRunning :: (Dir -> Action a) -> Action a -> Action a
ifRunning t e =
do
View
6 src/EffectAction.hs
@@ -93,11 +93,12 @@ effectToAction (Effect.Wound n) source target power msg =
else modify (deleteActor target) -- kills the enemy
return True
effectToAction Effect.Dominate source target power msg =
- if isAHero source -- Monsters are not strong-willed enough.
+ if isAMonster target -- Monsters have weaker will than heroes.
then do
b <- selectPlayer target
-- Prevent AI from getting a few free moves until new player ready.
updatePlayerBody (\ m -> m { mtime = 0})
+ stopRunning
return b
else return False
effectToAction Effect.SummonFriend source target power msg = do
@@ -281,3 +282,6 @@ displayItems msg sorted is = do
let ovl = inv ++ more
message msg
overlay ovl
+
+stopRunning :: Action ()
+stopRunning = updatePlayerBody (\ p -> p { mdir = Nothing })
View
10 src/Turn.hs
@@ -67,8 +67,8 @@ handle =
debug "handle"
state <- get
pl <- gets splayer
- let ptime = mtime (getPlayerBody state) -- time of hero's next move
- let time = stime state -- current game time
+ let ptime = mtime (getPlayerBody state) -- time of player's next move
+ let time = stime state -- current game time
debug $ "handle: time check. ptime = " ++ show ptime ++ ", time = " ++ show time
if ptime > time
then do
@@ -91,13 +91,15 @@ handleMonsters =
debug "handleMonsters"
time <- gets stime
ms <- gets (lmonsters . slevel)
+ pl <- gets splayer
if IM.null ms
then nextMove
else let order = Ord.comparing (mtime . snd)
(i, m) = L.minimumBy order (IM.assocs ms)
- in if mtime m > time
+ actor = AMonster i
+ in if mtime m > time || actor == pl
then nextMove -- no monster is ready for another move
- else handleMonster (AMonster i)
+ else handleMonster actor
-- | Handle the move of a single monster.
handleMonster :: Actor -> Action ()

0 comments on commit 8dabd75

Please sign in to comment.