summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-11-12 15:11:59 +0100
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-11-12 15:11:59 +0100
commitcf4bda4d1c9a5e3e57c0b2682c7647d811a31740 (patch)
tree097ec5c1f6ab241310b65c84866d331416feb509
parent0b448ae4be1718af7221a051e3be55347820ebc3 (diff)
download2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar
2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.gz
2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.bz2
2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.tar.xz
2017-01-16_17:13:37-cf4bda4d1c9a5e3e57c0b2682c7647d811a31740.zip
probabilistic focus
-rw-r--r--src/Main.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 3b7b3f5..54ec08a 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -53,6 +53,8 @@ import Sequence.Contact.Tests
53import Sequence.Utils 53import Sequence.Utils
54import Sequence.Formula 54import Sequence.Formula
55 55
56import Numeric.Probability.Game.Event (EventM, makeEventProb, enact)
57
56import Text.Layout.Table 58import Text.Layout.Table
57 59
58import Text.Read (readMaybe) 60import Text.Read (readMaybe)
@@ -82,6 +84,7 @@ main = do
82 , helpCommand "help" 84 , helpCommand "help"
83 , cmd "entities" listEntities "List all entities" 85 , cmd "entities" listEntities "List all entities"
84 , cmd "tip" focusTip "Focus the entity at the top of the queue" 86 , cmd "tip" focusTip "Focus the entity at the top of the queue"
87 , cmd "ptip" pFocusTip "Focus a random entity"
85 , cmd "focus" setFocus "Focus a specific entity" 88 , cmd "focus" setFocus "Focus a specific entity"
86 , cmd "blur" blur "Focus no entity" 89 , cmd "blur" blur "Focus no entity"
87 , cmd "remove" remove "Remove the focused entity from the queue" 90 , cmd "remove" remove "Remove the focused entity from the queue"
@@ -213,9 +216,21 @@ listFactions = use inhabitedFactions >>= mapM_ (shellPutStrLn . view faction')
213listEntities = use (gEntities . to Map.keys) >>= mapM_ (shellPutStrLn <=< toName) 216listEntities = use (gEntities . to Map.keys) >>= mapM_ (shellPutStrLn <=< toName)
214 217
215-- Automatic focus 218-- Automatic focus
216focusTip, blur :: Sh GameState () 219focusTip, blur, pFocusTip :: Sh GameState ()
217focusTip = gFocus <~ preuse tip 220focusTip = gFocus <~ preuse tip
218blur = gFocus .= Nothing 221blur = gFocus .= Nothing
222pFocusTip = do
223 round <- use gRound
224 let
225 eWeight :: Maybe SeqVal -> Int
226 eWeight sVal
227 | preview (_Just . seqRound . _Wrapped) sVal == Just round
228 , (preview (_Just . seqVal . _Just) -> Just n) <- sVal = n
229 | otherwise = 0
230 entities <- map (over _2 . view $ eSeqVal . to eWeight) . Map.toList <$> use gEntities
231 case entities of
232 [] -> gFocus .= Nothing
233 _ -> gFocus <~ Just <$> liftIO (enact $ makeEventProb entities)
219 234
220-- Manual focus 235-- Manual focus
221setFocus :: Completable EntityIdentifier -> Sh GameState () 236setFocus :: Completable EntityIdentifier -> Sh GameState ()