Remove list of projectile updates

This commit is contained in:
2025-08-03 14:05:34 +01:00
parent c3b2bb30f5
commit ea2e67c9ab
3 changed files with 25 additions and 54 deletions
+1 -10
View File
@@ -19,25 +19,18 @@ data Projectile = Shell
, _pjVel :: Point2 , _pjVel :: Point2
, _pjDir :: Float , _pjDir :: Float
, _pjSpin :: Float , _pjSpin :: Float
, _pjSpinFactor :: Float
, _pjID :: Int , _pjID :: Int
, _pjPayload :: Payload , _pjPayload :: Payload
, _pjTimer :: Int , _pjTimer :: Int
, _pjZ :: Float , _pjZ :: Float
, _pjZVel :: Float , _pjZVel :: Float
, _pjUpdates :: [ProjectileUpdate] , _pjBarrelSpin :: Maybe (Int, Float)
, _pjType :: ProjectileType , _pjType :: ProjectileType
, _pjDetonatorID :: Maybe (NewInt ItmInt) , _pjDetonatorID :: Maybe (NewInt ItmInt)
, _pjScreenID :: Maybe (NewInt ItmInt) , _pjScreenID :: Maybe (NewInt ItmInt)
} }
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ProjectileUpdate
= --ThrustPU {_pjuStart :: Int, _pjuEnd :: Int}
StartSpinPU {_pjuTime :: Int, _pjuCID :: Int, _pjuSpinAmound :: Int}
-- | RemoteDirectionPU {_pjuStart :: Int, _pjuEnd :: Int}
deriving (Show, Eq, Ord, Read) --Generic, Flat)
data ProjectileType data ProjectileType
= Grenade { _gnHitEffect :: GrenadeHitEffect } = Grenade { _gnHitEffect :: GrenadeHitEffect }
| Rocket | Rocket
@@ -64,12 +57,10 @@ data RocketSmoke
= ReducedRocketSmoke = ReducedRocketSmoke
deriving (Show, Eq, Ord, Read) --Generic, Flat) deriving (Show, Eq, Ord, Read) --Generic, Flat)
makeLenses ''ProjectileUpdate
makeLenses ''Projectile makeLenses ''Projectile
makeLenses ''ProjectileType makeLenses ''ProjectileType
makeLenses ''RocketHoming makeLenses ''RocketHoming
makeLenses ''GrenadeHitEffect makeLenses ''GrenadeHitEffect
deriveJSON defaultOptions ''ProjectileUpdate
deriveJSON defaultOptions ''GrenadeHitEffect deriveJSON defaultOptions ''GrenadeHitEffect
deriveJSON defaultOptions ''RocketHoming deriveJSON defaultOptions ''RocketHoming
deriveJSON defaultOptions ''RocketSmoke deriveJSON defaultOptions ''RocketSmoke
+7 -13
View File
@@ -43,13 +43,11 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
, _pjID = i , _pjID = i
, _pjDir = dir' , _pjDir = dir'
, _pjSpin = 0 , _pjSpin = 0
, _pjSpinFactor = spinfactor
, _pjPayload = payload , _pjPayload = payload
, _pjTimer = lifespan , _pjTimer = lifespan
, _pjUpdates = , _pjBarrelSpin = bs
anyspin -- , _pjUpdates =
-- <> [ RemoteDirectionPU 330 0 -- anyspin
-- ]
, _pjType = pjtype , _pjType = pjtype
, _pjDetonatorID = mdetonator , _pjDetonatorID = mdetonator
, _pjScreenID = mscreen , _pjScreenID = mscreen
@@ -58,14 +56,10 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
crvelcomponent = case stab of crvelcomponent = case stab of
Just StabOrthReduce -> projV (cr ^. crPos - cr ^. crOldPos) (unitVectorAtAngle dir) Just StabOrthReduce -> projV (cr ^. crPos - cr ^. crOldPos) (unitVectorAtAngle dir)
_ -> cr ^. crPos - cr ^. crOldPos _ -> cr ^. crPos - cr ^. crOldPos
anyspin = case stab of bs = case stab of
Just StabOrthReduce -> [] Just StabOrthReduce -> Nothing
Just StabSpinIncrease -> [StartSpinPU (lifespan - 15) (_crID cr) 4] Just StabSpinIncrease -> Just (_crID cr, 5)
_ -> [StartSpinPU (lifespan - 15) (_crID cr) 2] _ -> Just (_crID cr, 2)
spinfactor = case stab of
Just StabOrthReduce -> 0
Just StabSpinIncrease -> 2
_ -> 1
speed = case pjtype of speed = case pjtype of
Grenade{} -> 4 Grenade{} -> 4
Rocket{} -> 1 Rocket{} -> 1
+17 -31
View File
@@ -6,8 +6,7 @@ module Dodge.Projectile.Update (
) where ) where
import Control.Monad import Control.Monad
import Data.Foldable import Data.List (delete)
import Data.List (delete, deleteBy)
import Data.Maybe import Data.Maybe
import Dodge.Base import Dodge.Base
import Dodge.Data.World import Dodge.Data.World
@@ -30,20 +29,7 @@ updateProjectile pj w =
(cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer -~ 1) (cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer -~ 1)
. shellCollisionCheck pj . shellCollisionCheck pj
. moveProjectile pj . moveProjectile pj
. doGravityPU pj $ doGravityPU pj w
$ foldl' (flip $ upProjectile pj) w (_pjUpdates pj)
upProjectile :: Projectile -> ProjectileUpdate -> World -> World
upProjectile pj = \case
StartSpinPU t cid spinamount
| time == t -> trySpinByCID cid spinamount pj
| otherwise -> id
-- RemoteDirectionPU st et
-- | act st et -> pjRemoteSetDirection (pj ^? pjType . rkHoming) pj
-- | otherwise -> id
where
time = _pjTimer pj
-- act st et = time <= st && time >= et
doGravityPU :: Projectile -> World -> World doGravityPU :: Projectile -> World -> World
doGravityPU pj doGravityPU pj
@@ -141,6 +127,12 @@ destroyProjectile mitid pjid w =
loc <- w ^? cWorld . lWorld . itemLocations . ix itid loc <- w ^? cWorld . lWorld . itemLocations . ix itid
return $ pointerToItemLocation loc . itUse . uaParams . apProjectiles %~ delete pjid return $ pointerToItemLocation loc . itUse . uaParams . apProjectiles %~ delete pjid
trySpin :: Projectile -> World -> World
trySpin pj = fromMaybe id $ do
guard (pj ^. pjTimer == 335)
(cid,s) <- pj ^? pjBarrelSpin . _Just
return $ doBarrelSpin cid s pj
tryThrust :: Projectile -> World -> World tryThrust :: Projectile -> World -> World
tryThrust pj = fromMaybe id $ do tryThrust pj = fromMaybe id $ do
Rocket y x <- pj ^? pjType Rocket y x <- pj ^? pjType
@@ -175,26 +167,20 @@ doThrust pj smoke w =
-- there doesn't seem to be a more sensible way to filter the first occurence of -- there doesn't seem to be a more sensible way to filter the first occurence of
-- a list than deleteBy -- a list than deleteBy
trySpinByCID :: doBarrelSpin :: Int -> Float -> Projectile -> World -> World
-- | creature id doBarrelSpin cid i pj w =
Int ->
-- | Spin amount
Int ->
Projectile ->
World ->
World
trySpinByCID cid i pj w =
w & cWorld . lWorld . projectiles . ix pjid . pjSpin .~ newSpin w & cWorld . lWorld . projectiles . ix pjid . pjSpin .~ newSpin
& cWorld . lWorld . projectiles . ix pjid . pjUpdates %~ deleteBy f (StartSpinPU 0 0 0) & cWorld . lWorld . projectiles . ix pjid . pjBarrelSpin .~ Nothing
-- & cWorld . lWorld . projectiles . ix pjid . pjUpdates %~ deleteBy f (StartSpinPU 0 0 0)
where where
f _ StartSpinPU{} = True -- f _ StartSpinPU{} = True
-- f _ _ = False -- f _ _ = False
pjid = _pjID pj pjid = _pjID pj
dir = argV $ _pjVel pj dir = argV $ _pjVel pj
newSpin = case w ^? cWorld . lWorld . creatures . ix cid of newSpin = case w ^? cWorld . lWorld . creatures . ix cid of
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
_ -> 0 _ -> 0
spinFactor = 5 * (6 - fromIntegral i) spinFactor = 5 * (6 - i)
-- note this only allows YOU to remotely track projectiles -- note this only allows YOU to remotely track projectiles
pjRemoteSetDirection :: Maybe RocketHoming -> Projectile -> World -> World pjRemoteSetDirection :: Maybe RocketHoming -> Projectile -> World -> World
@@ -239,9 +225,9 @@ moveProjectile pj w
w w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99 & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~ _pjSpin pj
+~ (_pjSpin pj * _pjSpinFactor pj)
& tryThrust pj & tryThrust pj
& trySpin pj
explodeShell :: explodeShell ::
Projectile -> Projectile ->
@@ -249,7 +235,7 @@ explodeShell ::
World World
explodeShell pj w = explodeShell pj w =
w w
& cWorld . lWorld . projectiles . ix pjid . pjUpdates .~ [] -- & cWorld . lWorld . projectiles . ix pjid . pjUpdates .~ []
& cWorld . lWorld . projectiles . ix pjid . pjType .~ RetiredProjectile & cWorld . lWorld . projectiles . ix pjid . pjType .~ RetiredProjectile
& cWorld . lWorld . projectiles . ix pjid . pjVel .~ 0 & cWorld . lWorld . projectiles . ix pjid . pjVel .~ 0
& cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 30 & cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 30