Permalink
Browse files

rename Actor type to ActorId

(1/2) of #11 (comment)
  • Loading branch information...
1 parent a6e2b80 commit a72f56630e970b176dfca68a354167404d69ffc6 @Mikolaj Mikolaj committed Aug 16, 2011
Showing with 48 additions and 47 deletions.
  1. +2 −2 src/Action.hs
  2. +4 −4 src/Actions.hs
  3. +4 −4 src/EffectAction.hs
  4. +10 −10 src/ItemAction.hs
  5. +9 −9 src/Movable.hs
  6. +9 −9 src/MovableState.hs
  7. +5 −4 src/Perception.hs
  8. +1 −1 src/State.hs
  9. +3 −3 src/StrategyState.hs
  10. +1 −1 src/Turn.hs
View
@@ -228,7 +228,7 @@ checkCursor h = do
then h
else abortWith "this command does not work on remote levels"
-updateAnyActor :: Actor -> (Movable -> Movable) -> Action ()
+updateAnyActor :: ActorId -> (Movable -> Movable) -> Action ()
updateAnyActor actor f = modify (updateAnyActorBody actor f)
updatePlayerBody :: (Movable -> Movable) -> Action ()
@@ -237,7 +237,7 @@ updatePlayerBody f = do
updateAnyActor pl f
-- | Advance the move time for the given actor.
-advanceTime :: Actor -> Action ()
+advanceTime :: ActorId -> Action ()
advanceTime actor = do
time <- gets stime
let upd m = m { mtime = time + (nspeed (mkind m)) }
View
@@ -236,7 +236,7 @@ openclose o =
pl <- gets splayer
K.handleDirection e (actorOpenClose pl True o) (neverMind True)
-actorOpenClose :: Actor ->
+actorOpenClose :: ActorId ->
Bool -> -- ^ verbose?
Bool -> -- ^ open?
Dir -> Action ()
@@ -504,7 +504,7 @@ doLook =
-- i.e., it can handle monsters, heroes and both.
moveOrAttack :: Bool -> -- allow attacks?
Bool -> -- auto-open doors on move
- Actor -> -- who's moving?
+ ActorId -> -- who's moving?
Dir ->
Action ()
moveOrAttack allowAttacks autoOpen actor dir
@@ -557,7 +557,7 @@ moveOrAttack allowAttacks autoOpen actor dir
-- adjacent position.
-- This function is analogous to zapGroupItem, but for melee
-- and not using up the weapon.
-actorAttackActor :: Actor -> Actor -> Action ()
+actorAttackActor :: ActorId -> ActorId -> Action ()
actorAttackActor (AHero _) target@(AHero _) =
-- Select adjacent hero by bumping into him. Takes no time.
assertTrue $ selectPlayer target
@@ -593,7 +593,7 @@ attackToVerb _ = "hit"
-- | Resolves the result of an actor running into another.
-- This involves switching positions of the two movables.
-actorRunActor :: Actor -> Actor -> Action ()
+actorRunActor :: ActorId -> ActorId -> Action ()
actorRunActor source target = do
pl <- gets splayer
sloc <- gets (mloc . getActor source) -- source location
View
@@ -44,7 +44,7 @@ import qualified Effect
-- TODO: separately define messages for the case when source == target
-- and for the other case; then use the messages outside of effectToAction,
-- depending on the returned bool, perception and identity of the actors.
-effectToAction :: Effect.Effect -> Actor -> Actor -> Int ->
+effectToAction :: Effect.Effect -> ActorId -> ActorId -> Int ->
Action (Bool, String)
effectToAction Effect.NoEffect source target power = nullEffect
effectToAction Effect.Heal _source target power = do
@@ -123,7 +123,7 @@ nullEffect = return (False, "Nothing happens.")
-- | The source actor affects the target actor, with a given item.
-- If either actor is a hero, the item may get identified.
-itemEffectAction :: Actor -> Actor -> Item -> Action Bool
+itemEffectAction :: ActorId -> ActorId -> Item -> Action Bool
itemEffectAction source target item = do
state <- get
pl <- gets splayer
@@ -163,7 +163,7 @@ discover i = do
-- | Make the actor controlled by the player.
-- Focus on the actor if level changes. False, if nothing to do.
-selectPlayer :: Actor -> Action Bool
+selectPlayer :: ActorId -> Action Bool
selectPlayer actor =
do
pl <- gets splayer
@@ -191,7 +191,7 @@ selectPlayer actor =
messageAdd $ subjectMovable (mkind pbody) ++ " selected."
return True
-focusIfAHero :: Actor -> Action ()
+focusIfAHero :: ActorId -> Action ()
focusIfAHero target =
if isAHero target
then do
View
@@ -63,9 +63,9 @@ getGroupItem is groupName prompt packName =
header = capitalize $ suffixS groupName
in getItem prompt choice header is packName
-applyGroupItem :: Actor -> -- actor applying the item; on current level
- String -> -- how the "applying" is called
- Item -> -- the item to be applied
+applyGroupItem :: ActorId -> -- actor applying the item; on current level
+ String -> -- how the "applying" is called
+ Item -> -- the item to be applied
Action ()
applyGroupItem actor verb item = do
state <- get
@@ -103,10 +103,10 @@ quaffPotion = playerApplyGroupItem "potion"
readScroll :: Action ()
readScroll = playerApplyGroupItem "scroll"
-zapGroupItem :: Actor -> -- actor zapping the item; on current level
- Loc -> -- target location for the zapping
- String -> -- how the "zapping" is called
- Item -> -- the item to be zapped
+zapGroupItem :: ActorId -> -- actor zapping the item; on current level
+ Loc -> -- target location for the zapping
+ String -> -- how the "zapping" is called
+ Item -> -- the item to be zapped
Action ()
zapGroupItem source loc verb item = do
state <- get
@@ -180,7 +180,7 @@ dropItem = do
-- TODO: this is a hack for dropItem, because removeFromInventory
-- makes it impossible to drop items if the floor not empty.
-removeOnlyFromInventory :: Actor -> Item -> Loc -> Action ()
+removeOnlyFromInventory :: ActorId -> Item -> Loc -> Action ()
removeOnlyFromInventory actor i loc = do
updateAnyActor actor (\ m -> m { mitems = removeItemByLetter i (mitems m) })
@@ -191,7 +191,7 @@ removeOnlyFromInventory actor i loc = do
-- of dead heros/monsters. The subtle incorrectness helps here a lot,
-- because items of dead heroes land on the floor, so we use them up
-- in inventory, but remove them after use from the floor.
-removeFromInventory :: Actor -> Item -> Loc -> Action ()
+removeFromInventory :: ActorId -> Item -> Loc -> Action ()
removeFromInventory actor i loc = do
b <- removeFromLoc i loc
when (not b) $
@@ -210,7 +210,7 @@ removeFromLoc i loc = do
adj = M.adjust (\ (t, rt) -> (remove t, rt)) loc
remove t = t { titems = removeItemByIdentity i (titems t) }
-actorPickupItem :: Actor -> Action ()
+actorPickupItem :: ActorId -> Action ()
actorPickupItem actor = do
state <- get
pl <- gets splayer
View
@@ -43,31 +43,31 @@ instance Binary Movable where
mtime <- get
return (Movable mk mhp md tgt ml minv mletter mtime)
-data Actor = AHero Int -- ^ hero index (on the lheroes intmap)
- | AMonster Int -- ^ monster index (on the lmonsters intmap)
+data ActorId = AHero Int -- ^ hero index (on the lheroes intmap)
+ | AMonster Int -- ^ monster index (on the lmonsters intmap)
deriving (Show, Eq, Ord)
-isAHero :: Actor -> Bool
+isAHero :: ActorId -> Bool
isAHero (AHero _) = True
isAHero (AMonster _) = False
-isAMonster :: Actor -> Bool
+isAMonster :: ActorId -> Bool
isAMonster = not . isAHero
-instance Binary Actor where
+instance Binary ActorId where
put (AHero n) = putWord8 0 >> put n
put (AMonster n) = putWord8 1 >> put n
get = do
tag <- getWord8
case tag of
0 -> liftM AHero get
1 -> liftM AMonster get
- _ -> fail "no parse (Actor)"
+ _ -> fail "no parse (ActorId)"
data Target =
- TEnemy Actor Loc -- ^ fire at the actor; last seen location
- | TLoc Loc -- ^ fire at a given location
- | TCursor -- ^ fire at the current position of the cursor; default
+ TEnemy ActorId Loc -- ^ fire at the actor; last seen location
+ | TLoc Loc -- ^ fire at a given location
+ | TCursor -- ^ fire at the current position of the cursor; default
deriving (Show, Eq)
instance Binary Target where
View
@@ -18,7 +18,7 @@ import State
-- All the other actor and level operations only consider the current level.
-- | Finds an actor body on any level. Error if not found.
-findActorAnyLevel :: Actor -> State -> Maybe (LevelName, Movable)
+findActorAnyLevel :: ActorId -> State -> Maybe (LevelName, Movable)
findActorAnyLevel actor state@(State { slevel = lvl,
sdungeon = Dungeon m }) =
let chk lvl =
@@ -34,14 +34,14 @@ getPlayerBody state = snd $ fromMaybe (error "getPlayerBody") $
-- | The list of actors and levels for all heroes in the dungeon.
-- Heroes from the current level go first.
-allHeroesAnyLevel :: State -> [(Actor, LevelName)]
+allHeroesAnyLevel :: State -> [(ActorId, LevelName)]
allHeroesAnyLevel state =
let Dungeon m = sdungeon state
one (Level { lname = ln, lheroes = hs }) =
L.map (\ (i, _) -> (AHero i, ln)) (IM.assocs hs)
in L.concatMap one (slevel state : M.elems m)
-updateAnyActorBody :: Actor -> (Movable -> Movable) -> State -> State
+updateAnyActorBody :: ActorId -> (Movable -> Movable) -> State -> State
updateAnyActorBody actor f state =
case findActorAnyLevel actor state of
Just (ln, _) ->
@@ -74,28 +74,28 @@ targetToLoc visible state =
-- The operations below disregard levels other than the current.
-- | Checks if the actor is present on the current level.
-memActor :: Actor -> State -> Bool
+memActor :: ActorId -> State -> Bool
memActor a (State { slevel = lvl }) =
case a of
AHero n -> IM.member n (lheroes lvl)
AMonster n -> IM.member n (lmonsters lvl)
-- | Gets actor body from the current level. Error if not found.
-getActor :: Actor -> State -> Movable
+getActor :: ActorId -> State -> Movable
getActor a (State { slevel = lvl }) =
case a of
AHero n -> lheroes lvl IM.! n
AMonster n -> lmonsters lvl IM.! n
-- | Removes the actor, if present, from the current level.
-deleteActor :: Actor -> State -> State
+deleteActor :: ActorId -> State -> State
deleteActor a =
case a of
AHero n -> updateLevel (updateHeroes (IM.delete n))
AMonster n -> updateLevel (updateMonsters (IM.delete n))
-- | Add actor to the current level.
-insertActor :: Actor -> Movable -> State -> State
+insertActor :: ActorId -> Movable -> State -> State
insertActor a m =
case a of
AHero n -> updateLevel (updateHeroes (IM.insert n m))
@@ -106,13 +106,13 @@ levelHeroList (State { slevel = Level { lheroes = hs } }) = IM.elems hs
levelMonsterList (State { slevel = Level { lmonsters = ms } }) = IM.elems ms
-- | Finds an actor at a location on the current level. Perception irrelevant.
-locToActor :: Loc -> State -> Maybe Actor
+locToActor :: Loc -> State -> Maybe ActorId
locToActor loc state =
let l = locToActors loc state
in assert (L.length l <= 1) $
listToMaybe l
-locToActors :: Loc -> State -> [Actor]
+locToActors :: Loc -> State -> [ActorId]
locToActors loc state =
getIndex (lmonsters, AMonster) ++ getIndex (lheroes, AHero)
where
View
@@ -32,7 +32,7 @@ ptreachable = preachable . ptotal
ptvisible = pvisible . ptotal
actorPrLoc :: (Perception -> S.Set Loc) ->
- Actor -> Loc -> Perceptions -> Maybe Actor -> Bool
+ ActorId -> Loc -> Perceptions -> Maybe ActorId -> Bool
actorPrLoc projection actor loc per pl =
let tryHero = case actor of
AMonster _ -> Nothing
@@ -46,14 +46,15 @@ actorPrLoc projection actor loc per pl =
tryAny = tryHero `mplus` tryPl
in fromMaybe False tryAny -- assume not visible, if no perception found
-actorSeesLoc :: Actor -> Loc -> Perceptions -> Maybe Actor -> Bool
+actorSeesLoc :: ActorId -> Loc -> Perceptions -> Maybe ActorId -> Bool
actorSeesLoc = actorPrLoc pvisible
-actorReachesLoc :: Actor -> Loc -> Perceptions -> Maybe Actor -> Bool
+actorReachesLoc :: ActorId -> Loc -> Perceptions -> Maybe ActorId -> Bool
actorReachesLoc = actorPrLoc preachable
-- Not quite correct if FOV not symmetric (Shadow).
-actorReachesActor :: Actor -> Actor -> Loc -> Loc -> Perceptions -> Maybe Actor
+actorReachesActor :: ActorId -> ActorId -> Loc -> Loc
+ -> Perceptions -> Maybe ActorId
-> Bool
actorReachesActor actor1 actor2 loc1 loc2 per pl =
actorReachesLoc actor1 loc2 per pl ||
View
@@ -21,7 +21,7 @@ import qualified ItemKind
-- TODO: consider changing slevel to LevelName, removing the lname field
-- and not removing the current level from the dungeon.
data State = State
- { splayer :: Actor, -- ^ represents the player-controlled movable
+ { splayer :: ActorId, -- ^ represents the player-controlled movable
scursor :: Cursor, -- ^ cursor location and level to return to
shistory :: [Message],
ssensory :: SensoryMode,
View
@@ -27,7 +27,7 @@ import qualified Effect
-- import Debug.Trace
-strategy :: Actor -> State -> Perceptions -> Strategy (Action ())
+strategy :: ActorId -> State -> Perceptions -> Strategy (Action ())
strategy actor
oldState@(State { scursor = cursor,
splayer = pl,
@@ -164,7 +164,7 @@ strategy actor
.| onlyKeepsDir_9 moveRandomly
.| moveRandomly
-dirToAction :: Actor -> Target -> Bool -> Dir -> Action ()
+dirToAction :: ActorId -> Target -> Bool -> Dir -> Action ()
dirToAction actor tgt allowAttacks dir =
assert (dir /= (0,0)) $ do
-- set new direction
@@ -181,5 +181,5 @@ onlyMoves p l = only (\ x -> p (l `shift` x))
moveRandomly :: Strategy Dir
moveRandomly = liftFrequency $ uniform moves
-wait :: Actor -> Strategy (Action ())
+wait :: ActorId -> Strategy (Action ())
wait actor = return $ advanceTime actor
View
@@ -102,7 +102,7 @@ handleMonsters =
else handleMonster actor
-- | Handle the move of a single monster.
-handleMonster :: Actor -> Action ()
+handleMonster :: ActorId -> Action ()
handleMonster actor =
do
debug "handleMonster"

0 comments on commit a72f566

Please sign in to comment.