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