diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-10 14:02:54 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-10 14:02:54 +0200 |
commit | d8b49cbe1aff7cb3fcacac01d36128a248fc848b (patch) | |
tree | a006809f338a88a13c11dde14dd56782d0870ccd /src/Main.hs | |
parent | 736e78441ae8b0cffa610de4baa7248f726cf69c (diff) | |
download | 2017-01-16_17:13:37-d8b49cbe1aff7cb3fcacac01d36128a248fc848b.tar 2017-01-16_17:13:37-d8b49cbe1aff7cb3fcacac01d36128a248fc848b.tar.gz 2017-01-16_17:13:37-d8b49cbe1aff7cb3fcacac01d36128a248fc848b.tar.bz2 2017-01-16_17:13:37-d8b49cbe1aff7cb3fcacac01d36128a248fc848b.tar.xz 2017-01-16_17:13:37-d8b49cbe1aff7cb3fcacac01d36128a248fc848b.zip |
More sequence fu
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/Main.hs b/src/Main.hs index f46fd3e..e6d694a 100644 --- a/src/Main.hs +++ b/src/Main.hs | |||
@@ -78,26 +78,33 @@ main = do | |||
78 | , cmd "test" rollTest "Roll a test using the stats of the currently focused entity" | 78 | , cmd "test" rollTest "Roll a test using the stats of the currently focused entity" |
79 | , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat" | 79 | , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat" |
80 | , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat" | 80 | , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat" |
81 | , cmd "spend" spendSeq "Spend some of the current focusĀ“ AP" | ||
82 | , cmd "delay" delay "Spend AP until the current focusĀ“ sequence is no higher than the next highest" | ||
81 | ] | 83 | ] |
82 | } | 84 | } |
83 | void $ runShell description haskelineBackend (def :: GameState) | 85 | void $ runShell description haskelineBackend (def :: GameState) |
84 | 86 | ||
85 | stateOutline :: GameState -> String | 87 | stateOutline :: GameState -> String |
86 | stateOutline st | 88 | stateOutline st |
87 | | null pQueue = "" | 89 | | null (st ^. priorityQueue) = "" |
88 | | otherwise = layoutTableToString rowGs (Just ("" : factions, repeat def)) (repeat def) unicodeBoldHeaderS | 90 | | otherwise = unlines . map table $ st ^. gRounds' |
89 | where | 91 | where |
92 | table round = layoutTableToString rowGs (Just (roundStr round : factions, repeat def)) (repeat def) unicodeBoldHeaderS | ||
93 | where | ||
94 | pQueue = filter (\(v, _) -> round == v ^. seqRound . _Wrapped)$ st ^. priorityQueue | ||
95 | protoRows = groupBy ((==) `on` fst) pQueue | ||
96 | faction id = fromJust $ view eFaction <$> Map.lookup id (st ^. gEntities) | ||
97 | factionIndex id = fromJust $ elemIndex (view faction' $ faction id) factions | ||
98 | rowGs = do | ||
99 | rowGroup'@((seq, _):_) <- protoRows | ||
100 | let | ||
101 | rowGroup = map snd rowGroup' | ||
102 | factionColumn i = [evalState ?? st $ toName x | x <- rowGroup, factionIndex x == i ] | ||
103 | return . colsAllG top $ [maybe "" show $ view seqVal seq] : map factionColumn [0..(length factions - 1)] | ||
104 | roundStr 0 = "Current Round" | ||
105 | roundStr 1 = "Next Round" | ||
106 | roundStr n = show n ++ " Rounds later" | ||
90 | factions = map (view faction') $ st ^. inhabitedFactions | 107 | factions = map (view faction') $ st ^. inhabitedFactions |
91 | pQueue = st ^. priorityQueue | ||
92 | protoRows = groupBy ((==) `on` fst) pQueue | ||
93 | faction id = fromJust $ view eFaction <$> Map.lookup id (st ^. gEntities) | ||
94 | factionIndex id = fromJust $ elemIndex (view faction' $ faction id) factions | ||
95 | rowGs = do | ||
96 | rowGroup'@((seq, _):_) <- protoRows | ||
97 | let | ||
98 | rowGroup = map snd rowGroup' | ||
99 | factionColumn i = [evalState ?? st $ toName x | x <- rowGroup, factionIndex x == i ] | ||
100 | return . colsAllG top $ [show $ view seqVal seq] : map factionColumn [0..(length factions - 1)] | ||
101 | 108 | ||
102 | -- Query state | 109 | -- Query state |
103 | listFactions, listEntities :: Sh GameState () | 110 | listFactions, listEntities :: Sh GameState () |
@@ -203,6 +210,21 @@ entitySeqVal' ident = void . runMaybeT $ do | |||
203 | round <- use gRound | 210 | round <- use gRound |
204 | (newEntity, sNum) <- evalFormula name entity sVal | 211 | (newEntity, sNum) <- evalFormula name entity sVal |
205 | let val = Just $ def | 212 | let val = Just $ def |
206 | & set seqRound round | 213 | & set (seqRound . _Wrapped) round |
207 | & set seqVal (Just sNum) | 214 | & set seqVal (Just sNum) |
215 | & set seqEpsilon (entity ^. eStats . sSeqEpsilon) | ||
208 | gEntities . at ident .= Just (newEntity & set eSeqVal val) | 216 | gEntities . at ident .= Just (newEntity & set eSeqVal val) |
217 | |||
218 | spendSeq :: Int -> Sh GameState () | ||
219 | spendSeq n = withFocus $ \focusId -> do | ||
220 | gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just -= n | ||
221 | |||
222 | delay :: Sh GameState () | ||
223 | delay = withFocus $ \focusId -> () <$ runMaybeT (delay' focusId) | ||
224 | where | ||
225 | delay' focusId = do | ||
226 | tipId <- MaybeT $ preuse tip | ||
227 | tipSeq <- MaybeT . preuse $ gEntities . ix tipId . eStats . sSequence . _Just . seqVal . _Just | ||
228 | focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just | ||
229 | guard $ focusSeq > tipSeq | ||
230 | lift . spendSeq $ focusSeq - tipSeq | ||