First implementation of ammo distribution via machine
This commit is contained in:
@@ -41,6 +41,7 @@ tryPutItemInInv cid itid w = do
|
||||
& cWorld . lWorld . items . ix itid . itLocation .~ itloc
|
||||
& cWorld . lWorld . floorItems . at itid .~ Nothing
|
||||
& updateselectionextra invid
|
||||
& cWorld . highlightItems . at itid ?~ 20
|
||||
where
|
||||
updateselectionextra i
|
||||
| cid == 0 = (hud . diSelection . _Just . slSet %~ IS.map (f i))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
module Dodge.Item.MagAmmoType (
|
||||
magAmmoType,
|
||||
magMax,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
@@ -24,3 +25,6 @@ mAT = \case
|
||||
SHELLMAG -> LauncherAmmo
|
||||
BATTERY -> ElectricalAmmo
|
||||
CHEMFUELPOUCH -> GasAmmo
|
||||
|
||||
magMax :: Item -> Maybe Int
|
||||
magMax _ = Just 100
|
||||
|
||||
@@ -6,6 +6,10 @@ module Dodge.WorldEffect (
|
||||
doTmWdWd,
|
||||
) where
|
||||
|
||||
import Data.Traversable (mapAccumR)
|
||||
import Dodge.Item.MagAmmoType
|
||||
import qualified Data.IntSet as IS
|
||||
import Dodge.Data.AmmoType
|
||||
import Color
|
||||
import Dodge.Terminal
|
||||
import NewInt
|
||||
@@ -115,13 +119,35 @@ tmDistributeAmmo tm w = fromMaybe w $ do
|
||||
sid <- w ^? cWorld . lWorld . machines . ix mid
|
||||
. mcType . mcdStorageMachine . _Just
|
||||
McStorage atype aamount <- w ^? cWorld . lWorld . machines . ix sid . mcType
|
||||
return $ w & cWorld . lWorld . terminals . ix (tm ^. tmID) . tmStatus
|
||||
.~ TerminalPressTo ""
|
||||
let (x',w') = distributeAmmoToYou atype aamount w
|
||||
return $ w'
|
||||
& cWorld . lWorld . machines . ix sid . mcType . mcsAmount .~ x'
|
||||
& cWorld . lWorld . terminals . ix (tm ^. tmID) . tmFutureLines .~
|
||||
[TLine 1 [TerminalLineConst "" yellow] (TmTmSetStatus (TerminalPressTo "RETRY"))
|
||||
[TLine 1 [TerminalLineConst (show x' <>" "<>show atype<>" REMAINING IN STORAGE") white] TmWdId
|
||||
,TLine 1 [TerminalLineConst "" yellow] (TmTmSetStatus (TerminalPressTo "RETRY"))
|
||||
,TLine 1 [TerminalLineConst "" white] TmWdWdPowerDownTerminal
|
||||
]
|
||||
|
||||
distributeAmmoToYou :: AmmoType -> Int -> World -> (Int,World)
|
||||
distributeAmmoToYou atype x w = fromMaybe (0,w) $ do
|
||||
is <- fmap IM.elems $ w ^? cWorld . lWorld . creatures . ix 0 . crInv . unNIntMap
|
||||
let itms = IM.filter (\itm -> magAmmoType itm == Just atype) $
|
||||
IM.restrictKeys (w ^. cWorld . lWorld . items) (IS.fromList is)
|
||||
(x',itmams) = mapAccumR distributeAmmoToItem x itms
|
||||
return (x', IM.foldlWithKey' f w itmams)
|
||||
where
|
||||
f w' i y = w' & cWorld . highlightItems . at i ?~ 20
|
||||
& cWorld . lWorld . items . ix i . itConsumables . _Just .~ y
|
||||
|
||||
|
||||
distributeAmmoToItem :: Int -> Item -> (Int,Int)
|
||||
distributeAmmoToItem x itm = fromMaybe (x,0) $ do
|
||||
m <- magMax itm
|
||||
cur <- itm ^. itConsumables
|
||||
let d = m - cur
|
||||
t = min x d
|
||||
return (x-t,cur+t)
|
||||
|
||||
resetTerminal :: TerminalStatus -> Terminal -> World -> World
|
||||
resetTerminal x tm =
|
||||
(cWorld . lWorld . terminals . ix (_tmID tm) . tmStatus .~ x)
|
||||
|
||||
Reference in New Issue
Block a user