|
|
|
@@ -1,24 +1,24 @@
|
|
|
|
|
--{-# OPTIONS_GHC -Wno-unused-imports #-}
|
|
|
|
|
module Dodge.Projectile.Update
|
|
|
|
|
( updateProjectile
|
|
|
|
|
) where
|
|
|
|
|
module Dodge.Projectile.Update (
|
|
|
|
|
updateProjectile,
|
|
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
import Control.Monad
|
|
|
|
|
import Dodge.Movement.Turn
|
|
|
|
|
import NewInt
|
|
|
|
|
import Dodge.Payload
|
|
|
|
|
import Control.Lens
|
|
|
|
|
import Control.Monad
|
|
|
|
|
import Data.Foldable
|
|
|
|
|
import Data.Maybe
|
|
|
|
|
import Dodge.Base
|
|
|
|
|
import Dodge.Data.World
|
|
|
|
|
import Dodge.EnergyBall
|
|
|
|
|
import Dodge.Item.Location
|
|
|
|
|
import Dodge.Movement.Turn
|
|
|
|
|
import Dodge.Payload
|
|
|
|
|
import Dodge.SoundLogic
|
|
|
|
|
import Dodge.WorldEvent.Cloud
|
|
|
|
|
import Geometry
|
|
|
|
|
import qualified IntMapHelp as IM
|
|
|
|
|
import NewInt
|
|
|
|
|
import RandomHelp
|
|
|
|
|
import Data.Foldable
|
|
|
|
|
|
|
|
|
|
updateProjectile :: Projectile -> World -> World
|
|
|
|
|
updateProjectile pj w = foldl' (\w' pu -> upProjectile pu pj w') w (_prjUpdates pj)
|
|
|
|
@@ -38,16 +38,16 @@ upProjectile pu pj = case pu of
|
|
|
|
|
| otherwise -> id
|
|
|
|
|
ReduceSpinPU x -> reduceSpinBy x (_prjID pj)
|
|
|
|
|
DestroyPU mitid 0 -> destroyProjectile mitid (_prjID pj)
|
|
|
|
|
-- the following requires that this is at the top of the update list, which is
|
|
|
|
|
-- not ideal
|
|
|
|
|
-- the following requires that this is at the top of the update list, which is
|
|
|
|
|
-- not ideal
|
|
|
|
|
DestroyPU _ _ -> cWorld . lWorld . projectiles . ix (_prjID pj) . prjUpdates . ix 0 . pjuTimer -~ 1
|
|
|
|
|
where
|
|
|
|
|
time = _prjTimer pj
|
|
|
|
|
act st et = time <= st && time >= et
|
|
|
|
|
|
|
|
|
|
shellCollisionEffect :: Maybe (NewInt ItmInt) -> Projectile -> World -> World
|
|
|
|
|
shellCollisionEffect mscreenid = shellCollisionCheck
|
|
|
|
|
$ \pj -> explodeShell mscreenid (_prjID pj)
|
|
|
|
|
shellCollisionEffect mscreenid = shellCollisionCheck $
|
|
|
|
|
\pj -> explodeShell mscreenid (_prjID pj)
|
|
|
|
|
|
|
|
|
|
shellCollisionCheck :: (Projectile -> World -> World) -> Projectile -> World -> World
|
|
|
|
|
shellCollisionCheck f pj w
|
|
|
|
@@ -61,8 +61,9 @@ shellCollisionCheck f pj w
|
|
|
|
|
newPos = oldPos +.+ _prjVel pj
|
|
|
|
|
|
|
|
|
|
destroyProjectile :: Maybe (NewInt ItmInt) -> Int -> World -> World
|
|
|
|
|
destroyProjectile mitid pjid w = w & cWorld . lWorld . projectiles %~ IM.delete pjid
|
|
|
|
|
& removelink
|
|
|
|
|
destroyProjectile mitid pjid w =
|
|
|
|
|
w & cWorld . lWorld . projectiles %~ IM.delete pjid
|
|
|
|
|
& removelink
|
|
|
|
|
where
|
|
|
|
|
removelink = fromMaybe id $ do
|
|
|
|
|
itid <- fmap _unNInt mitid
|
|
|
|
@@ -70,7 +71,7 @@ destroyProjectile mitid pjid w = w & cWorld . lWorld . projectiles %~ IM.delete
|
|
|
|
|
itm <- w ^? pointerToItemLocation loc . itUse . uaParams . apLinkedProjectile . _Just
|
|
|
|
|
guard $ itm == pjid
|
|
|
|
|
return $ pointerToItemLocation loc . itUse . uaParams . apLinkedProjectile .~ Nothing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doThrust :: Projectile -> World -> World
|
|
|
|
|
doThrust pj w =
|
|
|
|
|
w
|
|
|
|
@@ -78,7 +79,9 @@ doThrust pj w =
|
|
|
|
|
& cWorld . lWorld . projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
|
|
|
|
|
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
|
|
|
|
|
& makeFlamelet (oldPos -.- vel) (vel +.+ rotateV (pi + sparkD) accel) 3 10
|
|
|
|
|
& shellTrailCloud trailage trailfadetime
|
|
|
|
|
& shellTrailCloud
|
|
|
|
|
trailage
|
|
|
|
|
trailfadetime
|
|
|
|
|
(addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
|
|
|
|
|
where
|
|
|
|
|
trailage = fst . randomR (300, 500) $ _randGen w
|
|
|
|
@@ -116,16 +119,17 @@ pjRemoteSetDirection ph pj w = case ph of
|
|
|
|
|
HomeUsingRemoteScreen screenid ->
|
|
|
|
|
let newdir
|
|
|
|
|
| w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
|
|
|
|
== w ^? cWorld . lWorld . itemLocations . ix (_unNInt screenid) . ilInvID
|
|
|
|
|
= (w ^. wCam . camRot) + argV (_mousePos (_input w))
|
|
|
|
|
== w ^? cWorld . lWorld . itemLocations . ix (_unNInt screenid) . ilInvID =
|
|
|
|
|
(w ^. wCam . camRot) + argV (_mousePos (_input w))
|
|
|
|
|
| otherwise = _prjDir pj
|
|
|
|
|
in w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
|
|
|
|
|
in w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
|
|
|
|
|
.~ magV (_prjAcc pj) *.* unitVectorAtAngle newdir
|
|
|
|
|
HomeUsingTargeting itid -> fromMaybe w $ do
|
|
|
|
|
tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just
|
|
|
|
|
return $ w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
|
|
|
|
|
return $
|
|
|
|
|
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
|
|
|
|
|
%~ vecTurnTo 0.2 (_prjPos pj) tp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--pjRemoteSetDirection mscreenid pj w = fromMaybe w $ do
|
|
|
|
|
-- screenid <- fmap _unNInt mscreenid
|
|
|
|
|
-- let newdir
|
|
|
|
@@ -159,5 +163,5 @@ explodeShell mitid pjid w =
|
|
|
|
|
& usePayload (_prjPayload thepj) (_prjPos thepj) (_prjVel thepj)
|
|
|
|
|
& stopSoundFrom (ShellSound pjid)
|
|
|
|
|
where
|
|
|
|
|
-- itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid-- _itemLocations (_cWorld w) IM.! itid
|
|
|
|
|
-- itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid-- _itemLocations (_cWorld w) IM.! itid
|
|
|
|
|
thepj = w ^?! cWorld . lWorld . projectiles . ix pjid
|
|
|
|
|