Implement tracking rockets

This commit is contained in:
2022-03-01 18:22:47 +00:00
parent fd62b5a3b7
commit 910542a96a
11 changed files with 118 additions and 31 deletions
+70 -12
View File
@@ -1,5 +1,6 @@
module Dodge.Item.Weapon.Launcher
( launcher
, trackingLauncher
, remoteLauncher
) where
import Dodge.Data
@@ -12,6 +13,7 @@ import Dodge.WorldEvent.Explosion
import Dodge.Item.Weapon.Shell
import Dodge.Item.Weapon.Remote
import Dodge.Item.Weapon.TriggerType
import Dodge.Movement.Turn
import Dodge.Base
import Dodge.Zone
import Dodge.SoundLogic
@@ -133,6 +135,20 @@ pjThrust i = pjEffTimeRange (st,et) doThrust
| otherwise = 40 - (i * 20)
st = et - 100
pjTrack :: Int -> Int -> Prop -> World -> World
pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
where
et | i == 0 = 36
| otherwise = 40 - (i * 20)
st = et - 100
pjpos = _pjPos pj
rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
--let tdir = argV $ tpos -.- pjpos
--return $ props . ix (_pjID pj) . pjSpin .~ tdir - turnTo 0.1 pjpos tpos tdir
return $ (props . ix (_pjID pj) . pjSpin .~ turnToAmount 0.15 pjpos tpos (argV $ _pjAcc pj))
itPoint = pointToItem $ _itemPositions w IM.! itid
doThrust :: Prop -> World -> World
doThrust pj w = w
& randGen .~ g
@@ -260,11 +276,19 @@ trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin
_ -> 0
spinFactor = 5 * (6 - fromIntegral i)
trackingLauncher :: Item
trackingLauncher = launcher
{ _itName = "ROCKO-TRACK"
, _itType = TRACKINGLAUNCHER
, _itUse = ruseRate 10 fireTrackingLauncher upHammer
[ ammoCheckI
, hammerCheckI
]
}
remoteLauncher :: Item
remoteLauncher = launcher
{ _itName = "ROCKO-REM"
, _itType = LAUNCHER
{ _itName = "ROCKO-REMOTE"
, _itType = REMOTELAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
@@ -279,9 +303,6 @@ remoteLauncher = launcher
[ ammoCheckI
, hammerCheckI
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
, _itScope = RemoteScope (V2 0 0) 1 True
-- , _itParams = ShellLauncher
-- { _tweakSel = 0
@@ -410,9 +431,46 @@ remoteShellPic t
retireRemoteRocket :: Int -> Int -> Int -> World -> World
retireRemoteRocket = retireRemoteProj $ const fireRemoteLauncher
setRemoteScope :: Int -> Prop -> World -> World
setRemoteScope itid pj w' = case w' ^? itemPositions . ix itid of
Just (InInv cid' invid )
-> w' & creatures . ix cid' . crInv . ix invid . itScope
. scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid'))
_ -> w'
fireTrackingLauncher :: Item -> Creature -> World -> World
fireTrackingLauncher it cr w = setLocation
$ soundStart (CrWeaponSound cid 0) pos tap4S Nothing
$ over props addTrackRocket w
where
i = IM.newKey $ _props w
am = _itConsumption it
cid = _crID cr
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
addTrackRocket = IM.insert i $ Shell
{ _pjPos = pos
, _pjZ = 20
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = _amPjDraw $ _aoType am
, _pjID = i
, _pjUpdate = \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
. pjTrack itid thrustdelay pj
. moveShell pj
, _pjAcc = rotateV dir (V2 3 0)
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = makeExplosionAt
, _pjTimer = 50
}
j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just
setLocation :: World -> World
setLocation w' = case maybeitid of
Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid
& itemPositions %~ IM.insert newitid (InInv cid j)
_ -> w'
itid = fromMaybe newitid maybeitid
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
spindrag = _shellSpinDrag params
params = _itParams it