From 28386ec8b96fc4971cb3805d22e57a399b849d0f Mon Sep 17 00:00:00 2001 From: jgk Date: Tue, 25 May 2021 18:25:42 +0200 Subject: [PATCH] Pass item to item use function --- src/Dodge/Creature/Action/UseItem.hs | 4 +- src/Dodge/Data.hs | 8 ++-- src/Dodge/Default/Weapon.hs | 2 +- src/Dodge/Item/Weapon.hs | 66 ++++++++++++++-------------- src/Dodge/Item/Weapon/Launcher.hs | 12 +++-- src/Dodge/Item/Weapon/TriggerType.hs | 8 ++-- src/Dodge/Item/Weapon/UseEffect.hs | 2 +- 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/Dodge/Creature/Action/UseItem.hs b/src/Dodge/Creature/Action/UseItem.hs index 668153391..95314730d 100644 --- a/src/Dodge/Creature/Action/UseItem.hs +++ b/src/Dodge/Creature/Action/UseItem.hs @@ -32,8 +32,8 @@ itemEffect -> World -> World itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w) -itemEffect cr Weapon{_itUse=eff} w = eff cr w -itemEffect cr Throwable{_itUse = eff} w = eff cr w +itemEffect cr it@Weapon{_itUse=eff} w = eff it cr w +itemEffect cr it@Throwable{_itUse = eff} w = eff it cr w itemEffect _ _ w = w useLeftItem diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index ee6d11118..699b06ec7 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -199,7 +199,7 @@ data Item , _wpReloadState :: Int , _itUseRate :: Int , _itUseTime :: Int - , _itUse :: Creature -> World -> World + , _itUse :: Item -> Creature -> World -> World , _itLeftClickUse :: Maybe (Creature -> Int -> World -> World) , _wpSpread :: Float , _wpRange :: Float @@ -268,7 +268,7 @@ data Item , _itFloorPict :: Picture , _twMaxRange :: Float , _twAccuracy :: Float - , _itUse :: Creature -> World -> World + , _itUse :: Item -> Creature -> World -> World , _itUseRate :: Int , _itUseTime :: Int , _itAimingSpeed :: Float @@ -387,9 +387,11 @@ type HitEffect = Particle -> [(Point2, Either3 Creature Wall ForceField)] -> Wor data Ammo = ShellAmmo { _amPayload :: Point2 -> World -> World + , _amString :: String } | BulletAmmo - { } + { _amString :: String + } | GenericAmmo data Projectile = Projectile diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index b2521fd3e..e380c3d1f 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -15,7 +15,7 @@ defaultGun = Weapon , _wpReloadState = 0 , _itUseRate = 8 , _itUseTime = 0 - , _itUse = \_ -> id + , _itUse = \_ _ -> id , _itLeftClickUse = Nothing , _wpSpread = 0.02 , _wpRange = 20 diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index 84883c2e4..b1bd0aabb 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -55,7 +55,7 @@ pistol = Weapon , _wpReloadState = 0 , _itUseRate = 8 , _itUseTime = 0 - , _itUse = + , _itUse = \_ -> hammerCheck . shootWithSound 0 . withRandomDir 0.1 @@ -90,12 +90,12 @@ defaultAutoGun = autoGun effectGun :: String -> (Creature -> World -> World) -> Item effectGun name eff = defaultGun { _itName = name ++ "Gun" - , _itUse = eff + , _itUse = \_ -> eff } autoEffectGun :: String -> (Creature -> World -> World) -> Item autoEffectGun name eff = defaultAutoGun { _itName = name ++ "Gun" - , _itUse = eff + , _itUse = \_ -> eff } autoGun :: Item autoGun = defaultGun @@ -107,7 +107,7 @@ autoGun = defaultGun , _wpReloadState = 0 , _itUseRate = 6 , _itUseTime = 0 - , _itUse = charFiringStrat + , _itUse = \_ -> charFiringStrat [('M',autoFireMode) ,('S',singleFireMode) ] @@ -144,7 +144,7 @@ rezGun = defaultGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot aTeslaArc + , _itUse = \_ -> shoot aTeslaArc , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color chartreuse $ pictures @@ -168,7 +168,7 @@ teslaGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot aTeslaArc + , _itUse = \_ -> shoot aTeslaArc , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color blue $ pictures @@ -193,7 +193,7 @@ lasGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot aLaser + , _itUse = \_ -> shoot aLaser , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 3 3 (-3) (-3) @@ -251,7 +251,7 @@ tractorGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot $ aTractorBeam 0 + , _itUse = \_ -> shoot $ aTractorBeam 0 , _wpSpread = 0.00001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ] @@ -271,7 +271,7 @@ useTargetPos f cr w = case cr ^? crInv . ix (_crInvSel cr) . itAttachment . _Jus bezierGun :: Item bezierGun = defaultAutoGun { _itName = "B-GUN" - , _itUse = useTargetPos $ \p -> + , _itUse = \_ -> useTargetPos $ \p -> shootWithSound 0 . withMuzFlare . withRecoil 40 @@ -321,7 +321,7 @@ remoteLauncher = defaultGun , _wpReloadState = 0 , _itUseRate = 10 , _itUseTime = 0 - , _itUse = hammerCheck fireRemoteLauncher + , _itUse = \_ -> hammerCheck fireRemoteLauncher , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) @@ -340,7 +340,7 @@ hvAutoGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 25 , _itUseTime = 0 - , _itUse = rateIncAB 24 10 (torqueBeforeForced 0.1 mkHvBul) $ torqueAfter 0.2 mkHvBul + , _itUse = \_ -> rateIncAB 24 10 (torqueBeforeForced 0.1 mkHvBul) $ torqueAfter 0.2 mkHvBul , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color orange $ polygon $ rectNESW 5 5 (-5) (-5) , _itAimingSpeed = 0.2 @@ -363,7 +363,7 @@ ltAutoGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 4 , _itUseTime = 0 - , _itUse = shootWithSound 0 . withRandomDir 0.3 . withSidePush 50 + , _itUse = \_ -> shootWithSound 0 . withRandomDir 0.3 . withSidePush 50 . withMuzFlare $ withVelWthHiteff (30,0) 2 basicBulletEffect , _wpSpread = 0.5 , _wpRange = 20 @@ -387,7 +387,7 @@ miniGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 2 , _itUseTime = 0 - , _itUse = withWarmUp 50 . torqueBefore 0.03 . withSidePush 50 . withRecoil 15 + , _itUse = \_ -> withWarmUp 50 . torqueBefore 0.03 . withSidePush 50 . withRecoil 15 . withRandomDir 0.1 . withRandomOffset 9 . withMuzFlare @@ -409,7 +409,7 @@ spreadGun = defaultGun , _wpReloadState = 0 , _itUseRate = 20 , _itUseTime = 0 - , _itUse = shootWithSound (fromIntegral shotgunSound) + , _itUse = \_ -> shootWithSound (fromIntegral shotgunSound) . withRecoil 100 . withMuzFlare $ spreadNumVelWthHiteff spreadGunSpread 9 (30,0) 2 basicBulletEffect @@ -430,7 +430,7 @@ multGun = defaultGun , _wpReloadState = 0 , _itUseRate = 20 , _itUseTime = 0 - , _itUse = shootWithSound (fromIntegral shotgunSound) + , _itUse = \_ -> shootWithSound (fromIntegral shotgunSound) . withRecoil 200 . withMuzFlare $ numVelWthHitEff 5 (50,0) 5 basicBulletEffect @@ -461,7 +461,7 @@ longGun = defaultGun , _wpReloadState = 0 , _itUseRate = 100 , _itUseTime = 0 - , _itUse = shootWithSound (fromIntegral longGunSound) + , _itUse = \_ -> shootWithSound (fromIntegral longGunSound) . withThickSmoke . torqueAfter 0.05 . withMuzFlare @@ -496,7 +496,7 @@ poisonSprayer = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot aGasCloud + , _itUse = \_ -> shoot aGasCloud , _wpSpread = 0.3 , _wpRange = 8 , _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) @@ -515,7 +515,7 @@ flamer = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = shoot $ withSidePush 5 $ withSidePushAfter 10 $ randWalkAngle 0.2 0.01 aFlame + , _itUse = \_ -> shoot $ withSidePush 5 $ withSidePushAfter 10 $ randWalkAngle 0.2 0.01 aFlame , _wpSpread = 0 , _wpRange = 8 , _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) @@ -535,7 +535,7 @@ blinkGun = defaultGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = hammerCheck $ shoot aSelf + , _itUse = \_ -> hammerCheck $ shoot aSelf , _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL , _wpSpread = 0.05 , _wpRange = 20 @@ -553,7 +553,7 @@ boosterGun = defaultGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = boostSelf 10 + , _itUse = \_ -> boostSelf 10 , _itLeftClickUse = Just $ boostSelfL 10 , _wpSpread = 0.05 , _wpRange = 20 @@ -632,7 +632,7 @@ pointToItem (OnFloor flid) = floorItems . ix flid . flIt retireRemoteRocket :: Int -> Int -> Int -> World -> World retireRemoteRocket itid 0 pjid w = set (pointToItem (_itemPositions w IM.! itid) . itAttachment . _Just . scopePos) (0,0) - $ set (pointToItem (_itemPositions w IM.! itid) . itUse) (hammerCheck fireRemoteLauncher) + $ set (pointToItem (_itemPositions w IM.! itid) . itUse) (\_ -> hammerCheck fireRemoteLauncher) (w & projectiles %~ IM.delete pjid) retireRemoteRocket itid t pjid w = setScope w & projectiles . ix pjid . pjUpdate .~ (\_ -> retireRemoteRocket itid (t-1) pjid) @@ -649,7 +649,7 @@ retireRemoteBomb itid 0 pjid w = w & pointToItem (_itemPositions w IM.! itid) %~ ( (itAttachment . _Just . scopePos .~ (0,0)) . (itZoom .~ defaultItZoom) - . (itUse .~ hammerCheck throwRemoteBomb) + . (itUse .~ (\_ -> hammerCheck throwRemoteBomb)) ) & projectiles %~ IM.delete pjid retireRemoteBomb itid t pjid w = setScope w @@ -721,7 +721,7 @@ grenade = Throwable , _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _twMaxRange = 150 , _twAccuracy = 30 - , _itUse = useTimeCheck $ throwGrenade makeExplosionAt + , _itUse = \_ -> useTimeCheck $ throwGrenade makeExplosionAt , _itAimingSpeed = 1 , _itAimingRange = 0 , _itZoom = defaultItZoom {_itAimZoomMax = f fuseTime, _itAimZoomMin = f fuseTime} @@ -744,7 +744,7 @@ grenade = Throwable flameGrenade :: Item flameGrenade = grenade { _itName = "FLMGREN " ++ show fuseTime - , _itUse = throwGrenade makeFlameExplosionAt + , _itUse = \_ -> throwGrenade makeFlameExplosionAt } where fuseTime = 50 :: Int @@ -753,7 +753,7 @@ flameGrenade = grenade { teslaGrenade :: Item teslaGrenade = grenade { _itName = "TLSGREN " ++ show fuseTime - , _itUse = throwGrenade makeTeslaExplosionAt + , _itUse = \_ -> throwGrenade makeTeslaExplosionAt } where fuseTime = 50 :: Int @@ -770,7 +770,7 @@ remoteBomb = defaultThrowable , _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _twMaxRange = 150 , _twAccuracy = 30 - , _itUse = hammerCheck throwRemoteBomb + , _itUse = \_ -> hammerCheck throwRemoteBomb , _itAttachment = Just $ ItScope (0,0) 0 1 True , _itEquipPict = pictureWeaponOnAim remoteBombUnarmedPic } @@ -798,7 +798,7 @@ fireRemoteLauncher cr w = setLocation newitid = IM.newKey $ _itemPositions w maybeitid = cr ^? crInv . ix j . itID . _Just resetFire = set (creatures . ix cid . crInv . ix j . itUse) - $ hammerCheck $ \_ -> explodeRemoteRocket itid i + $ \_ -> hammerCheck $ \_ -> explodeRemoteRocket itid i resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET" setLocation :: World -> World setLocation w' = case maybeitid of @@ -891,7 +891,7 @@ explodeRemoteRocket explodeRemoteRocket itid pjid w = set (projectiles . ix pjid . pjUpdate) (\_ -> retireRemoteRocket itid 30 pjid) $ set (projectiles . ix pjid . pjDraw) (\_ -> blank) - $ set (itPoint . itUse) (const id) + $ set (itPoint . itUse) (\_ _ -> id) $ resetName $ makeExplosionAt (_pjPos (_projectiles w IM.! pjid)) w where @@ -922,7 +922,7 @@ throwRemoteBomb cr w = setLocation resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE" removePict = set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> blank resetFire = set (creatures . ix cid . crInv . ix j . itUse) - $ hammerCheck $ explodeRemoteBomb itid i + $ \_ -> hammerCheck $ explodeRemoteBomb itid i p' = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr,0) p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr-4,0) | otherwise = p' @@ -939,7 +939,7 @@ explodeRemoteBomb :: Int -> Int -> Creature -> World -> World explodeRemoteBomb itid pjid cr w = set (projectiles . ix pjid . pjUpdate) (\_ -> retireRemoteBomb itid 30 pjid) $ set (projectiles . ix pjid . pjDraw) (\_ -> blank) - $ set (creatures . ix cid . crInv . ix j . itUse) (const id) + $ set (creatures . ix cid . crInv . ix j . itUse) (\_ -> const id) $ resetName $ resetPict -- $ resetScope @@ -989,7 +989,7 @@ radar = defaultGun , _wpReloadState = 0 , _itUseRate = 120 , _itUseTime = 0 - , _itUse = shoot aRadarPulse + , _itUse = \_ -> shoot aRadarPulse , _wpSpread = autogunSpread , _wpRange = 20 , _itHammer = HammerUp @@ -1012,7 +1012,7 @@ sonar = defaultGun , _wpReloadState = 0 , _itUseRate = 120 , _itUseTime = 0 - , _itUse = shoot aSonarPulse + , _itUse = \_ -> shoot aSonarPulse , _wpRange = 20 , _itHammer = HammerUp , _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) @@ -1064,7 +1064,7 @@ spawnGun cr = defaultGun , _wpReloadTime = 80 , _wpReloadState = 0 , _itUseRate = 100 - , _itUse = spawnCrNextTo cr + , _itUse = \_ -> spawnCrNextTo cr } spawnCrNextTo :: Creature -- ^ Creature to spawn diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index a1df19deb..482503c69 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -33,7 +33,7 @@ launcher = defaultGun , _wpReloadState = 0 , _itUseRate = 20 , _itUseTime = 0 - , _itUse = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeExplosionAt + , _itUse = \_ -> shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeExplosionAt , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) @@ -42,23 +42,27 @@ launcher = defaultGun , _itEquipPict = pictureWeaponOnAim $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) , _itHammer = NoHammer , _itEffect = NoItEffect + , _wpAmmo = ShellAmmo + { _amPayload = makeExplosionAt + , _amString = "" + } } flameLauncher :: Item flameLauncher = launcher { _itName = "FLROCKO" - , _itUse = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeFlameExplosionAt + , _itUse = \_ -> shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeFlameExplosionAt } poisonLauncher :: Item poisonLauncher = launcher { _itName = "POISROCK" - , _itUse = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makePoisonExplosionAt + , _itUse = \_ -> shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makePoisonExplosionAt } teslaLauncher :: Item teslaLauncher = launcher { _itName = "TESLROCK" - , _itUse = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeTeslaExplosionAt + , _itUse = \_ -> shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeTeslaExplosionAt } aRocketWithPayload diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 98078120f..c94740e83 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -91,14 +91,14 @@ withWarmUp t f cr w | reloadCondition = fromMaybe w $ startReloadingWeapon cr w | _wpReloadState item /= 0 = w | fState == 0 = w - & pointerToItem %~ ( (itUse .~ withWarmUp 100 f) . (itUseTime .~ 2) ) + & pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 100 f)) . (itUseTime .~ 2) ) | t > 2 = w - & pointerToItem %~ ( (itUse .~ withWarmUp (t-1) f) . (itUseTime .~ 2) ) + & pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) ) & soundFrom (CrWeaponSound cid) 26 2 0 | t > 0 = w - & pointerToItem %~ ( (itUse .~ withWarmUp (t-1) f) . (itUseTime .~ 2) ) + & pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) ) | otherwise = w - & pointerToItem %~ ( (itUse .~ withWarmUp 1 f) . (wpLoadedAmmo -~ 1) . (itUseTime .~ 2) ) + & pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 1 f)) . (wpLoadedAmmo -~ 1) . (itUseTime .~ 2) ) & f cr & soundFrom (CrWeaponSound cid) 28 2 0 where diff --git a/src/Dodge/Item/Weapon/UseEffect.hs b/src/Dodge/Item/Weapon/UseEffect.hs index 2148067c8..f83d82749 100644 --- a/src/Dodge/Item/Weapon/UseEffect.hs +++ b/src/Dodge/Item/Weapon/UseEffect.hs @@ -112,7 +112,7 @@ aTractorBeam -> World aTractorBeam col cr w = set (creatures . ix cid . crInv . ix itRef . itUse) - (shoot $ aTractorBeam ((col + 1) `mod` 10)) + (\_ -> shoot $ aTractorBeam ((col + 1) `mod` 10)) $ over projectiles (IM.insert i (tractorBeamAt col i pos dir)) w where i = newProjectileKey w