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
+17 -31
View File
@@ -6,8 +6,7 @@ module Dodge.Projectile.Update (
) where
import Control.Monad
import Data.Foldable
import Data.List (delete, deleteBy)
import Data.List (delete)
import Data.Maybe
import Dodge.Base
import Dodge.Data.World
@@ -30,20 +29,7 @@ updateProjectile pj w =
(cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer -~ 1)
. shellCollisionCheck pj
. moveProjectile pj
. doGravityPU pj
$ 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 pj w
doGravityPU :: Projectile -> World -> World
doGravityPU pj
@@ -141,6 +127,12 @@ destroyProjectile mitid pjid w =
loc <- w ^? cWorld . lWorld . itemLocations . ix itid
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 pj = fromMaybe id $ do
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
-- a list than deleteBy
trySpinByCID ::
-- | creature id
Int ->
-- | Spin amount
Int ->
Projectile ->
World ->
World
trySpinByCID cid i pj w =
doBarrelSpin :: Int -> Float -> Projectile -> World -> World
doBarrelSpin cid i pj w =
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
f _ StartSpinPU{} = True
-- f _ StartSpinPU{} = True
-- f _ _ = False
pjid = _pjID pj
dir = argV $ _pjVel pj
newSpin = case w ^? cWorld . lWorld . creatures . ix cid of
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
_ -> 0
spinFactor = 5 * (6 - fromIntegral i)
spinFactor = 5 * (6 - i)
-- note this only allows YOU to remotely track projectiles
pjRemoteSetDirection :: Maybe RocketHoming -> Projectile -> World -> World
@@ -239,9 +225,9 @@ moveProjectile pj w
w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir
+~ (_pjSpin pj * _pjSpinFactor pj)
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~ _pjSpin pj
& tryThrust pj
& trySpin pj
explodeShell ::
Projectile ->
@@ -249,7 +235,7 @@ explodeShell ::
World
explodeShell pj 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 . pjVel .~ 0
& cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 30