Major item refactor, still broken

This commit is contained in:
2025-08-24 19:34:09 +01:00
parent 22b4be440a
commit 94f6d5c630
62 changed files with 820 additions and 805 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+5 -3
View File
@@ -15,13 +15,15 @@ you w = w ^?! cWorld . lWorld . creatures . ix 0
yourSelectedItem :: World -> Maybe Item yourSelectedItem :: World -> Maybe Item
yourSelectedItem w = do yourSelectedItem w = do
i <- you w ^? crManipulation . manObject . imSelectedItem i <- you w ^? crManipulation . manObject . imSelectedItem
_crInv (you w) IM.!? i j <- _crInv (you w) IM.!? i
w ^? cWorld . lWorld . items . ix j
yourRootItem :: World -> Maybe Item yourRootItem :: World -> Maybe Item
yourRootItem w = do yourRootItem w = do
i <- you w ^? crManipulation . manObject . imRootSelectedItem i <- you w ^? crManipulation . manObject . imRootSelectedItem
_crInv (you w) IM.!? i j <- _crInv (you w) IM.!? i
w ^? cWorld . lWorld . items . ix j
yourInv :: World -> IM.IntMap Item yourInv :: World -> IM.IntMap Item
yourInv = _crInv . you yourInv w = fmap (\i -> w ^?! cWorld . lWorld . items . ix i) . _crInv . you $ w
+6 -5
View File
@@ -1,5 +1,6 @@
module Dodge.Bullet (updateBullet) where module Dodge.Bullet (updateBullet) where
import qualified Data.IntMap.Strict as IM
import Dodge.Damage import Dodge.Damage
import Data.Bifunctor import Data.Bifunctor
import Data.Foldable import Data.Foldable
@@ -105,10 +106,10 @@ updateBulVel bt = bt & buVel .*.*~ _buDrag bt
-- tpos <- cr ^? crTargeting . ctPos . _Just -- tpos <- cr ^? crTargeting . ctPos . _Just
-- return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. wCam)) -- return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. wCam))
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2 bounceDir :: IM.IntMap Item -> (Point2, Either Creature Wall) -> Maybe Point2
bounceDir (_, Right wl) | _wlBouncy wl = Just $ uncurry (-) (_wlLine wl) bounceDir _ (_, Right wl) | _wlBouncy wl = Just $ uncurry (-) (_wlLine wl)
bounceDir (p, Left cr) | crIsArmouredFrom p cr = Just $ vNormal $ p - _crPos cr bounceDir m (p, Left cr) | crIsArmouredFrom m p cr = Just $ vNormal $ p - _crPos cr
bounceDir _ = Nothing bounceDir _ _ = Nothing
useBulletPayload :: Bullet -> Point2 -> World -> World useBulletPayload :: Bullet -> Point2 -> World -> World
useBulletPayload bu = case _buPayload bu of useBulletPayload bu = case _buPayload bu of
@@ -154,7 +155,7 @@ hitEffFromBul w bu = case _buEffect bu of
PenetrateBullet -> movePenBullet bu hitstream w PenetrateBullet -> movePenBullet bu hitstream w
BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do
(hp, crwl) <- hitstream ^? _head (hp, crwl) <- hitstream ^? _head
dir <- bounceDir (hp, crwl) dir <- bounceDir (w ^. cWorld . lWorld . items) (hp, crwl)
return return
( w ( w
, bu , bu
+5 -7
View File
@@ -9,12 +9,10 @@ import Dodge.Data.Creature
import Geometry import Geometry
import Shape import Shape
import ShapePicture import ShapePicture
import qualified Data.IntMap.Strict as IM
makeCorpse :: Creature -> Corpse makeCorpse :: IM.IntMap Item -> Creature -> Corpse
makeCorpse = makeDefaultCorpse makeCorpse m cr =
makeDefaultCorpse :: Creature -> Corpse
makeDefaultCorpse cr =
defaultCorpse defaultCorpse
& cpPos .~ _crPos cr & cpPos .~ _crPos cr
& cpDir .~ _crDir cr & cpDir .~ _crDir cr
@@ -22,8 +20,8 @@ makeDefaultCorpse cr =
.~ noPic .~ noPic
( scaleSH (V3 crsize crsize crsize) $ ( scaleSH (V3 crsize crsize crsize) $
mconcat mconcat
[ colorSH (_skinHead cskin) $ deadScalp cr [ colorSH (_skinHead cskin) $ deadScalp m cr
, colorSH (_skinUpper cskin) $ deadUpperBody cr , colorSH (_skinUpper cskin) $ deadUpperBody m cr
, rotmdir $ colorSH (_skinLower cskin) $ deadFeet cr , rotmdir $ colorSH (_skinLower cskin) $ deadFeet cr
] ]
) )
+6 -7
View File
@@ -3,7 +3,7 @@ module Dodge.Creature (
module Dodge.Creature.ChaseCrit, module Dodge.Creature.ChaseCrit,
module Dodge.Creature.Inanimate, module Dodge.Creature.Inanimate,
launcherCrit, launcherCrit,
pistolCrit, -- pistolCrit,
ltAutoCrit, ltAutoCrit,
spreadGunCrit, spreadGunCrit,
autoCrit, autoCrit,
@@ -38,7 +38,6 @@ import Dodge.Creature.Inanimate
import Dodge.Creature.LauncherCrit import Dodge.Creature.LauncherCrit
import Dodge.Creature.LtAutoCrit import Dodge.Creature.LtAutoCrit
import Dodge.Creature.Perception import Dodge.Creature.Perception
import Dodge.Creature.PistolCrit
import Dodge.Creature.ReaderUpdate import Dodge.Creature.ReaderUpdate
import Dodge.Creature.SentinelAI import Dodge.Creature.SentinelAI
import Dodge.Creature.SpreadGunCrit import Dodge.Creature.SpreadGunCrit
@@ -64,28 +63,28 @@ spawnerCrit =
miniGunCrit :: Creature miniGunCrit :: Creature
miniGunCrit = miniGunCrit =
defaultCreature defaultCreature
& crInv .~ IM.fromList [(0, miniGunX 3)] -- & crInv .~ IM.fromList [(0, miniGunX 3)]
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
-- & crType . humanoidAI .~ MiniGunAI -- & crType . humanoidAI .~ MiniGunAI
longCrit :: Creature longCrit :: Creature
longCrit = longCrit =
defaultCreature defaultCreature
& crInv .~ IM.fromList [(0, sniperRifle)] -- & crInv .~ IM.fromList [(0, sniperRifle)]
-- & crType . humanoidAI .~ LongAI -- & crType . humanoidAI .~ LongAI
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
multGunCrit :: Creature multGunCrit :: Creature
multGunCrit = multGunCrit =
defaultCreature defaultCreature
& crInv .~ IM.fromList [(0, volleyGun 4)] -- & crInv .~ IM.fromList [(0, volleyGun 4)]
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
-- & crType . humanoidAI .~ MultGunAI -- & crType . humanoidAI .~ MultGunAI
addArmour :: Creature -> Creature addArmour :: Creature -> Creature
addArmour = over crInv insarmour addArmour = over crInv insarmour
where where
insarmour xs = IM.insert (IM.newKey xs) frontArmour xs insarmour xs = xs -- IM.insert (IM.newKey xs) frontArmour xs
{- | The creature you control. {- | The creature you control.
ID 0. ID 0.
@@ -99,7 +98,7 @@ startCr =
& crMvDir .~ pi / 2 & crMvDir .~ pi / 2
& crID .~ 0 & crID .~ 0
& crHP .~ 10000 & crHP .~ 10000
& crInv .~ startInventory & crInv .~ mempty
& crFaction .~ PlayerFaction & crFaction .~ PlayerFaction
-- & crMvType .~ MvWalking yourDefaultSpeed -- & crMvType .~ MvWalking yourDefaultSpeed
& crType .~ Avatar (PulseStatus 55 0) Flesh 50 50 50 3 & crType .~ Avatar (PulseStatus 55 0) Flesh 50 50 50 3
+5 -2
View File
@@ -170,18 +170,21 @@ dropExcept cr invid w =
-- why not a cid (Int)? -- why not a cid (Int)?
dropItem :: Creature -> Int -> World -> World dropItem :: Creature -> Int -> World -> World
dropItem cr invid = dropItem cr invid w' =
doanyitemdropeffect doanyitemdropeffect
. maybeshiftseldown . maybeshiftseldown
. rmInvItem (_crID cr) invid . rmInvItem (_crID cr) invid
. copyItemToFloor (_crPos cr) itm -- . mayberemoveequip . copyItemToFloor (_crPos cr) itm -- . mayberemoveequip
. soundStart (CrSound (_crID cr)) (_crPos cr) whiteNoiseFadeOutS Nothing . soundStart (CrSound (_crID cr)) (_crPos cr) whiteNoiseFadeOutS Nothing
$ w'
where where
--doanyitemdropeffect = fromMaybe id $ do --doanyitemdropeffect = fromMaybe id $ do
-- rmf <- itm ^? itEffect . ieOnDrop -- rmf <- itm ^? itEffect . ieOnDrop
-- return $ doInvEffect rmf itm cr -- return $ doInvEffect rmf itm cr
doanyitemdropeffect = itEffectOnDrop itm cr doanyitemdropeffect = itEffectOnDrop itm cr
itm = fromMaybe (error "dropItem cannot find item") $ cr ^? crInv . ix invid itm = fromMaybe (error "dropItem cannot find item") $ do
itid <- cr ^? crInv . ix invid
w' ^? cWorld . lWorld . items . ix itid
maybeshiftseldown w = fromMaybe w $ do maybeshiftseldown w = fromMaybe w $ do
3 <- w ^? hud . hudElement . diSelection . _Just . _1 3 <- w ^? hud . hudElement . diSelection . _Just . _1
return $ w & hud . hudElement . diSelection . _Just . _2 +~ 1 return $ w & hud . hudElement . diSelection . _Just . _2 +~ 1
+2 -2
View File
@@ -18,7 +18,7 @@ flockArmourChaseCrit =
, _crHP = 300 , _crHP = 300
, _crInv = , _crInv =
IM.fromList IM.fromList
[ (0, frontArmour) [ --(0, frontArmour)
] ]
, _crActionPlan = , _crActionPlan =
ActionPlan ActionPlan
@@ -39,7 +39,7 @@ armourChaseCrit =
, --, _crUpdate = defaultImpulsive [] , --, _crUpdate = defaultImpulsive []
_crInv = _crInv =
IM.fromList IM.fromList
[ (0, frontArmour) [ --(0, frontArmour)
] ]
-- , _crMvType = defaultChaseMvType{_mvTurnRad = FloatConst 0.05} -- , _crMvType = defaultChaseMvType{_mvTurnRad = FloatConst 0.05}
} }
+2 -2
View File
@@ -12,8 +12,8 @@ import qualified IntMapHelp as IM
autoCrit :: Creature autoCrit :: Creature
autoCrit = autoCrit =
defaultCreature defaultCreature
{ _crInv = IM.fromList [(0, autoRifle)] { --_crInv = IM.fromList [(0, autoRifle)]
, _crHP = 300 _crHP = 300
-- , _crMvType = defaultAimMvType -- , _crMvType = defaultAimMvType
} }
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
+2 -2
View File
@@ -21,8 +21,8 @@ smallChaseCrit =
invisibleChaseCrit :: Creature invisibleChaseCrit :: Creature
invisibleChaseCrit = invisibleChaseCrit =
chaseCrit chaseCrit
& crInv . at 0 ?~ wristInvisibility -- & crInv . at 0 ?~ wristInvisibility
& crEquipment . at OnLeftWrist ?~ 0 -- & crEquipment . at OnLeftWrist ?~ 0
chaseCrit :: Creature chaseCrit :: Creature
chaseCrit = chaseCrit =
+4 -3
View File
@@ -20,9 +20,10 @@ applyIndividualDamage cr w dm = damMatSideEffect dm (crMaterial (_crType cr)) (L
_ -> w & damageHP cr (_dmAmount dm) _ -> w & damageHP cr (_dmAmount dm)
applyPiercingDamage :: Creature -> Damage -> World -> World applyPiercingDamage :: Creature -> Damage -> World -> World
applyPiercingDamage cr dm applyPiercingDamage cr dm w
| crIsArmouredFrom p cr = f . makeSpark NormalSpark p1 (argV (p1 - p)) | crIsArmouredFrom (w ^. cWorld . lWorld . items) p cr
| otherwise = f . damageHP cr (_dmAmount dm) = f . makeSpark NormalSpark p1 (argV (p1 - p)) $ w
| otherwise = f . damageHP cr (_dmAmount dm) $ w
where where
f = cWorld . lWorld . creatures . ix (_crID cr) . crPos +~ _dmVector dm f = cWorld . lWorld . creatures . ix (_crID cr) . crPos +~ _dmVector dm
/ V2 x x / V2 x x
+51 -40
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.HandPos ( module Dodge.Creature.HandPos (
translatePointToLeftHand, translatePointToLeftHand,
translatePointToRightHand, translatePointToRightHand,
@@ -14,6 +15,8 @@ module Dodge.Creature.HandPos (
headPQ, headPQ,
) where ) where
import Dodge.Data.Equipment.Misc
import qualified Data.IntMap.Strict as IM
import qualified Quaternion as Q import qualified Quaternion as Q
import Control.Lens import Control.Lens
import Dodge.Creature.Test import Dodge.Creature.Test
@@ -21,14 +24,22 @@ import Dodge.Data.Creature
import Geometry import Geometry
import ShapePicture import ShapePicture
translatePointToRightHand :: Creature -> Point3 -> Point3 translatePointToRightHand :: IM.IntMap Item -> Creature -> Point3 -> Point3
translatePointToRightHand cr p = fst (rightHandPQ cr `Q.comp` (p,Q.qID)) translatePointToRightHand m cr p = fst (rightHandPQ m cr `Q.comp` (p,Q.qID))
rightHandPQ :: Creature -> Point3Q equipSitePQ :: EquipSite -> IM.IntMap Item -> Creature -> Point3Q
rightHandPQ cr equipSitePQ = \case
| oneH cr = (V3 11 (-3) 20, Q.qID) OnRightWrist -> rightHandPQ
| twists cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 4 (-10) 0,Q.qID) OnLeftWrist -> leftHandPQ
| twoFlat cr = (V3 4 (-8) 10, Q.qID) OnBack -> backPQ
OnChest -> chestPQ
_ -> undefined
rightHandPQ :: IM.IntMap Item -> Creature -> Point3Q
rightHandPQ m cr
| oneH m cr = (V3 11 (-3) 20, Q.qID)
| twists m cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 4 (-10) 0,Q.qID)
| twoFlat m cr = (V3 4 (-8) 10, Q.qID)
| otherwise = case cr ^? crStance . carriage of | otherwise = case cr ^? crStance . carriage of
Just (Walking sa LeftForward) -> (V3 (- f sa) (- off) 10, Q.qID) Just (Walking sa LeftForward) -> (V3 (- f sa) (- off) 10, Q.qID)
Just (Walking sa RightForward) -> (V3 (- g sa) (- off) 10, Q.qID) Just (Walking sa RightForward) -> (V3 (- g sa) (- off) 10, Q.qID)
@@ -39,18 +50,18 @@ rightHandPQ cr
f i = negate 2 + negate 6 * (sLen - i) / sLen f i = negate 2 + negate 6 * (sLen - i) / sLen
g i = negate 2 + negate 6 * i / sLen g i = negate 2 + negate 6 * i / sLen
translateToRightHand :: Creature -> SPic -> SPic translateToRightHand :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToRightHand = overPosSP . translatePointToRightHand translateToRightHand m = overPosSP . translatePointToRightHand m
translateToRightWrist :: Creature -> SPic -> SPic translateToRightWrist :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToRightWrist cr = overPosSP translateToRightWrist m cr = overPosSP
(\p -> fst $ rightHandPQ cr `Q.comp` (V3 0 (-4) (-4)+p, Q.qID)) (\p -> fst $ rightHandPQ m cr `Q.comp` (V3 0 (-4) (-4)+p, Q.qID))
leftHandPQ :: Creature -> Point3Q leftHandPQ :: IM.IntMap Item -> Creature -> Point3Q
leftHandPQ cr leftHandPQ m cr
| oneH cr = (V3 0 off 10, Q.qz 0.4) | oneH m cr = (V3 0 off 10, Q.qz 0.4)
| twists cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 12 4 0, Q.qz 0.4) | twists m cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 12 4 0, Q.qz 0.4)
| twoFlat cr = (V3 4 8 10, Q.qID) | twoFlat m cr = (V3 4 8 10, Q.qID)
| otherwise = case cr ^? crStance . carriage of | otherwise = case cr ^? crStance . carriage of
Just (Walking sa RightForward) -> (V3 (- f sa) off 10 , Q.qID) Just (Walking sa RightForward) -> (V3 (- f sa) off 10 , Q.qID)
Just (Walking sa LeftForward) -> (V3 (- g sa) off 10 , Q.qID) Just (Walking sa LeftForward) -> (V3 (- g sa) off 10 , Q.qID)
@@ -61,15 +72,15 @@ leftHandPQ cr
f i = negate 2 + negate 6 * (sLen - i) / sLen f i = negate 2 + negate 6 * (sLen - i) / sLen
g i = negate 2 + negate 6 * i / sLen g i = negate 2 + negate 6 * i / sLen
translatePointToLeftHand :: Creature -> Point3 -> Point3 translatePointToLeftHand :: IM.IntMap Item -> Creature -> Point3 -> Point3
translatePointToLeftHand cr p = fst (leftHandPQ cr `Q.comp` (p,Q.qID)) translatePointToLeftHand m cr p = fst (leftHandPQ m cr `Q.comp` (p,Q.qID))
translateToLeftHand :: Creature -> SPic -> SPic translateToLeftHand :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToLeftHand = overPosSP . translatePointToLeftHand translateToLeftHand m = overPosSP . translatePointToLeftHand m
translateToLeftWrist :: Creature -> SPic -> SPic translateToLeftWrist :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToLeftWrist cr = overPosSP translateToLeftWrist m cr = overPosSP
(\p -> fst $ leftHandPQ cr `Q.comp` (V3 0 4 (-4)+p, Q.qID)) (\p -> fst $ leftHandPQ m cr `Q.comp` (V3 0 4 (-4)+p, Q.qID))
leftLegPQ :: Creature -> Point3Q leftLegPQ :: Creature -> Point3Q
leftLegPQ cr = Q.comp (0,Q.qz (_crMvDir cr - _crDir cr)) leftLegPQ cr = Q.comp (0,Q.qz (_crMvDir cr - _crDir cr))
@@ -102,26 +113,26 @@ rightLegPQ cr = Q.comp (0,Q.qz (_crMvDir cr - _crDir cr))
translateToRightLeg :: Creature -> SPic -> SPic translateToRightLeg :: Creature -> SPic -> SPic
translateToRightLeg cr = overPosSP (\p -> fst (rightLegPQ cr `Q.comp` (p,Q.qID))) translateToRightLeg cr = overPosSP (\p -> fst (rightLegPQ cr `Q.comp` (p,Q.qID)))
translateToHead :: Creature -> SPic -> SPic translateToHead :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToHead cr = overPosSP (\p -> fst (headPQ cr `Q.comp` (p,Q.qID))) translateToHead m cr = overPosSP (\p -> fst (headPQ m cr `Q.comp` (p,Q.qID)))
headPQ :: Creature -> Point3Q headPQ :: IM.IntMap Item -> Creature -> Point3Q
headPQ cr headPQ m cr
| twists cr = (V3 0 2 20, Q.qz (-1)) `Q.comp` (V3 (negate 2.5) 0.25 0, Q.qz 1) | twists m cr = (V3 0 2 20, Q.qz (-1)) `Q.comp` (V3 (negate 2.5) 0.25 0, Q.qz 1)
| oneH cr = (V3 0 0 20, Q.qz 0.5) `Q.comp` (V3 2.5 0 0, Q.qz (-0.5)) | oneH m cr = (V3 0 0 20, Q.qz 0.5) `Q.comp` (V3 2.5 0 0, Q.qz (-0.5))
| otherwise = (V3 2.5 0 20, Q.qID) | otherwise = (V3 2.5 0 20, Q.qID)
translatePointToHead :: Creature -> Point3 -> Point3 translatePointToHead :: IM.IntMap Item -> Creature -> Point3 -> Point3
translatePointToHead cr p = fst (headPQ cr `Q.comp` (p,Q.qID)) translatePointToHead m cr p = fst (headPQ m cr `Q.comp` (p,Q.qID))
chestPQ :: Creature -> Point3Q chestPQ :: IM.IntMap Item -> Creature -> Point3Q
chestPQ cr = backPQ cr `Q.comp` (0,Q.qz pi) chestPQ m cr = backPQ m cr `Q.comp` (0,Q.qz pi)
translateToChest :: Creature -> SPic -> SPic translateToChest :: IM.IntMap Item -> Creature -> SPic -> SPic
translateToChest cr = overPosSP (\p -> fst $ chestPQ cr `Q.comp` (p,Q.qID)) translateToChest m cr = overPosSP (\p -> fst $ chestPQ m cr `Q.comp` (p,Q.qID))
backPQ :: Creature -> Point3Q backPQ :: IM.IntMap Item -> Creature -> Point3Q
backPQ cr backPQ m cr
| oneH cr = (V3 0 0 10, Q.qz 0.5) | oneH m cr = (V3 0 0 10, Q.qz 0.5)
| twists cr = (V3 0 3 10, Q.qz (-1.5)) | twists m cr = (V3 0 3 10, Q.qz (-1.5))
| otherwise = (V3 0 0 10, Q.qz 0) | otherwise = (V3 0 0 10, Q.qz 0)
+4 -4
View File
@@ -42,8 +42,8 @@ followImpulse cr w imp = case imp of
let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w) let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w)
in first ((randGen .~ newgen) .) $ followImpulse cr w newimp in first ((randGen .~ newgen) .) $ followImpulse cr w newimp
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown w cr) Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown w cr)
Move p -> crup $ crMvBy p cr Move p -> crup $ crMvBy p (w ^. cWorld . lWorld) cr
MoveForward x -> crup $ crMvForward x cr MoveForward x -> crup $ crMvForward x (w ^. cWorld . lWorld) cr
Turn a -> crup $ cr & crDir +~ a Turn a -> crup $ cr & crDir +~ a
TurnToward p a -> crup $ creatureTurnToward p a cr TurnToward p a -> crup $ creatureTurnToward p a cr
TurnTo p -> crup $ creatureTurnTo p cr TurnTo p -> crup $ creatureTurnTo p cr
@@ -54,7 +54,7 @@ followImpulse cr w imp = case imp of
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty
Melee cid' -> Melee cid' ->
( hitCr cid' ( hitCr cid'
, crMvAbsolute (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crType . meleeCooldown .~ 20 , crMvAbsolute (w ^. cWorld . lWorld) (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crType . meleeCooldown .~ 20
) )
RandomTurn a -> (randGen .~ snd (rr a), cr & crDir +~ fst (rr a)) RandomTurn a -> (randGen .~ snd (rr a), cr & crDir +~ fst (rr a))
MakeSound sid -> (soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing, cr) MakeSound sid -> (soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing, cr)
@@ -71,7 +71,7 @@ followImpulse cr w imp = case imp of
Just tcr -> followImpulse cr w (doCrImp f tcr) Just tcr -> followImpulse cr w (doCrImp f tcr)
_ -> crup cr _ -> crup cr
ImpulseUseAheadPos f -> followImpulse cr w (doP2Imp f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr))) ImpulseUseAheadPos f -> followImpulse cr w (doP2Imp f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
MvForward -> crup $ crMvForward speed cr MvForward -> crup $ crMvForward speed (w ^. cWorld . lWorld) cr
MvTurnToward p -> MvTurnToward p ->
crup $ crup $
creatureTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir)) cr creatureTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir)) cr
+6 -5
View File
@@ -20,17 +20,18 @@ For now, though, this cannot fail.
crMvBy :: crMvBy ::
-- | Movement translation vector, will be made relative to creature direction -- | Movement translation vector, will be made relative to creature direction
Point2 -> Point2 ->
LWorld ->
Creature -> Creature ->
Creature Creature
crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr crMvBy p lw cr = crMvAbsolute lw (rotateV (_crDir cr) p) cr
crMvAbsolute :: Point2 -> Creature -> Creature crMvAbsolute :: LWorld -> Point2 -> Creature -> Creature
crMvAbsolute p' cr = crMvAbsolute lw p' cr =
advanceStepCounter (magV p) cr advanceStepCounter (magV p) cr
& crPos +~ p & crPos +~ p
& crMvDir .~ argV p & crMvDir .~ argV p
where where
p = strengthFactor (getCrMoveSpeed cr) *.* p' p = strengthFactor (getCrMoveSpeed lw cr) *.* p'
strengthFactor :: Int -> Float strengthFactor :: Int -> Float
strengthFactor i strengthFactor i
@@ -38,7 +39,7 @@ strengthFactor i
| i < 1 = 0 | i < 1 = 0
| otherwise = 0.02 * fromIntegral i | otherwise = 0.02 * fromIntegral i
crMvForward :: Float -> Creature -> Creature crMvForward :: Float -> LWorld -> Creature -> Creature
crMvForward speed = crMvBy (V2 speed 0) crMvForward speed = crMvBy (V2 speed 0)
advanceStepCounter :: Float -> Creature -> Creature advanceStepCounter :: Float -> Creature -> Creature
+12 -9
View File
@@ -18,7 +18,7 @@ import qualified IntMapHelp as IM
useItem :: Int -> Int -> World -> Maybe World useItem :: Int -> Int -> World -> Maybe World
useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- invIndents (_crInv cr) ^? ix invid . _2 itmloc <- invIndents (fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ _crInv cr) ^? ix invid . _2
useItemLoc cr itmloc pt w useItemLoc cr itmloc pt w
useItemLoc :: Creature -> LocationDT OItem -> Int -> World -> Maybe World useItemLoc :: Creature -> LocationDT OItem -> Int -> World -> Maybe World
@@ -68,34 +68,37 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation invid w of
PutOnEquipment{_allocNewPos = newp} -> PutOnEquipment{_allocNewPos = newp} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & toitems . ix itid . itLocation . ilEquipSite ?~ newp
& onequip itm cr & onequip itm cr
MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} -> MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crEquipment . at oldp .~ Nothing & crpoint . crEquipment . at oldp .~ Nothing
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & toitems . ix itid . itLocation . ilEquipSite ?~ newp
SwapEquipment{_allocNewPos = newp, _allocOldPos = oldp, _allocSwapID = sid} -> SwapEquipment{_allocNewPos = newp, _allocOldPos = oldp, _allocSwapID = sid} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crEquipment . at oldp ?~ sid & crpoint . crEquipment . at oldp ?~ sid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & toitems . ix itid . itLocation . ilEquipSite ?~ newp
& crpoint . crInv . ix sid . itLocation . ilEquipSite ?~ oldp & toitems . ix (invidtoitid sid) . itLocation . ilEquipSite ?~ oldp
ReplaceEquipment{_allocNewPos = newp, _allocRemoveID = rid} -> ReplaceEquipment{_allocNewPos = newp, _allocRemoveID = rid} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & toitems . ix itid . itLocation . ilEquipSite ?~ newp
& crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing & toitems . ix (invidtoitid rid) . itLocation . ilEquipSite .~ Nothing
& onremove (itmat rid) cr & onremove (itmat rid) cr
& onequip itm cr & onequip itm cr
RemoveEquipment{_allocOldPos = oldp} -> RemoveEquipment{_allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at oldp .~ Nothing & crpoint . crEquipment . at oldp .~ Nothing
& crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing & toitems . ix itid . itLocation . ilEquipSite .~ Nothing
& onremove itm cr & onremove itm cr
where where
invidtoitid i = _crInv cr IM.! i
toitems = cWorld . lWorld . items
itid = _crInv cr IM.! invid
crpoint = cWorld . lWorld . creatures . ix (_crID cr) crpoint = cWorld . lWorld . creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i itmat i = w ^?! cWorld . lWorld . items . ix (_crInv cr IM.! i)
itm = itmat invid itm = itmat invid
onequip itm' = effectOnEquip itm' onequip itm' = effectOnEquip itm'
onremove itm' = effectOnRemove itm' onremove itm' = effectOnRemove itm'
+2 -2
View File
@@ -12,8 +12,8 @@ import qualified IntMapHelp as IM
launcherCrit :: Creature launcherCrit :: Creature
launcherCrit = launcherCrit =
defaultCreature defaultCreature
{ _crInv = IM.fromList [(0, rLauncher)] { -- _crInv = IM.fromList [(0, rLauncher)]
, _crHP = 300 _crHP = 300
} }
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
-- & crType . humanoidAI .~ LauncherAI -- & crType . humanoidAI .~ LauncherAI
+4 -4
View File
@@ -5,15 +5,15 @@ module Dodge.Creature.LtAutoCrit (
--import Control.Lens --import Control.Lens
import Dodge.Data.Creature import Dodge.Data.Creature
import Dodge.Default import Dodge.Default
import Dodge.Item.Held.Stick --import Dodge.Item.Held.Stick
import qualified IntMapHelp as IM --import qualified IntMapHelp as IM
--import Picture --import Picture
ltAutoCrit :: Creature ltAutoCrit :: Creature
ltAutoCrit = ltAutoCrit =
defaultCreature defaultCreature
{ _crInv = IM.fromList [(0, autoPistol)] { --_crInv = IM.fromList [(0, autoPistol)]
, _crHP = 500 _crHP = 500
} }
-- & crType .~ LtAutoCrit -- & crType .~ LtAutoCrit
-- & crType . humanoidAI .~ LtAutoAI -- & crType . humanoidAI .~ LtAutoAI
+23 -22
View File
@@ -10,6 +10,7 @@ module Dodge.Creature.Picture (
) where ) where
import Dodge.Creature.HandPos import Dodge.Creature.HandPos
import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
import Dodge.Creature.Radius import Dodge.Creature.Radius
import Dodge.Creature.Shape import Dodge.Creature.Shape
@@ -25,20 +26,20 @@ import Shape
--import Shape --import Shape
import ShapePicture import ShapePicture
basicCrPict :: Creature -> SPic basicCrPict :: IM.IntMap Item -> Creature -> SPic
basicCrPict cr = drawEquipment cr <> noPic (basicCrShape cr) basicCrPict m cr = drawEquipment m cr <> noPic (basicCrShape m cr)
crCamouflage :: Creature -> CamouflageStatus crCamouflage :: Creature -> CamouflageStatus
crCamouflage _ = FullyVisible crCamouflage _ = FullyVisible
basicCrShape :: Creature -> Shape basicCrShape :: IM.IntMap Item -> Creature -> Shape
basicCrShape cr basicCrShape m cr
| crCamouflage cr == Invisible = mempty | crCamouflage cr == Invisible = mempty
| otherwise = | otherwise =
scaleSH (V3 crsize crsize crsize) $ scaleSH (V3 crsize crsize crsize) $
mconcat mconcat
[ colorSH (_skinHead cskin) $ scalp cr [ colorSH (_skinHead cskin) $ scalp m cr
, colorSH (_skinUpper cskin) $ upperBody cr , colorSH (_skinUpper cskin) $ upperBody m cr
, rotmdir $ colorSH (_skinLower cskin) $ feet cr , rotmdir $ colorSH (_skinLower cskin) $ feet cr
] ]
where where
@@ -67,17 +68,17 @@ deadFeet :: Creature -> Shape
{-# INLINE deadFeet #-} {-# INLINE deadFeet #-}
deadFeet = feet deadFeet = feet
arms :: Creature -> Shape arms :: IM.IntMap Item -> Creature -> Shape
{-# INLINE arms #-} {-# INLINE arms #-}
arms cr = arms m cr =
(^. _1) $ (^. _1) $
translateToRightHand cr aHand translateToRightHand m cr aHand
<> translateToLeftHand cr aHand <> translateToLeftHand m cr aHand
where where
aHand = noPic $ translateSHz (-4) . upperPrismPolyHalfST 4 $ polyCirc 3 4 aHand = noPic $ translateSHz (-4) . upperPrismPolyHalfST 4 $ polyCirc 3 4
deadScalp :: Creature -> Shape deadScalp :: IM.IntMap Item -> Creature -> Shape
deadScalp cr = deadRot cr . translateSHz 10 . scalp $ cr deadScalp m cr = deadRot cr . translateSHz 10 . scalp m $ cr
deadRot :: Creature -> Shape -> Shape deadRot :: Creature -> Shape -> Shape
deadRot cr = overPosSH (Q.rotateToZ d) deadRot cr = overPosSH (Q.rotateToZ d)
@@ -88,18 +89,18 @@ deadRot cr = overPosSH (Q.rotateToZ d)
(addZ 0 . unitVectorAtAngle . subtract (_crDir cr + pi)) (addZ 0 . unitVectorAtAngle . subtract (_crDir cr + pi))
(damageDirection $ _crDamage cr) (damageDirection $ _crDamage cr)
scalp :: Creature -> Shape scalp :: IM.IntMap Item -> Creature -> Shape
{-# INLINE scalp #-} {-# INLINE scalp #-}
scalp cr = overPosSH (\p -> fst (headPQ cr `Q.comp` (p,Q.qID))) fhead scalp m cr = overPosSH (\p -> fst (headPQ m cr `Q.comp` (p,Q.qID))) fhead
-- | twists cr = translateSHxy 0 5 . rotateSH (-1) $ translateSHxy (negate 2.5) 0.25 fhead -- | twists cr = translateSHxy 0 5 . rotateSH (-1) $ translateSHxy (negate 2.5) 0.25 fhead
-- | oneH cr = rotateSH 0.5 $ translateSHxy 2.5 0 fhead -- | oneH cr = rotateSH 0.5 $ translateSHxy 2.5 0 fhead
-- | otherwise = translateSHxy 2.5 0 fhead -- | otherwise = translateSHxy 2.5 0 fhead
where where
fhead = colorSH (greyN 0.9) . upperPrismPolyHalfST 5 $ polyCirc 3 5 fhead = colorSH (greyN 0.9) . upperPrismPolyHalfST 5 $ polyCirc 3 5
torso :: Creature -> Shape torso :: IM.IntMap Item -> Creature -> Shape
{-# INLINE torso #-} {-# INLINE torso #-}
torso cr = overPosSH (\p -> fst (backPQ cr `Q.comp` (p,Q.qID))) tsh torso m cr = overPosSH (\p -> fst (backPQ m cr `Q.comp` (p,Q.qID))) tsh
-- | oneH cr = rotateSH 0.5 tsh -- | oneH cr = rotateSH 0.5 tsh
-- | twists cr = -- | twists cr =
-- translateSHxy 0 3 . rotateSH (-1.3) $ tsh -- translateSHxy 0 3 . rotateSH (-1.3) $ tsh
@@ -116,20 +117,20 @@ torso cr = overPosSH (\p -> fst (backPQ cr `Q.comp` (p,Q.qID))) tsh
] ]
aShoulder = scaleSH (V3 10 10 1) baseShoulder aShoulder = scaleSH (V3 10 10 1) baseShoulder
deadUpperBody :: Creature -> Shape deadUpperBody :: IM.IntMap Item -> Creature -> Shape
deadUpperBody cr = deadRot cr . translateSHz (negate 10) . upperBody $ cr deadUpperBody m cr = deadRot cr . translateSHz (negate 10) . upperBody m $ cr
baseShoulder :: Shape baseShoulder :: Shape
{-# INLINE baseShoulder #-} {-# INLINE baseShoulder #-}
baseShoulder = translateSHz (-20) . scaleSH (V3 0.5 1 1) . upperPrismPolyHalfMI 10 $ polyCirc 3 1 baseShoulder = translateSHz (-20) . scaleSH (V3 0.5 1 1) . upperPrismPolyHalfMI 10 $ polyCirc 3 1
upperBody :: Creature -> Shape upperBody :: IM.IntMap Item -> Creature -> Shape
{-# INLINE upperBody #-} {-# INLINE upperBody #-}
upperBody cr = arms cr <> shoulderSH (torso cr) upperBody m cr = arms m cr <> shoulderSH (torso m cr)
shoulderSH :: Shape -> Shape shoulderSH :: Shape -> Shape
shoulderSH = translateSHz 20 shoulderSH = translateSHz 20
drawEquipment :: Creature -> SPic drawEquipment :: IM.IntMap Item -> Creature -> SPic
{-# INLINE drawEquipment #-} {-# INLINE drawEquipment #-}
drawEquipment cr = foldMap (itemEquipPict cr) (invDT $ _crInv cr) drawEquipment m cr = foldMap (itemEquipPict m cr) (invDT . fmap (\i -> m ^?! ix i) $ _crInv cr)
-19
View File
@@ -1,19 +0,0 @@
module Dodge.Creature.PistolCrit (
pistolCrit,
) where
--import Control.Lens
import Dodge.Data.Creature
import Dodge.Default
import Dodge.Item.Held.Stick
import qualified IntMapHelp as IM
--import Picture
pistolCrit :: Creature
pistolCrit =
defaultCreature
{ _crInv = IM.fromList [(0, pistol)]
, _crHP = 500
}
-- & crType . humanoidAI .~ PistolAI
-- & crType . skinUpper .~ lightx4 red
+2 -2
View File
@@ -12,8 +12,8 @@ import qualified IntMapHelp as IM
spreadGunCrit :: Creature spreadGunCrit :: Creature
spreadGunCrit = spreadGunCrit =
defaultCreature defaultCreature
{ _crInv = IM.fromList [(0, bangStick 6)] { --_crInv = IM.fromList [(0, bangStick 6)]
, _crHP = 500 _crHP = 500
} }
-- & crType . humanoidAI .~ SpreadGunAI -- & crType . humanoidAI .~ SpreadGunAI
-- & crType . skinUpper .~ lightx4 red -- & crType . skinUpper .~ lightx4 red
+19 -21
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.State (
invItemEffs, invItemEffs,
) where ) where
import NewInt
import Control.Applicative import Control.Applicative
import Control.Monad import Control.Monad
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
@@ -53,7 +54,7 @@ applyPastDamages cr w
where where
dojitter x y = dojitter x y =
let (p, g) = runState (randInCirc x) (_randGen w) let (p, g) = runState (randInCirc x) (_randGen w)
in w & cWorld . lWorld . creatures . ix (_crID cr) %~ crMvBy p in w & cWorld . lWorld . creatures . ix (_crID cr) %~ crMvBy p (w ^. cWorld . lWorld)
& cWorld . lWorld . creatures . ix (_crID cr) . crPain -~ y & cWorld . lWorld . creatures . ix (_crID cr) . crPain -~ y
& randGen .~ g & randGen .~ g
@@ -64,7 +65,7 @@ invItemEffs cid w = fromMaybe w $ do
return . appEndo ( return . appEndo (
foldMap foldMap
(reduceLocDT (Endo . invItemLocUpdate cr) . LocDT TopDT) (reduceLocDT (Endo . invItemLocUpdate cr) . LocDT TopDT)
(invDT' (_crInv cr))) $ w (invDT' $ fmap (\k -> w ^?! cWorld . lWorld . items . ix k) (_crInv cr))) $ w
invItemLocUpdate :: Creature -> LocationDT OItem -> World -> World invItemLocUpdate :: Creature -> LocationDT OItem -> World -> World
invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
@@ -132,7 +133,7 @@ copierItemUpdate itm cr w = fromMaybe w $ do
invid <- itm ^? itLocation . ilInvID invid <- itm ^? itLocation . ilInvID
ip <- itm ^? itType . ibtPathing ip <- itm ^? itType . ibtPathing
i <- getInventoryPath x ip invid cr i <- getInventoryPath x ip invid cr
itm' <- cr ^? crInv . ix i itm' <- cr ^? crInv . ix i >>= \k -> w ^? cWorld . lWorld . items . ix k
v <- getItemValue itm' w cr v <- getItemValue itm' w cr
return $ w & pointerToItem itm . itUse . uValue .~ v return $ w & pointerToItem itm . itUse . uValue .~ v
@@ -149,22 +150,22 @@ tryUseParent loc w = fromMaybe w $ do
tryDrawToCapacitor :: LocationDT OItem -> World -> World tryDrawToCapacitor :: LocationDT OItem -> World -> World
tryDrawToCapacitor loc w = fromMaybe w $ do tryDrawToCapacitor loc w = fromMaybe w $ do
itm <- loc ^? locDT . dtValue . _1 itm <- loc ^? locDT . dtValue . _1
i <- itm ^? itLocation . ilInvID i <- itm ^? itID . unNInt
x <- loc ^? locDT . dtValue . _1 . itConsumables . _Just x <- loc ^? locDT . dtValue . _1 . itConsumables . _Just
guard $ x < 200 guard $ x < 200
bat <- loc ^? locDT . dtLeft . ix 0 . dtValue . _1 bat <- loc ^? locDT . dtLeft . ix 0 . dtValue . _1
j <- bat ^? itLocation . ilInvID j <- bat ^? itID . unNInt
y <- bat ^? itConsumables . _Just y <- bat ^? itConsumables . _Just
let z = min y 10 let z = min y 10
return $ w return $ w
& invpoint . ix i . itConsumables . _Just +~ z & invpoint . ix i . itConsumables . _Just +~ z
& invpoint . ix j . itConsumables . _Just -~ z & invpoint . ix j . itConsumables . _Just -~ z
where where
invpoint = cWorld . lWorld . creatures . ix 0 . crInv invpoint = cWorld . lWorld . items
trySynthBullet :: LocationDT OItem -> World -> World trySynthBullet :: LocationDT OItem -> World -> World
trySynthBullet loc w = fromMaybe w $ do trySynthBullet loc w = fromMaybe w $ do
i <- itm ^? itLocation . ilInvID i <- itm ^? itID . unNInt
x <- itm ^? itUse . uaParams . apInt x <- itm ^? itUse . uaParams . apInt
if x < 100 if x < 100
then do then do
@@ -177,7 +178,7 @@ trySynthBullet loc w = fromMaybe w $ do
& invpoint . ix j . itConsumables . _Just -~ 1 & invpoint . ix j . itConsumables . _Just -~ 1
else do else do
mag <- loc ^? locDtContext . cdtParent . _1 mag <- loc ^? locDtContext . cdtParent . _1
j <- mag ^? itLocation . ilInvID j <- mag ^? itID . unNInt
y <- mag ^. itConsumables y <- mag ^. itConsumables
ymax <- maxAmmo mag ymax <- maxAmmo mag
guard $ y < ymax guard $ y < ymax
@@ -186,7 +187,7 @@ trySynthBullet loc w = fromMaybe w $ do
& invpoint . ix j . itConsumables . _Just +~ 1 & invpoint . ix j . itConsumables . _Just +~ 1
where where
itm = loc ^. locDT . dtValue . _1 itm = loc ^. locDT . dtValue . _1
invpoint = cWorld . lWorld . creatures . ix 0 . crInv invpoint = cWorld . lWorld . items
drawARHUD :: LocationDT OItem -> World -> World drawARHUD :: LocationDT OItem -> World -> World
drawARHUD (LocDT con _) w = fromMaybe w $ do drawARHUD (LocDT con _) w = fromMaybe w $ do
@@ -202,13 +203,12 @@ shineTargetLaser cr loc w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ d
mag <- find (isammolink . (^. dtValue . _2)) (itmtree ^. dtLeft) mag <- find (isammolink . (^. dtValue . _2)) (itmtree ^. dtLeft)
i <- mag ^. dtValue . _1 . itConsumables i <- mag ^. dtValue . _1 . itConsumables
guard $ i >= x guard $ i >= x
maginvid <- mag ^? dtValue . _1 . itLocation . ilInvID magitid <- mag ^? dtValue . _1 . itID . unNInt
return $ return $
w w
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
& cWorld . lWorld . creatures . ix (_crID cr) & cWorld . lWorld . items
. crInv . ix magitid
. ix maginvid
. itConsumables . itConsumables
. _Just . _Just
-~ x -~ x
@@ -230,9 +230,8 @@ shineTargetLaser cr loc w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ d
pos = _crPos cr + xyV3 (rotate3 cdir p) pos = _crPos cr + xyV3 (rotate3 cdir p)
cdir = _crDir cr cdir = _crDir cr
itm = itmtree ^. dtValue . _1 itm = itmtree ^. dtValue . _1
pointittarg = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itTargeting pointittarg = cWorld . lWorld . items . ix itid . itTargeting
cid = _crID cr itid = itm ^. itID . unNInt
invid = _ilInvID $ _itLocation itm
col = blue -- mixColors reloadFrac (1-reloadFrac) blue red col = blue -- mixColors reloadFrac (1-reloadFrac) blue red
shineTorch :: Creature -> LocationDT OItem -> World -> World shineTorch :: Creature -> LocationDT OItem -> World -> World
@@ -241,10 +240,10 @@ shineTorch cr loc = fromMaybe id $ do
i <- mag ^. dtValue . _1 . itConsumables i <- mag ^. dtValue . _1 . itConsumables
guard $ crIsAiming cr guard $ crIsAiming cr
guard $ i >= x guard $ i >= x
invid <- mag ^? dtValue . _1 . itLocation . ilInvID itid <- mag ^? dtValue . _1 . itID . unNInt
return $ return $
(cWorld . lWorld . lights .:~ LSParam pos 250 0.7) (cWorld . lWorld . lights .:~ LSParam pos 250 0.7)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itConsumables . _Just -~ x) . (cWorld . lWorld . items . ix itid . itConsumables . _Just -~ x)
where where
itmtree = loc ^. locDT itmtree = loc ^. locDT
(p, q) = locOrient loc cr (p, q) = locOrient loc cr
@@ -281,9 +280,8 @@ updateItemTargeting tt cr itm w = case tt of
Nothing Nothing
True True
where where
pointittarg = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itTargeting pointittarg = cWorld . lWorld . items . ix itid . itTargeting
cid = _crID cr itid = itm ^. itID . unNInt
invid = _ilInvID $ _itLocation itm
isattached = itm ^?! itLocation . ilIsAttached isattached = itm ^?! itLocation . ilIsAttached
rbpressed = SDL.ButtonRight `M.member` _mouseButtons (_input w) rbpressed = SDL.ButtonRight `M.member` _mouseButtons (_input w)
+12 -9
View File
@@ -6,6 +6,7 @@ module Dodge.Creature.Statistics (
crIntelligence, crIntelligence,
) where ) where
import Dodge.Data.LWorld
import Data.Maybe import Data.Maybe
import Dodge.Data.Creature import Dodge.Data.Creature
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
@@ -42,11 +43,11 @@ crIntelligence cr = case cr ^. crType of
LampCrit {} -> 0 LampCrit {} -> 0
getCrMoveSpeed :: Creature -> Int getCrMoveSpeed :: LWorld -> Creature -> Int
getCrMoveSpeed cr = strFromHeldItem cr + strFromEquipment cr + crStrength cr getCrMoveSpeed lw cr = strFromHeldItem lw cr + strFromEquipment lw cr + crStrength cr
strFromEquipment :: Creature -> Int strFromEquipment :: LWorld -> Creature -> Int
strFromEquipment = sum . fmap equipmentStrValue . crCurrentEquipment strFromEquipment lw = sum . fmap equipmentStrValue . crCurrentEquipment lw
equipmentStrValue :: Item -> Int equipmentStrValue :: Item -> Int
equipmentStrValue itm = case _itType itm of equipmentStrValue itm = case _itType itm of
@@ -54,14 +55,16 @@ equipmentStrValue itm = case _itType itm of
EQUIP POWERLEGS -> 3 EQUIP POWERLEGS -> 3
_ -> 0 _ -> 0
crCurrentEquipment :: Creature -> IM.IntMap Item crCurrentEquipment :: LWorld -> Creature -> IM.IntMap Item
crCurrentEquipment = IM.filter (isJust . (^? itLocation . ilEquipSite . _Just)) . _crInv crCurrentEquipment lw = IM.filter (isJust . (^? itLocation . ilEquipSite . _Just)) . fmap f . _crInv
where
f i = lw ^?! items . ix i
strFromHeldItem :: Creature -> Int strFromHeldItem :: LWorld -> Creature -> Int
strFromHeldItem cr = fromMaybe 0 $ do strFromHeldItem lw cr = fromMaybe 0 $ do
Aiming <- cr ^? crStance . posture Aiming <- cr ^? crStance . posture
i <- cr ^? crManipulation . manObject . imRootSelectedItem i <- cr ^? crManipulation . manObject . imRootSelectedItem
fmap (negate . itemWeight) $ cr ^? crInv . ix i fmap (negate . itemWeight) $ lw ^? items . ix i
itemWeight :: Item -> Int itemWeight :: Item -> Int
itemWeight it = case it ^. itType of itemWeight it = case it ^. itType of
+15 -16
View File
@@ -24,6 +24,7 @@ module Dodge.Creature.Test (
crSafeDistFromTarg, crSafeDistFromTarg,
) where ) where
import qualified Data.IntMap.Strict as IM
import Dodge.Item.Grammar import Dodge.Item.Grammar
import Dodge.Creature.Radius import Dodge.Creature.Radius
import Dodge.Data.Equipment.Misc import Dodge.Data.Equipment.Misc
@@ -90,35 +91,33 @@ crAwayFromPost cr = case find sentinelGoal . _apGoal $ _crActionPlan cr of
--crCanShoot :: Creature -> Bool --crCanShoot :: Creature -> Bool
--crCanShoot cr = crIsAiming cr && crWeaponReady cr --crCanShoot cr = crIsAiming cr && crWeaponReady cr
crInAimStance :: AimStance -> Creature -> Bool crInAimStance :: AimStance -> IM.IntMap Item -> Creature -> Bool
crInAimStance as cr = crIsAiming cr && mitstance == Just as crInAimStance as m cr = crIsAiming cr && mitstance == Just as
where where
mitstance = do mitstance = do
i <- cr ^? crManipulation . manObject . imRootSelectedItem i <- cr ^? crManipulation . manObject . imRootSelectedItem
--itm <- invRootTrees' (cr ^. crInv) ^? ix i --itm <- invRootTrees' (cr ^. crInv) ^? ix i
itm <- fmap (fmap (\(a,b,_) -> (a,b))) $ invIMDT (cr ^. crInv) ^? ix i itm <- fmap (fmap (\(a,b,_) -> (a,b))) $ invIMDT (fmap (\i -> m ^?! ix i) (cr ^. crInv)) ^? ix i
return $ aimStance itm return $ aimStance itm
--cr ^? crInv . ix i . itUse . heldAim . aimStance --cr ^? crInv . ix i . itUse . heldAim . aimStance
oneH :: Creature -> Bool oneH :: IM.IntMap Item -> Creature -> Bool
oneH = crInAimStance OneHand oneH = crInAimStance OneHand
twoFlat :: Creature -> Bool twoFlat :: IM.IntMap Item -> Creature -> Bool
twoFlat = crInAimStance TwoHandFlat twoFlat = crInAimStance TwoHandFlat
twists :: Creature -> Bool twists :: IM.IntMap Item -> Creature -> Bool
twists cr = crInAimStance TwoHandUnder cr || crInAimStance TwoHandOver cr twists m cr = crInAimStance TwoHandUnder m cr || crInAimStance TwoHandOver m cr
-- the use of crOldPos is because the damage position is calculated on the -- the use of crOldPos is because the damage position is calculated on the
-- previous frame -- previous frame
-- Not sure if it is a good idea -- Not sure if it is a good idea
crIsArmouredFrom :: Point2 -> Creature -> Bool crIsArmouredFrom :: IM.IntMap Item -> Point2 -> Creature -> Bool
crIsArmouredFrom = hasFrontArmour crIsArmouredFrom m p cr = fromMaybe False $ do
hasFrontArmour :: Point2 -> Creature -> Bool
hasFrontArmour p cr = fromMaybe False $ do
invid <- cr ^? crEquipment . ix OnChest invid <- cr ^? crEquipment . ix OnChest
ittype <- cr ^? crInv . ix invid . itType itid <- cr ^? crInv . ix invid
ittype <- m ^? ix itid . itType
return $ return $
EQUIP FRONTARMOUR == ittype EQUIP FRONTARMOUR == ittype
&& p /= _crOldPos cr && p /= _crOldPos cr
@@ -127,9 +126,9 @@ hasFrontArmour p cr = fromMaybe False $ do
-- even though angleVV can generate NaN, the comparison seems to deal with it -- even though angleVV can generate NaN, the comparison seems to deal with it
frontarmdirection frontarmdirection
| crInAimStance OneHand cr = 0.5 | crInAimStance OneHand m cr = 0.5
| crInAimStance TwoHandUnder cr = negate 1 | crInAimStance TwoHandUnder m cr = negate 1
| crInAimStance TwoHandOver cr = negate 1 | crInAimStance TwoHandOver m cr = negate 1
| otherwise = 0 | otherwise = 0
--crOnSeg :: Point2 -> Point2 -> Creature -> Bool --crOnSeg :: Point2 -> Point2 -> Creature -> Bool
+2 -2
View File
@@ -99,14 +99,14 @@ destroyCreature cr
-- could look at the amount of damage here (given by maxDamage) too -- could look at the amount of damage here (given by maxDamage) too
corpseOrGib :: Creature -> World -> World corpseOrGib :: Creature -> World -> World
corpseOrGib cr = case cr ^? crDamage . to maxDamageType . _Just . _1 of corpseOrGib cr w = w & case cr ^? crDamage . to maxDamageType . _Just . _1 of
Just CookingDamage -> addcorpse (thecorpse & cpSPic %~ scorchSPic) Just CookingDamage -> addcorpse (thecorpse & cpSPic %~ scorchSPic)
Just PoisonDamage -> addcorpse (thecorpse & cpSPic %~ poisonSPic) Just PoisonDamage -> addcorpse (thecorpse & cpSPic %~ poisonSPic)
Just PhysicalDamage | _crPain cr > 200 -> addCrGibs cr Just PhysicalDamage | _crPain cr > 200 -> addCrGibs cr
_ -> addcorpse thecorpse _ -> addcorpse thecorpse
where where
addcorpse ctype = plNew (cWorld . lWorld . corpses) cpID ctype addcorpse ctype = plNew (cWorld . lWorld . corpses) cpID ctype
thecorpse = makeCorpse cr thecorpse = makeCorpse (w ^. cWorld . lWorld . items) cr
scorchSPic :: SPic -> SPic scorchSPic :: SPic -> SPic
scorchSPic = _1 %~ overColSH (mixColors 0.9 0.1 black . normalizeColor) scorchSPic = _1 %~ overColSH (mixColors 0.9 0.1 black . normalizeColor)
+25 -21
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.YourControl (
yourControl, yourControl,
) where ) where
import qualified Data.IntMap.Strict as IM
import Dodge.Creature.MoveType import Dodge.Creature.MoveType
import Dodge.Data.Equipment.Misc import Dodge.Data.Equipment.Misc
import Control.Monad import Control.Monad
@@ -48,14 +49,14 @@ handleHotkeys w
, Just hk <- , Just hk <-
listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
, Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem , Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
, Just itid <- lw ^? creatures . ix 0 . crInv . ix invid . itID = , Just itid <- lw ^? creatures . ix 0 . crInv . ix invid =
w & cWorld . lWorld %~ assignHotkey itid hk w & cWorld . lWorld %~ assignHotkey (NInt itid) hk
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl | ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
, Just hk <- , Just hk <-
listToMaybe . mapMaybe scancodeToHotkey . M.keys $ listToMaybe . mapMaybe scancodeToHotkey . M.keys $
w ^. input . pressedKeys w ^. input . pressedKeys
, Just itid <- lw ^? hotkeys . ix hk . unNInt , Just itid <- lw ^? hotkeys . ix hk . unNInt
, Just invid <- lw ^? itemLocations . ix itid . ilInvID = , Just invid <- lw ^? items . ix itid . itLocation . ilInvID =
w & invSetSelectionPos 0 invid w & invSetSelectionPos 0 invid
| otherwise = | otherwise =
M.foldl' M.foldl'
@@ -69,7 +70,7 @@ handleHotkeys w
useHotkey :: World -> (NewInt ItmInt, Int) -> World useHotkey :: World -> (NewInt ItmInt, Int) -> World
useHotkey w (NInt itid, pt) = fromMaybe w $ do useHotkey w (NInt itid, pt) = fromMaybe w $ do
invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID invid <- w ^? cWorld . lWorld . items . ix itid . itLocation . ilInvID
useItem invid pt w useItem invid pt w
hotkeyToScancode :: Hotkey -> SDL.Scancode hotkeyToScancode :: Hotkey -> SDL.Scancode
@@ -117,7 +118,7 @@ scancodeToHotkey x = case x of
within wasdMovement should probably be done first within wasdMovement should probably be done first
-} -}
wasdWithAiming :: World -> Creature -> Creature wasdWithAiming :: World -> Creature -> Creature
wasdWithAiming w cr = wasdAim inp w $ wasdMovement inp cam speed cr wasdWithAiming w cr = wasdAim inp w $ wasdMovement (w ^. cWorld . lWorld) inp cam speed cr
where where
speed = _mvSpeed $ crMvType cr speed = _mvSpeed $ crMvType cr
inp = w ^. input inp = w ^. input
@@ -127,31 +128,34 @@ wasdAim :: Input -> World -> Creature -> Creature
wasdAim inp w cr wasdAim inp w cr
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight | Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
, Nothing <- inp ^? mouseButtons . ix SDL.ButtonLeft = , Nothing <- inp ^? mouseButtons . ix SDL.ButtonLeft =
setAimPosture cr setAimPosture (w ^. cWorld . lWorld . items) cr
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mousedir cr | SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn (w ^. cWorld . lWorld)
| Aiming <- cr ^. crStance . posture = removeAimPosture cr mousedir cr
| Aiming <- cr ^. crStance . posture = removeAimPosture m cr
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr | otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
where where
m = w ^. cWorld . lWorld . items
mousedir = argV $ w ^. cWorld . lWorld . lAimPos - (cr ^. crPos) mousedir = argV $ w ^. cWorld . lWorld . lAimPos - (cr ^. crPos)
setAimPosture :: Creature -> Creature setAimPosture :: IM.IntMap Item -> Creature -> Creature
setAimPosture = (crStance . posture .~ Aiming) . doAimTwist (- twoHandTwistAmount) setAimPosture m = (crStance . posture .~ Aiming) . doAimTwist m (- twoHandTwistAmount)
doAimTwist :: Float -> Creature -> Creature doAimTwist :: IM.IntMap Item -> Float -> Creature -> Creature
doAimTwist x cr = fromMaybe cr $ do doAimTwist m x cr = fromMaybe cr $ do
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
astance <- fmap itemBaseStance $ cr ^? crInv . ix itRef itid <- cr ^? crInv . ix itRef
astance <- fmap itemBaseStance $ m ^? ix itid
guard $ astance == TwoHandOver || astance == TwoHandUnder guard $ astance == TwoHandOver || astance == TwoHandUnder
return $ cr & crDir +~ x return $ cr & crDir +~ x
removeAimPosture :: Creature -> Creature removeAimPosture :: IM.IntMap Item -> Creature -> Creature
removeAimPosture = (crStance . posture .~ AtEase) . doAimTwist twoHandTwistAmount removeAimPosture m = (crStance . posture .~ AtEase) . doAimTwist m twoHandTwistAmount
twoHandTwistAmount :: Float twoHandTwistAmount :: Float
twoHandTwistAmount = 1.6 * pi twoHandTwistAmount = 1.6 * pi
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature wasdMovement :: LWorld -> Input -> Camera -> Float -> Creature -> Creature
wasdMovement inp cam speed = theMovement . setMvAim wasdMovement lw inp cam speed = theMovement . setMvAim
where where
setMvAim = fromMaybe id $ do setMvAim = fromMaybe id $ do
dir <- safeArgV movDir dir <- safeArgV movDir
@@ -160,14 +164,14 @@ wasdMovement inp cam speed = theMovement . setMvAim
movAbs = rotateV (cam ^. camRot) $ normalizeV movDir movAbs = rotateV (cam ^. camRot) $ normalizeV movDir
theMovement theMovement
| movDir == V2 0 0 = id | movDir == V2 0 0 = id
| otherwise = crMvAbsolute (speed *.* movAbs) | otherwise = crMvAbsolute lw (speed *.* movAbs)
aimTurn :: Float -> Creature -> Creature aimTurn :: LWorld -> Float -> Creature -> Creature
aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr aimTurn lw a cr = creatureTurnTowardDir a (x * 0.2) cr
where where
x = fromMaybe 1 $ do x = fromMaybe 1 $ do
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
fmap itemBulkiness $ cr ^? crInv . ix itRef . itType fmap itemBulkiness $ cr ^? crInv . ix itRef >>= \k -> lw ^? items . ix k . itType
itemBulkiness :: ItemType -> Float itemBulkiness :: ItemType -> Float
itemBulkiness = \case itemBulkiness = \case
+1 -1
View File
@@ -45,7 +45,7 @@ data Creature = Creature
, _crType :: CreatureType , _crType :: CreatureType
, _crID :: Int , _crID :: Int
, _crHP :: Int , _crHP :: Int
, _crInv :: IM.IntMap Item , _crInv :: IM.IntMap Int
, _crManipulation :: Manipulation , _crManipulation :: Manipulation
, _crEquipment :: M.Map EquipSite Int , _crEquipment :: M.Map EquipSite Int
, _crDamage :: [Damage] , _crDamage :: [Damage]
+1 -1
View File
@@ -25,7 +25,7 @@ data EquipSite
| OnLeftWrist | OnLeftWrist
| OnRightWrist | OnRightWrist
| OnLegs | OnLegs
| OnSpecial -- | OnSpecial
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
--deriving (Eq, Ord, Show, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat)
@@ -20,7 +20,7 @@ data Manipulation -- should be ManipulatedObject?
data ManipulatedObject data ManipulatedObject
= SortInventory = SortInventory
| SelectedItem | SelectedItem
{ _imSelectedItem :: Int { _imSelectedItem :: Int -- this should probably be the itmid, not the invid
, _imRootSelectedItem :: Int , _imRootSelectedItem :: Int
, _imAttachedItems :: IS.IntSet , _imAttachedItems :: IS.IntSet
} }
+1 -1
View File
@@ -99,7 +99,7 @@ import Picture.Data
data LWorld = LWorld data LWorld = LWorld
{ _creatures :: IM.IntMap Creature { _creatures :: IM.IntMap Creature
, _creatureGroups :: IM.IntMap CrGroupParams , _creatureGroups :: IM.IntMap CrGroupParams
, _itemLocations :: IM.IntMap ItemLocation -- , _itemLocations :: IM.IntMap ItemLocation
, _items :: IM.IntMap Item , _items :: IM.IntMap Item
, _clouds :: [Cloud] , _clouds :: [Cloud]
, _dusts :: [Dust] , _dusts :: [Dust]
+7 -7
View File
@@ -3,7 +3,7 @@
module Dodge.Debug.Terminal where module Dodge.Debug.Terminal where
import Data.Foldable import Data.Foldable
import Dodge.Item.Location.Initialize --import Dodge.Item.Location.Initialize
import Control.Applicative import Control.Applicative
import Control.Lens import Control.Lens
--import Control.Monad --import Control.Monad
@@ -14,7 +14,7 @@ import Dodge.Data.Universe
import Dodge.Inventory.Add import Dodge.Inventory.Add
import Dodge.Item import Dodge.Item
--import Dodge.Menu.PushPop --import Dodge.Menu.PushPop
import qualified IntMapHelp as IM --import qualified IntMapHelp as IM
import LensHelp import LensHelp
import MaybeHelp import MaybeHelp
import Text.Read (readMaybe) import Text.Read (readMaybe)
@@ -28,22 +28,22 @@ applyTerminalString ss = case ss of
applyTerminalCommand :: String -> Universe -> Universe applyTerminalCommand :: String -> Universe -> Universe
applyTerminalCommand s = case s of applyTerminalCommand s = case s of
"NOCLIP" -> uvConfig . debug_booleans . at Noclip %~ toggleJust "NOCLIP" -> uvConfig . debug_booleans . at Noclip %~ toggleJust
['L', x] -> ['L', x] -> uvWorld %~ \w -> foldr createItemYou w (inventoryX x)
(uvWorld . cWorld . lWorld %~ initSpecificCrItemLocations 0) -- (uvWorld . cWorld . lWorld %~ initSpecificCrItemLocations 0)
. (uvWorld . cWorld . lWorld . creatures . ix 0 . crInv .~ IM.fromList (zip [0 ..] $ inventoryX x)) -- . (uvWorld . cWorld . lWorld . creatures . ix 0 . crInv .~ IM.fromList (zip [0 ..] $ inventoryX x))
-- . (uvWorld . cWorld . lWorld . creatures . ix 0 . crInvCapacity .~ 50) -- . (uvWorld . cWorld . lWorld . creatures . ix 0 . crInvCapacity .~ 50)
-- ['I','S',x,y] -> uvWorld . cWorld . lWorld . creatures . ix 0 . crInvCapacity .~ read [x,y] -- ['I','S',x,y] -> uvWorld . cWorld . lWorld . creatures . ix 0 . crInvCapacity .~ read [x,y]
"GODON" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crType . avatarMaterial .~ Crystal "GODON" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crType . avatarMaterial .~ Crystal
"GODOFF" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crType . avatarMaterial .~ Flesh "GODOFF" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crType . avatarMaterial .~ Flesh
x -> fromMaybe id $ do x -> fromMaybe id $ do
(ibt, n) <- parseItem [x] (ibt, n) <- parseItem [x]
return $ uvWorld %~ flip (foldl' (&)) (replicate n (snd . createItemYou (itemFromBase ibt))) return $ uvWorld %~ flip (foldl' (&)) (replicate n ( createItemYou (itemFromBase ibt)))
applyTerminalCommandArguments :: String -> [String] -> Universe -> Universe applyTerminalCommandArguments :: String -> [String] -> Universe -> Universe
applyTerminalCommandArguments command args u = case command of applyTerminalCommandArguments command args u = case command of
"IT" -> fromMaybe u $ do "IT" -> fromMaybe u $ do
(ibt, n) <- parseItem args (ibt, n) <- parseItem args
return $ u & uvWorld %~ flip (foldl' (&)) (replicate n (snd . createItemYou (itemFromBase ibt))) return $ u & uvWorld %~ flip (foldl' (&)) (replicate n ( createItemYou (itemFromBase ibt)))
"DEX" -> fromMaybe u $ do "DEX" -> fromMaybe u $ do
x <- readMaybe =<< args ^? _head x <- readMaybe =<< args ^? _head
return $ u & ypoint . crType . avDexterity .~ x return $ u & ypoint . crType . avDexterity .~ x
+1 -1
View File
@@ -102,7 +102,7 @@ defaultLWorld =
, _clouds = mempty , _clouds = mempty
, _dusts = mempty , _dusts = mempty
, _gusts = IM.empty , _gusts = IM.empty
, _itemLocations = IM.empty -- , _itemLocations = IM.empty
, _items = mempty , _items = mempty
, _props = IM.empty , _props = IM.empty
, _debris = mempty , _debris = mempty
+3 -3
View File
@@ -62,7 +62,7 @@ updateCombineSections w cfig =
(IM.fromDistinctAscList . zip [0 ..] $ combineList w) (IM.fromDistinctAscList . zip [0 ..] $ combineList w)
"COMBINATIONS" "COMBINATIONS"
$ w ^? hud . hudElement . subInventory . ciFilter . _Just $ w ^? hud . hudElement . subInventory . ciFilter . _Just
invitms = fold $ w ^? cWorld . lWorld . creatures . ix 0 . crInv invitms = fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ fold $ w ^? cWorld . lWorld . creatures . ix 0 . crInv
sclose' sclose'
| null sclose = | null sclose =
IM.singleton 0 $ IM.singleton 0 $
@@ -130,7 +130,7 @@ updateDisplaySections w cfig =
[ invhead [ invhead
, sinv , sinv
, IM.singleton 0 , IM.singleton 0
$ SelItem [displayFreeSlots (crNumFreeSlots cr)] 1 15 True invDimColor 2 Nothing $ SelItem [displayFreeSlots (crNumFreeSlots (w ^. cWorld . lWorld . items) cr)] 1 15 True invDimColor 2 Nothing
, nearbyhead , nearbyhead
, sclose , sclose
, interfaceshead , interfaceshead
@@ -163,7 +163,7 @@ updateDisplaySections w cfig =
invitems = invitems =
IM.map IM.map
(uncurry (invSelectionItem w)) (uncurry (invSelectionItem w))
(invIndents $ _crInv cr) (invIndents $ fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ _crInv cr)
filterSectionsPair :: filterSectionsPair ::
Bool -> -- check for whether filter is in focus, changes string at the end Bool -> -- check for whether filter is in focus, changes string at the end
+5 -4
View File
@@ -50,12 +50,13 @@ setWristShieldPos :: Item -> Creature -> World -> World
setWristShieldPos itm cr w = w & moveWallIDUnsafe i wlline setWristShieldPos itm cr w = w & moveWallIDUnsafe i wlline
where where
i = _itParamID $ _itParams itm i = _itParamID $ _itParams itm
m = w ^. cWorld . lWorld . items
wlline = (f (V3 (-10) 7 0), f (V3 10 7 0)) wlline = (f (V3 (-10) 7 0), f (V3 10 7 0))
invid = _ilInvID (_itLocation itm) invid = _ilInvID (_itLocation itm)
handtrans = case cr ^? crInv . ix invid . itLocation . ilEquipSite . _Just of handtrans = case cr ^? crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k . itLocation . ilEquipSite . _Just of
Just OnLeftWrist -> \cr' -> translatePointToLeftHand cr' . g Just OnLeftWrist -> \cr' -> translatePointToLeftHand m cr' . g
_ -> translatePointToRightHand _ -> translatePointToRightHand m
g g
| twists cr = (+.+.+ V3 (-5) 10 0) | twists m cr = (+.+.+ V3 (-5) 10 0)
| otherwise = id | otherwise = id
f = (+.+ _crPos cr) . stripZ . rotate3 (_crDir cr) . handtrans cr f = (+.+ _crPos cr) . stripZ . rotate3 (_crDir cr) . handtrans cr
+1 -1
View File
@@ -10,5 +10,5 @@ eqPosText ep = case ep of
OnLeftWrist -> "L.WRIST" OnLeftWrist -> "L.WRIST"
OnRightWrist -> "R.WRIST" OnRightWrist -> "R.WRIST"
OnLegs -> "LEGS" OnLegs -> "LEGS"
OnSpecial -> "EQUIPPED" -- OnSpecial -> "EQUIPPED"
+8 -6
View File
@@ -33,15 +33,16 @@ useMagShield mt _ cr w =
} }
setWristShieldPos :: Item -> Creature -> EquipSite -> World -> World setWristShieldPos :: Item -> Creature -> EquipSite -> World -> World
setWristShieldPos itm cr x = moveWallIDUnsafe i wlline setWristShieldPos itm cr x w = moveWallIDUnsafe i wlline w
where where
m = w ^. cWorld . lWorld . items
i = _itParamID $ _itParams itm i = _itParamID $ _itParams itm
wlline = (f (V3 (-10) 7 0), f (V3 10 7 0)) wlline = (f (V3 (-10) 7 0), f (V3 10 7 0))
handtrans = case x of handtrans = case x of
OnLeftWrist -> \cr' -> translatePointToLeftHand cr' . g OnLeftWrist -> \cr' -> translatePointToLeftHand m cr' . g
_ -> translatePointToRightHand _ -> translatePointToRightHand m
g g
| twists cr = (+.+.+ V3 (-5) 10 0) | twists m cr = (+.+.+ V3 (-5) 10 0)
| otherwise = id | otherwise = id
f = (+.+ _crPos cr) . stripZ . rotate3 (_crDir cr) . handtrans cr f = (+.+ _crPos cr) . stripZ . rotate3 (_crDir cr) . handtrans cr
@@ -53,9 +54,10 @@ setWristShieldPos itm cr x = moveWallIDUnsafe i wlline
-- _ -> w -- _ -> w
createHeadLamp :: Item -> Creature -> World -> World createHeadLamp :: Item -> Creature -> World -> World
createHeadLamp _ cr = createHeadLamp _ cr w = w &
cWorld . lWorld . lights cWorld . lWorld . lights
.:~ LSParam .:~ LSParam
((_crPos cr `v2z` 0) +.+.+ rotate3 (_crDir cr) (translatePointToHead cr (V3 5 0 3))) ((_crPos cr `v2z` 0) +.+.+ rotate3 (_crDir cr)
(translatePointToHead (w ^. cWorld . lWorld . items) cr (V3 5 0 3)))
200 200
0.7 0.7
-1
View File
@@ -23,7 +23,6 @@ copyItemToFloorID :: Point2 -> Item -> World -> World
copyItemToFloorID pos it w = copyItemToFloorID pos it w =
w' w'
& cWorld . lWorld . floorItems %~ IM.insert (_unNInt $ _itID it) theflit & cWorld . lWorld . floorItems %~ IM.insert (_unNInt $ _itID it) theflit
& cWorld . lWorld . itemLocations %~ IM.insert (_unNInt $ _itID it) OnFloor
& cWorld . lWorld . items . ix (_unNInt $ _itID it) . itLocation .~ OnFloor & cWorld . lWorld . items . ix (_unNInt $ _itID it) . itLocation .~ OnFloor
& hud . closeItems %~ (_itID it:) & hud . closeItems %~ (_itID it:)
-- & hud . hudElement . diSections . ix 3 . ssOffset .~ 0 -- & hud . hudElement . diSections . ix 3 . ssOffset .~ 0
+30 -37
View File
@@ -1,6 +1,6 @@
{-# LANGUAGE TupleSections #-}
{-# OPTIONS -Wno-incomplete-uni-patterns #-} {-# OPTIONS -Wno-incomplete-uni-patterns #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
module Dodge.HeldUse ( module Dodge.HeldUse (
gadgetEffect, gadgetEffect,
@@ -102,7 +102,7 @@ hammerCheck f pt loc cr w = case itemTriggerType loc of
in w & f loc cr in w & f loc cr
& cWorld . lWorld . delayedEvents .++~ map g is & cWorld . lWorld . delayedEvents .++~ map g is
& randGen .~ gen & randGen .~ gen
HammerTrigger t | timetest t , pt == 0 -> f loc cr w HammerTrigger t | timetest t, pt == 0 -> f loc cr w
SemiAutoTrigger t SemiAutoTrigger t
| timetest t | timetest t
, pt < w ^. cWorld . lWorld . lClock - timelastused -> , pt < w ^. cWorld . lWorld . lClock - timelastused ->
@@ -117,7 +117,7 @@ hammerCheck f pt loc cr w = case itemTriggerType loc of
-- the following is unsafe, but if ilInvID isn't correctly set we probably -- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also -- will have problems elsewhere also
invid = it ^?! itLocation . ilInvID invid = it ^?! itLocation . ilInvID
itmset = cWorld . lWorld . creatures . ix cid . crInv . ix invid itmset = cWorld . lWorld . items . ix (it ^. itID . unNInt)
setwarming = itmset . itParams . isWarming %~ const True setwarming = itmset . itParams . isWarming %~ const True
timelastused = it ^. itTimeLastUsed timelastused = it ^. itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) invid) g x = (x, WdWdBurstFireRepetition (_crID cr) invid)
@@ -137,9 +137,9 @@ heldEffectMuzzles loc cr w =
t = loc ^. locDT t = loc ^. locDT
bw = foldl' (loadMuzzle loc cr) (False, w) (locMuzzles loc) bw = foldl' (loadMuzzle loc cr) (False, w) (locMuzzles loc)
setusetime = setusetime =
cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itid . itTimeLastUsed cWorld . lWorld . items . ix itid . itTimeLastUsed
.~ w ^. cWorld . lWorld . lClock .~ w ^. cWorld . lWorld . lClock
itid = t ^?! dtValue . _1 . itLocation . ilInvID itid = t ^?! dtValue . _1 . itID . unNInt
locMuzzles :: LocationDT OItem -> [Muzzle] locMuzzles :: LocationDT OItem -> [Muzzle]
locMuzzles loc locMuzzles loc
@@ -341,26 +341,20 @@ vgunMuzzles i =
) )
doHeldUseEffect :: DTree OItem -> Creature -> World -> World doHeldUseEffect :: DTree OItem -> Creature -> World -> World
doHeldUseEffect t cr w = case t ^. dtValue . _1 . itType of doHeldUseEffect t _ w = case t ^. dtValue . _1 . itType of
HELD (VOLLEYGUN j) -> case itm ^? itParams . unfiredBarrels of HELD (VOLLEYGUN j) -> case itm ^? itParams . unfiredBarrels of
Just [_] -> fromMaybe w $ do Just [_] -> fromMaybe w $ do
let (is, g) = runState (shuffle [0 .. j -1]) $ w ^. randGen let (is, g) = runState (shuffle [0 .. j -1]) $ w ^. randGen
i <- itm ^? itLocation . ilInvID
return $ return $
w w
& randGen .~ g & randGen .~ g
& crinvset . ix i . itParams . unfiredBarrels %~ const is & crinvset . itParams . unfiredBarrels %~ const is
Just (_ : _ : _) -> fromMaybe w $ do Just (_ : _ : _) -> w & crinvset . itParams . unfiredBarrels %~ tail
i <- itm ^? itLocation . ilInvID
return $ w & crinvset . ix i . itParams . unfiredBarrels %~ tail
_ -> w _ -> w
HELD ALTERIFLE -> fromMaybe w $ do HELD ALTERIFLE -> w & crinvset . itParams . alteRifleSwitch %~ ((`mod` 2) . (+ 1))
i <- t ^? dtValue . _1 . itLocation . ilInvID
return $
w & crinvset . ix i . itParams . alteRifleSwitch %~ ((`mod` 2) . (+ 1))
_ -> w _ -> w
where where
crinvset = cWorld . lWorld . creatures . ix (_crID cr) . crInv crinvset = cWorld . lWorld . items . ix (itm ^. itID . unNInt)
itm = t ^. dtValue . _1 itm = t ^. dtValue . _1
-- should probably unify failure with time use check in some way... -- should probably unify failure with time use check in some way...
@@ -637,8 +631,8 @@ loadMuzzle loc cr (b, w) mz = maybe (b, w) (True,) $ do
find find
((== PulseBallSF) . (^. dtValue . _2)) ((== PulseBallSF) . (^. dtValue . _2))
(loc ^. locDT . dtLeft) (loc ^. locDT . dtLeft)
mid <- mag ^? dtValue . _1 . itLocation . ilInvID mid <- mag ^? dtValue . _1 . itID . unNInt
availableammo <- w ^? cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix mid . itConsumables . _Just availableammo <- w ^? cWorld . lWorld . items . ix mid . itConsumables . _Just
let usedammo = case as ^?! aps of let usedammo = case as ^?! aps of
UseUpTo x -> min x availableammo UseUpTo x -> min x availableammo
UseExactly x UseExactly x
@@ -724,7 +718,7 @@ useLoadedAmmo ::
World -> World ->
World World
useLoadedAmmo loc cr mz m w = useLoadedAmmo loc cr mz m w =
removeAmmoFromMag m cr . makeMuzzleFlare mz loc cr $ case _mzEffect mz of removeAmmoFromMag m . makeMuzzleFlare mz loc cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullets loc cr (mz, x, magtree) w MuzzleShootBullet -> shootBullets loc cr (mz, x, magtree) w
MuzzleLaser -> creatureShootLaser loc cr mz w MuzzleLaser -> creatureShootLaser loc cr mz w
MuzzlePulseLaser -> creatureShootPulseLaser loc cr mz w MuzzlePulseLaser -> creatureShootPulseLaser loc cr mz w
@@ -741,7 +735,7 @@ useLoadedAmmo loc cr mz m w =
mz mz
cr cr
w w
MuzzleNozzle{} -> useGasParams mid mz loc cr $ walkNozzle mz itm cr w MuzzleNozzle{} -> useGasParams mid mz loc cr $ walkNozzle mz itm w
MuzzleShatter -> shootShatter itm cr w MuzzleShatter -> shootShatter itm cr w
MuzzleDetector -> MuzzleDetector ->
itemDetectorEffect itemDetectorEffect
@@ -782,13 +776,11 @@ itemDetectorEffect itm mitid armitid cr w = fromMaybe w $ do
f CREATUREDETECTOR = OTCreature f CREATUREDETECTOR = OTCreature
f WALLDETECTOR = OTWall f WALLDETECTOR = OTWall
walkNozzle :: Muzzle -> Item -> Creature -> World -> World walkNozzle :: Muzzle -> Item -> World -> World
walkNozzle mz itm cr w = fromMaybe w $ do walkNozzle mz itm w =
invid <- itm ^? itLocation . ilInvID
return $
w w
& cWorld . lWorld . creatures . ix (_crID cr) . crInv & cWorld . lWorld . items
. ix invid . ix (itm ^. itID . unNInt)
. itParams . itParams
. nzAngle . nzAngle
%~ f %~ f
@@ -927,14 +919,12 @@ shootPulseBall p dir w =
i = IM.newKey $ w ^. cWorld . lWorld . pulseBalls i = IM.newKey $ w ^. cWorld . lWorld . pulseBalls
--removeAmmoFromMag :: Int -> Maybe Int -> Creature -> World -> World --removeAmmoFromMag :: Int -> Maybe Int -> Creature -> World -> World
removeAmmoFromMag :: Maybe (Int, DTree OItem) -> Creature -> World -> World removeAmmoFromMag :: Maybe (Int, DTree OItem) -> World -> World
removeAmmoFromMag m cr = fromMaybe id $ do removeAmmoFromMag m = fromMaybe id $ do
(x, magtree) <- m (x, magtree) <- m
magid <- magtree ^? dtValue . _1 . itLocation . ilInvID magid <- magtree ^? dtValue . _1 . itID . unNInt
return $ return $
cWorld . lWorld . creatures cWorld . lWorld . items
. ix (_crID cr)
. crInv
. ix magid . ix magid
. itConsumables . itConsumables
. _Just . _Just
@@ -1139,7 +1129,7 @@ useGasParams mmagid mz loc cr w =
gastype = fromMaybe (error "cannot find gas ammo") $ do gastype = fromMaybe (error "cannot find gas ammo") $ do
magid <- mmagid magid <- mmagid
hit <- itm ^? itType . ibtHeld hit <- itm ^? itType . ibtHeld
fueltype <- cr ^? crInv . ix magid >>= magAmmoParams >>= (^? ampCreateGas) fueltype <- cr ^? crInv . ix magid >>= \k -> w ^? cWorld . lWorld . items . ix k >>= magAmmoParams >>= (^? ampCreateGas)
gasType hit fueltype gasType hit fueltype
(V3 x y _, q) = (V3 x y _, q) =
locOrient loc cr locOrient loc cr
@@ -1224,11 +1214,11 @@ mcShootAuto itm mc w
-- | assumes that the item is held -- | assumes that the item is held
shootTeslaArc :: LocationDT OItem -> Creature -> Muzzle -> World -> World shootTeslaArc :: LocationDT OItem -> Creature -> Muzzle -> World -> World
shootTeslaArc loc cr mz w = shootTeslaArc loc cr mz w =
w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itParams .~ ip w' & cWorld . lWorld . items . ix itid . itParams .~ ip
& soundContinue (CrWeaponSound (_crID cr) 0) pos elecCrackleS (Just 2) & soundContinue (CrWeaponSound (_crID cr) 0) pos elecCrackleS (Just 2)
where where
itm = loc ^. locDT . dtValue . _1 itm = loc ^. locDT . dtValue . _1
invid = itm ^?! itLocation . ilInvID itid = itm ^. itID . unNInt
(w', ip) = makeTeslaArc (itm ^. itParams) pos dir w (w', ip) = makeTeslaArc (itm ^. itParams) pos dir w
(V3 x y _, q) = (V3 x y _, q) =
locOrient loc cr locOrient loc cr
@@ -1328,9 +1318,11 @@ createProjectile ::
Creature -> Creature ->
World -> World ->
World World
createProjectile x pjtype magtree stab muz cr = fromMaybe failsound $ do createProjectile x pjtype magtree stab muz cr w =
w
& ( fromMaybe failsound $ do
magid <- magtree ^? dtValue . _1 . itLocation . ilInvID magid <- magtree ^? dtValue . _1 . itLocation . ilInvID
ammoitem <- cr ^? crInv . ix magid ammoitem <- cr ^? crInv . ix magid >>= \k -> w ^? cWorld . lWorld . items . ix k
let rdetonate = let rdetonate =
(^. dtValue . _1 . itID) (^. dtValue . _1 . itID)
<$> find isrdet (magtree ^. dtLeft) <$> find isrdet (magtree ^. dtLeft)
@@ -1344,6 +1336,7 @@ createProjectile x pjtype magtree stab muz cr = fromMaybe failsound $ do
return $ return $
createShell x rdetonate rscreen stab pjtype aparams muz cr createShell x rdetonate rscreen stab pjtype aparams muz cr
. startthesound . startthesound
)
where where
isrdet :: DTree OItem -> Bool isrdet :: DTree OItem -> Bool
isrdet y = case y ^. dtValue . _2 of isrdet y = case y ^. dtValue . _2 of
+10 -8
View File
@@ -45,10 +45,10 @@ destroyInvItem cid invid w =
& removeithotkey & removeithotkey
where where
removeitloc = fromMaybe id $ do removeitloc = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
return $ cWorld . lWorld . itemLocations . at itid .~ Nothing return $ cWorld . lWorld . items . at itid .~ Nothing
removeithotkey = fromMaybe id $ do removeithotkey = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
hk <- w ^? cWorld . lWorld . imHotkeys . unNIntMap . ix itid hk <- w ^? cWorld . lWorld . imHotkeys . unNIntMap . ix itid
return $ return $
(cWorld . lWorld . imHotkeys . unNIntMap . at itid .~ Nothing) (cWorld . lWorld . imHotkeys . unNIntMap . at itid .~ Nothing)
@@ -62,14 +62,14 @@ destroyAllInvItems cr w =
$ cr ^. crInv $ cr ^. crInv
destroyItem :: Int -> World -> World destroyItem :: Int -> World -> World
destroyItem itid w = case w ^? cWorld . lWorld . itemLocations . ix itid of destroyItem itid w = case w ^? cWorld . lWorld . items . ix itid . itLocation of
Nothing -> error $ "Tried to destroy item that does not exist; item id: " ++ show itid Nothing -> error $ "Tried to destroy item that does not exist; item id: " ++ show itid
Just InInv{_ilCrID = cid, _ilInvID = invid} -> destroyInvItem cid invid w Just InInv{_ilCrID = cid, _ilInvID = invid} -> destroyInvItem cid invid w
Just OnTurret{} -> error "need to write code for destroying items on turrets" Just OnTurret{} -> error "need to write code for destroying items on turrets"
Just OnFloor -> Just OnFloor ->
w & cWorld . lWorld . itemLocations . at itid .~ Nothing w & cWorld . lWorld . items . at itid .~ Nothing
& cWorld . lWorld . floorItems . at itid .~ Nothing & cWorld . lWorld . floorItems . at itid .~ Nothing
Just InVoid -> w & cWorld . lWorld . itemLocations . at itid .~ Nothing Just InVoid -> w & cWorld . lWorld . items . at itid .~ Nothing
-- note rmInvItem does not fully destroy the item, other updates to the item -- note rmInvItem does not fully destroy the item, other updates to the item
-- location are required -- location are required
@@ -82,7 +82,7 @@ rmInvItem cid invid w =
& pointcid . crEquipment . each %~ g & pointcid . crEquipment . each %~ g
& updateselection & updateselection
& updateselectionextra & updateselectionextra
& pointcid %~ updateRootItemID & pointcid %~ updateRootItemID (w ^. cWorld . lWorld . items)
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
where where
pointcid = cWorld . lWorld . creatures . ix cid pointcid = cWorld . lWorld . creatures . ix cid
@@ -95,7 +95,8 @@ rmInvItem cid invid w =
| otherwise = | otherwise =
pointcid . crManipulation . manObject . imSelectedItem %~ g pointcid . crManipulation . manObject . imSelectedItem %~ g
cr = w ^?! cWorld . lWorld . creatures . ix cid cr = w ^?! cWorld . lWorld . creatures . ix cid
itm = _crInv cr IM.! invid itid = _crInv cr IM.! invid
itm = w ^?! cWorld . lWorld . items . ix itid
dounequipfunction = effectOnRemove itm cr dounequipfunction = effectOnRemove itm cr
-- fromMaybe id $ do -- fromMaybe id $ do
-- rmf <- itm ^? itUse . uequipEffect . eeOnRemove -- rmf <- itm ^? itUse . uequipEffect . eeOnRemove
@@ -104,6 +105,7 @@ rmInvItem cid invid w =
epos <- epos <-
w w
^? cWorld . lWorld . creatures . ix cid . crInv . ix invid ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
>>= \k -> w ^? cWorld . lWorld . items . ix k
. itLocation . itLocation
. ilEquipSite . ilEquipSite
. _Just . _Just
+5 -8
View File
@@ -36,9 +36,9 @@ tryPutItemInInv cid itid w = do
return $ (invid,) $ w return $ (invid,) $ w
& cWorld . lWorld %~ crUpdateItemLocations cid & cWorld . lWorld %~ crUpdateItemLocations cid
-- not sure about the order of these... -- not sure about the order of these...
& cWorld . lWorld . creatures . ix cid . crInv . at invid ?~ newitm & cWorld . lWorld . creatures . ix cid . crInv . at invid ?~ itid
& cWorld . lWorld . items . at itid ?~ newitm & cWorld . lWorld . items . at itid ?~ newitm
& cWorld . lWorld . itemLocations . at itid ?~ itloc -- & cWorld . lWorld . itemLocations . at itid ?~ itloc
& cWorld . lWorld . floorItems . at itid .~ Nothing & cWorld . lWorld . floorItems . at itid .~ Nothing
& updateselectionextra & updateselectionextra
where where
@@ -110,13 +110,10 @@ tryPutItemInInvAt i cid itid w = do
-- copyItemToFloorID (_crPos $ you w) (applyModules it) w -- copyItemToFloorID (_crPos $ you w) (applyModules it) w
-- return (Just i, w') -- return (Just i, w')
createItemYou :: Item -> World -> (ItemLocation, World) createItemYou :: Item -> World -> World
createItemYou itm w = fromMaybe (OnFloor, w') $ do createItemYou itm w = fromMaybe w' $ fmap snd $ tryPutItemInInv 0 itid w'
(invid, w'') <- tryPutItemInInv 0 itid w'
itloc <- w'' ^? cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itLocation
return (itloc, w'')
where where
itid = IM.newKey $ w ^. cWorld . lWorld . itemLocations itid = IM.newKey $ w ^. cWorld . lWorld . items
pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos
w' = copyItemToFloorID pos (itm & itID .~ NInt itid) w w' = copyItemToFloorID pos (itm & itID .~ NInt itid) w
+5 -3
View File
@@ -17,12 +17,14 @@ import qualified IntMapHelp as IM
checkInvSlotsYou :: Item -> World -> Maybe Int checkInvSlotsYou :: Item -> World -> Maybe Int
checkInvSlotsYou it w = do checkInvSlotsYou it w = do
ycr <- w ^? cWorld . lWorld . creatures . ix 0 ycr <- w ^? cWorld . lWorld . creatures . ix 0
guard $ crNumFreeSlots ycr >= itInvHeight it guard $ crNumFreeSlots (w ^. cWorld . lWorld . items) ycr >= itInvHeight it
Just . IM.newKey $ _crInv ycr Just . IM.newKey $ _crInv ycr
crNumFreeSlots :: Creature -> Int crNumFreeSlots :: IM.IntMap Item -> Creature -> Int
--crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr) --crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)
crNumFreeSlots cr = maxInvSlots - invSize (_crInv cr) crNumFreeSlots m cr = maxInvSlots - invSize (fmap f (_crInv cr))
where
f i = m ^?! ix i
maxInvSlots :: Int maxInvSlots :: Int
maxInvSlots = 25 maxInvSlots = 25
+25 -21
View File
@@ -4,9 +4,12 @@ module Dodge.Inventory.Location (
setInvPosFromSS, setInvPosFromSS,
) where ) where
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Data.Foldable
import Control.Applicative import Control.Applicative
import Control.Lens import Control.Lens
import Data.IntMap.Merge.Strict --import Data.IntMap.Merge.Strict
import qualified Data.IntSet as IS import qualified Data.IntSet as IS
import Data.Maybe import Data.Maybe
import Dodge.Base.You import Dodge.Base.You
@@ -26,43 +29,43 @@ tryGetRootAttachedFromInvID invid im = do
-- this assumes the creature inventory is well formed, specifically the -- this assumes the creature inventory is well formed, specifically the
-- location ids -- location ids
tryGetRootItemInvID :: Int -> Creature -> Maybe Int tryGetRootItemInvID :: IM.IntMap Item -> Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do tryGetRootItemInvID m i cr = do
let adj = invAdj (_crInv cr) let adj = invAdj $ fmap (\k -> m ^?! ix k) (_crInv cr)
theroot <- adj ^? ix i theroot <- adj ^? ix i
theroot ^? _1 . _Just . _1 <|> Just i theroot ^? _1 . _Just . _1 <|> Just i
updateRootItemID :: Creature -> Creature updateRootItemID :: IM.IntMap Item -> Creature -> Creature
updateRootItemID cr = fromMaybe cr $ do updateRootItemID m cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
j <- tryGetRootItemInvID i cr j <- tryGetRootItemInvID m i cr
return $ cr & crManipulation . manObject . imRootSelectedItem .~ j return $ cr & crManipulation . manObject . imRootSelectedItem .~ j
-- the following assumes that the crManipulation is correct -- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> LWorld -> LWorld crUpdateItemLocations :: Int -> LWorld -> LWorld
crUpdateItemLocations crid lw = fromMaybe lw $ do crUpdateItemLocations crid lw = fromMaybe lw $ do
mo <- lw ^? creatures . ix crid . crManipulation . manObject mo <- lw ^? creatures . ix crid . crManipulation . manObject
crinv <- lw ^? creatures . ix crid . crInv itids <- lw ^? creatures . ix crid . crInv
let crinv = IM.restrictKeys (lw ^. items) (IS.fromList $ IM.elems itids)
return $ crSetRoots crid $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw crinv return $ crSetRoots crid $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw crinv
crSetRoots :: Int -> LWorld -> LWorld crSetRoots :: Int -> LWorld -> LWorld
crSetRoots cid w = fromMaybe w $ do crSetRoots cid w = fromMaybe w $ do
inv <- w ^? creatures . ix cid . crInv inv <- w ^? creatures . ix cid . crInv
return $ let cinv = invIMDT $ fmap (\i -> w ^?! items . ix i) inv
w & creatures . ix cid . crInv return $ foldl' f (foldl' g w inv) cinv
%~ merge
dropMissing
preserveMissing
(zipWithMatched f)
(invIMDT inv)
where where
f _ _ = itLocation . ilIsRoot .~ True g w' i = w' & items . ix i . itLocation . ilIsRoot .~ False
f :: LWorld -> DTree OItem -> LWorld
f w' x = w'
& items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True
crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld
crUpdateInvidLocations mo crid lw invid itm = crUpdateInvidLocations mo crid lw invid itm =
lw lw
& creatures . ix crid . crInv . ix invid . itLocation .~ newloc & creatures . ix crid . crInv . ix invid .~ itid -- . itLocation .~ newloc
& itemLocations %~ IM.insert itid newloc & items . ix invid .~ (itm & itLocation .~ newloc)
-- & itemLocations %~ IM.insert itid newloc
where where
itid = itm ^. itID . unNInt itid = itm ^. itID . unNInt
newloc = newloc =
@@ -72,8 +75,8 @@ crUpdateInvidLocations mo crid lw invid itm =
, _ilIsRoot = Just invid == mo ^? imRootSelectedItem , _ilIsRoot = Just invid == mo ^? imRootSelectedItem
, _ilIsSelected = Just invid == mo ^? imSelectedItem , _ilIsSelected = Just invid == mo ^? imSelectedItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems) , _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
, _ilEquipSite = lw ^? creatures . ix crid . crInv . ix invid , _ilEquipSite = do
. itLocation . ilEquipSite . _Just lw ^? items . ix itid . itLocation . ilEquipSite . _Just
} }
-- this should be looked at, as it is sometimes used in functions that need not -- this should be looked at, as it is sometimes used in functions that need not
@@ -89,7 +92,8 @@ setInvPosFromSS w =
case i of case i of
(-1) -> Just SortInventory (-1) -> Just SortInventory
0 -> do 0 -> do
(rootid, aset) <- tryGetRootAttachedFromInvID j (you w ^. crInv) (rootid, aset) <- tryGetRootAttachedFromInvID j (fmap (\k -> w ^?! cWorld . lWorld . items . ix k )
$ you w ^. crInv)
return return
SelectedItem SelectedItem
{ _imSelectedItem = j { _imSelectedItem = j
+10 -8
View File
@@ -4,6 +4,7 @@ module Dodge.Inventory.RBList (
eqSiteToPositions, eqSiteToPositions,
) where ) where
import qualified Data.IntMap.Strict as IM
import Dodge.Data.Equipment.Misc import Dodge.Data.Equipment.Misc
import Dodge.Data.EquipType import Dodge.Data.EquipType
import Control.Applicative import Control.Applicative
@@ -21,11 +22,11 @@ updateRBList w = case w ^. rbOptions of
EquipOptions{} -> w EquipOptions{} -> w
_ -> fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do _ -> fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
esite <- cr ^? crInv . ix i >>= equipType -- . itUse . uequipEffect . eeType esite <- cr ^? crInv . ix i >>= \k -> w ^? cWorld . lWorld . items . ix k >>= equipType -- . itUse . uequipEffect . eeType
return $ return $
w & rbOptions w & rbOptions
.~ EquipOptions .~ EquipOptions
{ _opSel = chooseEquipPosition cr (eqSiteToPositions esite) { _opSel = chooseEquipPosition (w ^. cWorld . lWorld . items) cr (eqSiteToPositions esite)
} }
where where
norightclick = not $ SDL.ButtonRight `M.member` (w ^. input . mouseButtons) norightclick = not $ SDL.ButtonRight `M.member` (w ^. input . mouseButtons)
@@ -33,10 +34,11 @@ updateRBList w = case w ^. rbOptions of
-- want to choose the current position if the item is equipped, otherwise try to -- want to choose the current position if the item is equipped, otherwise try to
-- find a free equipment slot -- find a free equipment slot
chooseEquipPosition :: Creature -> [EquipSite] -> Int chooseEquipPosition :: IM.IntMap Item -> Creature -> [EquipSite] -> Int
chooseEquipPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do chooseEquipPosition m cr eps = fromMaybe (chooseFreeSite cr eps) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
ep <- cr ^? crInv . ix i . itLocation . ilEquipSite . _Just itid <- cr ^? crInv . ix i
ep <- m ^? ix itid . itLocation . ilEquipSite . _Just
elemIndex ep eps elemIndex ep eps
chooseFreeSite :: Creature -> [EquipSite] -> Int chooseFreeSite :: Creature -> [EquipSite] -> Int
@@ -46,12 +48,12 @@ chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
getEquipmentAllocation :: Int -> World -> EquipmentAllocation getEquipmentAllocation :: Int -> World -> EquipmentAllocation
getEquipmentAllocation invid w = fromMaybe DoNotMoveEquipment $ do getEquipmentAllocation invid w = fromMaybe DoNotMoveEquipment $ do
esite <- you w ^? crInv . ix invid >>= equipType-- . itUse . uequipEffect . eeType esite <- you w ^? crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k >>= equipType-- . itUse . uequipEffect . eeType
i <- i <-
w ^? rbOptions . opSel w ^? rbOptions . opSel
<|> Just (chooseEquipPosition (you w) (eqSiteToPositions esite)) <|> Just (chooseEquipPosition (w ^. cWorld . lWorld . items) (you w) (eqSiteToPositions esite))
es <- eqSiteToPositions esite ^? ix i es <- eqSiteToPositions esite ^? ix i
return $ case you w ^? crInv . ix invid . itLocation . ilEquipSite . _Just of return $ case you w ^? crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k . itLocation . ilEquipSite . _Just of
Just epos Just epos
| es == epos -> RemoveEquipment{_allocOldPos = epos} | es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos Just epos
+6 -3
View File
@@ -92,15 +92,18 @@ itemExternalValue itm w cr
= Just (Right "ON") = Just (Right "ON")
| BINGATE <- itm ^. itType = do | BINGATE <- itm ^. itType = do
invid <- itm ^? itLocation . ilInvID invid <- itm ^? itLocation . ilInvID
litm <- cr ^? crInv . ix (invid -2) litid <- cr ^? crInv . ix (invid -2)
ritm <- cr ^? crInv . ix (invid -1) ritid <- cr ^? crInv . ix (invid -1)
litm <- w ^? cWorld . lWorld . items . ix litid
ritm <- w ^? cWorld . lWorld . items . ix ritid
x <- itm ^? itScroll . itsRangeInt x <- itm ^? itScroll . itsRangeInt
l <- getItemValue litm w cr ^? _Just . _Left l <- getItemValue litm w cr ^? _Just . _Left
r <- getItemValue ritm w cr ^? _Just . _Left r <- getItemValue ritm w cr ^? _Just . _Left
Just . Left $ bgateCalc x l r Just . Left $ bgateCalc x l r
| UNIGATE <- itm ^. itType = do | UNIGATE <- itm ^. itType = do
invid <- itm ^? itLocation . ilInvID invid <- itm ^? itLocation . ilInvID
itm' <- cr ^? crInv . ix (invid -1) itid' <- cr ^? crInv . ix (invid -1)
itm' <- w ^? cWorld . lWorld . items . ix itid'
x <- itm ^? itScroll . itsRangeInt x <- itm ^? itScroll . itsRangeInt
y <- getItemValue itm' w cr ^? _Just . _Left y <- getItemValue itm' w cr ^? _Just . _Left
Just . Left $ ugateCalc x y Just . Left $ ugateCalc x y
+3 -2
View File
@@ -48,7 +48,7 @@ swapInvItems f i w = fromMaybe w $ do
. swapSite i k . swapSite i k
. swapSite k i . swapSite k i
cr = you w cr = you w
swapSite a b = case cr ^? crInv . ix a . itLocation . ilEquipSite . _Just of swapSite a b = case cr ^? crInv . ix a >>= \k -> w ^? cWorld . lWorld . items . ix k . itLocation . ilEquipSite . _Just of
Just epos -> crEquipment . ix epos .~ b Just epos -> crEquipment . ix epos .~ b
Nothing -> id Nothing -> id
@@ -63,8 +63,9 @@ swapAnyExtraSelection i k w = fromMaybe w $ do
checkConnection :: SoundOrigin -> SoundID -> Int -> Int -> World -> World checkConnection :: SoundOrigin -> SoundID -> Int -> Int -> World -> World
checkConnection so s i j w = fromMaybe w $ do checkConnection so s i j w = fromMaybe w $ do
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv inv' <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
cpos <- w ^? cWorld . lWorld . creatures . ix 0 . crPos cpos <- w ^? cWorld . lWorld . creatures . ix 0 . crPos
let inv = fmap (\k -> w ^?! cWorld . lWorld . items . ix k) inv'
let locs = invIndents inv -- why indents? let locs = invIndents inv -- why indents?
iit <- locs ^? ix i . _2 iit <- locs ^? ix i . _2
jit <- locs ^? ix j . _2 jit <- locs ^? ix j . _2
+13 -12
View File
@@ -4,6 +4,7 @@ module Dodge.Item.Draw (
itemEquipPict, itemEquipPict,
) where ) where
import qualified Data.IntMap.Strict as IM
import qualified Quaternion as Q import qualified Quaternion as Q
import Dodge.Data.Equipment.Misc import Dodge.Data.Equipment.Misc
import Dodge.Data.ComposedItem import Dodge.Data.ComposedItem
@@ -16,12 +17,12 @@ import Dodge.Item.Draw.SPic
import Dodge.Item.HeldOffset import Dodge.Item.HeldOffset
import ShapePicture import ShapePicture
itemEquipPict :: Creature -> DTree CItem -> SPic itemEquipPict :: IM.IntMap Item -> Creature -> DTree CItem -> SPic
itemEquipPict cr itmtree itemEquipPict m cr itmtree
| Just i <- itm ^? itLocation . ilInvID | Just i <- itm ^? itLocation . ilInvID
, Just esite <- cr ^? crInv . ix i . itLocation . ilEquipSite . _Just , Just esite <- itm ^? itLocation . ilEquipSite . _Just
, Just attachpos <- equipAttachPos <$> itm ^? itType . ibtEquip , Just attachpos <- equipAttachPos <$> itm ^? itType . ibtEquip
= equipPosition esite cr attachpos (itemSPic itm) = equipPosition esite m cr attachpos (itemSPic itm)
| itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem | itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem
= overPosSP (Q.prePos $ handHandleOrient loc cr) (itemTreeSPic itmtree) = overPosSP (Q.prePos $ handHandleOrient loc cr) (itemTreeSPic itmtree)
| otherwise = mempty | otherwise = mempty
@@ -37,15 +38,15 @@ equipAttachPos = \case
BULLETBELTBRACER -> V3 (-9) 0 10 BULLETBELTBRACER -> V3 (-9) 0 10
_ -> 0 _ -> 0
equipPosition :: EquipSite -> Creature -> Point3 -> SPic -> SPic equipPosition :: EquipSite -> IM.IntMap Item -> Creature -> Point3 -> SPic -> SPic
equipPosition epos cr p sh = case epos of equipPosition epos m cr p sh = case epos of
OnLeftWrist -> translateToLeftWrist cr sh OnLeftWrist -> translateToLeftWrist m cr sh
OnRightWrist -> translateToRightWrist cr sh OnRightWrist -> translateToRightWrist m cr sh
OnLegs -> OnLegs ->
translateToLeftLeg cr sh translateToLeftLeg cr sh
<> translateToRightLeg cr sh-- (mirrorSPxz sh) <> translateToRightLeg cr sh-- (mirrorSPxz sh)
OnHead -> translateToHead cr sh OnHead -> translateToHead m cr sh
OnChest -> translateToChest cr sh OnChest -> translateToChest m cr sh
--OnBack -> translateToBack cr p sh --OnBack -> translateToBack cr p sh
OnBack -> overPosSP (\x -> fst $ backPQ cr `Q.comp` (p + x,Q.qID)) sh OnBack -> overPosSP (\x -> fst $ backPQ m cr `Q.comp` (p + x,Q.qID)) sh
OnSpecial -> sh -- OnSpecial -> sh
+6 -14
View File
@@ -26,26 +26,18 @@ import Dodge.Data.World
pointerYourSelectedItem :: Applicative a => (Item -> a Item) -> World -> a World pointerYourSelectedItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourSelectedItem f w = fromMaybe (pure w) $ do pointerYourSelectedItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
Just $ (cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid) f w itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w
-- note the ilIsRoot/Selected/Attached booleans are irrelevant -- note the ilIsRoot/Selected/Attached booleans are irrelevant
pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourRootItem f w = fromMaybe (pure w) $ do pointerYourRootItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem
Just $ (cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid) f w itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w
pointerToItem :: Applicative f => Item -> (Item -> f Item) -> World -> f World pointerToItem :: Applicative f => Item -> (Item -> f Item) -> World -> f World
pointerToItem x = case x ^. itLocation of pointerToItem x = cWorld . lWorld . items . ix (x ^. itID . unNInt)
OnFloor -> cWorld . lWorld . items . ix (x ^. itID . unNInt)
OnTurret _ -> cWorld . lWorld . items . ix (x ^. itID . unNInt)
InInv cid invid _ _ _ _ -> cWorld . lWorld . creatures . ix cid . crInv . ix invid
InVoid -> const pure
pointerToItemID :: Applicative f => NewInt ItmInt -> (Item -> f Item) -> World -> f World pointerToItemID :: Applicative f => NewInt ItmInt -> (Item -> f Item) -> World -> f World
pointerToItemID itid f w = fromMaybe (pure w) $ do pointerToItemID itid = cWorld . lWorld . items . ix (itid ^. unNInt)
itloc <- w ^? cWorld . lWorld . itemLocations . ix (_unNInt itid)
return $ (\x -> x f w) $ case itloc of
OnFloor -> cWorld . lWorld . items . ix (itid ^. unNInt)
OnTurret _ -> cWorld . lWorld . items . ix (itid ^. unNInt)
InInv cid invid _ _ _ _ -> cWorld . lWorld . creatures . ix cid . crInv . ix invid
InVoid -> const pure
+64 -64
View File
@@ -1,6 +1,6 @@
module Dodge.Item.Location.Initialize module Dodge.Item.Location.Initialize
( initSpecificCrItemLocations ( -- initSpecificCrItemLocations
, initItemLocations --, initItemLocations
) )
where where
import NewInt import NewInt
@@ -9,68 +9,68 @@ import Control.Lens
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import Data.Traversable import Data.Traversable
initItemLocations :: LWorld -> LWorld --initItemLocations :: LWorld -> LWorld
--initItemLocations = initCrsItemLocations . initFlItemsLocations . initTusItemLocations ----initItemLocations = initCrsItemLocations . initFlItemsLocations . initTusItemLocations
initItemLocations = initCrsItemLocations -- . initTusItemLocations --initItemLocations = initCrsItemLocations -- . initTusItemLocations
--
initCrsItemLocations :: LWorld -> LWorld --initCrsItemLocations :: LWorld -> LWorld
initCrsItemLocations w = w' & creatures .~ newcreatures --initCrsItemLocations w = w' & creatures .~ newcreatures
where
(w', newcreatures) = mapAccumR initCrItemLocations w (w ^. creatures)
--initFlItemsLocations :: LWorld -> LWorld
--initFlItemsLocations w = w' & floorItems .~ newfloorItems
-- where -- where
-- (w', newfloorItems) = mapAccumR initFlItemLocation w (w ^. floorItems) -- (w', newcreatures) = mapAccumR initCrItemLocations w (w ^. creatures)
--
--initTusItemLocations :: LWorld -> LWorld ----initFlItemsLocations :: LWorld -> LWorld
--initTusItemLocations w = w' & machines .~ newmachines ----initFlItemsLocations w = w' & floorItems .~ newfloorItems
---- where
---- (w', newfloorItems) = mapAccumR initFlItemLocation w (w ^. floorItems)
--
----initTusItemLocations :: LWorld -> LWorld
----initTusItemLocations w = w' & machines .~ newmachines
---- where
---- (w', newmachines) = mapAccumR initTuItemLocation w (w ^. machines)
--
--initSpecificCrItemLocations :: Int -> LWorld -> LWorld
--initSpecificCrItemLocations crid w = w' & creatures . ix crid .~ newcr
-- where -- where
-- (w', newmachines) = mapAccumR initTuItemLocation w (w ^. machines) -- (w',newcr) = initCrItemLocations w (w ^?! creatures . ix crid)
--
initSpecificCrItemLocations :: Int -> LWorld -> LWorld --initCrItemLocations :: LWorld -> Creature -> (LWorld, Creature)
initSpecificCrItemLocations crid w = w' & creatures . ix crid .~ newcr --initCrItemLocations w cr = (w', cr & crInv .~ newinv)
where
(w',newcr) = initCrItemLocations w (w ^?! creatures . ix crid)
initCrItemLocations :: LWorld -> Creature -> (LWorld, Creature)
initCrItemLocations w cr = (w', cr & crInv .~ newinv)
where
(w',newinv) = imapAccumR (initCrItemLocation cr) w (_crInv cr)
-- does not worry about creature manipulation for now
initCrItemLocation :: Creature -> Int -> LWorld -> Item -> (LWorld,Item)
initCrItemLocation cr invid w it = (w & itemLocations . at locid ?~ loc
,it & itID .~ NInt locid
& itLocation .~ loc)
where
locid = IM.newKey ( w ^. itemLocations)
loc = InInv
{ _ilCrID = _crID cr
, _ilInvID = invid
, _ilIsRoot = False
, _ilIsSelected = False
, _ilIsAttached = False
, _ilEquipSite = Nothing
}
--initFlItemLocation :: LWorld -> FloorItem -> (LWorld, FloorItem)
--initFlItemLocation w flit = (w & itemLocations . at locid ?~ loc
-- , flit & flIt . itID .~ NInt locid
-- & flIt . itLocation .~ loc
-- )
-- where -- where
-- locid = IM.newKey (w ^. itemLocations ) -- (w',newinv) = imapAccumR (initCrItemLocation cr) w (_crInv cr)
-- loc = OnFloor (_flItID flit) --
---- does not worry about creature manipulation for now
--initTuItemLocation :: LWorld -> Machine -> (LWorld, Machine) --initCrItemLocation :: Creature -> Int -> LWorld -> Int -> (LWorld,Item)
--initTuItemLocation w mc = case mc ^? mcType . _McTurret . tuWeapon of --initCrItemLocation cr invid w itid = (w & itemLocations . at locid ?~ loc
-- Nothing -> (w, mc) -- ,it & itID .~ NInt locid
-- Just _ -> -- & itLocation .~ loc)
-- let locid = IM.newKey ( w ^. itemLocations) -- where
-- loc = OnTurret (_mcID mc) -- locid = IM.newKey ( w ^. itemLocations)
-- in ( w & itemLocations . at locid ?~ loc -- loc = InInv
-- , mc & mcType . _McTurret . tuWeapon . itID .~ NInt locid -- { _ilCrID = _crID cr
-- & mcType . _McTurret . tuWeapon . itLocation .~ loc -- , _ilInvID = invid
-- ) -- , _ilIsRoot = False
-- , _ilIsSelected = False
-- , _ilIsAttached = False
-- , _ilEquipSite = Nothing
-- }
--
--
----initFlItemLocation :: LWorld -> FloorItem -> (LWorld, FloorItem)
----initFlItemLocation w flit = (w & itemLocations . at locid ?~ loc
---- , flit & flIt . itID .~ NInt locid
---- & flIt . itLocation .~ loc
---- )
---- where
---- locid = IM.newKey (w ^. itemLocations )
---- loc = OnFloor (_flItID flit)
--
----initTuItemLocation :: LWorld -> Machine -> (LWorld, Machine)
----initTuItemLocation w mc = case mc ^? mcType . _McTurret . tuWeapon of
---- Nothing -> (w, mc)
---- Just _ ->
---- let locid = IM.newKey ( w ^. itemLocations)
---- loc = OnTurret (_mcID mc)
---- in ( w & itemLocations . at locid ?~ loc
---- , mc & mcType . _McTurret . tuWeapon . itID .~ NInt locid
---- & mcType . _McTurret . tuWeapon . itLocation .~ loc
---- )
+2 -2
View File
@@ -17,7 +17,7 @@ import Data.Traversable
import Dodge.Data.GenWorld import Dodge.Data.GenWorld
import Dodge.Default.Wall import Dodge.Default.Wall
import Dodge.GameRoom import Dodge.GameRoom
import Dodge.Item.Location.Initialize --import Dodge.Item.Location.Initialize
import Dodge.LevelGen.LevelStructure import Dodge.LevelGen.LevelStructure
import Dodge.LevelGen.StaticWalls import Dodge.LevelGen.StaticWalls
import Dodge.Path import Dodge.Path
@@ -36,7 +36,7 @@ generateLevelFromRoomList gr' w =
over gwWorld initWallZoning over gwWorld initWallZoning
. over gwWorld randomCompass . over gwWorld randomCompass
. over gwWorld setupWorldBounds . over gwWorld setupWorldBounds
. over (gwWorld . cWorld . lWorld) initItemLocations -- . over (gwWorld . cWorld . lWorld) initItemLocations
. doAfterPlacements . doAfterPlacements
. doInPlacements . doInPlacements
. doOutPlacements . doOutPlacements
+1 -1
View File
@@ -121,7 +121,7 @@ someCrits :: RandomGen g => State g [Creature]
someCrits = do someCrits = do
nCrits <- state $ randomR (1, 3) nCrits <- state $ randomR (1, 3)
fmap (take nCrits) . shuffle $ fmap (take nCrits) . shuffle $
[spreadGunCrit, pistolCrit, autoCrit, armourChaseCrit] [spreadGunCrit, autoCrit, armourChaseCrit]
++ replicate 20 chaseCrit ++ replicate 20 chaseCrit
--addcrits :: RandomGen g => [Item] -> State g (Tree Room) --addcrits :: RandomGen g => [Item] -> State g (Tree Room)
+2 -1
View File
@@ -153,7 +153,8 @@ mcProximitySensorUpdate mc w = case ( _proxStatus sens
mcProxTest :: Machine -> World -> Bool mcProxTest :: Machine -> World -> Bool
mcProxTest mc w = case mc ^? mcType . _McSensor . proxRequirement of mcProxTest mc w = case mc ^? mcType . _McSensor . proxRequirement of
Just (RequireHealth x) -> _crHP cr >= x Just (RequireHealth x) -> _crHP cr >= x
Just (RequireEquipment ct) -> any (\itm -> _itType itm == ct) (_crInv cr) Just (RequireEquipment ct) -> any (\itm -> _itType itm == ct)
(fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ _crInv cr)
_ -> False _ -> False
where where
cr = you w cr = you w
+3 -4
View File
@@ -109,8 +109,8 @@ placeSpotID' ps pt w = case pt of
PutProp prp -> plNewUpID (cWorld . lWorld . props) prID (mvProp p rot prp) w PutProp prp -> plNewUpID (cWorld . lWorld . props) prID (mvProp p rot prp) w
PutButton bt -> plNewUpID (cWorld . lWorld . buttons) btID (mvButton p rot bt) w PutButton bt -> plNewUpID (cWorld . lWorld . buttons) btID (mvButton p rot bt) w
PutTerminal tm -> plNewUpID (cWorld . lWorld . terminals) tmID tm w PutTerminal tm -> plNewUpID (cWorld . lWorld . terminals) tmID tm w
PutFlIt itm -> let i = IM.newKey (w ^. cWorld . lWorld . itemLocations) PutFlIt itm -> let i = IM.newKey (w ^. cWorld . lWorld . items)
in (i, w & cWorld . lWorld . itemLocations . at i ?~ OnFloor in (i, w
& cWorld . lWorld . floorItems . at i ?~ createFlIt p rot & cWorld . lWorld . floorItems . at i ?~ createFlIt p rot
& cWorld . lWorld . items . at i ?~ (itm & itID .~ NInt i & cWorld . lWorld . items . at i ?~ (itm & itID .~ NInt i
& itLocation .~ OnFloor) & itLocation .~ OnFloor)
@@ -205,12 +205,11 @@ plTurret wallpoly mc wl itm p rot gw =
, gw & cWorld . lWorld . machines %~ addMc , gw & cWorld . lWorld . machines %~ addMc
& cWorld . lWorld . walls %~ placeMachineWalls wl col wallpoly mcid wlid & cWorld . lWorld . walls %~ placeMachineWalls wl col wallpoly mcid wlid
& cWorld . lWorld . items . at itid ?~ itm' & cWorld . lWorld . items . at itid ?~ itm'
& cWorld . lWorld . itemLocations . at itid ?~ OnTurret mcid
) )
where where
itm' = itm & itID .~ NInt itid itm' = itm & itID .~ NInt itid
& itLocation .~ OnTurret mcid & itLocation .~ OnTurret mcid
itid = IM.newKey $ gw ^. cWorld . lWorld . itemLocations itid = IM.newKey $ gw ^. cWorld . lWorld . items
col = _mcColor mc col = _mcColor mc
mcid = IM.newKey $ gw ^. cWorld . lWorld . machines mcid = IM.newKey $ gw ^. cWorld . lWorld . machines
wlid = IM.newKey $ gw ^. cWorld . lWorld . walls wlid = IM.newKey $ gw ^. cWorld . lWorld . walls
+1 -1
View File
@@ -228,7 +228,7 @@ pjRemoteSetDirection :: Maybe RocketHoming -> Projectile -> World -> World
pjRemoteSetDirection ph pj w = case ph of pjRemoteSetDirection ph pj w = case ph of
Just (HomeUsingRemoteScreen screenid) Just (HomeUsingRemoteScreen screenid)
| lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem | lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
== lw ^? itemLocations . ix (_unNInt screenid) . ilInvID -> == lw ^? items . ix (_unNInt screenid) . itLocation . ilInvID ->
w w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir & cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir
.~ (w ^. wCam . camRot) + argV (w ^. input . mousePos) .~ (w ^. wCam . camRot) + argV (w ^. input . mousePos)
+8 -5
View File
@@ -62,7 +62,8 @@ drawInventory sss w cfig =
f = fmap (\(x, y, _) -> (x, y)) f = fmap (\(x, y, _) -> (x, y))
curs = invCursorParams w curs = invCursorParams w
itemconnections = fromMaybe mempty $ do itemconnections = fromMaybe mempty $ do
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv inv' <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
let inv = fmap (\k -> w ^?! cWorld . lWorld . items . ix k) inv'
case w ^? hud . hudElement . diInvFilter . _Just of case w ^? hud . hudElement . diInvFilter . _Just of
Just (_ : _) -> Nothing Just (_ : _) -> Nothing
_ -> return . drawItemConnections sss cfig $ invAdj inv _ -> return . drawItemConnections sss cfig $ invAdj inv
@@ -79,7 +80,8 @@ drawRootCursor w sss msel ldp cfig = fromMaybe mempty $ do
guard $ crIsAiming cr guard $ crIsAiming cr
(i, j) <- msel (i, j) <- msel
guard $ i == 0 guard $ i == 0
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv inv' <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
let inv = fmap (\k -> w ^?! cWorld . lWorld . items . ix k) inv'
(x, y) <- getRootItemBounds j inv (x, y) <- getRootItemBounds j inv
return $ return $
drawSSMultiCursor drawSSMultiCursor
@@ -201,7 +203,7 @@ drawExamineInventory cfig w =
yourAugmentedItem yourAugmentedItem
itemInfo itemInfo
(yourInfo (you w)) (yourInfo (you w))
(closeObjectInfo (crNumFreeSlots (you w))) (closeObjectInfo (crNumFreeSlots (w ^. cWorld . lWorld . items) (you w)))
w w
) )
) )
@@ -248,7 +250,7 @@ drawRBOptions cfig w = fold $ do
invid <- you w ^? crManipulation . manObject . imSelectedItem invid <- you w ^? crManipulation . manObject . imSelectedItem
eslist <- eslist <-
fmap eqSiteToPositions $ fmap eqSiteToPositions $
you w ^? crInv . ix invid >>= equipType -- . itUse . uequipEffect . eeType you w ^? crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k >>= equipType -- . itUse . uequipEffect . eeType
i <- w ^? rbOptions . opSel i <- w ^? rbOptions . opSel
let ae = getEquipmentAllocation invid w let ae = getEquipmentAllocation invid w
sss <- w ^? hud . hudElement . diSections sss <- w ^? hud . hudElement . diSections
@@ -297,7 +299,8 @@ drawRBOptions cfig w = fold $ do
| a == b - 1 = listCursorChooseBorderScale 0 1 (bc South) curpos 0 white 7 1 | a == b - 1 = listCursorChooseBorderScale 0 1 (bc South) curpos 0 white 7 1
| otherwise = mempty | otherwise = mempty
otheritem j = fromMaybe "" $ do otheritem j = fromMaybe "" $ do
itype <- you w ^? crInv . ix j . itType itid <- you w ^? crInv . ix j
itype <- w ^? cWorld . lWorld . items . ix itid . itType
return $ itemBaseName itype return $ itemBaseName itype
equipAllocString :: EquipmentAllocation -> String equipAllocString :: EquipmentAllocation -> String
+5 -4
View File
@@ -28,7 +28,8 @@ worldSPic cfig u =
<> foldup (shiftDraw _blPos _blDir (drawBlock . _blDraw)) (filtOn _blPos _blocks) <> foldup (shiftDraw _blPos _blDir (drawBlock . _blDraw)) (filtOn _blPos _blocks)
<> foldup (shiftDraw _fsPos _fsDir (const _fsSPic)) (filtOn _fsPos _foregroundShapes) <> foldup (shiftDraw _fsPos _fsDir (const _fsSPic)) (filtOn _fsPos _foregroundShapes)
<> foldup (shiftDraw' _cpPos _cpDir _cpSPic) (filtOn _cpPos _corpses) <> foldup (shiftDraw' _cpPos _cpDir _cpSPic) (filtOn _cpPos _corpses)
<> foldup drawCreature (filtOn _crPos _creatures) <> foldup (drawCreature (u ^. uvWorld . cWorld . lWorld . items))
(filtOn _crPos _creatures)
<> foldup (Prelude.uncurry floorItemSPic) (IM.intersectionWith (,) (u^.uvWorld.cWorld.lWorld.items) (filtOn _flItPos (_floorItems))) <> foldup (Prelude.uncurry floorItemSPic) (IM.intersectionWith (,) (u^.uvWorld.cWorld.lWorld.items) (filtOn _flItPos (_floorItems)))
<> foldup btSPic (filtOn _btPos _buttons) <> foldup btSPic (filtOn _btPos _buttons)
<> foldup (mcSPic (u ^. uvWorld . cWorld . lWorld)) (filtOn _mcPos _machines) <> foldup (mcSPic (u ^. uvWorld . cWorld . lWorld)) (filtOn _mcPos _machines)
@@ -57,12 +58,12 @@ drawPulseBall pb =
. setLayer BloomLayer . setLayer BloomLayer
$ circleSolidCol green white 10 $ circleSolidCol green white 10
drawCreature :: Creature -> SPic drawCreature :: IM.IntMap Item -> Creature -> SPic
drawCreature cr = translateSPz (_crZ cr) . uncurryV translateSPxy (_crPos cr) . rotateSP (_crDir cr) $ drawCreature m cr = translateSPz (_crZ cr) . uncurryV translateSPxy (_crPos cr) . rotateSP (_crDir cr) $
case cr ^. crType of case cr ^. crType of
BarrelCrit{} -> barrelShape BarrelCrit{} -> barrelShape
LampCrit{_lampHeight = h} -> lampCrSPic h LampCrit{_lampHeight = h} -> lampCrSPic h
_ -> basicCrPict cr _ -> basicCrPict m cr
barrelShape :: SPic barrelShape :: SPic
barrelShape = noPic $ cylinderPoly Medium Important (map (addZ 20) ps) (map (addZ 0) ps) barrelShape = noPic $ cylinderPoly Medium Important (map (addZ 20) ps) (map (addZ 0) ps)
+1 -1
View File
@@ -268,7 +268,7 @@ randomFourCornerRoom its = do
nCrits <- state $ randomR (1, 3) nCrits <- state $ randomR (1, 3)
crits <- crits <-
takeN nCrits <=< shuffle $ takeN nCrits <=< shuffle $
[spreadGunCrit, pistolCrit, autoCrit, armourChaseCrit] [spreadGunCrit, autoCrit, armourChaseCrit]
++ replicate 20 chaseCrit ++ replicate 20 chaseCrit
randomFourCornerRoomCrsIts crits its randomFourCornerRoomCrsIts crits its
+1 -1
View File
@@ -326,7 +326,7 @@ pistolerRoom = do
3 3
( psPtPl ( psPtPl
(rprBool $ \rp _ -> _rpPlacementUse rp == 0 && rpIsOnPath rp) (rprBool $ \rp _ -> _rpPlacementUse rp == 0 && rpIsOnPath rp)
(PutCrit pistolCrit) (PutCrit chaseCrit)
) )
shootingRange :: RandomGen g => State g (MetaTree Room String) shootingRange :: RandomGen g => State g (MetaTree Room String)
+1 -1
View File
@@ -29,7 +29,7 @@ import qualified Data.Map.Strict as M
import NewInt import NewInt
testStringInit :: Universe -> [String] testStringInit :: Universe -> [String]
testStringInit u = map show (IM.keys $ u ^. uvWorld . cWorld . lWorld . itemLocations) testStringInit u = map show (IM.keys $ u ^. uvWorld . cWorld . lWorld . items)
<> map show (IM.keys $ u ^. uvWorld . cWorld . lWorld . floorItems) <> map show (IM.keys $ u ^. uvWorld . cWorld . lWorld . floorItems)
<> map show (u ^. uvWorld . hud . closeItems) <> map show (u ^. uvWorld . hud . closeItems)
-- map shortShow (u ^.. uvWorld . cWorld . lWorld . debris . each . to g) -- map shortShow (u ^.. uvWorld . cWorld . lWorld . debris . each . to g)
+11 -6
View File
@@ -95,28 +95,33 @@ moveZoomCamera cfig theinput cr w campos =
where where
mremotepos = do mremotepos = do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
j <- cr ^? crInv . ix i . itUse . uaParams . apProjectiles . ix 0 itid <- cr ^? crInv . ix i
guard $ Just REMOTESCREEN == cr ^? crInv . ix i . itType . ibtAttach j <- w ^? cWorld . lWorld . items . ix itid . itUse . uaParams . apProjectiles . ix 0
guard $ Just REMOTESCREEN == w ^? cWorld . lWorld . items . ix itid . itType . ibtAttach
w ^? cWorld . lWorld . projectiles . ix j . pjPos . _xy w ^? cWorld . lWorld . projectiles . ix j . pjPos . _xy
docamrot = rotateV (campos ^. camRot) docamrot = rotateV (campos ^. camRot)
offset = fromMaybe noscopeoffset $ do offset = fromMaybe noscopeoffset $ do
guard (SDL.ButtonRight `M.member` _mouseButtons theinput) guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
fmap docamrot (cr ^? crInv . ix i . itUse . uScope . opticPos) itid <- cr ^? crInv . ix i
fmap docamrot (w ^? cWorld . lWorld . items . ix itid . itUse . uScope . opticPos)
noscopeoffset = noscopeoffset =
docamrot $ docamrot $
((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
newzoom = fromMaybe (newDefaultZoom * newItemZoom) $ do newzoom = fromMaybe (newDefaultZoom * newItemZoom) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
cr ^? crInv . ix i . itUse . uScope . opticZoom itid <- cr ^? crInv . ix i
w ^? cWorld . lWorld . items . ix itid . itUse . uScope . opticZoom
idealDefaultZoom = clipZoom wallZoom idealDefaultZoom = clipZoom wallZoom
newDefaultZoom = fromMaybe (changeZoom (campos ^. camDefaultZoom) idealDefaultZoom) $ do newDefaultZoom = fromMaybe (changeZoom (campos ^. camDefaultZoom) idealDefaultZoom) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
cr ^? crInv . ix i . itUse . uScope . opticZoom itid <- cr ^? crInv . ix i
w ^? cWorld . lWorld . items . ix itid . itUse . uScope . opticZoom
idealItemZoom = fromMaybe 1 $ do idealItemZoom = fromMaybe 1 $ do
guard $ crIsAiming cr guard $ crIsAiming cr
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
getAimZoom <$> (cr ^? crInv . ix i) itid <- cr ^? crInv . ix i
getAimZoom <$> (w ^? cWorld . lWorld . items . ix itid)
newItemZoom = changeZoom (campos ^. camItemZoom) idealItemZoom newItemZoom = changeZoom (campos ^. camItemZoom) idealItemZoom
changeZoom curZoom idealZoom changeZoom curZoom idealZoom
| curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed | curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed
+3 -2
View File
@@ -131,7 +131,7 @@ tryPickupSelected k mpos w = do
guard $ k == 3 guard $ k == 3
guard $ maybe True (\(i, _) -> i == 0 || i == 1) mpos guard $ maybe True (\(i, _) -> i == 0 || i == 1) mpos
cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
let nfreeslots = crNumFreeSlots cr let nfreeslots = crNumFreeSlots (w ^. cWorld . lWorld . items) cr
xs <- w ^? hud . hudElement . diSelection . _Just . _3 xs <- w ^? hud . hudElement . diSelection . _Just . _3
let itmstopickup = mapMaybe g $ IS.toList xs let itmstopickup = mapMaybe g $ IS.toList xs
let slotsneeded = alaf Sum foldMap itInvHeight itmstopickup let slotsneeded = alaf Sum foldMap itInvHeight itmstopickup
@@ -238,6 +238,7 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
str <- str <-
fmap (take 5) $ fmap (take 5) $
w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix j w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix j
>>= \k -> w ^? cWorld . lWorld . items . ix k
>>= (listToMaybe . basicItemDisplay) >>= (listToMaybe . basicItemDisplay)
return . (worldEventFlags . at CombineInventoryChange ?~ ()) $ return . (worldEventFlags . at CombineInventoryChange ?~ ()) $
case w ^? hud . hudElement . subInventory . ciFilter . _Just of case w ^? hud . hudElement . subInventory . ciFilter . _Just of
@@ -541,7 +542,7 @@ tryCombine (i, j) w = fromMaybe w $ do
CombinableItem is it <- sss ^? ix i . ssItems . ix j . siPayload . _Just CombinableItem is it <- sss ^? ix i . ssItems . ix j . siPayload . _Just
p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos
return $ return $
snd (createItemYou it (foldr (destroyInvItem 0) w (sort is))) (createItemYou it (foldr (destroyInvItem 0) w (sort is)))
& soundStart InventorySound p wrench1S Nothing & soundStart InventorySound p wrench1S Nothing
& hud . hudElement . diSelection . _Just . _3 .~ mempty & hud . hudElement . diSelection . _Just . _3 .~ mempty
+7 -4
View File
@@ -3,6 +3,7 @@ module Dodge.Update.Scroll (
updateWheelEvent, updateWheelEvent,
) where ) where
import NewInt
import Control.Applicative import Control.Applicative
import qualified Data.ListTrie.Patricia.Map.Enum as PTE import qualified Data.ListTrie.Patricia.Map.Enum as PTE
import Dodge.Data.Terminal.Status import Dodge.Data.Terminal.Status
@@ -44,13 +45,13 @@ updateBaseWheelEvent yi w
bdown b = w & has (input . mouseButtons . ix b) bdown b = w & has (input . mouseButtons . ix b)
rbscrollmax = fromMaybe 1 $ do rbscrollmax = fromMaybe 1 $ do
invid <- you w ^? crManipulation . manObject . imSelectedItem invid <- you w ^? crManipulation . manObject . imSelectedItem
esite <- you w ^? crInv . ix invid >>= equipType -- . itUse . uequipEffect . eeType esite <- you w ^? crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k >>= equipType -- . itUse . uequipEffect . eeType
return . length $ eqSiteToPositions esite return . length $ eqSiteToPositions esite
selectedItemScroll :: Int -> World -> Maybe World selectedItemScroll :: Int -> World -> Maybe World
selectedItemScroll yi w = do selectedItemScroll yi w = do
i <- you w ^? crManipulation . manObject . imSelectedItem i <- you w ^? crManipulation . manObject . imSelectedItem
itm <- you w ^? crInv . ix i itm <- you w ^? crInv . ix i >>= \k -> w ^? cWorld . lWorld . items . ix k
return $ itemScroll yi i itm w return $ itemScroll yi i itm w
itemScroll :: Int -> Int -> Item -> World -> World itemScroll :: Int -> Int -> Item -> World -> World
@@ -69,7 +70,8 @@ itemScroll yi invid itm w
%~ ((`mod` y) . (+ yi)) %~ ((`mod` y) . (+ yi))
| otherwise = w | otherwise = w
where where
itmlens = cWorld . lWorld . creatures . ix 0 . crInv . ix invid --itmlens = cWorld . lWorld . creatures . ix 0 . crInv . ix invid
itmlens = cWorld . lWorld . items . ix (itm ^. itID . unNInt)
-- note that your _crInvLock does not apply to this TODO check that this is what -- note that your _crInvLock does not apply to this TODO check that this is what
-- is wanted -- is wanted
@@ -82,7 +84,8 @@ updateScopeZoom i w
w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) (w ^. input . mousePos) w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) (w ^. input . mousePos)
| otherwise = w & wppointer %~ resetscope | otherwise = w & wppointer %~ resetscope
where where
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itUse . uScope itid = w ^?! cWorld . lWorld . creatures . ix 0 . crInv . ix i
wppointer = cWorld . lWorld . items . ix itid . itUse . uScope
resetscope (OpticScope _ _ defz) = OpticScope (V2 0 0) defz defz resetscope (OpticScope _ _ defz) = OpticScope (V2 0 0) defz defz
doScopeZoom :: Int -> Point2 -> Scope -> Scope doScopeZoom :: Int -> Point2 -> Scope -> Scope
+1 -1
View File
@@ -46,7 +46,7 @@ doWdWd we = case we of
WdWdBurstFireRepetition cid invid -> \w -> fromMaybe w $ do WdWdBurstFireRepetition cid invid -> \w -> fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix cid cr <- w ^? cWorld . lWorld . creatures . ix cid
--itree <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT --itree <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT
loc <- invIndents (cr ^. crInv) ^? ix invid . _2 loc <- invIndents (fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ cr ^. crInv) ^? ix invid . _2
return $ heldEffectMuzzles loc cr w return $ heldEffectMuzzles loc cr w
accessTerminal :: Int -> World -> World accessTerminal :: Int -> World -> World
+6
View File
@@ -19,6 +19,12 @@ newtype NewIntMap a b = NIntMap { _unNIntMap :: IM.IntMap b}
deriving newtype (Monoid,Semigroup) deriving newtype (Monoid,Semigroup)
deriving (Eq,Ord,Show,Read) deriving (Eq,Ord,Show,Read)
--instance Ixed (NewIntMap (NewInt a)) where
-- type Index (NewIntMap (NewInt a)) = NewInt a
-- type Index (NewIntMap (NewInt a)) = NewInt a
-- ix :: (NewInt a) -> IndexedTraversal' (NewIntMap (NewInt a))
-- ix (NInt k) (NewIntMap m) = NIntMap <$> ix k m
makeLenses ''NewInt makeLenses ''NewInt
makeLenses ''NewIntMap makeLenses ''NewIntMap
deriveJSON defaultOptions ''NewInt deriveJSON defaultOptions ''NewInt
+323 -331
View File
File diff suppressed because it is too large Load Diff