summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs
index a38b514..e93d725 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -31,10 +31,12 @@ import Data.List
31import Data.List 31import Data.List
32import Data.Maybe 32import Data.Maybe
33import Data.Bool 33import Data.Bool
34import Data.Monoid (All(..))
34 35
35import Data.Function 36import Data.Function
36 37
37import Control.Monad.State.Strict 38import Control.Monad.State.Strict
39import Control.Monad.Reader
38import Control.Monad.Trans.Maybe 40import Control.Monad.Trans.Maybe
39import Control.Monad.List 41import Control.Monad.List
40 42
@@ -157,9 +159,28 @@ stateMaintenance = do
157 isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious) 159 isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious)
158 guard $ isDead || isUnconscious 160 guard $ isDead || isUnconscious
159 when isDead . lift . shellPutStrLn $ name ++ " died" 161 when isDead . lift . shellPutStrLn $ name ++ " died"
160 when isUnconscious . lift . shellPutStrLn $ name ++ " is unconscious" 162 when (isUnconscious && not isDead) . lift . shellPutStrLn $ name ++ " is unconscious"
161 gFocus' . eSeqVal .= Nothing 163 gFocus' . eSeqVal .= Nothing
162 gFocus .= Nothing 164 gFocus .= Nothing
165 void $ do
166 round <- use gRound
167 let
168 finished sVal = fromMaybe False (previews (seqVal . _Just) (<= 0) sVal) || view (seqRound . _Wrapped) sVal /= round
169 allFinished <- getAll . foldMapOf (gEntities . each . eStats . sSequence . _Just) (All . finished) <$> get
170 when allFinished $ do
171 let
172 advanceRound' :: EntityIdentifier -> Entity -> Sh GameState Entity
173 advanceRound' ident entity = fmap (fromMaybe entity . (\(m, s) -> s <$ m)) . (runStateT ?? entity) . runMaybeT $ do
174 cRound <- MaybeT . preuse $ eStats . sSequence . _Just . seqRound . _Wrapped
175 guard $ cRound < 0
176 cVal <- MaybeT . preuse $ eStats . sSequence . _Just . seqVal . _Just
177 name <- lift . lift $ toName ident
178 nVal' <- MaybeT . preuse $ eStats . sSeqVal
179 nVal <- MaybeT . focusState eStats $ evalFormula' name nVal'
180 eStats . sSequence . _Just . seqVal . _Just += nVal
181 eStats . sSequence . _Just . seqRound . _Wrapped += 1
182 gRounds -= 1
183 gEntities <~ (imapM advanceRound' =<< use gEntities)
163 184
164-- Query state 185-- Query state
165listFactions, listEntities :: Sh GameState () 186listFactions, listEntities :: Sh GameState ()