Use NewIntMap InvInt for crInv
This commit is contained in:
@@ -13,6 +13,7 @@ module Dodge.Creature.Action (
|
||||
youDropItem,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Dodge.Creature.MoveType
|
||||
import Dodge.Creature.Radius
|
||||
import Dodge.Item.BackgroundEffect
|
||||
@@ -166,14 +167,15 @@ performAction cr w ac = case ac of
|
||||
dropExcept :: Creature -> Int -> World -> World
|
||||
dropExcept cr invid w =
|
||||
foldr (dropItem cr) w . IM.keys $
|
||||
invid `IM.delete` _crInv cr
|
||||
-- invid `IM.delete` _crInv cr
|
||||
invid `IM.delete` (_unNIntMap $ _crInv cr)
|
||||
|
||||
-- why not a cid (Int)?
|
||||
dropItem :: Creature -> Int -> World -> World
|
||||
dropItem cr invid w' =
|
||||
doanyitemdropeffect
|
||||
. maybeshiftseldown
|
||||
. rmInvItem (_crID cr) invid
|
||||
. rmInvItem (_crID cr) (NInt invid)
|
||||
. copyItemToFloor (_crPos cr) itm -- . mayberemoveequip
|
||||
. soundStart (CrSound (_crID cr)) (_crPos cr) whiteNoiseFadeOutS Nothing
|
||||
$ w'
|
||||
@@ -183,7 +185,7 @@ dropItem cr invid w' =
|
||||
-- return $ doInvEffect rmf itm cr
|
||||
doanyitemdropeffect = itEffectOnDrop itm cr
|
||||
itm = fromMaybe (error "dropItem cannot find item") $ do
|
||||
itid <- cr ^? crInv . ix invid
|
||||
itid <- cr ^? crInv . ix (NInt invid)
|
||||
w' ^? cWorld . lWorld . items . ix itid
|
||||
maybeshiftseldown w = fromMaybe w $ do
|
||||
3 <- w ^? hud . hudElement . diSelection . _Just . _1
|
||||
@@ -193,8 +195,8 @@ dropItem cr invid w' =
|
||||
youDropItem :: World -> World
|
||||
youDropItem w = fromMaybe w $ do
|
||||
curpos <-
|
||||
cr ^? crManipulation . manObject . imSelectedItem
|
||||
<|> fmap fst (IM.lookupMax (cr ^. crInv))
|
||||
cr ^? crManipulation . manObject . imSelectedItem . unNInt
|
||||
<|> fmap fst (IM.lookupMax (cr ^. crInv . unNIntMap))
|
||||
--guard $ not $ _crInvLock cr
|
||||
guard $ not $ w ^. cWorld . lWorld . lInvLock
|
||||
return $ case cr ^. crStance . posture of
|
||||
|
||||
@@ -9,17 +9,17 @@ import Dodge.Creature.ChaseCrit
|
||||
import Dodge.Data.Creature
|
||||
import Dodge.Default
|
||||
--import Dodge.Item.Equipment
|
||||
import qualified IntMapHelp as IM
|
||||
--import qualified IntMapHelp as IM
|
||||
|
||||
flockArmourChaseCrit :: Creature
|
||||
flockArmourChaseCrit =
|
||||
defaultCreature
|
||||
{ _crName = "armourChaseCrit"
|
||||
, _crHP = 300
|
||||
, _crInv =
|
||||
IM.fromList
|
||||
[ --(0, frontArmour)
|
||||
]
|
||||
, _crInv = mempty
|
||||
-- IM.fromList
|
||||
-- [ --(0, frontArmour)
|
||||
-- ]
|
||||
, _crActionPlan =
|
||||
ActionPlan
|
||||
{ _apImpulse = []
|
||||
@@ -36,11 +36,11 @@ armourChaseCrit :: Creature
|
||||
armourChaseCrit =
|
||||
chaseCrit
|
||||
{ _crName = "armourChaseCrit"
|
||||
, --, _crUpdate = defaultImpulsive []
|
||||
_crInv =
|
||||
IM.fromList
|
||||
[ --(0, frontArmour)
|
||||
]
|
||||
-- , --, _crUpdate = defaultImpulsive []
|
||||
-- _crInv =
|
||||
-- IM.fromList
|
||||
-- [ --(0, frontArmour)
|
||||
-- ]
|
||||
-- , _crMvType = defaultChaseMvType{_mvTurnRad = FloatConst 0.05}
|
||||
}
|
||||
& crEquipment . at OnChest ?~ 0
|
||||
|
||||
@@ -4,6 +4,7 @@ module Dodge.Creature.Impulse (
|
||||
impulsiveAIBefore,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Dodge.Creature.MoveType
|
||||
import Data.Foldable
|
||||
import Control.Monad.State
|
||||
@@ -51,7 +52,7 @@ followImpulse cr w imp = case imp of
|
||||
UseItem -> undefined
|
||||
-- UseItem -> (useSelectedItem $ _crID cr
|
||||
-- , cr)
|
||||
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty
|
||||
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem (NInt i) (NInt i) mempty
|
||||
Melee cid' ->
|
||||
( hitCr cid'
|
||||
, crMvAbsolute (w ^. cWorld . lWorld) (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crType . meleeCooldown .~ 20
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
module Dodge.Creature.Impulse.UseItem (useItem) where
|
||||
|
||||
import NewInt
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Data.ComposedItem
|
||||
@@ -13,7 +14,7 @@ import Dodge.HeldUse
|
||||
import Dodge.Inventory
|
||||
import Dodge.Item.Grammar
|
||||
import Dodge.Item.Location
|
||||
import qualified IntMapHelp as IM
|
||||
--import qualified IntMapHelp as IM
|
||||
|
||||
useItem :: Int -> Int -> World -> Maybe World
|
||||
useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
|
||||
@@ -62,7 +63,7 @@ activateDetonator det = fromMaybe id $ do
|
||||
pjid <- det ^? dtValue . _1 . itUse . uaParams . apProjectiles . ix 0
|
||||
return $ cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 0
|
||||
|
||||
toggleEquipmentAt :: Int -> Creature -> World -> World
|
||||
toggleEquipmentAt :: NewInt InvInt -> Creature -> World -> World
|
||||
toggleEquipmentAt invid cr w = case getEquipmentAllocation invid w of
|
||||
DoNotMoveEquipment -> w
|
||||
PutOnEquipment{_allocNewPos = newp} ->
|
||||
@@ -94,11 +95,12 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation invid w of
|
||||
& toitems . ix itid . itLocation . ilEquipSite .~ Nothing
|
||||
& onremove itm cr
|
||||
where
|
||||
invidtoitid i = _crInv cr IM.! i
|
||||
invidtoitid :: NewInt InvInt -> Int
|
||||
invidtoitid i = cr ^?! crInv . ix i -- _crInv cr IM.! i
|
||||
toitems = cWorld . lWorld . items
|
||||
itid = _crInv cr IM.! invid
|
||||
itid = invidtoitid invid
|
||||
crpoint = cWorld . lWorld . creatures . ix (_crID cr)
|
||||
itmat i = w ^?! cWorld . lWorld . items . ix (_crInv cr IM.! i)
|
||||
itmat i = w ^?! cWorld . lWorld . items . ix (invidtoitid i)
|
||||
itm = itmat invid
|
||||
onequip itm' = effectOnEquip itm'
|
||||
onremove itm' = effectOnRemove itm'
|
||||
|
||||
@@ -11,7 +11,7 @@ module Dodge.Creature.Inanimate (
|
||||
import Dodge.Creature.Lamp
|
||||
import Dodge.Data.Creature
|
||||
import Dodge.Default
|
||||
import qualified IntMapHelp as IM
|
||||
--import qualified IntMapHelp as IM
|
||||
--import LensHelp
|
||||
|
||||
barrel :: Creature
|
||||
@@ -19,7 +19,7 @@ barrel =
|
||||
defaultInanimate
|
||||
{ _crHP = 500
|
||||
, _crType = BarrelCrit PlainBarrel
|
||||
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
-- , _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
}
|
||||
|
||||
explosiveBarrel :: Creature
|
||||
@@ -27,6 +27,6 @@ explosiveBarrel =
|
||||
defaultInanimate
|
||||
{ _crHP = 400
|
||||
, _crType = BarrelCrit (ExplosiveBarrel [])
|
||||
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
-- , _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
}
|
||||
-- & crMaterial .~ Crystal
|
||||
|
||||
@@ -132,8 +132,8 @@ copierItemUpdate itm cr w = fromMaybe w $ do
|
||||
x <- itm ^? itScroll . itsInt
|
||||
invid <- itm ^? itLocation . ilInvID
|
||||
ip <- itm ^? itType . ibtPathing
|
||||
i <- getInventoryPath x ip invid cr
|
||||
itm' <- cr ^? crInv . ix i >>= \k -> w ^? cWorld . lWorld . items . ix k
|
||||
i <- getInventoryPath x ip (_unNInt invid) cr
|
||||
itm' <- cr ^? crInv . ix (NInt i) >>= \k -> w ^? cWorld . lWorld . items . ix k
|
||||
v <- getItemValue itm' w cr
|
||||
return $ w & pointerToItem itm . itUse . uValue .~ v
|
||||
|
||||
@@ -170,7 +170,7 @@ trySynthBullet loc w = fromMaybe w $ do
|
||||
if x < 100
|
||||
then do
|
||||
bat <- loc ^? locDT . dtLeft . ix 0 . dtValue . _1
|
||||
j <- bat ^? itLocation . ilInvID
|
||||
j <- bat ^? itID . unNInt
|
||||
y <- bat ^. itConsumables
|
||||
guard $ y > 0
|
||||
return $ w
|
||||
|
||||
@@ -6,6 +6,7 @@ module Dodge.Creature.Statistics (
|
||||
crIntelligence,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Dodge.Data.LWorld
|
||||
import Data.Maybe
|
||||
import qualified IntMapHelp as IM
|
||||
@@ -54,8 +55,8 @@ equipmentStrValue itm = case _itType itm of
|
||||
EQUIP POWERLEGS -> 3
|
||||
_ -> 0
|
||||
|
||||
crCurrentEquipment :: LWorld -> Creature -> IM.IntMap Item
|
||||
crCurrentEquipment lw = IM.filter (isJust . (^? itLocation . ilEquipSite . _Just)) . fmap f . _crInv
|
||||
crCurrentEquipment :: LWorld -> Creature -> NewIntMap InvInt Item
|
||||
crCurrentEquipment lw = over unNIntMap (IM.filter (isJust . (^? itLocation . ilEquipSite . _Just))) . fmap f . _crInv
|
||||
where
|
||||
f i = lw ^?! items . ix i
|
||||
|
||||
@@ -63,7 +64,8 @@ strFromHeldItem :: LWorld -> Creature -> Int
|
||||
strFromHeldItem lw cr = fromMaybe 0 $ do
|
||||
Aiming <- cr ^? crStance . posture
|
||||
i <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
fmap (negate . itemWeight) $ lw ^? items . ix i
|
||||
j <- cr ^? crInv . ix i
|
||||
fmap (negate . itemWeight) $ lw ^? items . ix j
|
||||
|
||||
itemWeight :: Item -> Int
|
||||
itemWeight it = case it ^. itType of
|
||||
|
||||
@@ -24,6 +24,7 @@ module Dodge.Creature.Test (
|
||||
crSafeDistFromTarg,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Dodge.Item.Grammar
|
||||
import Dodge.Creature.Radius
|
||||
@@ -97,7 +98,7 @@ crInAimStance as m cr = crIsAiming cr && mitstance == Just as
|
||||
mitstance = do
|
||||
i <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
--itm <- invRootTrees' (cr ^. crInv) ^? ix i
|
||||
itm <- fmap (fmap (\(a,b,_) -> (a,b))) $ invIMDT (fmap (\k -> m ^?! ix k) (cr ^. crInv)) ^? ix i
|
||||
itm <- fmap (fmap (\(a,b,_) -> (a,b))) $ invIMDT (fmap (\k -> m ^?! ix k) (cr ^. crInv)) ^? ix (_unNInt i)
|
||||
return $ aimStance itm
|
||||
--cr ^? crInv . ix i . itUse . heldAim . aimStance
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module Dodge.Creature.Update (updateCreature) where
|
||||
|
||||
import NewInt
|
||||
import Color
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import qualified Data.List as List
|
||||
@@ -116,7 +117,7 @@ poisonSPic = _1 %~ overColSH (mixColors 0.5 0.5 green . normalizeColor)
|
||||
|
||||
-- reverse keys, otherwise two or more inv items will cause errors
|
||||
dropAll :: Creature -> World -> World
|
||||
dropAll cr w = foldl' (flip (dropItem cr)) w . reverse . IM.keys $ _crInv cr
|
||||
dropAll cr w = foldl' (flip (dropItem cr)) w . reverse . IM.keys . _unNIntMap $ _crInv cr
|
||||
|
||||
chasmTest :: Creature -> World -> World
|
||||
chasmTest cr w
|
||||
|
||||
@@ -57,7 +57,7 @@ handleHotkeys w
|
||||
w ^. input . pressedKeys
|
||||
, Just itid <- lw ^? hotkeys . ix hk . unNInt
|
||||
, Just invid <- lw ^? items . ix itid . itLocation . ilInvID =
|
||||
w & invSetSelectionPos 0 invid
|
||||
w & invSetSelectionPos 0 (_unNInt invid)
|
||||
| otherwise =
|
||||
M.foldl'
|
||||
useHotkey
|
||||
@@ -70,7 +70,7 @@ handleHotkeys w
|
||||
|
||||
useHotkey :: World -> (NewInt ItmInt, Int) -> World
|
||||
useHotkey w (NInt itid, pt) = fromMaybe w $ do
|
||||
invid <- w ^? cWorld . lWorld . items . ix itid . itLocation . ilInvID
|
||||
invid <- w ^? cWorld . lWorld . items . ix itid . itLocation . ilInvID . unNInt
|
||||
useItem invid pt w
|
||||
|
||||
hotkeyToScancode :: Hotkey -> SDL.Scancode
|
||||
@@ -231,6 +231,6 @@ tryClickUse pkeys w = fromMaybe w $ do
|
||||
^? cWorld . lWorld . creatures . ix 0
|
||||
. crManipulation
|
||||
. manObject
|
||||
. imSelectedItem of
|
||||
. imSelectedItem . unNInt of
|
||||
Just invid -> useItem invid ltime w
|
||||
Nothing -> interactWithCloseObj <$> getSelectedCloseObj w ?? w
|
||||
|
||||
Reference in New Issue
Block a user