Make launcherX use multiple ammo sources

This commit is contained in:
2024-06-28 22:40:24 +01:00
parent 009a6cd30f
commit 32cb2b2e80
17 changed files with 220 additions and 342 deletions
+9 -13
View File
@@ -1,19 +1,22 @@
module Dodge.Base.You where
module Dodge.Base.You
(you
, yourScopeInvID
, yourInv
, yourScrollAttachment
, yourItem
)where
import Dodge.Data.World
import Dodge.HeldScroll
import qualified IntMapHelp as IM
import qualified Data.Map.Strict as M
--import qualified Data.Map.Strict as M
import Control.Lens
import Control.Monad
import Data.Maybe
--import Data.Maybe
you :: World -> Creature
you w = w ^?! cWorld . lWorld . creatures . ix 0
youc :: CWorld -> Creature
youc w = w ^?! lWorld . creatures . ix 0
yourItem :: World -> Maybe Item
yourItem w = do
i <- you w ^? crManipulation . manObject . inInventory . ispItem
@@ -36,13 +39,6 @@ yourScopeInvID w = do
yourInv :: World -> IM.IntMap Item
yourInv = _crInv . you
attachmentTree :: Creature -> M.Map AttachType Int
attachmentTree cr = fromMaybe mempty $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ upDownAttachments cr i i mempty
upDownAttachments :: Creature -> Int -> Int -> M.Map AttachType Int -> M.Map AttachType Int
upDownAttachments _ _ _ s = s
--yourInvSel :: World -> Int
--yourInvSel = crSel . you
-3
View File
@@ -56,11 +56,8 @@ updateBulVel bt = case _buTrajectory bt of
where
t = _buTimer bt
-- should be made safe?
-- should be renamed to shootBullet or something
shootBullet :: [Item] -> Item -> Creature -> World -> World
shootBullet ams it cr w = fromMaybe (error "cannot find bullet ammo when expected to") $ do
invid <- it ^? itLocation . ipInvID
thebullet <- ams ^? ix 0 . itUse . amagParams . ampBullet
return $ w & cWorld . lWorld . instantBullets
.:~ ( thebullet
+10
View File
@@ -224,6 +224,16 @@ inventoryX c = case c of
'L' -> [scrollWatch]
'M' -> stackedInventory
'N' -> [zoomScope,targetingScope TARGETLASER, sniperRifle]
'O' -> [ launcherX 2
, shellMag
, shellMag
, launcherX 3
, shellMag
, shellMag
, shellMag
, rifle
, shellMag
]
'T' -> testInventory
_ -> []
+1 -9
View File
@@ -34,16 +34,8 @@ useItemRightClick cr' w = fromMaybe (f w) $ do
getAmmoMags :: Item -> Creature -> [Item]
getAmmoMags itm cr = fromMaybe [] $ do
atypes <- itm ^? itUse . heldConsumption
i <- itm ^? itLocation . ipInvID
let amags = cr ^.. crInv . dropping (i + 1) traverse
mmags = zipWith f atypes amags
return $ catMaybes mmags
where
f atype itm' = do
itype <- itm' ^? itUse . amagType
guard $ itype == atype
return $ itm'
return $ cr ^.. crInv . dropping (i + 1) traverse
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^. itUse of
-2
View File
@@ -99,8 +99,6 @@ data HeldMod
| BurstRifleRepeatMod
| MiniGunMod Int
| SmgMod
| RevolverXMod
| RevolverXRepeatMod
| BangConeMod
deriving (Eq, Ord, Show, Read) --Generic, Flat)
-10
View File
@@ -98,16 +98,6 @@ data ScrollAttachParams
| CharScrollParams
{ _scrollChar :: Seq.Seq Char}
data ItemUse'
= ItemHeld HeldUse'
| ItemEquip EquipUse'
| ItemConsume ConsumeUse'
| ItemCraft Int
data HeldUse' = HeldUse'
data EquipUse' = EquipUse'
data ConsumeUse' = ConsumeUse'
data AimParams = AimParams
{ _aimWeight :: Int
, _aimTurnSpeed :: Float
-11
View File
@@ -27,17 +27,6 @@ module Dodge.Default.Weapon where
--defaultChargeable :: LeftConsumption
--defaultChargeable = ChargeableAmmo 100 100
--defaultrUse :: ItemUse
--defaultrUse =
-- RightUse
-- { _rUse = HeldDoNothing
-- , _useDelay = FixedRate{_rateMax = 8, _rateTime = 0}
-- , _useMods = HeldModNothing
-- , _useHammer = HammerUp
-- , _useAim = defaultAimParams
-- , _heldScroll = HeldScrollDoNothing
-- , _heldConsumption = defaultLoadable
-- }
--
--
+24 -51
View File
@@ -58,10 +58,10 @@ useMod hm = case hm of
, ammoCheckI
]
LauncherMod ->
[ useAmmoAmount 1
, withSoundStart tap4S
, useTimeCheck
, ammoCheckI
--[ useAmmoAmount 1
-- , withSoundStart tap4S
[ useTimeCheck
-- , ammoCheckI
, blCheck
]
TeslaMod ->
@@ -108,11 +108,11 @@ useMod hm = case hm of
, duplicateLoadedBarrels
, ammoCheckI
]
LauncherXMod i ->
[ useAmmoAmount i
, withSoundStart tap4S
, useTimeCheck
, ammoCheckI
LauncherXMod _ ->
--[ useAmmoAmount i
--, withSoundStart tap4S
[ useTimeCheck
--, ammoCheckI
, blCheck
]
ShatterMod ->
@@ -314,30 +314,6 @@ useMod hm = case hm of
, useTimeCheck
, ammoCheckI
]
RevolverXMod ->
[ withRecoil
, withTorqueAfter
, withFlare
, duplicateLoadedBarrels
, useAmmoUpTo 1
, withSoundStart tap3S
, repeatOnFrames [2, 4, 6, 8, 10] RevolverXRepeatMod
, lockInvFor 10
, -- rather than locking the inventory, a better solution may be to check
-- that the weapon is still in your hands in the repeated frames
useTimeCheck
, ammoCheckI
, blCheck
]
RevolverXRepeatMod ->
[ withRecoil
, withTorqueAfter
, withFlare
, duplicateLoadedBarrels
, useAmmoUpTo 1
, withSoundStart tap3S
, ammoCheckI
]
BangConeMod ->
[ withRandomItem coneRandItemParams
, withRandomItemUpdate coneRandItemUpdate
@@ -388,7 +364,7 @@ useHeld hu = case hu of
HeldUseAmmoParams -> shootBullet
HeldOverNozzlesUseGasParams -> overNozzles useGasParams
HeldPJCreation -> usePjCreation
HeldPJCreationX i -> usePjCreationX i
HeldPJCreationX _ -> usePjCreationX
HeldFireRemoteShell -> fireRemoteShell
HeldDetectorEffect dt -> const $ detectorEffect dt
HeldTeslaArc -> shootTeslaArc
@@ -403,20 +379,17 @@ useHeld hu = case hu of
usePjCreation :: [Item] -> Item -> Creature -> World -> World
usePjCreation ams itm cr = fromMaybe id $ do
apm <- ams ^? ix 0 . itUse . amagParams
return $ createProjectile apm itm cr
apm <- ams ^? ix 0
muz <- itm ^? itUse . heldAim . aimMuzzles . ix 0
return $ createProjectile apm muz itm cr
usePjCreationX :: Int -> [Item] -> Item -> Creature -> World -> World
usePjCreationX i ams itm cr =
foldr
f
(createProjectile apm itm cr)
[1 .. i -1]
usePjCreationX :: [Item] -> Item -> Creature -> World -> World
usePjCreationX ams itm cr = fromMaybe id $ do
muzs <- itm ^? itUse . heldAim . aimMuzzles
return $ foldr
f id (zip muzs ams)
where
apm = fromMaybe (error "cannot find shell ammo projectile") $ do
invid <- itm ^? itLocation . ipInvID
cr ^? crInv . ix (invid + 1) . itUse . amagParams
f n = (. createProjectile apm itm (cr & crDir +~ (2 * pi * fromIntegral n / fromIntegral i)))
f (muz,am) = (createProjectile am muz itm cr .)
overNozzles ::
(Nozzle -> [Item] -> Item -> Creature -> World -> World) ->
@@ -469,7 +442,7 @@ getAmmoMagazine itm cr = do
return mag
useGasParams :: Nozzle -> [Item] -> Item -> Creature -> World -> World
useGasParams nz ams it cr =
useGasParams nz ams _ cr =
createGas
gastype
(_nzPressure nz)
@@ -478,7 +451,6 @@ useGasParams nz ams it cr =
cr
where
gastype = fromMaybe (error "cannot find gas ammo") $ ams ^? ix 0 . itUse . amagParams . ampCreateGas
-- amag = fromMaybe (error "cannot find gas ammo") $ getAmmoMagazine it cr
dir = _crDir cr
pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr))
@@ -493,10 +465,11 @@ fireRemoteShell ams it cr w =
i = IM.newKey $ w ^. cWorld . lWorld . props
cid = _crID cr
apm = fromMaybe (error "cannot find shell ammo projectile") $ do
invid <- it ^? itLocation . ipInvID
cr ^? crInv . ix (invid + 1) . itUse . amagParams
ams ^? ix 0
addRemRocket =
makeShell apm
-- the following is unsafe!
(it ^?! itUse . heldAim . aimMuzzles . ix 0)
it
cr
[ PJRemoteShellCollisionCheck
@@ -539,7 +512,7 @@ mcShootLaser it mc = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParam
-- | assumes that the item is held
shootTeslaArc :: [Item] -> Item -> Creature -> World -> World
shootTeslaArc ams it cr w =
shootTeslaArc _ it cr w =
w'
& cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip
where
+1
View File
@@ -101,6 +101,7 @@ miniGunUse i =
& heldAim . aimRange .~ 1
& heldAim . aimStance .~ TwoHandUnder
& heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& heldConsumption .~ [BulletAmmo]
miniGunX :: Int -> Item
miniGunX i =
+5 -1
View File
@@ -32,7 +32,7 @@ launcher =
-- & itUse . heldAim . aimHandlePos .~ V2 3 0
-- & itUse . heldAim . aimMuzPos .~ 20
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 20 0) 0 0]
& itUse . heldConsumption .~ [BulletAmmo]
& itUse . heldConsumption .~ [ProjectileAmmo]
& itType . iyBase .~ HELD LAUNCHER
& itType . iyModules . at ModLauncherHoming ?~ EMPTYMODULE
@@ -42,6 +42,10 @@ launcherX i =
& itType . iyBase .~ HELD (LAUNCHERX i)
& itUse . heldUse .~ HeldPJCreationX i
& itUse . heldMods .~ LauncherXMod i
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 20 0) a 0 | a <- angles]
where
angles = take i [0,2*pi/ fromIntegral i ..]
--angles = take i [1,2 ..]
remoteLauncher :: Item
remoteLauncher =
+1 -51
View File
@@ -22,23 +22,6 @@ import Picture
--import Control.Monad.State
--lasPulse :: Item
--lasPulse = lasGun
-- & itType . iyBase .~ LASPULSE
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 (100 * frac it) (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withSoundForVol (frac it) tone440sawtoothquietS 2
-- , withItemUpdate itup
-- $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) (frac it * 0.8)
-- , useAmmoAmount 1
-- ]
-- where
-- itup it = it
-- & itParams . lasCycle %~ (\i -> (i+1) `mod` 20)
-- & itParams . lasDamage .~ ceiling ((22 :: Float) * frac it)
-- & itParams . lasColor .~ frac it * orange
-- frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.1))
--lasWidePulse :: Item
--lasWidePulse = lasGun
@@ -89,43 +72,10 @@ import Picture
-- x it = [ 15 * sin (pi * fromIntegral x' * 0.05) ]
-- where
-- x' = _lasCycle $ _itParams it
--lasFocus :: Int -> Item
--lasFocus n = lasGunWide n
-- & itType . iyBase .~ LASGUNFOCUS n
-- & itParams . lasColor .~ red
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , useAmmoAmount 1
-- , duplicateOffsetsFocus xs
-- ]
-- where
-- n' = 9 * n
-- xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
--lasSwing :: Item
--lasSwing = lasGun
-- & itType . iyBase .~ LASGUNSWING
-- & itParams . lasColor .~ orange
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , useAmmoAmount 1
-- , withItemUpdate itup $ \it -> duplicateOffsetsFocus (x it)
-- ]
-- where
-- itup = itParams . lasCycle %~ (\i -> (i+1) `mod` 200)
-- x it = [-y,y]
-- where
-- y = 15 * sin (pi * fromIntegral x' * 0.01)
-- x' = _lasCycle $ _itParams it
shootLaser :: [Item] -> Item -> Creature -> World -> World
shootLaser ams it cr =
shootLaser _ it cr =
cWorld . lWorld . lasers
.:~ lasRayAt
(_lasColor $ _itParams it)
-19
View File
@@ -18,25 +18,6 @@ module Dodge.Item.Weapon.SonicGuns where
----import Data.Tuple
----import qualified IntMapHelp as IM
--
----sonicGun :: Item
----sonicGun = defaultAutoGun
---- { _itConsumption = defaultLoadable
---- & laMax .~ 10
---- & laCycle .~ [loadEject 10, loadInsert 10 , loadPrime 60]
---- , _itParams = NoParams
---- , _itTweaks = NoTweaks
---- }
---- & itDimension . dimRad .~ 10
---- & itDimension . dimCenter .~ V3 15 0 0
---- & itUse . useDelay . rateMax .~ 8
---- & itUse . rUse .~ HeldSonicWave --aSonicWave
---- & itUse . useMods .~ AmmoHammerTimeUseOneMod
---- & itUse . useAim . aimWeight .~ 6
---- & itUse . useAim . aimRange .~ 1
---- & itUse . useAim . aimStance .~ TwoHandTwist
---- & itUse . useAim . aimMuzPos .~ 25
---- & itType . iyBase .~ HELD SONICGUN
--
----aSonicWave :: Item -> Creature -> World -> World
----aSonicWave it cr = instantParticles .:~ sonicWave pos dir cpos
---- where
+6 -3
View File
@@ -73,7 +73,7 @@ import Dodge.Reloading
import Dodge.SoundLogic
import Dodge.WorldEvent
import Geometry
import qualified IntMapHelp as IM
--import qualified IntMapHelp as IM
import LensHelp
import RandomHelp
import qualified SDL
@@ -145,6 +145,9 @@ ammoCheckI :: ChainEffect
ammoCheckI eff ams itm cr w = fromMaybe (failsound w) $ do
x <- ams ^? ix 0 . itUse . amagLoadStatus . iaLoaded
guard $ x > 0
matype <- ams ^? ix 0 . itUse . amagType
iatype <- itm ^? itUse . heldConsumption . ix 0
guard $ matype == iatype
return $ eff ams itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where
failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -239,7 +242,7 @@ withSoundStart ::
SoundID ->
ChainEffect
withSoundStart soundid f ams item cr =
soundMultiFrom [CrWeaponSound cid 0, CrWeaponSound cid 1, CrWeaponSound cid 2] (_crPos cr) soundid Nothing
soundMultiFrom [CrWeaponSound cid j | j <- [0..3]] (_crPos cr) soundid Nothing
. f ams item cr
where
cid = _crID cr
@@ -346,7 +349,7 @@ useAllAmmo eff ams item cr w = fromMaybe w $ do
useAmmoUpTo :: Int -> ChainEffect
useAmmoUpTo amAmount eff ams itm cr = fromMaybe id $ do
x <- ams ^? ix 0 . itUse . amagLoadStatus . iaLoaded
_ <- ams ^? ix 0 . itUse . amagLoadStatus . iaLoaded
invid <- ams ^? ix 0 . itLocation . ipInvID
return $ eff ams itm cr
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . amagLoadStatus . iaLoaded
+69 -44
View File
@@ -1,22 +1,42 @@
module Dodge.Projectile.Create where
import Dodge.SoundLogic
import Dodge.Reloading
import Control.Monad
import Data.Maybe
import Dodge.Data.World
import Geometry
import qualified IntMapHelp as IM
import LensHelp
--import Data.Maybe
import qualified SDL
createProjectile :: AmmoParams -> Item -> Creature -> World -> World
createProjectile apm itm cr = case pt of
CreateShell -> fireShell apm itm cr
CreateTrackingShell -> fireTrackingShell apm itm cr
createProjectile :: Item -> Muzzle -> Item -> Creature -> World -> World
createProjectile ammoitem muz itm cr = fromMaybe failsound $ do
x <- ammoitem ^? itUse . amagLoadStatus . iaLoaded
guard $ x > 0
matype <- ammoitem ^? itUse . amagType
guard $ matype == ProjectileAmmo
j <- ammoitem ^? itLocation . ipInvID
pt <- ammoitem ^? itUse . amagParams . ampPjCreation
return $ case pt of
CreateShell -> fireShell ammoitem muz itm cr . extrafuncs j
CreateTrackingShell -> fireTrackingShell ammoitem muz itm cr . extrafuncs j
where
pt = _ampPjCreation apm
extrafuncs j = cancelanyreloading . startthesound . useammo j
useammo j = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix j . itUse . amagLoadStatus . iaLoaded -~ 1
cancelanyreloading = cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
-- the sound should be moved to the projectile firing
startthesound = soundMultiFrom [CrWeaponSound (_crID cr) j | j <- [0..3]] (_crPos cr) tap4S Nothing
failsound w' = case w' ^? input . mouseButtons . ix SDL.ButtonLeft of
Just 0 -> soundStart (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing w'
_ -> soundContinue (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing w'
fireShell :: AmmoParams -> Item -> Creature -> World -> World
fireShell ap it cr =
fireShell :: Item -> Muzzle -> Item -> Creature -> World -> World
fireShell ammoitem muz it cr =
makeShell
ap
ammoitem
muz
it
cr
[ PJShellCollisionCheck
@@ -31,43 +51,48 @@ fireShell ap it cr =
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
makeShell :: AmmoParams -> Item -> Creature -> [ProjectileUpdate] -> World -> World
makeShell ap it cr theupdate w =
w & cWorld . lWorld . projectiles . at i
?~ Shell
{ _prjPos = pos
, _prjZ = 20
, _prjStartPos = pos
, _prjVel = rotateV dir (V2 1 0)
, _prjDraw = DrawShell
, _prjID = i
, _prjAcc = rotateV dir (V2 3 0)
, _prjDir = dir
, _prjSpin = 0
, _prjPayload = _ampPayload ap
, _prjTimer = 350
, _prjUpdates = theupdate
, _prjMITID = Just $ _itID it
}
makeShell :: Item -> Muzzle -> Item -> Creature -> [ProjectileUpdate] -> World -> World
makeShell ammoitem muz it cr theupdate w = fromMaybe w $ do
aparams <- ammoitem ^? itUse . amagParams
return $
w & cWorld . lWorld . projectiles . at i
?~ Shell
{ _prjPos = pos
, _prjZ = 20
, _prjStartPos = pos
, _prjVel = rotateV dir (V2 1 0)
, _prjDraw = DrawShell
, _prjID = i
, _prjAcc = rotateV dir (V2 3 0)
, _prjDir = dir
, _prjSpin = 0
, _prjPayload = _ampPayload aparams
, _prjTimer = 350
, _prjUpdates = theupdate
, _prjMITID = Just $ _itID it
}
where
i = IM.newKey $ w ^. cWorld . lWorld . props-- _props (_cWorld w)
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
--am = _heldConsumption $ _itUse it
i = IM.newKey $ w ^. cWorld . lWorld . projectiles -- _props (_cWorld w)
dir = _crDir cr + _mzRot muz
pos = _crPos cr +.+ rotateV dir (_mzPos muz)
fireTrackingShell :: AmmoParams -> Item -> Creature -> World -> World
fireTrackingShell ap it cr =
makeShell
ap
it
cr
[ PJRemoteShellCollisionCheck
, PJDecTimMvVel
, PJSpin 335 (_crID cr) spinamount
, PJTrack (350 - thrustdelay) 0 (_itID it)
, PJThrust (350 - thrustdelay) 0
, PJReduceSpin (1 - fromIntegral spindrag * 2 / 200)
]
--am = _heldConsumption $ _itUse it
fireTrackingShell :: Item -> Muzzle -> Item -> Creature -> World -> World
fireTrackingShell ammoitem muz it cr = fromMaybe id $ do
return $
makeShell
ammoitem
muz
it
cr
[ PJRemoteShellCollisionCheck
, PJDecTimMvVel
, PJSpin 335 (_crID cr) spinamount
, PJTrack (350 - thrustdelay) 0 (_itID it)
, PJThrust (350 - thrustdelay) 0
, PJReduceSpin (1 - fromIntegral spindrag * 2 / 200)
]
where
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
+5 -2
View File
@@ -17,9 +17,12 @@ import Dodge.Data.Universe
--import Data.Maybe
--import ShortShow
--import qualified Data.Map.Strict as M
--import qualified IntMapHelp as IM
import qualified IntMapHelp as IM
testStringInit :: Universe -> [String]
testStringInit _ = []
testStringInit u = [fromMaybe "" $ do
proj <- u ^? uvWorld . cWorld . lWorld . projectiles
return $ show $ IM.size proj
]
-- [fromMaybe "" $ do
-- cr <- u ^? uvWorld . cWorld . lWorld . creatures . ix 0
-- i <- cr ^? crManipulation . manObject . inInventory . ispItem