diff --git a/src/Dodge/Data/Item/Use/Consumption/Ammo.hs b/src/Dodge/Data/Item/Use/Consumption/Ammo.hs index 431411fca..de15661ed 100644 --- a/src/Dodge/Data/Item/Use/Consumption/Ammo.hs +++ b/src/Dodge/Data/Item/Use/Consumption/Ammo.hs @@ -27,6 +27,9 @@ data ProjectileUpdate | PJRemoteDirection {_pjuStart :: Int, _pjuEnd :: Int, _pjuCID :: Int, _pjuITID :: Int} | PJSetScope {_pjuITID :: Int} | PJRetireRemote {_pjuITID :: Int, _pjuTimer :: Int, _pjuPJID :: Int} + | PJDecTimMvVel + | PJShellCollisionCheck + | PJRemoteShellCollisionCheck deriving (Show, Read, Eq, Ord) data AmmoType diff --git a/src/Dodge/Data/Projectile.hs b/src/Dodge/Data/Projectile.hs index 3c4e39302..3fd79a353 100644 --- a/src/Dodge/Data/Projectile.hs +++ b/src/Dodge/Data/Projectile.hs @@ -10,16 +10,7 @@ import Dodge.Data.Item.Use.Consumption.Ammo import Geometry.Data data Proj - = RemoteShell - { _prjPos :: Point2 - , _prjStartPos :: Point2 - , _prjVel :: Point2 - , _prjDraw :: ProjectileDraw - , _prjID :: Int - , _prjPayload :: Payload - , _prjMITID :: Maybe Int - } - | Shell + = Shell { _prjPos :: Point2 , _prjStartPos :: Point2 , _prjVel :: Point2 diff --git a/src/Dodge/HeldUse.hs b/src/Dodge/HeldUse.hs index 0d0ad02a1..78b2d5d51 100644 --- a/src/Dodge/HeldUse.hs +++ b/src/Dodge/HeldUse.hs @@ -458,7 +458,9 @@ fireRemoteShell it cr w = makeShell it cr - [ PJSetScope itid + [ PJRemoteShellCollisionCheck + , PJSetScope itid + , PJDecTimMvVel , PJThrust 330 0 , PJRemoteDirection 340 0 cid itid ] diff --git a/src/Dodge/Projectile/Create.hs b/src/Dodge/Projectile/Create.hs index 592b62342..3ac889e88 100644 --- a/src/Dodge/Projectile/Create.hs +++ b/src/Dodge/Projectile/Create.hs @@ -5,6 +5,7 @@ import Dodge.Item.Location import Geometry import qualified IntMapHelp as IM import LensHelp +import Data.Maybe createProjectile :: ProjectileCreate -> Item -> Creature -> World -> World createProjectile pt = case pt of @@ -16,7 +17,9 @@ fireShell it cr = makeShell it cr - [ PJSpin 335 (_crID cr) spinamount + [ PJShellCollisionCheck + , PJDecTimMvVel + , PJSpin 335 (_crID cr) spinamount , PJThrust (350 - thrustdelay) 0 , PJReduceSpin (1 - fromIntegral spindrag * 2 / 200) ] @@ -44,7 +47,7 @@ makeShell it cr theupdate w = , _prjPayload = _amPayload $ _laAmmoType am , _prjTimer = 350 , _prjUpdates = theupdate - , _prjMITID = _itID it + , _prjMITID = Just . fromJust $ _itID it } where i = IM.newKey $ _props (_cWorld w) @@ -198,7 +201,9 @@ fireTrackingShell it cr w = addTrackRocket w' makeShell it cr - [ PJSpin 335 (_crID cr) spinamount + [ PJRemoteShellCollisionCheck + , PJDecTimMvVel + , PJSpin 335 (_crID cr) spinamount , PJTrack (350 - thrustdelay) 0 itid , PJThrust (350 - thrustdelay) 0 , PJReduceSpin (1 - fromIntegral spindrag * 2 / 200) diff --git a/src/Dodge/Projectile/Update.hs b/src/Dodge/Projectile/Update.hs index 4b74bdfae..54cb0b95e 100644 --- a/src/Dodge/Projectile/Update.hs +++ b/src/Dodge/Projectile/Update.hs @@ -29,11 +29,31 @@ import qualified Streaming.Prelude as S updateProjectile :: Proj -> World -> World updateProjectile pj = case pj of - Shell{} -> updateShell pj . decTimMvVel pj . upsProjectile pj - RemoteShell{} -> updateRemoteShell pj . decTimMvVel pj . upsProjectile pj + Shell{} -> upsProjectile pj -updateRemoteShell :: Proj -> World -> World -updateRemoteShell pj w +--explodeRemoteRocket' :: +-- -- | Item id +---- Maybe Int -> +-- Proj -> +-- World -> +-- World +--explodeRemoteRocket' thepj w = +-- w +-- & cWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile +-- & usePayload (_prjPayload thepj) (_prjPos thepj) +-- & updateitem +-- where +-- mitid = _prjMITID thepj +-- updateitem = fromMaybe (cWorld . projectiles . at pjid .~ Nothing) $ do +-- itid <- mitid +-- itpos <- w ^? cWorld . itemLocations . ix itid +-- return $ +-- (pointerToItemLocation itpos . itUse . heldUse .~ HeldDoNothing) +-- . (cWorld . projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid]) +-- pjid = _prjID thepj + +remoteShellCollisionCheck :: Proj -> World -> World +remoteShellCollisionCheck pj w | time > 340 = if circOnSomeWall oldPos 4 w then doExplode @@ -43,36 +63,12 @@ updateRemoteShell pj w | otherwise = doExplode where time = _prjTimer pj - doExplode = - w - & usePayload (_prjPayload pj) oldPos - & stopSoundFrom (ShellSound i) - & cWorld . projectiles %~ IM.delete i + doExplode = explodeRemoteRocket (fromJust (_prjMITID pj)) (_prjID pj) w i = _prjID pj oldPos = _prjPos pj vel = _prjVel pj newPos = oldPos +.+ vel -explodeRemoteRocket' :: - -- | Item id - Maybe Int -> - Proj -> - World -> - World -explodeRemoteRocket' mitid thepj w = - w - & cWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile - & usePayload (_prjPayload thepj) (_prjPos thepj) - & updateitem - where - updateitem = fromMaybe (cWorld . projectiles . at pjid .~ Nothing) $ do - itid <- mitid - itpos <- w ^? cWorld . itemLocations . ix itid - return $ - (pointerToItemLocation itpos . itUse . heldUse .~ HeldDoNothing) - . (cWorld . projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid]) - pjid = _prjID thepj - updateShell :: Proj -> World -> World updateShell pj w | time > 340 = @@ -99,6 +95,9 @@ upsProjectile pj w' = foldr (`upProjectile` pj) w' (_prjUpdates pj) upProjectile :: ProjectileUpdate -> Proj -> World -> World upProjectile pu pj = case pu of + PJRemoteShellCollisionCheck -> remoteShellCollisionCheck pj + PJShellCollisionCheck -> updateShell pj + PJDecTimMvVel -> decTimMvVel pj PJThrust st et | act st et -> doThrust' pj | otherwise -> id