Start making projectile update function rather than folded list

This commit is contained in:
2024-12-28 21:31:33 +00:00
parent e028c54948
commit 2fdc6ae557
9 changed files with 95 additions and 87 deletions
-2
View File
@@ -254,10 +254,8 @@ anythingHitCirc rad sp ep w = hitCr || circHitWall sp ep rad w
f cid bl =
maybe
False
--(\cr -> null $ intersectCircSeg (_crPos cr) (rad + _crRad cr) sp ep)
(\cr -> intersectCircSegTest (_crPos cr) (rad + _crRad cr) sp ep)
(w ^? cWorld . lWorld . creatures . ix cid)
|| bl
-- hitWl = collideCircWalls sp ep rad $ wlsNearSeg xsp xep w
-- this should probably be wallsOnLine or something
+15 -19
View File
@@ -2,14 +2,13 @@ module Dodge.Creature.Impulse.UseItem (
useSelectedItem,
) where
import Data.Foldable (foldl')
import Dodge.DoubleTree
import Control.Lens
import Control.Monad
import Data.Maybe
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.World
import Dodge.DoubleTree
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Hotkey
@@ -38,33 +37,30 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
& pointerToItem itm . itUse . heldHammer .~ HammerDown
RemoteDetonatorSF -> do
guard (_crHammerPosition cr == HammerUp)
return $ activateDetonator usedloc cr w
return $ activateDetonator usedloc w
_ | isJust $ itm ^? itUse . uequipEffect -> do
guard (_crHammerPosition cr == HammerUp)
invid' <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid' cr w
_ -> Nothing
where
fst3 (x,_,_) = x
fst3 (x, _, _) = x
activateDetonator
:: LabelDoubleTree ItemLink ComposedItem -> Creature -> World
-> World
activateDetonator det _ w = foldl' remoteDetonate w
(det ^. ldtValue . _1 . itUse . uaParams . apProjectiles)
& pointerToItemID (det ^. ldtValue . _1 . itID) . itUse . uaParams . apProjectiles .~ []
remoteDetonate :: World -> Int -> World
remoteDetonate w pjid = w
& cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 0
activateDetonator ::
LabelDoubleTree ItemLink ComposedItem ->
World ->
World
activateDetonator det = fromMaybe id $ do
pjid <- det ^? ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
return $ cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 0
useLocation :: LocationLDT ItemLink ComposedItem -> UseFocus
useLocation loc
useLocation loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just
= UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
= UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just =
UseFromLocation
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
UseFromLocation
| otherwise = UseFromRoot
toggleEquipmentAt :: Int -> Creature -> World -> World
+3 -3
View File
@@ -26,9 +26,9 @@ data ProjectileUpdate
,_pjuTimer :: Int}
| TimePU
| CollisionEffectPU
{_pjuDetonatorID :: Maybe (NewInt ItmInt)
,_pjuScreenID :: Maybe (NewInt ItmInt)
}
-- {_pjuDetonatorID :: Maybe (NewInt ItmInt)
-- ,_pjuScreenID :: Maybe (NewInt ItmInt)
-- }
| ApplyGravityPU
deriving (Show, Eq, Ord, Read) --Generic, Flat)
+12
View File
@@ -26,15 +26,20 @@ data Projectile
, _pjZVel :: Float
, _pjUpdates :: [ProjectileUpdate]
, _pjType :: ProjectileType
, _pjDetonatorID :: Maybe (NewInt ItmInt)
, _pjScreenID :: Maybe (NewInt ItmInt)
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ProjectileType
= Grenade
{ _gnHitEffect :: GrenadeHitEffect
}
| Rocket
{_rkHoming :: RocketHoming
,_rkSmoke :: Maybe RocketSmoke
}
| RetiredProjectile
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data RocketHoming
@@ -43,6 +48,11 @@ data RocketHoming
| HomeUsingTargeting {_phTargetingID :: NewInt ItmInt}
deriving (Show, Eq, Ord, Read) --Generic, Flat)
data GrenadeHitEffect
= GBounce {_bounceTolerance :: Float}
| GStick
deriving (Show, Eq, Ord, Read) --Generic, Flat)
data RocketSmoke
= ReducedRocketSmoke
deriving (Show, Eq, Ord, Read) --Generic, Flat)
@@ -51,6 +61,8 @@ data RocketSmoke
makeLenses ''Projectile
makeLenses ''ProjectileType
makeLenses ''RocketHoming
makeLenses ''GrenadeHitEffect
deriveJSON defaultOptions ''GrenadeHitEffect
deriveJSON defaultOptions ''RocketHoming
deriveJSON defaultOptions ''RocketSmoke
deriveJSON defaultOptions ''ProjectileType
+7 -7
View File
@@ -46,10 +46,10 @@ drawFlamelet pt =
( mixColors
(fromIntegral (max 0 (time -2)))
(10 - fromIntegral time)
(V4 2 0 0 1)
(V4 2 0 0 1)
--(V4 2 0 0 1)
--(V4 2 0 0 0)
--(V4 2 0 0 1)
(V4 2 0 0 1)
(V4 2 0 0 0)
)
. rotate (negate (rot - 0.1 * fromIntegral time))
. scale s1 s1
@@ -62,10 +62,10 @@ drawFlamelet pt =
( mixColors
(fromIntegral (max 0 (time -2)))
(10 - fromIntegral time)
(V4 2 1 0 1)
(V4 0 0 0 1)
--(V4 2 1 0 0.5)
--(V4 0 0 0 0)
--(V4 2 1 0 1)
--(V4 0 0 0 1)
(V4 2 1 0 0.5)
(V4 0 0 0 0)
)
. rotate (negate (rot + 0.2 * fromIntegral time))
. scale s2 s2
+1 -1
View File
@@ -300,7 +300,7 @@ useLoadedAmmo itmtree cr (cme, w) (mzid, Just (mz, x, magtree)) = (,) (cme & cme
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam cr w
MuzzleRLauncher -> createProjectileR itmtree magtree mz cr w
MuzzleGLauncher -> createProjectile Grenade magtree mz cr w
MuzzleGLauncher -> createProjectile (Grenade (GBounce 2)) magtree mz cr w
MuzzleNozzle{} -> useGasParams mid mz itm cr $ walkNozzle mzid mz itm cr w
MuzzleShatter -> shootShatter itm cr w
MuzzleDetector -> itemDetectorEffect itm cr w
+8 -6
View File
@@ -32,24 +32,26 @@ createShell mdetonator mscreen pjtype payload muz cr w = w
, _pjPayload = payload
, _pjTimer = lifespan
, _pjUpdates =
[ CollisionEffectPU mdetonator mscreen
[ CollisionEffectPU
, TimePU
, StartSpinPU (lifespan - 15) (_crID cr) spinamount
, RemoteDirectionPU (lifespan - thrustdelay) 0
, ReduceSpinPU (1 - spindrag * 2 / 200)
] <> thrustorgrav
, _pjType = pjtype
, _pjDetonatorID = mdetonator
, _pjScreenID = mscreen
}
where
speed = case pjtype of
Grenade -> 4
Grenade {} -> 4
Rocket{} -> 1
lifespan = case pjtype of
Grenade -> 150
Rocket{} -> 350
RetiredProjectile -> 0
lifespan = 350
thrustorgrav = case pjtype of
Grenade -> [ApplyGravityPU]
Grenade {}-> [ApplyGravityPU]
Rocket{} -> [ThrustPU (lifespan - thrustdelay) 0]
RetiredProjectile -> []
spindrag = 1
spinamount = 2
thrustdelay = 20
+6 -9
View File
@@ -26,10 +26,10 @@ updateProjectile pj w = foldl' (flip $ upProjectile pj) w (_pjUpdates pj)
upProjectile :: Projectile -> ProjectileUpdate -> World -> World
upProjectile pj pu = case pu of
CollisionEffectPU mdetonatorid mscreenid ->
CollisionEffectPU ->
shellCollisionCheck
mdetonatorid
mscreenid
(pj ^. pjDetonatorID)
(pj ^. pjScreenID)
pj
TimePU -> decTimMvVel pj
ThrustPU st et
@@ -79,7 +79,7 @@ applyGravityPU pj w
| otherwise = x * 0.9
newz = pj ^. pjZ + pj ^. pjZVel
--shellCollisionCheck :: (Projectile -> World -> World) -> Projectile -> World -> World
-- consider using thingHit, pushing any hit creature back
shellCollisionCheck ::
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
@@ -174,12 +174,9 @@ decTimMvVel :: Projectile -> World -> World
decTimMvVel pj =
cWorld . lWorld . projectiles . ix (_pjID pj)
%~ ( (pjTimer -~ 1)
. (pjPos %~ (+.+ vel))
. (pjDir +~ rot)
. (pjPos +~ _pjVel pj)
. (pjDir +~ _pjSpin pj)
)
where
rot = _pjSpin pj
vel = _pjVel pj
explodeShell ::
Maybe (NewInt ItmInt) ->