Permalink
Browse files

fix and extend HP regeneration

  • Loading branch information...
1 parent 5dd6b46 commit 3efa011b4a7ec6a6d2f5784ac553bec4fbcf9fb0 @Mikolaj Mikolaj committed Mar 25, 2011
Showing with 26 additions and 27 deletions.
  1. +18 −19 src/Actions.hs
  2. +1 −1 src/LambdaHack.config.default
  3. +4 −4 src/MovableAdd.hs
  4. +3 −3 src/Turn.hs
View
37 src/Actions.hs
@@ -632,7 +632,7 @@ drinkPotion =
-- only one potion is consumed even if several
-- are joined in the inventory
let consumed = i' { icount = 1 }
- baseHp = Config.get (sconfig state) "heroes" "baseHp"
+ baseHP = Config.get (sconfig state) "heroes" "baseHP"
removeFromInventory consumed
message (subjectVerbIObject state pbody "drink" consumed "")
-- the potion is identified after drinking
@@ -642,7 +642,7 @@ drinkPotion =
PotionHealing -> do
messageAdd "You feel better."
let php p =
- min (nhpMax (mkind p)) (mhp p + baseHp `div` 4)
+ min (nhpMax (mkind p)) (mhp p + baseHP `div` 4)
updatePlayerBody (\ p -> p { mhp = php p })
Just _ -> abortWith "you cannot drink that"
Nothing -> neverMind True
@@ -915,14 +915,14 @@ actorDamageActor source target damage weaponMsg =
sm <- gets (getActor source)
tm <- gets (getActor target)
let -- Damage the target.
- newHp = mhp tm - damage
- killed = newHp <= 0
+ newHP = mhp tm - damage
+ killed = newHP <= 0
-- 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.
combatVerb = if killed then "kill" else "hit"
combatMsg = subjectVerbMObject state sm combatVerb tm weaponMsg
- updateAnyActor target $ \ m -> m { mhp = newHp }
+ updateAnyActor target $ \ m -> m { mhp = newHP }
per <- currentPerception
let perceived = mloc sm `S.member` ptvisible per
messageAdd $
@@ -977,19 +977,18 @@ playerAdvanceTime = do
pl <- gets splayer
advanceTime pl
--- | Possibly regenerate HP for the given actor.
-regenerate :: Actor -> Action ()
-regenerate actor =
+-- | Possibly regenerate HP for all movables on the current level.
+regenerateLevelHP :: Action ()
+regenerateLevelHP =
do
- pl <- gets splayer
- pbody <- gets getPlayerBody
time <- gets stime
- let upd m = m { mhp = min (nhpMax (mkind m)) (mhp m + 1) }
- when (time `mod` (nregen (mkind pbody)) == 0) $ do
- -- We really want hero selection to be a purely UI distinction,
- -- so all heroes need to regenerate, not just the player.
- -- TODO: currently only the heroes on the current level regenerate.
- -- TODO: do this for all heroes or all monsters, never for 1 actor.
- if (actor == pl)
- then modify (updateLevel (updateHeroes (IM.map upd)))
- else updateAnyActor actor upd
+ let upd m = if time `mod` (nregen (mkind m)) /= 0
+ then m
+ else m { mhp = min (nhpMax (mkind m)) (mhp m + 1) }
+ -- We really want hero selection to be a purely UI distinction,
+ -- so all heroes need to regenerate, not just the player.
+ -- Only the heroes on the current level regenerate (others are frozen
+ -- in time together with their level). This prevents cheating
+ -- via sending one hero to a safe level and waiting there.
+ modify (updateLevel (updateHeroes (IM.map upd)))
+ modify (updateLevel (updateMonsters (IM.map upd)))
View
2 src/LambdaHack.config.default
@@ -30,7 +30,7 @@ highScores: LambdaHack.scores
saveGame: LambdaHack.save
[heroes]
-baseHp: 50
+baseHP: 50
extraHeroes: 0
firstDeathEnds: False
HeroName_0: you
View
8 src/MovableAdd.hs
@@ -53,14 +53,14 @@ findHeroName config n =
addHero :: Loc -> State -> State
addHero ploc state =
let config = sconfig state
+ bHP = Config.get config "heroes" "baseHP"
n = newMovableIndex lheroes state
- bHp = Config.get config "heroes" "baseHp"
symbol = if n < 1 || n > 9 then '@' else Char.intToDigit n
name = findHeroName config n
- mk = hero {nhpMin = bHp, nhpMax = bHp, nsymbol = symbol, nname = name }
+ mk = hero {nhpMin = bHP, nhpMax = bHP, nsymbol = symbol, nname = name }
loc = nearbyFreeLoc ploc state
- startHp = bHp `div` (min 10 (n + 1))
- m = template mk startHp loc
+ startHP = bHP `div` (min 10 (n + 1))
+ m = template mk startHP loc
in updateLevel (updateHeroes (IM.insert n m)) state
-- | Create a set of initial heroes on the current level, at location ploc.
View
6 src/Turn.hs
@@ -41,7 +41,7 @@ import Version
--
-- What's happening where:
--
--- handle: HP regeneration, determine who moves next,
+-- handle: determine who moves next,
-- dispatch to handleMonsters or handlePlayer
--
-- handlePlayer: remember, display, get and process commmand(s),
@@ -51,7 +51,7 @@ import Version
--
-- handleMonster: determine and process monster action, advance monster time
--
--- nextMove: advance global game time, monster generation
+-- nextMove: advance global game time, HP regeneration, monster generation
--
-- This is rather convoluted, and the functions aren't named very aptly, so we
-- should clean this up later. TODO.
@@ -66,7 +66,6 @@ handle =
pl <- gets splayer
let ptime = mtime (getPlayerBody state) -- time of hero's next move
let time = stime state -- current game time
- regenerate pl -- heroes regenerate even if outside the player's turn
debug $ "handle: time check. ptime = " ++ show ptime ++ ", time = " ++ show time
if ptime > time
then do
@@ -134,6 +133,7 @@ nextMove =
do
debug "nextMove"
modify (updateTime (+1))
+ regenerateLevelHP
generateMonster
handle

0 comments on commit 3efa011

Please sign in to comment.