diff --git a/src/Dodge/Bullet.hs b/src/Dodge/Bullet.hs index 4f03727bf..30eea2b75 100644 --- a/src/Dodge/Bullet.hs +++ b/src/Dodge/Bullet.hs @@ -3,6 +3,7 @@ module Dodge.Bullet ( useAmmoParams, ) where +import Linear import Dodge.Item.Weapon.Bullet import System.Random import Data.Foldable @@ -59,13 +60,15 @@ useAmmoParams :: Item -> Creature -> World -> World useAmmoParams it cr w = w & cWorld . lWorld . instantBullets .:~ ( _amBullet bultype - & buPos .~ sp + -- & buPos .~ sp + & buPos .~ _crPos cr & buTrajectory %~ settrajectory & buVel %~ (rotateV dir . (muzvel *.*)) & buDrag *~ _rifling (_itParams it) ) where - sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir + --sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir + sp = _crPos cr +.+ (muzlength ^?! _head . _x) *.* unitVectorAtAngle dir dir = _crDir cr bultype = _laAmmoType $ _heldConsumption $ _itUse it muzvel = _muzVel $ _itParams it diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index 39c283cf0..4511b623b 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -259,6 +259,7 @@ stackedInventory = , flatShield , spawnGun (lamp 5) , lasGun + , lasWide 5 , flameThrower , poisonSprayer , launcher diff --git a/src/Dodge/Creature/HandPos.hs b/src/Dodge/Creature/HandPos.hs index c7e73b760..45f5083fa 100644 --- a/src/Dodge/Creature/HandPos.hs +++ b/src/Dodge/Creature/HandPos.hs @@ -1,5 +1,6 @@ module Dodge.Creature.HandPos where +import Linear import Control.Lens import Data.Maybe import Dodge.Creature.Test @@ -20,10 +21,18 @@ aimingWeaponZeroPos cr it = aimingWeaponHandlePos cr it - fromMaybe 0 (it ^? itUse . heldAim . aimHandlePos) -aimingMuzzlePos :: Creature -> Item -> Float -aimingMuzzlePos cr it = - aimingWeaponZeroPos cr it - + fromMaybe 0 (it ^? itUse . heldAim . aimMuzPos) +aimingMuzzlePos :: Creature -> Item -> [Point2] +aimingMuzzlePos cr it = fmap ((+ zp) . _mzPos) (it ^.. itUse . heldAim . aimMuzzles . folded) + where + zp = V2 (aimingWeaponZeroPos cr it) 0 + +aimingMuzzleOff :: Creature -> Item -> [Point2] +aimingMuzzleOff cr it = fmap (rotateV (_crDir cr) . (+ zp) . _mzPos) (it ^.. itUse . heldAim . aimMuzzles . folded) + where + zp = V2 (aimingWeaponZeroPos cr it) 0 + +aimingMuzzleLength :: Creature -> Item -> Float +aimingMuzzleLength cr it = head (aimingMuzzlePos cr it) ^. _x translatePointToRightHand :: Creature -> Point3 -> Point3 translatePointToRightHand cr = translatePointToRightHand' cr . mirrorV3xz diff --git a/src/Dodge/Data/Item/Params.hs b/src/Dodge/Data/Item/Params.hs index 83567da7b..c7df462cf 100644 --- a/src/Dodge/Data/Item/Params.hs +++ b/src/Dodge/Data/Item/Params.hs @@ -48,7 +48,6 @@ data ItemParams { _muzVel :: Float , _rifling :: Float , _bore :: Float - , _gunBarrels :: [GunBarrel] , _recoil :: Float , _torqueAfter :: Float , _randomOffset :: Float @@ -76,12 +75,6 @@ data ShrinkGunStatus = FullSize | Shrunk data PreviousArcEffect = NoPreviousArcEffect | PerturbTillBreakPreviousArc --deriving (Eq, Ord, Show, Read) --Generic, Flat) -data GunBarrel = GunBarrel - { _barlPos :: Point2 - , _barlRot :: Float - , _barlInaccuracy :: Float - } - --data GunBarrels ---- = MultiBarrel ---- { _brlSpread :: BarrelSpread @@ -103,21 +96,9 @@ data Nozzle = Nozzle } --deriving (Eq, Ord, Show, Read) --Generic, Flat) ---data BarrelSpread --- = AlignedBarrels --- | SpreadBarrels {_spreadAngle :: Float} --- | RotatingBarrels {_rotatingBarrelInaccuracy :: Float} --- --deriving (Eq, Ord, Show, Read) --Generic, Flat) - ---makeLenses ''BarrelSpread makeLenses ''ItemParams makeLenses ''Nozzle ---makeLenses ''GunBarrels -makeLenses ''GunBarrel deriveJSON defaultOptions ''ShrinkGunStatus deriveJSON defaultOptions ''PreviousArcEffect deriveJSON defaultOptions ''Nozzle ---deriveJSON defaultOptions ''BarrelSpread -deriveJSON defaultOptions ''GunBarrel ---deriveJSON defaultOptions ''GunBarrels deriveJSON defaultOptions ''ItemParams diff --git a/src/Dodge/Data/Item/Use.hs b/src/Dodge/Data/Item/Use.hs index a196b6155..ba2fbfd0a 100644 --- a/src/Dodge/Data/Item/Use.hs +++ b/src/Dodge/Data/Item/Use.hs @@ -14,6 +14,7 @@ module Dodge.Data.Item.Use ( module Dodge.Data.Item.Targeting, ) where +import Linear import Control.Lens import Data.Aeson import Data.Aeson.TH @@ -72,10 +73,17 @@ data AimParams = AimParams , _aimZoom :: ItZoom , _aimStance :: AimStance , _aimHandlePos :: Float - , _aimMuzPos :: Float + , _aimMuzzles :: [Muzzle] } --deriving (Eq, Ord, Show, Read) --Generic, Flat) +data Muzzle = Muzzle + { _mzPos :: V2 Float + , _mzRot :: Float + , _mzInaccuracy :: Float + } + + data AimStance = TwoHandTwist | TwoHandFlat @@ -94,6 +102,8 @@ data ItZoom = ItZoom makeLenses ''ItemUse makeLenses ''AimParams makeLenses ''ItZoom +makeLenses ''Muzzle +deriveJSON defaultOptions ''Muzzle deriveJSON defaultOptions ''AimStance deriveJSON defaultOptions ''ItZoom deriveJSON defaultOptions ''AimParams diff --git a/src/Dodge/Default/Item/Use/AimParams.hs b/src/Dodge/Default/Item/Use/AimParams.hs index 047485f06..3a169cb44 100644 --- a/src/Dodge/Default/Item/Use/AimParams.hs +++ b/src/Dodge/Default/Item/Use/AimParams.hs @@ -1,6 +1,7 @@ module Dodge.Default.Item.Use.AimParams where import Dodge.Data.Item.Use +import Linear defaultAimParams :: AimParams defaultAimParams = @@ -11,5 +12,6 @@ defaultAimParams = , _aimZoom = ItZoom 20 0.2 1 , _aimStance = OneHand , _aimHandlePos = 10 - , _aimMuzPos = 20 + , _aimMuzzles = [Muzzle (V2 20 0) 0 0] +-- , _aimMuzPos = 20 } diff --git a/src/Dodge/HeldUse.hs b/src/Dodge/HeldUse.hs index 32bf9b860..a3828e73b 100644 --- a/src/Dodge/HeldUse.hs +++ b/src/Dodge/HeldUse.hs @@ -87,6 +87,7 @@ useMod hm = case hm of , withSoundForI tone440sawtoothquietS 2 , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) + , duplicateLoadedBarrels , ammoCheckI ] DualBeamMod -> @@ -97,11 +98,11 @@ useMod hm = case hm of , ammoCheckI ] LasMod -> - [ crAtMuzPos - , useAmmoAmount 1 - , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 + [ useAmmoAmount 1 +-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 , withSoundForI tone440sawtoothquietS 2 - , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) +-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) + , duplicateLoadedBarrels , ammoCheckI ] LauncherXMod i -> @@ -130,7 +131,7 @@ useMod hm = case hm of [ withMuzFlareI , withSmoke 1 black 20 200 5 , withRecoil - , applyInaccuracy + , duplicateLoadedBarrels , withTorqueAfter , useAmmoAmount 1 , withSoundStart tap3S @@ -141,7 +142,6 @@ useMod hm = case hm of VolleyGunMod -> [ withRecoil , withMuzFlareI - , applyInaccuracy , duplicateLoadedBarrels , withTorqueAfter , useAllAmmo @@ -155,7 +155,7 @@ useMod hm = case hm of [ withMuzFlareI , withSmoke 1 black 20 200 5 , withRecoil - , applyInaccuracy + , duplicateLoadedBarrels , withTorqueAfter , useAmmoAmount 1 , withSoundStart tap3S @@ -166,7 +166,7 @@ useMod hm = case hm of [ withRecoil , withMuzFlareI , withThickSmokeI - , applyInaccuracy + , duplicateLoadedBarrels , withTorqueAfter , useAmmoAmount 1 , withSoundStart bangEchoS @@ -178,7 +178,7 @@ useMod hm = case hm of [ withRecoil , withMuzFlareI , withThickSmokeI - , applyInaccuracy + , duplicateLoadedBarrels , withTorqueAfter , useAmmoAmount 1 , withSoundStart bangEchoS @@ -190,7 +190,7 @@ useMod hm = case hm of [ withRecoil , withMuzFlareI , withThickSmokeI - , applyInaccuracy + , duplicateLoadedBarrels , withTorqueAfter , useAmmoAmount 1 , withSoundStart bangEchoS @@ -222,7 +222,7 @@ useMod hm = case hm of , withSidePushI 50 , withRecoil , withTorqueAfter - , applyInaccuracy + , duplicateLoadedBarrels , withSoundStart tap3S , useAmmoAmount 1 , useTimeCheck @@ -234,7 +234,7 @@ useMod hm = case hm of , withSidePushI 50 , withRecoil , withTorqueAfter - , applyInaccuracy + , duplicateLoadedBarrels , withSoundStart tap3S , useAmmoAmount 1 , useTimeCheck @@ -245,7 +245,7 @@ useMod hm = case hm of , withRecoil , withSidePushI 50 , withTorqueAfter - , applyInaccuracy + , duplicateLoadedBarrels , withSoundStart tap1S , useAmmoAmount 1 , useTimeCheck @@ -254,7 +254,7 @@ useMod hm = case hm of BurstRifleMod -> [ withRecoil , withMuzFlareI - , applyInaccuracy + , duplicateLoadedBarrels , useAmmoAmount 1 , withSoundStart tap3S , repeatOnFrames [3, 6] BurstRifleRepeatMod @@ -267,7 +267,7 @@ useMod hm = case hm of BurstRifleRepeatMod -> [ withRecoil , withMuzFlareI - , applyInaccuracy + , duplicateLoadedBarrels , useAmmoAmount 1 , withSoundStart tap3S , sideEffectOnFrame 7 (\_ cr -> TorqueCr 0.2 (_crID cr)) --(torqueSideEffect 0.2) @@ -294,7 +294,7 @@ useMod hm = case hm of , withSidePushI 30 , withRecoil , withTorqueAfter - , applyInaccuracy + , duplicateLoadedBarrels , withSoundStart tap3S , useAmmoAmount 1 , useTimeCheck @@ -305,7 +305,7 @@ useMod hm = case hm of , withTorqueAfter -- , spreadLoaded , withMuzFlareI - , applyInaccuracy + , duplicateLoadedBarrels , useAmmoUpTo 1 , withSoundStart tap3S , repeatOnFrames [2, 4, 6, 8, 10] RevolverXRepeatMod @@ -320,7 +320,7 @@ useMod hm = case hm of [ withRecoil , withTorqueAfter , withMuzFlareI - , applyInaccuracy + , duplicateLoadedBarrels , useAmmoUpTo 1 , withSoundStart tap3S , ammoCheckI @@ -329,9 +329,9 @@ useMod hm = case hm of [ withRandomItemParams coneRandItemParams , withRandomItemUpdate coneRandItemUpdate , withRandomOffset - , applyInaccuracy - , withMuzFlareI + , duplicateLoadedBarrels , duplicateLoaded + , withMuzFlareI , withRecoil , withTorqueAfter , useAllAmmo @@ -511,7 +511,7 @@ shootTeslaArc it cr w = where itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change (w', ip) = makeTeslaArc (_itParams it) pos dir w - pos = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + pos = _crPos cr +.+ aimingMuzzleLength cr it *.* unitVectorAtAngle dir dir = _crDir cr -- I believe because the targeting returns to nothing straight after you release diff --git a/src/Dodge/Item/Draw/SPic.hs b/src/Dodge/Item/Draw/SPic.hs index 4daa2e303..a7f3d0b0e 100644 --- a/src/Dodge/Item/Draw/SPic.hs +++ b/src/Dodge/Item/Draw/SPic.hs @@ -121,7 +121,7 @@ bangStickAmmoPos :: Int -> Item -> AmmoPosition bangStickAmmoPos _ itm = Bullets [(rotate3z a (V3 5 0 3), Q.axisAngle (V3 0 0 1) a) - | a <- map _barlRot (itm ^?! itParams . gunBarrels)] + | a <- map _mzRot (itm ^?! itUse . heldAim . aimMuzzles)] volleygunAmmoPos :: Int -> AmmoPosition volleygunAmmoPos i = @@ -208,9 +208,9 @@ modulesSPic it _ imt = case imt of _ -> mempty baseStickShapeX :: Item -> Int -> Shape -baseStickShapeX it _ = foldMap f (it ^?! itParams . gunBarrels) +baseStickShapeX it _ = foldMap f (it ^?! itUse . heldAim . aimMuzzles) where - f brl = rotateSH (_barlRot brl) baseStickShape + f brl = rotateSH (_mzRot brl) baseStickShape baseStickShape :: Shape baseStickShape = colorSH green $ xCylinderST 3 10 @@ -219,7 +219,7 @@ bangConeShape :: Float -> Shape bangConeShape x = colorSH cyan $ xCylinderST 3 x - <> upperPrismPolyST 6 (reverse $ rectNSWE 4 (-4) x (10 + x)) + <> upperPrismPolyST 6 ( rectNSWE 4 (-4) x (10 + x)) defSPic :: SPic defSPic = noPic $ colorSH green $ upperPrismPolyST 3 $ square 4 diff --git a/src/Dodge/Item/Held/BatteryGuns.hs b/src/Dodge/Item/Held/BatteryGuns.hs index e18a84b84..94570f9dd 100644 --- a/src/Dodge/Item/Held/BatteryGuns.hs +++ b/src/Dodge/Item/Held/BatteryGuns.hs @@ -31,7 +31,8 @@ teslaGun = & itUse . heldAim . aimWeight .~ 6 & itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimHandlePos .~ 4 - & itUse . heldAim . aimMuzPos .~ 4 + -- & itUse . heldAim . aimMuzPos .~ 4 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 4 0) 0 0] & itType . iyBase .~ HELD TESLAGUN lasGun :: Item @@ -63,7 +64,8 @@ lasGun = & itUse . heldAim . aimRange .~ 1 & itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 30 + -- & itUse . heldAim . aimMuzPos .~ 30 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 30 0) 0 0] & itType . iyBase .~ HELD LASGUN lasGunTweak :: TweakParam @@ -94,7 +96,7 @@ tractorGun = & itUse . heldAim . aimRange .~ 1 & itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 30 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 30 0) 0 0] & itType . iyBase .~ HELD TRACTORGUN tractorGunTweak :: TweakParam @@ -149,7 +151,7 @@ dualBeam :: Item dualBeam = lasGun & itType . iyBase .~ HELD DUALBEAM - & itUse . heldAim . aimMuzPos .~ 0 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 30 0) 0 0] & itParams .~ DualBeam { _phaseV = 1 diff --git a/src/Dodge/Item/Held/Cane.hs b/src/Dodge/Item/Held/Cane.hs index bbd74f451..d01c640e6 100644 --- a/src/Dodge/Item/Held/Cane.hs +++ b/src/Dodge/Item/Held/Cane.hs @@ -22,7 +22,6 @@ defaultBangCane = { _muzVel = 0.8 , _rifling = 0.9 , _bore = 2 - , _gunBarrels = [GunBarrel 0 0 0.01] , _recoil = 50 , _torqueAfter = 0.1 , _randomOffset = 0 @@ -33,7 +32,7 @@ defaultBangCane = & itUse . heldMods .~ BangCaneMod & itUse . heldAim . aimStance .~ OneHand & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 15 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 0) 0 0.01] & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 1 & itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadPartialInsert 10 1] @@ -47,20 +46,17 @@ volleyGun i = & itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 15 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3] & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i & itParams .~ BulletShooter { _muzVel = 0.8 , _rifling = 0.9 , _bore = 2 - , _gunBarrels = [GunBarrel 0 0 0.01] , _recoil = 50 , _torqueAfter = 0.1 , _randomOffset = 0 } - & itParams . gunBarrels - .~ [ GunBarrel (V2 0 x) 0 0.1 | x <- spreadAroundCenter i 3] & itParams . torqueAfter .~ 0.48 + 0.2 * fromIntegral i & itType . iyBase .~ HELD (VOLLEYGUN i) @@ -96,7 +92,7 @@ burstRifle :: Item burstRifle = repeater & itType . iyBase .~ HELD BURSTRIFLE - & itParams . gunBarrels . ix 0 . barlInaccuracy .~ 0.05 + & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0.05 & itUse . heldDelay . rateMax .~ 18 & itUse . heldMods .~ BurstRifleMod @@ -124,12 +120,12 @@ miniGunX i = autoRifle & itUse .~ miniGunUse i & itUse . heldAim . aimTurnSpeed .~ 0.5 + & itUse . heldAim . aimMuzzles .~ replicate i (Muzzle (V2 15 0) 0 0.05) & itParams .~ BulletShooter { _muzVel = 1 , _rifling = 0.9 , _bore = 2 - , _gunBarrels = replicate i (GunBarrel 0 0 0.05) , _recoil = 10 , _torqueAfter = 0 , _randomOffset = 10 diff --git a/src/Dodge/Item/Held/Cone.hs b/src/Dodge/Item/Held/Cone.hs index 1fd9c5635..e40d993aa 100644 --- a/src/Dodge/Item/Held/Cone.hs +++ b/src/Dodge/Item/Held/Cone.hs @@ -1,10 +1,11 @@ -module Dodge.Item.Held.Cone - where -import Dodge.Default.Item -import Dodge.Data.Item -import Dodge.Reloading.Action +module Dodge.Item.Held.Cone where + import Control.Lens +import Dodge.Data.Item +import Dodge.Default.Item +import Dodge.Reloading.Action import Geometry.Data +import Linear bangCone :: Item bangCone = @@ -14,7 +15,6 @@ bangCone = { _muzVel = 0.7 , _rifling = 0.8 , _bore = 5 - , _gunBarrels = [GunBarrel 0 0 0.5] , _recoil = 150 , _torqueAfter = 0.1 , _randomOffset = 12 @@ -25,7 +25,7 @@ bangCone = & itUse . heldDelay . rateMax .~ 20 & itUse . heldMods .~ BangConeMod & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 15 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 0) 0 0.5] & itType . iyBase .~ HELD BANGCONE & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 5 & itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadEject 5, loadInsert 20, loadPrime 5] @@ -38,7 +38,7 @@ blunderbuss = & itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimWeight .~ 6 & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 30 + & itUse . heldAim . aimMuzzles . ix 0 . mzPos . _x .~ 30 & itType . iyBase .~ HELD BLUNDERBUSS grapeCannon :: Int -> Item diff --git a/src/Dodge/Item/Held/Launcher.hs b/src/Dodge/Item/Held/Launcher.hs index eace069f2..c7ab1a4c3 100644 --- a/src/Dodge/Item/Held/Launcher.hs +++ b/src/Dodge/Item/Held/Launcher.hs @@ -30,7 +30,8 @@ launcher = & itUse . heldAim . aimRange .~ 0.5 & itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 20 + -- & itUse . heldAim . aimMuzPos .~ 20 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 20 0) 0 0] & itUse . heldConsumption . laAmmoType .~ ProjectileAmmo { _amPayload = ExplosionPayload diff --git a/src/Dodge/Item/Held/Rod.hs b/src/Dodge/Item/Held/Rod.hs index 000cdba46..8e0d3afbe 100644 --- a/src/Dodge/Item/Held/Rod.hs +++ b/src/Dodge/Item/Held/Rod.hs @@ -22,7 +22,6 @@ bangRod = { _muzVel = 0.8 , _rifling = 1 , _bore = 2 - , _gunBarrels = [GunBarrel 0 0 0.1] , _recoil = 50 , _torqueAfter = 0.3 , _randomOffset = 0 @@ -39,7 +38,7 @@ bangRod = & itUse . heldAim . aimStance .~ OneHand & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 30 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 30 0) 0 0.1] & itUse . heldConsumption . laAmmoType .~ hvBulletAmmo elephantGun :: Item @@ -47,7 +46,7 @@ elephantGun = bangRod & itType . iyBase .~ HELD ELEPHANTGUN & itUse . heldAim . aimStance .~ TwoHandTwist - & itParams . gunBarrels .~ [GunBarrel 0 0 0.05] + & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0.05 & itUse . heldMods .~ ElephantGunMod & itParams . recoil .~ 50 & itParams . torqueAfter .~ 0.1 @@ -68,7 +67,7 @@ sniperRifle :: Item sniperRifle = elephantGun & itType . iyBase .~ HELD SNIPERRIFLE - & itParams . gunBarrels .~ [GunBarrel 0 0 0] + & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0 & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1} & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itScope .~ ZoomScope (V2 0 0) 1 0.5 False diff --git a/src/Dodge/Item/Held/SprayGuns.hs b/src/Dodge/Item/Held/SprayGuns.hs index 1828647d8..3388ff676 100644 --- a/src/Dodge/Item/Held/SprayGuns.hs +++ b/src/Dodge/Item/Held/SprayGuns.hs @@ -93,7 +93,7 @@ flameThrower = & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 5, _izMin = 1.5} & itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimHandlePos .~ 0 - & itUse . heldAim . aimMuzPos .~ 18 + & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 18 0) 0 0] & itUse . heldConsumption .~ ( defaultLoadable & laSource . _InternalSource . iaMax .~ 250 diff --git a/src/Dodge/Item/Held/Stick.hs b/src/Dodge/Item/Held/Stick.hs index 4b00e762d..0f211fae5 100644 --- a/src/Dodge/Item/Held/Stick.hs +++ b/src/Dodge/Item/Held/Stick.hs @@ -23,7 +23,6 @@ bangStick i = { _muzVel = 0.8 , _rifling = 0.8 , _bore = 2 - , _gunBarrels = [GunBarrel 0 a 0.01 | a <- spreadAroundCenter i baseStickSpread] , _recoil = 25 , _torqueAfter = 0.18 + 0.02 * fromIntegral i , _randomOffset = 0 @@ -35,7 +34,7 @@ bangStick i = & itUse . heldDelay . rateMax .~ 8 & itUse . heldMods .~ BangStickMod & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 10 + & itUse . heldAim . aimMuzzles .~ [Muzzle 10 a 0.01 | a <- spreadAroundCenter i baseStickSpread] & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i & itUse . heldConsumption . laSource . _InternalSource . iaCycle .~ [loadPartialInsert 10 1] @@ -62,11 +61,11 @@ pistol = ) & itUse . heldDelay . rateMax .~ 6 & itUse . heldMods .~ PistolMod + & itUse . heldAim . aimMuzzles .~ [Muzzle 0 0 0.05] & itParams %~ ( (muzVel .~ 0.8) . (rifling .~ 0.8) . (bore .~ 2) - . (gunBarrels .~ [GunBarrel 0 0 0.05]) . (recoil .~ 10) . (torqueAfter .~ 0.2) ) diff --git a/src/Dodge/Item/Held/Utility.hs b/src/Dodge/Item/Held/Utility.hs index 5d5b1819a..0d19d2dd8 100644 --- a/src/Dodge/Item/Held/Utility.hs +++ b/src/Dodge/Item/Held/Utility.hs @@ -1,10 +1,11 @@ module Dodge.Item.Held.Utility where +import Linear import Dodge.Default.Item import Color import Control.Lens import Dodge.Data.Item -import Geometry.Data +--import Geometry.Data flatShield :: Item flatShield = @@ -14,7 +15,6 @@ flatShield = & itUse . heldAim . aimTurnSpeed .~ 0.5 & itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimHandlePos .~ 0 - & itUse . heldAim . aimMuzPos .~ 0 & itInvSize .~ 3 & itType . iyBase .~ HELD FLATSHIELD @@ -35,7 +35,7 @@ binoculars = & itScope .~ ZoomScope (V2 0 0) 1 0.5 False & itType . iyBase .~ HELD BINOCULARS & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 10 +-- & itUse . heldAim . aimMuzPos .~ 10 & itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5, _izFac = 1} @@ -47,7 +47,7 @@ torch = & itEffect . ieInv .~ EffectWhileHeld CreateHeldLight & itType . iyBase .~ HELD TORCH & itUse . heldAim . aimHandlePos .~ 5 - & itUse . heldAim . aimMuzPos .~ 10 + & itUse . heldAim . aimMuzzles . ix 0 . mzPos . _x .~ 10 forceFieldGun :: Item forceFieldGun = diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index 33a3938f8..27aacebfa 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -165,7 +165,7 @@ shootDualLaser it cr w = itid = _itID it dir = _crDir cr pos = _crPos cr +.+ aimlength *.* unitVectorAtAngle dir - aimlength = aimingMuzzlePos cr it + aimlength = aimingMuzzleLength cr it gap = _dbGap . _itParams $ it posl = pos +.+ (- gap) *.* vNormal (unitVectorAtAngle dir) posr = pos +.+ gap *.* vNormal (unitVectorAtAngle dir) diff --git a/src/Dodge/Item/Weapon/Shatter.hs b/src/Dodge/Item/Weapon/Shatter.hs index 0a052766b..b9c1d0294 100644 --- a/src/Dodge/Item/Weapon/Shatter.hs +++ b/src/Dodge/Item/Weapon/Shatter.hs @@ -19,7 +19,7 @@ shootShatter it cr w = Opaque {} -> True SeeThrough -> True _ -> False - sp = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + sp = _crPos cr +.+ aimingMuzzleLength cr it *.* unitVectorAtAngle dir dir = _crDir cr ep = sp +.+ 200 *.* unitVectorAtAngle dir diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 249e77bd2..52a0117cd 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -44,30 +44,24 @@ module Dodge.Item.Weapon.TriggerType ( withSidePushAfterI, withSidePushI, withWarmUp, - --spreadNumI, - --spreadLoaded, repeatOnFrames, sideEffectOnFrame, duplicateItem, duplicateLoadedBarrels, duplicateLoaded, - duplicateOffsets, duplicateOffsetsV2, duplicateOffsetsFocus, hammerCheckL, shootL, useTimeCheck, ammoCheckI, - applyInaccuracy, modClock, blCheck, ) where -import qualified SDL import Data.Foldable import Data.Maybe import Dodge.Base -import Dodge.Creature.HandPos import Dodge.Creature.Test import Dodge.Data.World import Dodge.Inventory.Lock @@ -76,10 +70,11 @@ import Dodge.Reloading import Dodge.SoundLogic import Dodge.WorldEvent import Geometry +import qualified IntMapHelp as IM import LensHelp import RandomHelp +import qualified SDL import Sound.Data -import qualified IntMapHelp as IM type ChainEffect = (Item -> Creature -> World -> World) -> @@ -137,14 +132,16 @@ withThickSmokeI eff item cr w = -- fire. ammoCheckI :: ChainEffect ammoCheckI eff itm cr w = case itm ^? itUse . heldConsumption . laSource of - Just (InternalSource ia) | _iaLoaded ia <= 0 || not (_iaPrimed ia) - -> failsound w - Just AboveSource | fromMaybe True $ do + Just (InternalSource ia) + | _iaLoaded ia <= 0 || not (_iaPrimed ia) -> + failsound w + Just AboveSource + | fromMaybe True $ do invid <- itm ^? itLocation . ipInvID x <- cr ^? crInv . ix (invid - 1) . itUse . equipEffect . eeUse . euseAmmoAmount - return $ x <= 0 - -> failsound w - _ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading + return $ x <= 0 -> + failsound w + _ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading where failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of Just 0 -> soundStart (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing @@ -360,11 +357,12 @@ useAmmoAmount amAmount eff item cr = useAmmoAmount' :: Int -> Int -> IM.IntMap Item -> IM.IntMap Item useAmmoAmount' itref x inv = case inv ^? ix itref . itUse . heldConsumption . laSource of - Just InternalSource{} - -> inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x - Just AboveSource - -> inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x + Just InternalSource{} -> + inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x + Just AboveSource -> + inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x _ -> inv + -- . crInv . ix itRef . itUse . heldConsumption . laSource {- | @@ -380,7 +378,6 @@ useTimeCheck f item cr w = case item ^? itUse . heldDelay . rateTime of itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change userate = fromMaybe 0 $ item ^? itUse . heldDelay . rateMax - -- | Applies a world effect after a hammer position check. blCheck :: ChainEffect blCheck f it cr w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of @@ -457,47 +454,44 @@ modClock n chainEff eff it cr w withMuzFlareI :: ChainEffect withMuzFlareI f it cr w = - makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) flashPos - . muzFlareAt (V4 5 5 0 2) flarePos cdir + makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (cpos `v2z` 20) + . muzFlareAt (V4 5 5 0 2) (cpos `v2z` 20) cdir $ f it cr w +-- makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) flashPos +-- . muzFlareAt (V4 5 5 0 2) flarePos cdir +-- $ f it cr w where - flarePos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 0 0 20) - flashPos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 5 0 20) - -- muzzleOffset = V3 (_muzPos (_dimPortage (_itDimension it))) 0 0 +-- flarePos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 0 0 20) +-- flashPos = addZ 0 (_crPos cr) +.+.+ rotate3z cdir (muzzleOffset cr it +.+.+ V3 5 0 20) +-- -- muzzleOffset = V3 (_muzPos (_dimPortage (_itDimension it))) 0 0 cdir = _crDir cr + cpos = _crPos cr -muzzleOffset :: Creature -> Item -> Point3 -muzzleOffset cr it = V3 (holdOffset + 5 + _aimMuzPos dimPort - _aimHandlePos dimPort) 0 0 - where - dimPort = _heldAim $ _itUse it - holdOffset - | crInAimStance OneHand cr = 10 - | otherwise = 0 +--muzzleOffset :: Creature -> Item -> Point3 +--muzzleOffset cr it = V3 (holdOffset + 5 + _aimMuzPos dimPort - _aimHandlePos dimPort) 0 0 +-- where +-- dimPort = _heldAim $ _itUse it +-- holdOffset +-- | crInAimStance OneHand cr = 10 +-- | otherwise = 0 withMuzPos :: (Point3 -> World -> World) -> ChainEffect withMuzPos = withMuzPosShift (V2 0 0) withMuzPosShift :: Point2 -> (Point3 -> World -> World) -> ChainEffect -withMuzPosShift p g f it cr w = - g (pos `v2z` 20) $ - f it cr w +withMuzPosShift p g f it cr = g thepos . f it cr where - pos = - _crPos cr - +.+ rotateV dir p - +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir - dir = _crDir cr + thepos = (_crPos cr `v2z` 20) + --thepos = (pos `v2z` 20) + --pos = + -- _crPos cr + -- +.+ rotateV dir p + -- +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + --dir = _crDir cr crAtMuzPos :: ChainEffect -crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVectorAtAngle (_crDir cr))) - -{- | Applies the effect to a randomly rotated creature, - - rotation amount given by inaccuracy in itParams --} -applyInaccuracy :: ChainEffect -applyInaccuracy f it = withRandomDirI acc f it - where - acc = fromMaybe 0 $ it ^? itParams . gunBarrels . ix 0 . barlInaccuracy +--crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVectorAtAngle (_crDir cr))) +crAtMuzPos f it cr = f it cr -- | Applies the effect to a randomly rotated creature. withRandomDirI :: @@ -612,27 +606,6 @@ withTorqueAfter feff item cr w (rot, g) = randomR (- torque, torque) $ _randGen w torque = fromMaybe 0 $ item ^? itParams . torqueAfter ---spreadNumI :: ChainEffect ---spreadNumI eff item cr w = foldr f w dirs --- where --- dirs = --- zipWith --- (+) --- [- spread, - spread + (2 * spread / fromIntegral numBul) .. spread] --- (randomRs (0, spread / fromIntegral numBul) (_randGen w)) --- f dir = eff item (cr & crDir +~ dir) --- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item --- numBul = _brlNum . _gunBarrels $ _itParams item - ---spreadLoaded :: ChainEffect ---spreadLoaded eff item cr w = foldr f w dirs --- where --- cd = 0.5 * spread * fromIntegral (numBulLoaded -1) --- dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1] --- f dir = eff item (cr & crDir +~ dir) --- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item --- numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded - sideEffectOnFrame :: Int -> (Item -> Creature -> WdWd) -> @@ -669,12 +642,19 @@ duplicateLoaded eff it cr w = foldr f w [1 .. numBul] numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded duplicateLoadedBarrels :: ChainEffect -duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itParams . gunBarrels) +duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itUse . heldAim . aimMuzzles) where numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded - f brl = eff itm (cr & crPos +~ _barlPos brl - & crDir +~ _barlRot brl - ) -- worry about inaccuracy later + f brl w' = + eff + itm + ( cr & crPos +~ (rotateV (_crDir cr) (_mzPos brl)) + & crDir +~ (_mzRot brl + a) + ) + (w' & randGen .~ g) + where + inacc = _mzInaccuracy brl + (a,g) = randomR (-inacc,inacc) $ _randGen w' duplicateOffsetsFocus :: [Float] -> ChainEffect duplicateOffsetsFocus xs eff item cr w = foldr f w poss @@ -686,13 +666,14 @@ duplicateOffsetsFocus xs eff item cr w = foldr f w poss cr & crPos %~ (+.+ pos) & crDir .~ thedir pos - thedir pos - | dist (mouseWorldPos (w ^. input) (w ^. wCam)) (_crPos cr) < aimingMuzzlePos cr item = - argV - ( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr) - -.- (_crPos cr +.+ pos) - ) - | otherwise = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos)) + --thedir pos + -- | dist (mouseWorldPos (w ^. input) (w ^. wCam)) (_crPos cr) < aimingMuzzlePos cr item = + -- argV + -- ( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr) + -- -.- (_crPos cr +.+ pos) + -- ) + -- | otherwise = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos)) + thedir pos = argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- (_crPos cr +.+ pos)) duplicateItem :: (Item -> [Item]) -> ChainEffect duplicateItem fit eff itm cr w = foldr f w (fit itm) @@ -704,10 +685,3 @@ duplicateOffsetsV2 xs eff item cr w = foldr f w poss where poss = map (rotateV (_crDir cr)) xs f pos = eff item (cr & crPos +.+.~ pos) - -duplicateOffsets :: [Float] -> ChainEffect -duplicateOffsets xs eff item cr w = foldr f w poss - where - poss :: [V2 Float] - poss = map (rotateV (_crDir cr) . V2 0) xs - f pos = eff item (cr & crPos +.+.~ pos)