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
, _pjDir :: Float
, _pjSpin :: Float
, _pjSpinFactor :: Float
, _pjID :: Int
, _pjPayload :: Payload
, _pjTimer :: Int
, _pjZ :: Float
, _pjZVel :: Float
, _pjUpdates :: [ProjectileUpdate]
, _pjBarrelSpin :: Maybe (Int, Float)
, _pjType :: ProjectileType
, _pjDetonatorID :: Maybe (NewInt ItmInt)
, _pjScreenID :: Maybe (NewInt ItmInt)
}
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
= Grenade { _gnHitEffect :: GrenadeHitEffect }
| Rocket
@@ -64,12 +57,10 @@ data RocketSmoke
= ReducedRocketSmoke
deriving (Show, Eq, Ord, Read) --Generic, Flat)
makeLenses ''ProjectileUpdate
makeLenses ''Projectile
makeLenses ''ProjectileType
makeLenses ''RocketHoming
makeLenses ''GrenadeHitEffect
deriveJSON defaultOptions ''ProjectileUpdate
deriveJSON defaultOptions ''GrenadeHitEffect
deriveJSON defaultOptions ''RocketHoming
deriveJSON defaultOptions ''RocketSmoke
+7 -13
View File
@@ -43,13 +43,11 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
, _pjID = i
, _pjDir = dir'
, _pjSpin = 0
, _pjSpinFactor = spinfactor
, _pjPayload = payload
, _pjTimer = lifespan
, _pjUpdates =
anyspin
-- <> [ RemoteDirectionPU 330 0
-- ]
, _pjBarrelSpin = bs
-- , _pjUpdates =
-- anyspin
, _pjType = pjtype
, _pjDetonatorID = mdetonator
, _pjScreenID = mscreen
@@ -58,14 +56,10 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
crvelcomponent = case stab of
Just StabOrthReduce -> projV (cr ^. crPos - cr ^. crOldPos) (unitVectorAtAngle dir)
_ -> cr ^. crPos - cr ^. crOldPos
anyspin = case stab of
Just StabOrthReduce -> []
Just StabSpinIncrease -> [StartSpinPU (lifespan - 15) (_crID cr) 4]
_ -> [StartSpinPU (lifespan - 15) (_crID cr) 2]
spinfactor = case stab of
Just StabOrthReduce -> 0
Just StabSpinIncrease -> 2
_ -> 1
bs = case stab of
Just StabOrthReduce -> Nothing
Just StabSpinIncrease -> Just (_crID cr, 5)
_ -> Just (_crID cr, 2)
speed = case pjtype of
Grenade{} -> 4
Rocket{} -> 1
+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