Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

multiple heroes: Tab cycles heroes also in look mode

So it's now possible to move more than one hero to levels > 1.
  • Loading branch information...
commit 4e1f146e16b872308847da65dd54cd268f6e7052 1 parent 0417f4f
Mikolaj Konarski Mikolaj authored
Showing with 24 additions and 4 deletions.
  1. +18 −4 src/Actions.hs
  2. +3 −0  src/Level.hs
  3. +3 −0  src/State.hs
22 src/Actions.hs
View
@@ -285,17 +285,31 @@ fleeDungeon =
end
-- | Switches current hero to the next hero on the level, if any, wrapping.
--- TODO: extend to look mode, which is tricky when visiting other levels.
-- TODO: extend to number keys switching to heroes on any levels.
cycleHero =
do
state <- get
let player = splayer state
i = playerNumber player
+ pls = lplayers (slevel state)
case slook state of
- Just (_loc, _tgt, _ln) -> abortWith "not implemented in look mode"
- Nothing ->
- let (lt, gt) = IM.split i (lplayers (slevel state))
+ Just (_loc, _tgt, ln)
+ | ln /= lname (slevel state) ->
+ case IM.assocs pls of
+ [] -> abortWith "No heroes on this level."
+ (ni, np) : _ ->
+ do
+ let ins = IM.insert i player
+ pli = updatePlayers ins
+ del = IM.delete ni
+ nln = lname (slevel state)
+ modify (updateDungeon (updateDungeonLevel pli ln))
+ modify (updateLevel (updatePlayers del))
+ modify (updatePlayer (const np))
+ modify (updateLook (const $ Just (_loc, _tgt, nln)))
+ messageAdd "A hero selected."
+ _ ->
+ let (lt, gt) = IM.split i pls
in case IM.assocs gt ++ IM.assocs lt of
[] -> abortWith "Only one hero on this level."
(ni, np) : _ ->
3  src/Level.hs
View
@@ -63,6 +63,9 @@ getDungeonLevel ln (Dungeon dng) = (dng ! ln, Dungeon (M.delete ln dng))
putDungeonLevel :: Level -> Dungeon -> Dungeon
putDungeonLevel lvl (Dungeon dng) = Dungeon (M.insert (lname lvl) lvl dng)
+updateDungeonLevel :: (Level -> Level) -> LevelName -> Dungeon -> Dungeon
+updateDungeonLevel f ln (Dungeon dng) = Dungeon (M.adjust f ln dng)
+
sizeDungeon :: Dungeon -> Int
sizeDungeon (Dungeon dng) = M.size dng
3  src/State.hs
View
@@ -69,6 +69,9 @@ updateDiscoveries f s = s { sdiscoveries = f (sdiscoveries s) }
updateLevel :: (Level -> Level) -> State -> State
updateLevel f s = s { slevel = f (slevel s) }
+updateDungeon :: (Dungeon -> Dungeon) -> State -> State
+updateDungeon f s = s {sdungeon = f (sdungeon s)}
+
updateTime :: (Time -> Time) -> State -> State
updateTime f s = s { stime = f (stime s) }
Please sign in to comment.
Something went wrong with that request. Please try again.