Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

create a separate file for in-game effects

  • Loading branch information...
commit 7be79d75b45bbda5792c2a907aee22f554d64926 1 parent c5c829a
@Mikolaj Mikolaj authored
View
2  LambdaHack.cabal
@@ -25,7 +25,7 @@ executable LambdaHack
main-is: LambdaHack.hs
hs-source-dirs:src
other-modules: Action, Actions, Color, Command, Config, ConfigDefault,
- Display, Dungeon, DungeonState, File,
+ Display, Dungeon, DungeonState, Effect, File,
FOV, FOV.Common, FOV.Digital, FOV.Permissive, FOV.Shadow,
Frequency, Geometry, GeometryRnd, Grammar,
HighScores, Item, ItemKind, ItemState,
View
5 src/Actions.hs
@@ -33,6 +33,7 @@ import State
import qualified Config
import qualified Save
import Terrain
+import qualified Effect
displayHistory :: Action ()
displayHistory =
@@ -639,7 +640,7 @@ drinkPotion =
-- the potion is identified after drinking
discover i'
case ItemKind.jeffect (ItemKind.getIK (ikind i')) of -- TODO: redo
- (ItemKind.AffectHP n) -> do
+ (Effect.AffectHP n) -> do
messageAdd "You feel better."
let php p = min (nhpMax (mkind p)) (mhp p + n)
updatePlayerBody (\ p -> p { mhp = php p })
@@ -897,7 +898,7 @@ actorAttackActor source target = do
let -- Determine the weapon used for the attack.
weapon = strongestWeapon (mitems sm)
-- TODO: redo
- damage = case weapon of Just (Item { ikind = ik, ipower = k }) -> (case ItemKind.jeffect (ItemKind.getIK ik) of ItemKind.AffectHP n -> - n + k; _ -> 3) ; _ -> 3
+ damage = case weapon of Just (Item { ikind = ik, ipower = k }) -> (case ItemKind.jeffect (ItemKind.getIK ik) of Effect.AffectHP n -> - n + k; _ -> 3) ; _ -> 3
weaponMsg = if damage == 3
then ""
else " with a (+" ++ show (damage - 3) ++ ") sword" -- TODO: generate proper message
View
19 src/Effect.hs
@@ -0,0 +1,19 @@
+module Effect where
+
+data Effect =
+ NoEffect
+ | AffectHP Int -- base damage, to-dam bonus in Item
+ | Dominate
+ | SummonFriend
+ | SummonEnemy
+ deriving (Show, Eq, Ord)
+
+effectToName :: Effect -> String
+effectToName NoEffect = ""
+effectToName (AffectHP n)
+ | n > 0 = "of healing (" ++ show n ++ ")"
+ | n < 0 = "" -- "(base dmg " ++ show (-n) ++ ")"
+ | otherwise = "of life"
+effectToName Dominate = "of domination"
+effectToName SummonFriend = "of aid calling"
+effectToName SummonEnemy = "of summoning"
View
1  src/Grammar.hs
@@ -11,6 +11,7 @@ import MovableKind
import State
import ItemState
import ItemKind
+import Effect
-- | How to refer to a movable in object position of a sentence.
objectMovable :: MovableKind -> String
View
19 src/ItemKind.hs
@@ -5,6 +5,7 @@ import qualified Data.List as L
import qualified Data.IntMap as IM
import Color
+import Effect
data ItemKind = ItemKind
{ jsymbol :: !Char
@@ -22,14 +23,6 @@ type Roll = (Word8, Word8, Word8, Word8)
type Flavour = (Color, Bool) -- the flag tells to use fancy color names
-data Effect =
- NoEffect
- | AffectHP Int -- base damage, to-dam bonus in Item
- | Dominate
- | SummonFriend
- | SummonEnemy
- deriving (Show, Eq, Ord)
-
rollOne = (1, 0, 0, 0)
zipPlain cs = L.zip cs (repeat False)
@@ -46,16 +39,6 @@ flavourToName (c, True) = colorToName' c
flavourToColor :: Flavour -> Color
flavourToColor (c, _) = c
-effectToName :: Effect -> String
-effectToName NoEffect = ""
-effectToName (AffectHP n)
- | n > 0 = "of healing (" ++ show n ++ ")"
- | n < 0 = "" -- "(base dmg " ++ show (-n) ++ ")"
- | otherwise = "of life"
-effectToName Dominate = "of domination"
-effectToName SummonFriend = "of aid calling"
-effectToName SummonEnemy = "of summoning"
-
dungeonLoot :: IM.IntMap ItemKind
dungeonLoot = IM.fromDistinctAscList (L.zip [0..] loot)
Please sign in to comment.
Something went wrong with that request. Please try again.