(Re)Implement nozzle walking

This commit is contained in:
2024-09-21 19:42:28 +01:00
parent 241f6fdf10
commit 86d8e3a98a
7 changed files with 329 additions and 362 deletions
+1 -1
View File
@@ -1 +1 @@
All good (617 modules, at 19:05:46) All good (617 modules, at 19:41:21)
+2
View File
@@ -274,6 +274,8 @@ stackedInventory =
, megaTinMag , megaTinMag
, teslaGun , teslaGun
, megaBattery , megaBattery
, flameThrower
, chemFuelPouch
, bulletSynthesizer , bulletSynthesizer
, drumMag , drumMag
, launcher , launcher
-9
View File
@@ -44,11 +44,6 @@ data ItemParams
, _dbGap :: Float , _dbGap :: Float
} }
| Attracting {_attractionPower :: Point2} | Attracting {_attractionPower :: Point2}
| AngleWalk
{ _maxWalkAngle :: Float
, _currentWalkAngle :: Float
, _walkSpeed :: Float
}
| Arcing | Arcing
{ _currentArc :: Maybe [ArcStep] { _currentArc :: Maybe [ArcStep]
, _arcSize :: Float , _arcSize :: Float
@@ -77,12 +72,8 @@ data PreviousArcEffect = NoPreviousArcEffect | PerturbTillBreakPreviousArc
-- } -- }
--deriving (Eq, Ord, Show, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Nozzle = Nozzle
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''ItemParams makeLenses ''ItemParams
makeLenses ''Nozzle
deriveJSON defaultOptions ''ShrinkGunStatus deriveJSON defaultOptions ''ShrinkGunStatus
deriveJSON defaultOptions ''PreviousArcEffect deriveJSON defaultOptions ''PreviousArcEffect
deriveJSON defaultOptions ''Nozzle
deriveJSON defaultOptions ''ItemParams deriveJSON defaultOptions ''ItemParams
+43 -45
View File
@@ -1,5 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
@@ -11,28 +11,28 @@ module Dodge.Data.Item.Use (
module Dodge.Data.Item.Use.Consumption, module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Hammer, module Dodge.Data.Hammer,
module Dodge.Data.Item.Targeting, module Dodge.Data.Item.Targeting,
module Dodge.Data.GenFloat module Dodge.Data.GenFloat,
) where ) where
import Dodge.Data.GenFloat
import Sound.Data
import qualified Data.IntMap.Strict as IM
import Geometry.Data
import Control.Lens import Control.Lens
import Data.Aeson import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
import qualified Data.IntMap.Strict as IM
import Dodge.Data.GenFloat
--import qualified Data.Sequence as Seq --import qualified Data.Sequence as Seq
import Dodge.Data.Hammer import Dodge.Data.Hammer
import Dodge.Data.Item.HeldDelay
import Dodge.Data.Item.HeldUse import Dodge.Data.Item.HeldUse
import Dodge.Data.Item.Targeting
import Dodge.Data.Item.Use.Consumption import Dodge.Data.Item.Use.Consumption
import Dodge.Data.Item.Use.Equipment import Dodge.Data.Item.Use.Equipment
import Dodge.Data.Item.HeldDelay import Geometry.Data
import Dodge.Data.Item.Targeting import Sound.Data
data ItemUse data ItemUse
= HeldUse = HeldUse
{ -- _heldUse :: Huse { -- _heldUse :: Huse
_heldDelay :: UseDelay _heldDelay :: UseDelay
, _heldMods :: HeldMod , _heldMods :: HeldMod
, _heldHammer :: HammerPosition , _heldHammer :: HammerPosition
, _heldAim :: AimParams , _heldAim :: AimParams
@@ -40,7 +40,7 @@ data ItemUse
, _heldParams :: HeldParams , _heldParams :: HeldParams
, _heldTriggerType :: TriggerType , _heldTriggerType :: TriggerType
, _heldUsageTime :: Int -- this is not yet implemented , _heldUsageTime :: Int -- this is not yet implemented
-- , _useTargeting :: Maybe TargetType -- , _useTargeting :: Maybe TargetType
} }
| LeftUse | LeftUse
{ _leftUse :: Luse { _leftUse :: Luse
@@ -51,44 +51,45 @@ data ItemUse
} }
| ConsumeUse | ConsumeUse
{ _cUse :: Cuse { _cUse :: Cuse
-- , _useAmount :: ItAmount -- , _useAmount :: ItAmount
} }
| EquipUse | EquipUse
{ _equipEffect :: EquipEffect { _equipEffect :: EquipEffect
, _equipTargeting :: Maybe TargetType , _equipTargeting :: Maybe TargetType
} }
| CraftUse | CraftUse
-- {_useAmount :: ItAmount} | -- {_useAmount :: ItAmount}
| AttachUse AttachUse
-- {_attachParams :: AttachParams} | -- {_attachParams :: AttachParams}
| AmmoMagUse AmmoMagUse
{ _amagLoadStatus :: ReloadStatus { _amagLoadStatus :: ReloadStatus
, _amagParams :: AmmoParams , _amagParams :: AmmoParams
, _amagType :: AmmoType , _amagType :: AmmoType
} }
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
data TriggerType = AutoTrigger data TriggerType
= AutoTrigger
| HammerTrigger | HammerTrigger
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
data HeldParams data HeldParams
= DefaultHeldParams = DefaultHeldParams
| GasSprayParams | GasSprayParams
{_gasCreation :: GasCreate { _gasCreation :: GasCreate
, _recoil :: Float , _recoil :: Float
, _torqueAfter :: Float , _torqueAfter :: Float
, _randomOffset :: Float , _randomOffset :: Float
, _sidePush :: Float , _sidePush :: Float
, _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel , _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel
-- if >0, continue playing sound for -- if >0, continue playing sound for
-- given time -- given time
, _weaponInvLock :: Int , _weaponInvLock :: Int
, _weaponRepeat :: [Int] , _weaponRepeat :: [Int]
} }
| BeamShooterParams | BeamShooterParams
{ _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel { _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel
-- TODO remove duplicate -- TODO remove duplicate
} }
| BulletShooterParams | BulletShooterParams
{ _muzVel :: GenFloat { _muzVel :: GenFloat
@@ -98,20 +99,15 @@ data HeldParams
, _randomOffset :: Float , _randomOffset :: Float
, _sidePush :: Float , _sidePush :: Float
, _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel , _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel
-- if >0, continue playing sound for -- if >0, continue playing sound for
-- given time -- given time
, _weaponInvLock :: Int , _weaponInvLock :: Int
, _weaponRepeat :: [Int] , _weaponRepeat :: [Int]
} }
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
--data AttachParams data AmmoParams
-- = ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams} = BulletParams {_ampBullet :: Bullet}
-- | TargetAttachParams
-- | NoAttachParams
-- deriving (Eq, Show, Read) --Generic, Flat)
data AmmoParams = BulletParams {_ampBullet :: Bullet}
| ProjectileParams | ProjectileParams
{ _ampPayload :: Payload { _ampPayload :: Payload
, _ampPjDraw :: ProjectileDraw , _ampPjDraw :: ProjectileDraw
@@ -136,14 +132,15 @@ data AimParams = AimParams
} }
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
data FlareType
data FlareType = DefaultFlareType = DefaultFlareType
| PistolFlare | PistolFlare
| MiniGunFlare | MiniGunFlare
| HeavySmokeFlare | HeavySmokeFlare
| LasGunFlare | LasGunFlare
| TeslaGunFlare | TeslaGunFlare
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
data MuzzleEffect data MuzzleEffect
= MuzzleShootBullet = MuzzleShootBullet
| MuzzleLaser | MuzzleLaser
@@ -156,9 +153,9 @@ data MuzzleEffect
, _nzCurrentWalkAngle :: Float , _nzCurrentWalkAngle :: Float
, _nzWalkSpeed :: Float , _nzWalkSpeed :: Float
} }
| MuzzleShatter | MuzzleShatter
| MuzzleForceField | MuzzleForceField
| MuzzleDetector | MuzzleDetector
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Muzzle = Muzzle data Muzzle = Muzzle
@@ -169,24 +166,23 @@ data Muzzle = Muzzle
, _mzFlareType :: FlareType , _mzFlareType :: FlareType
, _mzEffect :: MuzzleEffect , _mzEffect :: MuzzleEffect
, _mzChargeRequirement :: Maybe Int , _mzChargeRequirement :: Maybe Int
-- , _mzRecoil :: Float -- , _mzRecoil :: Float
-- , _mzTorque :: Float -- , _mzTorque :: Float
-- , _mzSidePush :: Float -- , _mzSidePush :: Float
-- , _mzRandomOffset :: Float -- , _mzRandomOffset :: Float
-- , _mzVel :: Float -- , _mzVel :: Float
-- , _mzRifling :: Float -- , _mzRifling :: Float
-- , _mzAmmoSlot :: Either Int -- , _mzAmmoSlot :: Either Int
-- , _mzAmmoPerShot :: Int -- , _mzAmmoPerShot :: Int
} }
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
data AimStance data AimStance
= TwoHandUnder = TwoHandUnder
| TwoHandOver | TwoHandOver
| TwoHandFlat | TwoHandFlat
| OneHand | OneHand
-- | LeaveHolstered -- | LeaveHolstered
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
--deriving (Eq, Show, Ord, Enum, Read) --Generic, Flat) --deriving (Eq, Show, Ord, Enum, Read) --Generic, Flat)
@@ -202,6 +198,7 @@ makeLenses ''AimParams
makeLenses ''ItZoom makeLenses ''ItZoom
makeLenses ''Muzzle makeLenses ''Muzzle
makeLenses ''HeldParams makeLenses ''HeldParams
--makeLenses ''AttachParams --makeLenses ''AttachParams
--makeLenses ''ScrollAttachParams --makeLenses ''ScrollAttachParams
makeLenses ''AmmoParams makeLenses ''AmmoParams
@@ -213,6 +210,7 @@ deriveJSON defaultOptions ''AmmoParams
deriveJSON defaultOptions ''HeldParams deriveJSON defaultOptions ''HeldParams
deriveJSON defaultOptions ''Muzzle deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AimStance deriveJSON defaultOptions ''AimStance
--deriveJSON defaultOptions ''ScrollAttachParams --deriveJSON defaultOptions ''ScrollAttachParams
--deriveJSON defaultOptions ''AttachParams --deriveJSON defaultOptions ''AttachParams
deriveJSON defaultOptions ''ItZoom deriveJSON defaultOptions ''ItZoom
+29 -25
View File
@@ -56,7 +56,7 @@ bulGunEffect' :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> Wo
bulGunEffect' t cr w = fromMaybe (error "error in bulGunEffect") $ do bulGunEffect' t cr w = fromMaybe (error "error in bulGunEffect") $ do
muzzles <- t ^? ldtValue . itUse . heldAim . aimMuzzles muzzles <- t ^? ldtValue . itUse . heldAim . aimMuzzles
let (upitm,loadedmuzzles) = mapAccumR loadMuzzle t muzzles let (upitm,loadedmuzzles) = mapAccumR loadMuzzle t muzzles
cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) $ loadedmuzzles cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) $ zip [0..] loadedmuzzles
return $ uncurry (applyCME (_ldtValue t) cr) cmew return $ uncurry (applyCME (_ldtValue t) cr) cmew
& cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles & cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
& doWeaponRepetitions upitm cr & doWeaponRepetitions upitm cr
@@ -177,17 +177,17 @@ isAmmoIntLink :: Int -> ComposeLinkType -> Bool
isAmmoIntLink i (AmmoInLink j _) = i == j isAmmoIntLink i (AmmoInLink j _) = i == j
isAmmoIntLink _ _ = False isAmmoIntLink _ _ = False
useLoadedAmmo :: Item -> Creature -> (CumulativeMuzzleEffect,World) -> (Muzzle,Int,Maybe Int) useLoadedAmmo :: Item -> Creature -> (CumulativeMuzzleEffect,World) -> (Int,(Muzzle,Int,Maybe Int))
-> (CumulativeMuzzleEffect,World) -> (CumulativeMuzzleEffect,World)
useLoadedAmmo _ _ (cme,w) (_,0,_) = (cme, w) useLoadedAmmo _ _ (cme,w) (_,(_,0,_)) = (cme, w)
useLoadedAmmo itm cr (cme,w) (mz,x,mid) = (,) (cme & cmeSound .~ True) $ useLoadedAmmo itm cr (cme,w) (mzid,(mz,x,mid)) = (,) (cme & cmeSound .~ True) $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itm cr $ case _mzEffect mz of removeAmmoFromMag x mid cr . makeMuzzleFlare mz itm cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullet itm cr w (mz,x,mid) MuzzleShootBullet -> shootBullet itm cr w (mz,x,mid)
MuzzleLaser -> shootLaser' itm cr mz w MuzzleLaser -> shootLaser' itm cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam itm cr w MuzzleTractor -> shootTractorBeam itm cr w
MuzzleLauncher -> createProjectile' mid mz itm cr w MuzzleLauncher -> createProjectile' mid mz itm cr w
MuzzleNozzle {} -> useGasParams mid mz itm cr $ walkNozzle mz itm cr w MuzzleNozzle {} -> useGasParams mid mz itm cr $ walkNozzle mzid mz itm cr w
MuzzleShatter -> shootShatter itm cr w MuzzleShatter -> shootShatter itm cr w
MuzzleForceField -> useForceFieldGun itm cr w MuzzleForceField -> useForceFieldGun itm cr w
MuzzleDetector -> itemDetectorEffect itm cr w MuzzleDetector -> itemDetectorEffect itm cr w
@@ -197,15 +197,19 @@ itemDetectorEffect itm cr w = fromMaybe w $ do
HELDDETECTOR dt <- itm ^? itType . iyBase . ibtHeld HELDDETECTOR dt <- itm ^? itType . iyBase . ibtHeld
return $ detectorEffect dt itm cr w return $ detectorEffect dt itm cr w
walkNozzle :: Muzzle -> Item -> Creature -> World -> World walkNozzle :: Int -> Muzzle -> Item -> Creature -> World -> World
walkNozzle _ _ _ w = w walkNozzle mzid mz itm cr w = fromMaybe w $ do
-- & randGen .~ g invid <- itm ^? itLocation . ipInvID
-- where return $ w
-- nz = _mzEffect mz & cWorld . lWorld . creatures . ix (_crID cr) . crInv
-- (walkamount, g) = randomR (- aspeed, aspeed) (_randGen w) . ix invid . itUse . heldAim . aimMuzzles . ix mzid . mzEffect . nzCurrentWalkAngle .~ wa
-- aspeed = _nzWalkSpeed nz & randGen .~ g
-- maxa = _nzMaxWalkAngle nz where
-- wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount) nz = _mzEffect mz
(walkamount, g) = randomR (- aspeed, aspeed) (_randGen w)
aspeed = _nzWalkSpeed nz
maxa = _nzMaxWalkAngle nz
wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount)
shootTractorBeam :: Item -> Creature -> World -> World shootTractorBeam :: Item -> Creature -> World -> World
@@ -313,17 +317,17 @@ useHeld hu = case hu of
HeldShatter -> shootShatter . _ldtValue HeldShatter -> shootShatter . _ldtValue
HeldExplodeRemoteShell itid pjid -> const $ const $ explodeRemoteRocket itid pjid HeldExplodeRemoteShell itid pjid -> const $ const $ explodeRemoteRocket itid pjid
usePjCreation :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World --usePjCreation :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
usePjCreation itm cr = fromMaybe id $ do --usePjCreation itm cr = fromMaybe id $ do
atype <- itm ^? ldtValue . itUse . heldAmmoTypes . ix 0 -- atype <- itm ^? ldtValue . itUse . heldAmmoTypes . ix 0
leftitms <- itm ^? ldtLeft -- leftitms <- itm ^? ldtLeft
mag <- lookup (AmmoInLink 0 atype) leftitms -- mag <- lookup (AmmoInLink 0 atype) leftitms
apm <- mag ^? ldtValue -- apm <- mag ^? ldtValue
muz <- itm ^? ldtValue . itUse . heldAim . aimMuzzles . ix 0 -- muz <- itm ^? ldtValue . itUse . heldAim . aimMuzzles . ix 0
return $ createProjectile apm muz (_ldtValue itm) cr -- return $ createProjectile apm muz (_ldtValue itm) cr
usePjCreationX :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World --usePjCreationX :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
usePjCreationX = undefined --usePjCreationX = undefined
--usePjCreationX ams itm cr = fromMaybe id $ do --usePjCreationX ams itm cr = fromMaybe id $ do
-- muzs <- itm ^? itUse . heldAim . aimMuzzles -- muzs <- itm ^? itUse . heldAim . aimMuzzles
-- return $ foldr -- return $ foldr
@@ -399,7 +403,7 @@ useGasParams mmagid mz itm cr w =
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm) pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
(a,g') = randomR (-inacc,inacc) g (a,g') = randomR (-inacc,inacc) g
inacc = _mzInaccuracy mz inacc = _mzInaccuracy mz
dir = _crDir cr + _mzRot mz + a dir = _crDir cr + _mzRot mz + a + (_nzCurrentWalkAngle $ _mzEffect mz)
gasCreate :: GasFuel -> GasCreate -> GasCreate gasCreate :: GasFuel -> GasCreate -> GasCreate
gasCreate = flip const gasCreate = flip const
-22
View File
@@ -9,28 +9,6 @@ import qualified IntMapHelp as IM
import LensHelp import LensHelp
import qualified SDL import qualified SDL
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
--extrafuncs j = cancelanyreloading . startthesound . useammo j
extrafuncs j = 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 (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w'
_ -> soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) click1S Nothing w'
createProjectile' :: Maybe Int -> Muzzle -> Item -> Creature -> World -> World createProjectile' :: Maybe Int -> Muzzle -> Item -> Creature -> World -> World
createProjectile' mmagid muz itm cr = fromMaybe failsound $ do createProjectile' mmagid muz itm cr = fromMaybe failsound $ do
+254 -260
View File
File diff suppressed because it is too large Load Diff