Permalink
Browse files

rename the Monster/Hero type to Movable

  • Loading branch information...
Mikolaj committed Mar 7, 2011
1 parent d0c1b04 commit 41125e8ce9733b2c3bf52cf3983d9c529b5ca554
Showing with 83 additions and 81 deletions.
  1. +23 −23 src/Actions.hs
  2. +3 −3 src/Actor.hs
  3. +2 −2 src/Display2.hs
  4. +26 −26 src/Grammar.hs
  5. +7 −7 src/Level.hs
  6. +20 −18 src/Monster.hs
  7. +1 −1 src/StrategyState.hs
  8. +1 −1 src/Turn.hs
View
@@ -83,7 +83,7 @@ endTargeting accept = do
modify (updateCursor (\ c -> c { clocation = ploc }))
let heroMsg = "Hero number " ++ show (heroNumber player)
targetMsg = case target of
- TEnemy i -> objectMonster (mtype (monsters !! i))
+ TEnemy i -> objectMovable (mtype (monsters !! i))
TLoc loc -> "location " ++ show loc
TCursor -> "current cursor position continuously"
end = if accept then "." else "!"
@@ -143,7 +143,7 @@ continueRun dir =
do
state <- get
let lvl@(Level { lmonsters = ms, lmap = lmap, lheroes = hs }) = slevel state
- let player@(Monster { mloc = loc }) = splayer state
+ let player@(Movable { mloc = loc }) = splayer state
let mslocs = S.fromList (L.map mloc ms)
let t = lmap `at` loc -- tile at current location
per <- currentPerception
@@ -281,7 +281,7 @@ actorOpenClose actor v o dir =
-- door is in unsuitable state
abortIfWith isVerbose ("already " ++ txt)
| not (unoccupied ms lmap dloc) ->
- -- door is blocked by a monster
+ -- door is blocked by a monster; TODO: consider heroes, too
abortIfWith isVerbose "blocked"
| otherwise -> -- door can be opened / closed
-- TODO: print message if action performed by monster and perceived
@@ -488,7 +488,7 @@ search :: Action ()
search =
do
Level { lmap = lmap } <- gets slevel
- Monster { mloc = ploc } <- gets splayer
+ Movable { mloc = ploc } <- gets splayer
let searchTile (Tile (Door hv (Just n)) x,t') = Just (Tile (Door hv (Just (max (n - 1) 0))) x, t')
searchTile t = Just t
slmap = foldl (\ l m -> update searchTile (shift ploc m) l) lmap moves
@@ -572,7 +572,7 @@ doLook =
let monsterMsg =
if S.member loc (pvisible per)
then case L.find (\ m -> mloc m == loc) ms of
- Just m -> subjectMonster (mtype m) ++ " is here. "
+ Just m -> subjectMovable (mtype m) ++ " is here. "
Nothing -> ""
else ""
mode = case target of
@@ -612,7 +612,7 @@ drinkPotion =
do
state <- get
let lvl @(Level { lmap = lmap }) = slevel state
- let player@(Monster { mloc = ploc }) = splayer state
+ let player@(Movable { mloc = ploc }) = splayer state
if L.null (mitems player)
then abortWith "You are not carrying anything."
else do
@@ -639,7 +639,7 @@ dropItem :: Action ()
dropItem =
do
state <- get
- let player@(Monster { mloc = ploc }) = splayer state
+ let player@(Movable { mloc = ploc }) = splayer state
if L.null (mitems player)
then abortWith "You are not carrying anything."
else do
@@ -682,33 +682,33 @@ actorPickupItem actor =
state <- get
per <- currentPerception
let lvl@(Level { lmap = lmap }) = slevel state
- let monster = getActor state actor
- let loc = mloc monster
+ let movable = getActor state actor
+ let loc = mloc movable
let t = lmap `at` loc -- the map tile in question
let perceived = loc `S.member` pvisible per
let isPlayer = actor == APlayer
-- check if something is here to pick up
case titems t of
[] -> abortIfWith isPlayer "nothing here"
(i:rs) -> -- pick up first item; TODO: let player select item; not for monsters
- case assignLetter (iletter i) (mletter monster) (mitems monster) of
+ case assignLetter (iletter i) (mletter movable) (mitems movable) of
Just l ->
do
- let (ni, nitems) = joinItem (i { iletter = Just l }) (mitems monster)
+ let (ni, nitems) = joinItem (i { iletter = Just l }) (mitems movable)
-- message is dependent on who picks up and if the hero can perceive it
if isPlayer
then message (letterLabel (iletter ni) ++ objectItem state (icount ni) (itype ni))
else when perceived $
- message $ subjectCompoundVerbIObject state monster "pick" "up" i ""
+ message $ subjectCompoundVerbIObject state movable "pick" "up" i ""
removeFromLoc i loc
-- add item to actor's inventory:
updateActor actor $ \ m ->
- m { mitems = nitems, mletter = maxLetter l (mletter monster) }
+ m { mitems = nitems, mletter = maxLetter l (mletter movable) }
Nothing -> abortIfWith isPlayer "you cannot carry any more"
-- | Replaces the version in Actor module
updateActor :: Actor -> -- ^ who to update
- (Monster -> Monster) -> -- ^ the update
+ (Movable -> Movable) -> -- ^ the update
Action ()
updateActor (AMonster n) f =
do
@@ -828,9 +828,9 @@ moveOrAttack allowAttacks autoOpen actor dir
-- | Resolves the result of an actor moving into a passive target. Usually this
-- involves melee attack, but with two heroes it just changes focus.
--- Monsters on blocked locations can be attacked without any restrictions.
--- For instance, a monster on an open door can be attacked diagonally,
--- and a monster capable of moving through walls can be attacked from an
+-- Movables on blocked locations can be attacked without any restrictions.
+-- For instance, a movable on an open door can be attacked diagonally,
+-- and a movable capable of moving through walls can be attacked from an
-- adjacent position.
-- TODO: When monsters have permanent number (right now their actor number
-- is just the temporary position on the monsters list), do not pass
@@ -839,15 +839,15 @@ moveOrAttack allowAttacks autoOpen actor dir
-- then be enough.
-- TODO: This function and the next show the shortcomings of the actor
-- mechanism, since here we need to query and modify not only actors.
--- but also monsters/heroes that are passive targets of the actions.
+-- but also movables that are passive targets of the actions.
-- To fix this, we should either consider everybody an actor all the time
-- (add permanent monster number and add (AHero n) actors)
-- or forgo actors alltogether and just pass around and modify
--- values of the Monster type and, when done, overwrite with them
+-- values of the Movable type and, when done, overwrite with them
-- their old copy stored on a level (as we currently do with target heroes,
-- without the need for their actor representation).
actorAttackActor :: Actor -> -- the attacker, the actual actor
- (Actor, Monster) -> -- the passive target
+ (Actor, Movable) -> -- the passive target
Action ()
actorAttackActor APlayer (APlayer, tm) = do -- TODO: do not take a turn!!!
-- Select adjacent hero by bumping into him.
@@ -896,9 +896,9 @@ actorAttackActor actor (target, tm) =
in modify (updateLevel (updateMonsters upd))
-- | Resolves the result of an actor running into a passive target.
--- This involves switching positions of the two monsters/heroes.
+-- This involves switching positions of the two movables.
-- Always takes time.
-actorRunActor :: Actor -> (Actor, Monster) -> Action ()
+actorRunActor :: Actor -> (Actor, Movable) -> Action ()
actorRunActor actor (target, tm) = do
state <- get
let sm = getActor state actor
@@ -939,7 +939,7 @@ regenerate :: Actor -> Action ()
regenerate actor =
do
time <- gets stime
- -- TODO: remove hardcoded time interval, regeneration should be an attribute of the monster
+ -- TODO: remove hardcoded time interval, regeneration should be an attribute of the movable
let upd m = m { mhp = min (mhpmax m) (mhp m + 1) }
when (time `mod` 1500 == 0) $ do
updateActor actor upd
View
@@ -8,14 +8,14 @@ data Actor = AMonster Int -- offset in monster list
| APlayer
deriving (Show, Eq)
-getActor :: State -> Actor -> Monster
+getActor :: State -> Actor -> Movable
getActor (State { slevel = lvl, splayer = p }) a =
case a of
AMonster n -> lmonsters lvl !! n
APlayer -> p
-updateActor :: (Monster -> Monster) -> -- the update
- (Monster -> State -> IO a) -> -- continuation
+updateActor :: (Movable -> Movable) -> -- the update
+ (Movable -> State -> IO a) -> -- continuation
Actor -> -- who to update
State -> IO a -- transformed continuation
updateActor f k (AMonster n) state@(State { slevel = lvl, splayer = p }) =
View
@@ -142,7 +142,7 @@ stringByLocation sy xs =
displayLevel :: Session -> Perception -> State -> Message -> Maybe String -> IO Bool
displayLevel session per
- (state@(State { splayer = player@(Monster { mhpmax = phpmax, mhp = php, mdir = pdir, mloc = ploc }),
+ (state@(State { splayer = player@(Movable { mhpmax = phpmax, mhp = php, mdir = pdir, mloc = ploc }),
stime = time,
sassocs = assocs,
slevel = lvl@(Level nm hs sz@(sy,sx) ms smap nlmap lmeta) }))
@@ -173,7 +173,7 @@ displayLevel session per
rea = S.member loc reachable
(rv,ra) = case L.find (\ m -> loc == mloc m) (hs ++ ms) of
_ | sTer > 0 -> viewTerrain sTer False (tterrain tile)
- Just m | sOmn || vis -> viewMonster (mtype m) (mtype m == mtype player)
+ Just m | sOmn || vis -> viewMovable (mtype m) (mtype m == mtype player)
_ | sSml && sml >= 0 -> viewSmell sml
| otherwise -> viewTile vis tile assocs
vision =
View
@@ -7,26 +7,26 @@ import Monster
import State
import ItemState
--- | How to refer to a monster in object position of a sentence.
-objectMonster :: MonsterType -> String
+-- | How to refer to a movable in object position of a sentence.
+objectMovable :: MovableType -> String
-- Hard to make it compatible with 1-hero mode and sounds strange, anyway.
--- objectMonster (Hero n) = "hero " ++ show n
-objectMonster (Hero _) = "you"
-objectMonster Eye = "the reducible eye"
-objectMonster FastEye = "the super-fast eye"
-objectMonster Nose = "the point-free nose"
+-- objectMovable (Hero n) = "hero " ++ show n
+objectMovable (Hero _) = "you"
+objectMovable Eye = "the reducible eye"
+objectMovable FastEye = "the super-fast eye"
+objectMovable Nose = "the point-free nose"
--- | How to refer to a monster in subject position of a sentence.
-subjectMonster :: MonsterType -> String
-subjectMonster x = let (s:r) = objectMonster x in toUpper s : r
+-- | How to refer to a movable in subject position of a sentence.
+subjectMovable :: MovableType -> String
+subjectMovable x = let (s:r) = objectMovable x in toUpper s : r
-verbMonster :: MonsterType -> String -> String
-verbMonster (Hero _) v = v
-verbMonster _ v = v ++ "s"
+verbMovable :: MovableType -> String -> String
+verbMovable (Hero _) v = v
+verbMovable _ v = v ++ "s"
-compoundVerbMonster :: MonsterType -> String -> String -> String
-compoundVerbMonster (Hero _) v p = v ++ " " ++ p
-compoundVerbMonster _ v p = v ++ "s " ++ p
+compoundVerbMovable :: MovableType -> String -> String -> String
+compoundVerbMovable (Hero _) v p = v ++ " " ++ p
+compoundVerbMovable _ v p = v ++ "s " ++ p
objectItem :: State -> Int -> ItemType -> String
objectItem _ n Ring = makeObject n id "ring"
@@ -38,21 +38,21 @@ objectItem _ n Gem = makeObject n id "gem"
objectItem _ n Gold = makeObject n id "gold piece"
objectItem _ n (Sword i) = makeObject n id ("(+" ++ show i ++ ") sword")
-subjectVerbIObject :: State -> Monster -> String -> Item -> String -> String
+subjectVerbIObject :: State -> Movable -> String -> Item -> String -> String
subjectVerbIObject state m v o add =
- subjectMonster (mtype m) ++ " " ++
- verbMonster (mtype m) v ++ " " ++
+ subjectMovable (mtype m) ++ " " ++
+ verbMovable (mtype m) v ++ " " ++
objectItem state (icount o) (itype o) ++ add ++ "."
-subjectVerbMObject :: State -> Monster -> String -> Monster -> String -> String
+subjectVerbMObject :: State -> Movable -> String -> Movable -> String -> String
subjectVerbMObject state m v o add =
- subjectMonster (mtype m) ++ " " ++
- verbMonster (mtype m) v ++ " " ++
- objectMonster (mtype o) ++ add ++ "."
+ subjectMovable (mtype m) ++ " " ++
+ verbMovable (mtype m) v ++ " " ++
+ objectMovable (mtype o) ++ add ++ "."
-subjectCompoundVerbIObject :: State -> Monster -> String -> String ->
+subjectCompoundVerbIObject :: State -> Movable -> String -> String ->
Item -> String -> String
subjectCompoundVerbIObject state m v p o add =
- subjectMonster (mtype m) ++ " " ++
- compoundVerbMonster (mtype m) v p ++ " " ++
+ subjectMovable (mtype m) ++ " " ++
+ compoundVerbMovable (mtype m) v p ++ " " ++
objectItem state (icount o) (itype o) ++ add ++ "."
View
@@ -74,11 +74,11 @@ instance Binary Dungeon where
-- that level.
type DungeonLoc = (LevelName, Loc)
-type LMonsters = IM.IntMap Monster
+type LMovables = IM.IntMap Movable
data Level = Level
{ lname :: LevelName,
- lheroes :: LMonsters, -- ^ all but the current selected hero on the level
+ lheroes :: LMovables, -- ^ all but the current selected hero on the level
lsize :: (Y,X),
lmonsters :: [Monster],
lsmell :: SMap,
@@ -95,10 +95,10 @@ updateSMap f lvl = lvl { lsmell = f (lsmell lvl) }
updateMonsters :: ([Monster] -> [Monster]) -> Level -> Level
updateMonsters f lvl = lvl { lmonsters = f (lmonsters lvl) }
-updateHeroes :: (LMonsters -> LMonsters) -> Level -> Level
+updateHeroes :: (LMovables -> LMovables) -> Level -> Level
updateHeroes f lvl = lvl { lheroes = f (lheroes lvl) }
-lmEmpty :: LMonsters
+lmEmpty :: LMovables
lmEmpty = IM.empty
instance Binary Level where
@@ -355,9 +355,9 @@ posToDir O = moves
-- checks for the presence of monsters (and items); it does *not* check
-- if the tile is open ...
-unoccupied :: [Monster] -> LMap -> Loc -> Bool
-unoccupied monsters _lmap loc =
- all (\ m -> mloc m /= loc) monsters
+unoccupied :: [Movable] -> LMap -> Loc -> Bool
+unoccupied movables _lmap loc =
+ all (\ m -> mloc m /= loc) movables
-- check whether one location is accessible from the other
-- precondition: the two locations are next to each other
Oops, something went wrong.

0 comments on commit 41125e8

Please sign in to comment.