Implement remote screen for launcher projectiles

This commit is contained in:
2024-09-27 10:39:21 +01:00
parent fb6fcff61c
commit 5f9fb183a9
35 changed files with 238 additions and 170 deletions
+14 -11
View File
@@ -16,9 +16,9 @@ import LensHelp
fireShell :: Item -> Muzzle -> Item -> Creature -> World -> World
fireShell ammoitem muz it cr =
makeShell
Nothing
ammoitem
muz
it
cr
[ PJShellCollisionCheck
, PJDecTimMvVel
@@ -32,8 +32,8 @@ fireShell ammoitem muz it cr =
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
makeShell :: Item -> Muzzle -> Item -> Creature -> [ProjectileUpdate] -> World -> World
makeShell ammoitem muz it cr theupdate w = fromMaybe w $ do
makeShell :: Maybe Int -> Item -> Muzzle -> Creature -> [ProjectileUpdate] -> World -> World
makeShell mscreeninvid ammoitem muz cr theupdate w = fromMaybe w $ do
aparams <- ammoitem ^? itUse . amagParams
return $
w & cWorld . lWorld . projectiles . at i
@@ -50,27 +50,30 @@ makeShell ammoitem muz it cr theupdate w = fromMaybe w $ do
, _prjPayload = _ampPayload aparams
, _prjTimer = 350
, _prjUpdates = theupdate
, _prjMITID = Just $ _itID it
-- , _prjMITID = Just $ _itID it
}
& updatescreen
where
updatescreen = fromMaybe id $ do
screeninvid <- mscreeninvid
return $ cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix screeninvid
. itUse . atLinkedProjectile ?~ i
i = IM.newKey $ w ^. cWorld . lWorld . projectiles -- _props (_cWorld w)
dir = _crDir cr + _mzRot muz
pos = _crPos cr +.+ rotateV dir (_mzPos muz)
--am = _heldConsumption $ _itUse it
fireTrackingShell :: Item -> Muzzle -> Item -> Creature -> World -> World
fireTrackingShell ammoitem muz it cr = fromMaybe id $ do
return $
makeShell
fireTrackingShell :: Int -> Int -> Item -> Muzzle -> Item -> Creature -> World -> World
fireTrackingShell screenid screeninvid ammoitem muz it cr = makeShell
(Just screeninvid)
ammoitem
muz
it
cr
[ PJRemoteShellCollisionCheck
[ PJRemoteShellCollisionCheck screenid
, PJDecTimMvVel
, PJSpin 335 (_crID cr) spinamount
, PJTrack (350 - thrustdelay) 0 (_itID it)
, PJRemoteSetDirection (350 - thrustdelay) 0 screenid
, PJThrust (350 - thrustdelay) 0
, PJReduceSpin (1 - fromIntegral spindrag * 2 / 200)
]
+81 -40
View File
@@ -39,8 +39,8 @@ shellCollisionCheck doExplode pj w
vel = _prjVel pj
newPos = oldPos +.+ vel
remoteShellCollisionCheck :: Proj -> World -> World
remoteShellCollisionCheck = shellCollisionCheck $ \pj -> explodeRemoteRocket (fromJust (_prjMITID pj)) (_prjID pj)
remoteShellCollisionCheck :: Int -> Proj -> World -> World
remoteShellCollisionCheck screenid = shellCollisionCheck $ \pj -> explodeRemoteRocket screenid (_prjID pj)
plainShellCollisionCheck :: Proj -> World -> World
plainShellCollisionCheck = shellCollisionCheck $ \pj ->
@@ -53,7 +53,7 @@ upsProjectile pj w' = foldr (`upProjectile` pj) w' (_prjUpdates pj)
upProjectile :: ProjectileUpdate -> Proj -> World -> World
upProjectile pu pj = case pu of
PJRemoteShellCollisionCheck -> remoteShellCollisionCheck pj
PJRemoteShellCollisionCheck screenid -> remoteShellCollisionCheck screenid pj
PJShellCollisionCheck -> plainShellCollisionCheck pj
PJDecTimMvVel -> decTimMvVel pj
PJThrust st et
@@ -62,15 +62,17 @@ upProjectile pu pj = case pu of
PJSpin t cid spinamount
| ain t -> trySpinByCID cid spinamount pj
| otherwise -> id
PJTrack st et crid
| act st et -> pjTrack crid pj
PJRemoteSetDirection st et screenid
| act st et -> pjRemoteSetDirection screenid pj
| otherwise -> id
PJReduceSpin x -> reduceSpinBy x pj
PJRemoteDirection st et cid itid
| act st et -> setRemoteDir cid itid pj
| otherwise -> id
PJSetScope itid -> setRemoteScope itid (_prjPos pj)
-- PJRemoteDirection st et cid itid
-- | act st et -> setRemoteDir cid itid pj
-- | otherwise -> id
-- PJSetScope itid -> setRemoteScope itid (_prjPos pj)
PJRetireRemote itid 0 pjid -> retireRemoteProj itid pjid
-- the following requires that this is at the top of the update list, which is
-- not ideal
PJRetireRemote _ _ pjid -> cWorld . lWorld . projectiles . ix pjid . prjUpdates . ix 0 . pjuTimer -~ 1
where
time = _prjTimer pj
@@ -78,26 +80,38 @@ upProjectile pu pj = case pu of
ain t = time == t
retireRemoteProj :: Int -> Int -> World -> World
retireRemoteProj itid pjid w =
w
& pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid)
%~ ( (itScope . remotePos .~ V2 0 0)
-- . (itUse . heldUse .~ HeldFireRemoteShell)
. (itUse . heldMods .~ FireRemoteShellMod)
)
& cWorld . lWorld . props %~ IM.delete pjid
setRemoteDir :: Int -> Int -> Proj -> World -> World
setRemoteDir cid itid pj w = w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc .~ turntonewdir
retireRemoteProj itid pjid w = w & cWorld . lWorld . projectiles %~ IM.delete pjid
& removelink
where
turntonewdir = magV (_prjAcc pj) *.* unitVectorAtAngle newdir
--i = _prjID pj
newdir
| SDL.ButtonRight `M.member` _mouseButtons (_input w)
&& w ^? cWorld . lWorld . creatures . ix cid . crManipulation . manObject . imSelectedItem
== w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID
= (w ^. wCam . camRot) + argV (_mousePos (_input w))
| otherwise = _prjDir pj
removelink = fromMaybe id $ do
loc <- w ^? cWorld . lWorld . itemLocations . ix itid
itm <- w ^? pointerToItemLocation loc . itUse . atLinkedProjectile . _Just
guard $ itm == pjid
--return $ pointerToItemLocation . itUse . atLinkedProjectile .~ Nothing
return $ pointerToItemLocation loc . itUse . atLinkedProjectile .~ Nothing
--retireRemoteProj :: Int -> Int -> World -> World
--retireRemoteProj itid pjid w =
-- w
-- & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid)
-- %~ ( (itScope . remotePos .~ V2 0 0)
-- . (itUse . heldUse .~ HeldFireRemoteShell)
-- . (itUse . heldMods .~ FireRemoteShellMod)
-- )
-- & cWorld . lWorld . props %~ IM.delete pjid
--setRemoteDir :: Int -> Int -> Proj -> World -> World
--setRemoteDir cid itid pj w = w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc .~ turntonewdir
-- where
-- turntonewdir = magV (_prjAcc pj) *.* unitVectorAtAngle newdir
-- --i = _prjID pj
-- newdir
-- | SDL.ButtonRight `M.member` _mouseButtons (_input w)
-- && w ^? cWorld . lWorld . creatures . ix cid . crManipulation . manObject . imSelectedItem
-- == w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID
-- = (w ^. wCam . camRot) + argV (_mousePos (_input w))
-- | otherwise = _prjDir pj
doThrust :: Proj -> World -> World
doThrust pj w =
@@ -137,19 +151,46 @@ trySpinByCID cid i pj w = w & cWorld . lWorld . projectiles . ix pjid . prjSpin
_ -> 0
spinFactor = 5 * (6 - fromIntegral i)
pjTrack :: Int -> Proj -> World -> World
pjTrack crid pj w = rotateToTarget pj w
--pjTrack :: Int -> Proj -> World -> World
--pjTrack crid pj w = rotateToTarget pj w
-- where
-- rotateToTarget _ = fromMaybe id $ do
-- tpos <- w ^? cWorld . lWorld . creatures . ix crid . crTargeting . ctPos . _Just
-- return $
-- cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin
-- .~ turnToAmount
-- 0.15
-- (_prjPos pj)
-- tpos
-- (argV $ _prjAcc pj)
-- --itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid
-- note this only allows YOU to remotely track projectiles
pjRemoteSetDirection :: Int -> Proj -> World -> World
pjRemoteSetDirection screenid pj w = w
& cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc .~ turntonewdir
where
rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? cWorld . lWorld . creatures . ix crid . crTargeting . ctPos . _Just
return $
cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin
.~ turnToAmount
0.15
(_prjPos pj)
tpos
(argV $ _prjAcc pj)
--itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid
turntonewdir = magV (_prjAcc pj) *.* unitVectorAtAngle newdir
--i = _prjID pj
newdir
| w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
== w ^? cWorld . lWorld . itemLocations . ix screenid . ilInvID
= (w ^. wCam . camRot) + argV (_mousePos (_input w))
| otherwise = _prjDir pj
--pjTrack :: Int -> Proj -> World -> World
--pjTrack screenid pj w = w-- rotateToTarget pj w
-- where
-- rotateToTarget _ = fromMaybe id $ do
-- tpos <- w ^? cWorld . lWorld . creatures . ix crid . crTargeting . ctPos . _Just
-- return $
-- cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin
-- .~ turnToAmount
-- 0.15
-- (_prjPos pj)
-- tpos
-- (argV $ _prjAcc pj)
-- --itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid
reduceSpinBy :: Float -> Proj -> World -> World
reduceSpinBy x pj = cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin *~ x