From 652af6b0a9cbaf1dd0a75fd7fcaa20c168026e53 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 27 Nov 2021 18:10:05 +0000 Subject: [PATCH] Fold aiming parameters into item use datatype --- src/Dodge/Creature/Impulse/Movement.hs | 4 +- src/Dodge/Creature/Picture.hs | 6 +-- src/Dodge/Data.hs | 28 ++++++------- src/Dodge/Default.hs | 6 --- src/Dodge/Default/Weapon.hs | 28 +++++++------ src/Dodge/Item.hs | 4 -- src/Dodge/Item/Attachment.hs | 2 +- src/Dodge/Item/Craftable.hs | 1 - src/Dodge/Item/Draw.hs | 7 ++-- src/Dodge/Item/Equipment.hs | 3 +- src/Dodge/Item/Weapon/AmmoParams.hs | 8 ++++ src/Dodge/Item/Weapon/BatteryGuns.hs | 19 +++++---- src/Dodge/Item/Weapon/Bezier.hs | 8 ++-- src/Dodge/Item/Weapon/Booster.hs | 2 - src/Dodge/Item/Weapon/BulletGuns.hs | 55 ++++++++++++-------------- src/Dodge/Item/Weapon/Drone.hs | 8 ++-- src/Dodge/Item/Weapon/ExtraEffect.hs | 6 +-- src/Dodge/Item/Weapon/Grenade.hs | 11 ++---- src/Dodge/Item/Weapon/Launcher.hs | 14 +++---- src/Dodge/Item/Weapon/Radar.hs | 20 ++++------ src/Dodge/Item/Weapon/SprayGuns.hs | 14 +++---- src/Dodge/Item/Weapon/TriggerType.hs | 25 ++++++------ src/Dodge/Item/Weapon/Utility.hs | 7 ---- src/Dodge/Update/Camera.hs | 4 +- 24 files changed, 135 insertions(+), 155 deletions(-) diff --git a/src/Dodge/Creature/Impulse/Movement.hs b/src/Dodge/Creature/Impulse/Movement.hs index 9bc3efdc6..90b084ad7 100644 --- a/src/Dodge/Creature/Impulse/Movement.hs +++ b/src/Dodge/Creature/Impulse/Movement.hs @@ -22,7 +22,7 @@ crMvBy p' cr = advanceStepCounter (magV p) cr = product $ map equipAimSpeed $ IM.elems $ _crInv cr | otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr aimingFactor - | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itAimingSpeed + | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itUse . useAim . aimSpeed | otherwise = 1 it = _crInv cr IM.! _crInvSel cr @@ -40,7 +40,7 @@ crMvAbsolute p' cr = advanceStepCounter (magV p) cr = product $ map equipAimSpeed $ IM.elems $ _crInv cr | otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr aimingFactor - | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itAimingSpeed + | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itUse . useAim . aimSpeed | otherwise = 1 it = _crInv cr IM.! _crInvSel cr diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 078603653..e4990a637 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -182,17 +182,17 @@ scalp cr fhead = colorSH (greyN 0.9) . upperPrismPolyHalf 5 $ polyCirc 4 5 oneH :: Creature -> Bool -oneH cr = crIsAiming' cr && crIt ^? itAimStance == Just OneHand +oneH cr = crIsAiming' cr && crIt ^? itUse . useAim . aimStance == Just OneHand where crIt = _crInv cr IM.! _crInvSel cr twoFlat :: Creature -> Bool -twoFlat cr = crIsAiming' cr && crIt ^? itAimStance == Just TwoHandFlat +twoFlat cr = crIsAiming' cr && crIt ^? itUse . useAim . aimStance == Just TwoHandFlat where crIt = _crInv cr IM.! _crInvSel cr twists :: Creature -> Bool -twists cr = crIsAiming' cr && crIt ^? itAimStance == Just TwoHandTwist +twists cr = crIsAiming' cr && crIt ^? itUse . useAim . aimStance == Just TwoHandTwist where crIt = _crInv cr IM.! _crInvSel cr diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 240d33d86..38711643a 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -301,13 +301,22 @@ data ItemUse , _useDelay :: UseDelay , _useMods :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] , _useHammer :: HammerType + , _useAim :: AimParams } | LeftUse { _lUse :: Creature -> Int -> World -> World - , _itUseDelay :: UseDelay - , _itHammer :: HammerType + , _useDelay :: UseDelay + , _useHammer :: HammerType } | NoUse +data AimParams = AimParams + { _aimSpeed :: Float + , _aimRange :: Float + , _aimZoom :: ItZoom + , _aimStance :: AimStance + } +_itUseAimStance :: Item -> AimStance +_itUseAimStance = _aimStance . _useAim . _itUse data ItemAmmo = LoadableAmmo { _aoType :: AmmoType @@ -333,10 +342,7 @@ data Item , _wpSpread :: Float , _wpRange :: Float , _itFloorPict :: Item -> SPic - , _itAimingSpeed :: Float - , _itAimingRange :: Float , _itZoom :: ItZoom - , _itAimZoom :: ItZoom , _itEquipPict :: Creature -> Int -> SPic , _itScroll :: Float -> Creature -> Item -> Item , _itIdentity :: ItemIdentity @@ -347,7 +353,6 @@ data Item , _itInvColor :: Color , _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture) , _itWorldTrigger :: Maybe (Int -> World -> Bool) - , _itAimStance :: AimStance , _wpNumBarrels :: Int , _itDimension :: ItemDimension , _itCurseStatus :: CurseStatus @@ -364,7 +369,6 @@ data Item , _itInvDisplay :: Item -> String , _itInvColor :: Color , _itEffect :: ItEffect - , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension } @@ -378,7 +382,6 @@ data Item , _itID :: Maybe Int , _itInvDisplay :: Item -> String , _itInvColor :: Color - , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension } @@ -389,13 +392,9 @@ data Item , _itIdentity :: ItemIdentity , _itEffect :: ItEffect , _itID :: Maybe Int - , _itAimingSpeed :: Float - , _itAimingRange :: Float , _itZoom :: ItZoom - , _itAimZoom :: ItZoom , _itInvDisplay :: Item -> String , _itInvColor :: Color - , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension } @@ -407,10 +406,7 @@ data Item , _twMaxRange :: Float , _twAccuracy :: Float , _itUse :: ItemUse - , _itAimingSpeed :: Float - , _itAimingRange :: Float , _itZoom :: ItZoom - , _itAimZoom :: ItZoom , _itEquipPict :: Creature -> Int -> SPic , _itIdentity :: ItemIdentity , _itID :: Maybe Int @@ -419,7 +415,6 @@ data Item , _itInvColor :: Color , _itEffect :: ItEffect , _itScroll :: Float -> Creature -> Item -> Item - , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension } @@ -894,3 +889,4 @@ makeLenses ''Zone makeLenses ''ItemDimension makeLenses ''Vocalization makeLenses ''UseDelay +makeLenses ''AimParams diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 7579dd4ee..300080a1e 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -138,13 +138,9 @@ defaultEquipment = Equipment , _itEquipPict = \_ _ -> (,) emptySH blank , _itEffect = NoItEffect , _itID = Nothing - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom , _itInvColor = yellow , _itInvDisplay = _itName - , _itAimStance = LeaveHolstered , _itDimension = defaultItemDimension } defaultItZoom :: ItZoom @@ -163,7 +159,6 @@ defaultConsumable = Consumable , _itInvColor = blue , _itInvDisplay = \it -> _itName it ++ " x" ++ show (_itAmount it) , _itEffect = wpRecock - , _itAimStance = LeaveHolstered , _itDimension = defaultItemDimension } defaultApplyDamage :: [DamageType] -> Creature -> (World -> World, Creature) @@ -212,7 +207,6 @@ defaultIt = Consumable , _itInvDisplay = _itName , _itInvColor = blue , _itEffect = NoItEffect - , _itAimStance = LeaveHolstered } defaultMachine :: Machine defaultMachine = Machine diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index abb0eb41f..f36cd6284 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -10,6 +10,8 @@ import Shape import Geometry.Vector3D import Geometry +import Control.Lens + defaultAmmo :: ItemAmmo defaultAmmo = LoadableAmmo { _aoType = GenericAmmo @@ -33,6 +35,7 @@ ruseRate i f ht usemods = RightUse } , _useMods = usemods , _useHammer = ht + , _useAim = defaultAimParams } ruseInstant @@ -45,6 +48,7 @@ ruseInstant f ht usemods = RightUse , _useDelay = NoDelay , _useMods = usemods , _useHammer = ht + , _useAim = defaultAimParams } defaultrUse :: ItemUse @@ -53,19 +57,27 @@ defaultrUse = RightUse , _useDelay = DelayRate {_rateMax = 8, _rateTime = 0} , _useMods = [] , _useHammer = HasHammer HammerUp + , _useAim = defaultAimParams } defaultlUse :: ItemUse defaultlUse = LeftUse { _lUse = \_ _ -> id - , _itUseDelay = DelayRate {_rateMax = 8, _rateTime = 0} - , _itHammer = NoHammer + , _useDelay = DelayRate {_rateMax = 8, _rateTime = 0} + , _useHammer = NoHammer } luseInstantNoH :: (Creature -> Int -> World -> World) -> ItemUse luseInstantNoH f = LeftUse { _lUse = f - , _itUseDelay = NoDelay - , _itHammer = NoHammer + , _useDelay = NoDelay + , _useHammer = NoHammer + } +defaultAimParams :: AimParams +defaultAimParams = AimParams + { _aimSpeed = 1 + , _aimRange = 0 + , _aimZoom = ItZoom 20 0.2 1 + , _aimStance = OneHand } defaultGun :: Item @@ -85,10 +97,7 @@ defaultGun = Weapon (map (addZ 3) $ rectNESW 3 3 (-3) (-3)) (map (addZ 0) $ rectNESW 5 3 (-5) (-7)) ) - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = ItZoom 20 0.2 1 - , _itAimZoom = ItZoom 20 0.2 1 , _itEquipPict = pictureWeaponOnAim , _itScroll = \_ _ -> id , _itAttachment = NoItAttachment @@ -98,7 +107,6 @@ defaultGun = Weapon , _itInvColor = white , _itTargeting = Nothing , _itWorldTrigger = Nothing - , _itAimStance = OneHand , _wpNumBarrels = 1 , _itDimension = defaultItemDimension } @@ -113,9 +121,7 @@ defaultItemDimension = ItemDimension defaultAutoGun :: Item defaultAutoGun = defaultGun - { _itInvDisplay = basicWeaponDisplay - , _itAimStance = TwoHandTwist - } + & itUse . useAim . aimStance .~ TwoHandTwist defaultShellAmmo :: AmmoType defaultShellAmmo = ShellAmmo { _amPayload = const id diff --git a/src/Dodge/Item.hs b/src/Dodge/Item.hs index 1f4c0a725..2dd58f6f0 100644 --- a/src/Dodge/Item.hs +++ b/src/Dodge/Item.hs @@ -18,8 +18,6 @@ keyToken n = defaultEquipment , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) keyPic , _itEffect = NoItEffect , _itID = Nothing - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom , _itInvColor = yellow , _itInvDisplay = _itName @@ -41,8 +39,6 @@ latchkey n = defaultEquipment , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) latchkeyPic , _itEffect = NoItEffect , _itID = Nothing - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom , _itInvColor = yellow , _itInvDisplay = _itName diff --git a/src/Dodge/Item/Attachment.hs b/src/Dodge/Item/Attachment.hs index e2d736a21..4300e42a9 100644 --- a/src/Dodge/Item/Attachment.hs +++ b/src/Dodge/Item/Attachment.hs @@ -61,7 +61,7 @@ changeFuse -> Item changeFuse scrollAmount _ it = it & ( itAttachment .~ ItFuse newTime ) - & ( itAimZoom .~ defaultItZoom{_itZoomMax = zm, _itZoomMin = zm} ) + & ( itUse . useAim . aimZoom .~ defaultItZoom{_itZoomMax = zm, _itZoomMin = zm} ) where oldTime = _itFuseTime $ _itAttachment it newTime = min 90 $ max 20 $ oldTime - round (5 * scrollAmount) diff --git a/src/Dodge/Item/Craftable.hs b/src/Dodge/Item/Craftable.hs index 67e96dfa1..4ea156bc8 100644 --- a/src/Dodge/Item/Craftable.hs +++ b/src/Dodge/Item/Craftable.hs @@ -19,5 +19,4 @@ pipe = Craftable , _itID = Nothing , _itInvDisplay = _itName , _itInvColor = green - , _itAimStance = LeaveHolstered } diff --git a/src/Dodge/Item/Draw.hs b/src/Dodge/Item/Draw.hs index 77613033c..838b9091c 100644 --- a/src/Dodge/Item/Draw.hs +++ b/src/Dodge/Item/Draw.hs @@ -68,9 +68,10 @@ pictureWeaponOnAimItem p cr posInInv Just (Walking x LeftForward) -> f x * 50 _ -> 0 theIt = _crInv cr IM.! posInInv - isTwisting = _itAimStance theIt == TwoHandTwist - isOneHand = _itAimStance theIt == OneHand - isTwoHandFlat = _itAimStance theIt == TwoHandFlat + isTwisting = theIt ^? itUseAimStance == Just TwoHandTwist + isOneHand = theIt ^? itUseAimStance == Just OneHand + isTwoHandFlat = theIt ^? itUseAimStance == Just TwoHandFlat + itUseAimStance = itUse . useAim . aimStance f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen sLen = _strideLength $ _crStance cr diff --git a/src/Dodge/Item/Equipment.hs b/src/Dodge/Item/Equipment.hs index ba0b88d06..a2a9843a0 100644 --- a/src/Dodge/Item/Equipment.hs +++ b/src/Dodge/Item/Equipment.hs @@ -50,8 +50,7 @@ frontArmour = defaultEquipment } flatShield :: Item flatShield = defaultEquipment - { _itEquipPict = pictureWeaponOnAim' flatShieldEquipSPic - , _itAimStance = TwoHandFlat + { _itEquipPict = pictureWeaponOnAim' flatShieldEquipSPic -- this will not work any more because the shield has no aim stance , _itEffect = effectOnOffEquip createShieldWall removeShieldWall , _itName = "SHIELD" , _itIdentity = FlatShield diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index 02c5aee51..5e618d0ca 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -21,6 +21,14 @@ useAmmoParamsRate rate ht usemods = RightUse , _useDelay = DelayRate {_rateMax = rate,_rateTime = 0} , _useMods = usemods , _useHammer = ht + , _useAim = defaultAimParams + } +defaultAimParams :: AimParams +defaultAimParams = AimParams + { _aimSpeed = 1 + , _aimRange = 0 + , _aimZoom = ItZoom 20 0.2 1 + , _aimStance = OneHand } useAmmoParams :: Item -> Creature -> World -> World diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index ffc49c00b..f07c26510 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -42,20 +42,18 @@ teslaGun = defaultGun , _wpLoadedAmmo = 200 , _wpReloadTime = 80 } - , _itAimStance = TwoHandFlat , _itUse = ruseInstant (const aTeslaArc) NoHammer [ ammoCheckI - , useTimeCheckI , withTempLight 1 100 (V3 0 0 1) , withSoundForI elecCrackleS 1 , useAmmo 1 ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimStance .~ TwoHandFlat , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = teslaGunPic - , _itAimingSpeed = 0.4 , _itZoom = defaultItZoom - , _itAimingRange = 0 } teslaGunPic :: Item -> SPic teslaGunPic _ = noPic $ colorSH blue $ @@ -76,16 +74,16 @@ lasGun = defaultAutoGun } , _itUse = ruseInstant (const aLaser) NoHammer [ ammoCheckI - , useTimeCheckI , withTempLight 1 100 (V3 1 1 0) , withSoundForI tone440sawtoothquietS 2 , useAmmo 1 ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = lasGunPic - , _itAimingSpeed = 0.4 - , _itAimingRange = 1 , _itAttachment = ItCharMode $ Seq.fromList "/VZ" , _itScroll = scrollCharMode , _itInvDisplay = basicWeaponDisplay @@ -113,13 +111,14 @@ tractorGun = defaultAutoGun , _wpReloadTime = 40 } , _itUse = ruseInstant aTractorBeam NoHammer - [ ammoUseCheckI + [ ammoCheckI ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0.00001 , _wpRange = 20 , _itFloorPict = tractorGunSPic - , _itAimingSpeed = 0.4 - , _itAimingRange = 0.5 } -- TODO own picture for tractor gun tractorGunSPic :: Item -> SPic diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index 731702aa9..19867500c 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -26,23 +26,25 @@ bezierGun = defaultGun , _itUse = ruseRate 6 (\_ -> useTargetPos $ \p -> shootBezier $ fromJust p) -- <- the start point NoHammer [ ammoCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart tap2S , useAmmo 1 , withMuzFlareI . withRecoilI 40 . torqueBefore 0.05 ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 0 + & useAim . aimStance .~ TwoHandTwist + -- & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} , _itFloorPict = bezierGunSPic , _itAttachment = NoItAttachment , _itScroll = \_ _ -> removeItTarget , _itEffect = rbSetTarget , _itZoom = defaultItZoom - , _itAimingRange = 0 , _wpAmmo = defaultAmmo { _wpMaxAmmo = 50 } - , _itAimStance = TwoHandTwist } bezierGunSPic :: Item -> SPic bezierGunSPic = autoGunPic diff --git a/src/Dodge/Item/Weapon/Booster.hs b/src/Dodge/Item/Weapon/Booster.hs index 0265ce2aa..587e59c4f 100644 --- a/src/Dodge/Item/Weapon/Booster.hs +++ b/src/Dodge/Item/Weapon/Booster.hs @@ -122,8 +122,6 @@ boosterGun = defaultGun , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itEffect = resetAttachmentID } resetAttachmentID :: ItEffect diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 3587ee119..a5d117c1b 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -46,7 +46,7 @@ autoGun = defaultAutoGun , charFiringStratI [('S', hammerCheckI) ] - , useTimeCheckI + , useTimeCheck , charFiringStratI [('M', torqueBefore 0.08) ,('S', torqueBefore 0.05) @@ -58,13 +58,14 @@ autoGun = defaultAutoGun , withMuzFlareI , withSmoke 1 black 20 200 5 ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} , _wpSpread = autogunSpread , _wpRange = 20 , _itFloorPict = autoGunPic - , _itAimingSpeed = 0.4 - , _itAimingRange = 1 , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom {_itZoomFac = 1.5} , _itEquipPict = pictureWeaponOnAim , _itAttachment = ItCharMode $ Seq.fromList "MS" , _itScroll = scrollCharMode @@ -93,7 +94,7 @@ pistol = defaultGun , _itUse = useAmmoParamsRate 8 upHammer [ ammoCheckI , hammerCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart tap3S , useAmmo 1 , randSpreadDir @@ -102,8 +103,6 @@ pistol = defaultGun , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = pistolPic - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom , _itEquipPict = pictureWeaponAim pistolPic , _itID = Nothing @@ -143,10 +142,12 @@ hvAutoGun = defaultAutoGun , withThinSmokeI , withMuzFlareI ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} , _wpRange = 20 , _itFloorPict = hvAutoGunPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 1 } hvAutoGunPic :: Item -> SPic hvAutoGunPic it = @@ -171,7 +172,7 @@ ltAutoGun = defaultAutoGun } , _itUse = useAmmoParamsRate 3 NoHammer [ ammoCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart tap1S , useAmmo 1 , withRandomDirI 0.1 @@ -182,10 +183,7 @@ ltAutoGun = defaultAutoGun , _wpSpread = 0.5 , _wpRange = 20 , _itFloorPict = ltAutoGunPic - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom - , _itAimStance = OneHand } & itDimension . muzzleLength .~ 10 ltAutoGunPic :: Item -> SPic @@ -212,7 +210,6 @@ miniGun = defaultAutoGun , _itUse = ruseInstant (useAmmoParamsVelMod vm4) NoHammer [ ammoCheckI , withWarmUpI crankSlowS - , useTimeCheckI --, afterRecoil recoilAmount , withSoundForI mini1S 2 --, withThinSmokeI @@ -242,10 +239,12 @@ miniGun = defaultAutoGun , withOldDir od3 , withSmoke 1 black 20 200 5 ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} , _wpRange = 20 , _itFloorPict = miniGunPictItem - , _itAimingSpeed = 0.4 - , _itAimingRange = 1 , _itEquipPict = pictureWeaponAim miniGunPictItem } & itDimension . muzzleLength .~ 15 where @@ -300,7 +299,7 @@ spreadGun = defaultGun , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI , hammerCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart shotgunS , useAmmo 1 , withRecoilI 100 @@ -310,8 +309,6 @@ spreadGun = defaultGun , _wpSpread = spreadGunSpread , _wpRange = 20 , _itFloorPict = spreadGunPic - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _wpNumBarrels = 50 } spreadGunPic :: Item -> SPic @@ -335,21 +332,21 @@ multGun = defaultGun , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI , hammerCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart shotgunS , useAmmo 1 , withRecoilI 200 , withMuzFlareI , numI ] + & useAim . aimSpeed .~ 0.4 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} , _wpSpread = spreadGunSpread , _wpRange = 20 , _itFloorPict = multGunSPic - , _itAimingSpeed = 0.4 - , _itAimingRange = 1 , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom {_itZoomFac = 1.5} - , _itAimStance = TwoHandTwist , _wpNumBarrels = 5 } multGunSPic :: Item -> SPic @@ -381,23 +378,23 @@ longGun = defaultGun , _itUse = useAmmoParamsRate 100 upHammer [ ammoCheckI , hammerCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart bangEchoS , useAmmo 1 , withThickSmokeI , torqueAfterI 0.05 , withMuzFlareI ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 1 + & useAim . aimStance .~ TwoHandTwist + & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} , _wpRange = 200 , _itFloorPict = longGunSPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 1 , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} , _itScroll = zoomLongGun , _itAttachment = ItScope (V2 0 0) 0 1 False , _itEffect = itemLaserScopeEffect - , _itAimStance = TwoHandTwist } longGunSPic :: Item -> SPic longGunSPic _ = diff --git a/src/Dodge/Item/Weapon/Drone.hs b/src/Dodge/Item/Weapon/Drone.hs index c3d760df7..81f45b4d6 100644 --- a/src/Dodge/Item/Weapon/Drone.hs +++ b/src/Dodge/Item/Weapon/Drone.hs @@ -31,17 +31,17 @@ lasDrones = defaultGun } , _itUse = ruseRate 20 aDroneWithItemParams upHammer [ ammoCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart tap4S , useAmmo 1 ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 0.5 + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = lasDronesPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 0.5 , _itEffect = NoItEffect - , _itAimStance = TwoHandTwist } lasDronesPic :: Item -> SPic diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 4a7b29ad5..a370a43be 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -34,11 +34,11 @@ wpRecock = ItInvEffect ,_itEffectCounter = 0 } where - f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i + f _ cr invid = creatures . ix (_crID cr) . crInv . ix invid + . itUse . useHammer . hammerPosition %~ moveHammerUp moveHammerUp HammerDown = HammerReleased moveHammerUp HammerReleased = HammerUp moveHammerUp HammerUp = HammerUp - fOnIt it = it & itUse . itHammer . hammerPosition %~ moveHammerUp --{- | --Special recock for the bezier gun. --Not sure of its purpose at this time... -} @@ -65,7 +65,7 @@ itemLaserScopeEffect f _ cr invid w | invid == _crInvSel cr && crIsAiming' cr = w & particles %~ (:) (makeLaserScope sp ep reloadFrac) - & creatures . ix (_crID cr) . crInv . ix invid . itUse . itHammer . hammerPosition %~ moveHammerUp + & creatures . ix (_crID cr) . crInv . ix invid . itUse . useHammer . hammerPosition %~ moveHammerUp | otherwise = w where p = _crPos cr diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index d6eb69927..4c3a18dd9 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -35,12 +35,10 @@ grenade = Throwable , _twMaxRange = 150 , _twAccuracy = 30 , _itUse = ruseRate 25 (\_ -> throwGrenade makeExplosionAt) upHammer - [ useTimeCheckI + [ useTimeCheck ] - , _itAimingSpeed = 1 - , _itAimingRange = 0 + & useAim . aimZoom .~ defaultItZoom {_itZoomMax = f fuseTime, _itZoomMin = f fuseTime} , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom {_itZoomMax = f fuseTime, _itZoomMin = f fuseTime} , _itEquipPict = pictureWeaponOnAim' $ \_ -> grenadePic fuseTime , _itID = Nothing , _itAttachment = ItFuse fuseTime @@ -48,7 +46,6 @@ grenade = Throwable , _itInvDisplay = basicWeaponDisplay , _itEffect = wpRecock , _itScroll = changeFuse - , _itAimStance = OneHand } where fuseTime = 50 @@ -129,7 +126,7 @@ throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x } f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i counterDown it | _itEffectCounter (_itEffect it) == 0 = it - & itUse . itHammer . hammerPosition .~ HammerUp + & itUse . useHammer . hammerPosition .~ HammerUp & itEquipPict .~ pictureWeaponOnAim' (\_ -> grenadePic 50) | otherwise = it & itEffect . itEffectCounter -~ 1 @@ -207,7 +204,7 @@ setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of InInv cid invid -> w' & creatures . ix cid . crInv . ix invid . itAttachment . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid)) - & creatures . ix cid . crInv . ix invid . itAimZoom + & creatures . ix cid . crInv . ix invid . itUse . useAim . aimZoom .~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}) _ -> w' diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 01440289c..1ef31950a 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -51,17 +51,17 @@ launcher = defaultGun } , _itUse = ruseRate 20 aRocketWithItemParams upHammer [ ammoCheckI - , useTimeCheckI + , useTimeCheck , withSoundStart tap4S , useAmmo 1 ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 0.5 + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = launcherPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 0.5 , _itEffect = NoItEffect - , _itAimStance = TwoHandTwist } launcherPic :: Item -> SPic @@ -251,13 +251,13 @@ remoteLauncher = defaultGun [ ammoCheckI , hammerCheckI ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 0.5 + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = launcherPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 0.5 , _itAttachment = ItScope (V2 0 0) 0 1 True - , _itAimStance = TwoHandTwist } fireRemoteLauncher :: Creature -> World -> World diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index ab4899e07..a38c558fb 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -14,6 +14,8 @@ import Geometry import Picture import Shape +import Control.Lens + {- | Sends out pulses that display walls. -} radar :: Item @@ -26,14 +28,14 @@ radar = defaultGun , _wpReloadTime = 200 } , _itUse = ruseRate 120 (const aRadarPulse) upHammer - [ ammoUseCheckI + [ ammoUseCheck ] + & useAim . aimRange .~ 1 + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1} , _wpSpread = autogunSpread , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) - , _itAimingRange = 1 , _itZoom = defaultItZoom { _itZoomMax = 1} - , _itAimZoom = defaultItZoom { _itZoomMax = 1} , _itEquipPict = pictureWeaponOnAim' $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) } {- | @@ -48,13 +50,13 @@ sonar = defaultGun , _wpReloadTime = 200 } , _itUse = ruseRate 120 (const aSonarPulse) upHammer - [ ammoUseCheckI + [ ammoUseCheck ] + & useAim . aimRange .~ 1 + & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1} , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) - , _itAimingRange = 1 , _itZoom = defaultItZoom {_itZoomMax = 1} - , _itAimZoom = defaultItZoom {_itZoomMax = 1} , _itEquipPict = pictureWeaponOnAim' $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) } {- | @@ -69,10 +71,7 @@ autoSonar = defaultEquipment , _itEquipPict = \_ _ -> (,) emptySH blank , _itEffect = autoSonarEffect , _itID = Nothing - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom {_itZoomMax = 1} - , _itAimZoom = defaultItZoom {_itZoomMax = 1} } {- | Automatically sends out pulses that display walls. -} @@ -86,8 +85,5 @@ autoRadar = defaultEquipment , _itEquipPict = \_ _ -> (,) emptySH blank , _itEffect = autoRadarEffect , _itID = Nothing - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itZoom = defaultItZoom {_itZoomMax = 1} - , _itAimZoom = defaultItZoom {_itZoomMax = 1} } diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 3b15f9011..66fe5fe88 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -41,15 +41,14 @@ poisonSprayer = defaultAutoGun } , _itUse = ruseInstant (const aGasCloud) NoHammer [ ammoCheckI - , useTimeCheckI , withSoundForI foamSprayLoopS 5 , useAmmo 1 , spreadNumI - ] + ] + & useAim . aimSpeed .~ 0.2 + & useAim . aimRange .~ 0 , _wpRange = 8 , _itFloorPict = flamerPic - , _itAimingSpeed = 0.2 - , _itAimingRange = 0 , _itZoom = defaultItZoom , _wpSpread = 0.1 , _wpNumBarrels = 3 @@ -64,18 +63,17 @@ flamer = defaultAutoGun , _wpReloadTime = 100 } , _itUse = ruseInstant (\_ -> randWalkAngle 0.2 0.01 aFlame) NoHammer - [ ammoUseCheckI + [ ammoCheckI , withSidePushI 5 --, withTempLight 1 100 (V3 1 0 0) , withSidePushAfterI 20 ] + & useAim . aimSpeed .~ 0.5 + & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5} , _wpSpread = 0 , _wpRange = 8 , _itFloorPict = flamerPic - , _itAimingSpeed = 0.5 - , _itAimingRange = 0 , _itZoom = defaultItZoom - , _itAimZoom = defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5} , _itAttachment = NoItAttachment } flamerPic :: Item -> SPic diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 866ab515e..c9af6d696 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -6,7 +6,7 @@ module Dodge.Item.Weapon.TriggerType , withOldDir , trigDoAlso , withTempLight - , ammoUseCheckI + , ammoUseCheck , rateIncABI , torqueBefore , torqueBeforeAtLeast @@ -30,7 +30,7 @@ module Dodge.Item.Weapon.TriggerType , hammerCheckI , hammerCheckL , shootL - , useTimeCheckI + , useTimeCheck , ammoCheckI , randSpreadDir , modClock @@ -220,26 +220,27 @@ useAmmo amAmount eff item cr = eff item cr . (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo -~ amAmount) {- | Applies a world effect after an item use cooldown check. -} -useTimeCheckI :: ChainEffect -useTimeCheckI f item cr w = case item ^? itUse . useDelay . rateTime of +useTimeCheck :: ChainEffect +useTimeCheck f item cr w = case item ^? itUse . useDelay . rateTime of Just 0 -> f item cr $ setUseTime w - _ -> w - where + _ -> w + where cid = _crID cr setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUse . useDelay . rateTime +~ userate userate = fromMaybe 0 $ item ^? itUse . useDelay . rateMax {- | Applies a world effect after a hammer position check. -} hammerCheckI :: ChainEffect -hammerCheckI f it cr w = case it ^? itUse . itHammer . hammerPosition of +hammerCheckI f it cr w = case it ^? itUse . useHammer . hammerPosition of Just HammerUp -> f it cr $ setHammerDown w _ -> setHammerDown w where cid = _crID cr setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itUse - . itHammer . hammerPosition .~ HammerDown + . useHammer . hammerPosition .~ HammerDown {- | Applies a world effect after an ammo check. -} -ammoUseCheckI :: ChainEffect -ammoUseCheckI f item cr w +-- this should be made "safe" incase there is no _rateTime +ammoUseCheck :: ChainEffect +ammoUseCheck f item cr w | fireCondition = f item cr w & pointerToItem %~ ( (wpAmmo . wpLoadedAmmo -~ 1) . (itUse . useDelay . rateTime .~ _rateMax ( _useDelay (_itUse item)) )) @@ -261,12 +262,12 @@ hammerCheckL -> Int -> World -> World -hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itUse . itHammer . hammerPosition of +hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itUse . useHammer . hammerPosition of Just HammerUp -> f cr invid $ setHammerDown w _ -> setHammerDown w where cid = _crID cr - setHammerDown = creatures . ix cid . crInv . ix invid . itUse . itHammer . hammerPosition .~ HammerDown + setHammerDown = creatures . ix cid . crInv . ix invid . itUse . useHammer . hammerPosition .~ HammerDown {- | Applies a world effect after an ammo check. Arbitrary inventory position. -} shootL diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 6a3415964..3f22bf1c2 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -60,13 +60,10 @@ shrinkGun = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 20 } - , _itAimStance = TwoHandFlat , _itUse = defaultlUse {_lUse = \cr invid -> useShrinkGun (_crInv cr IM.! invid) cr} , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = shrinkGunPic - , _itAimingSpeed = 1 - , _itAimingRange = 0 , _itAttachment = ItBool True } @@ -97,8 +94,6 @@ blinkGun = defaultGun , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2[(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] - , _itAimingSpeed = 1 - , _itAimingRange = 0 } @@ -132,8 +127,6 @@ forceFieldGun = defaultGun , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] - , _itAimingSpeed = 0.4 - , _itAimingRange = 0.5 } -- grapGun = defaultGun -- { _itName = "grapGun" diff --git a/src/Dodge/Update/Camera.hs b/src/Dodge/Update/Camera.hs index 9fd4a5b68..b1eedf896 100644 --- a/src/Dodge/Update/Camera.hs +++ b/src/Dodge/Update/Camera.hs @@ -38,7 +38,7 @@ moveCamera w = w where aimRangeFactor | _cameraZoom w == 0 = 0 - | otherwise = fromMaybe 0 (yourItem w ^? itAimingRange) / _cameraZoom w + | otherwise = fromMaybe 0 (yourItem w ^? itUse . useAim . aimRange) / _cameraZoom w aimingMult | SDL.ButtonRight `S.member` _mouseButtons w = 1 | otherwise = 0 @@ -164,7 +164,7 @@ autoZoomCamera w wallZoom = farWallDist camPos w idealZoom | SDL.ButtonRight `S.member` _mouseButtons w - = theScopeZoom * maybe zoomNoItem zoomFromItem (yourItem w ^? itAimZoom) wallZoom + = theScopeZoom * maybe zoomNoItem zoomFromItem (yourItem w ^? itUse . useAim . aimZoom) wallZoom | otherwise = maybe zoomNoItem zoomFromItem (yourItem w ^? itZoom) wallZoom changeZoom curZoom