From 910542a96a341c43d6c11920d5d3eccf6e1d9496 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 1 Mar 2022 18:22:47 +0000 Subject: [PATCH] Implement tracking rockets --- src/Dodge/Combine/Combinations.hs | 10 ++-- src/Dodge/Combine/Data.hs | 7 ++- src/Dodge/Creature.hs | 1 + src/Dodge/Data.hs | 2 +- src/Dodge/Item/Weapon/AmmoParams.hs | 1 - src/Dodge/Item/Weapon/Grenade.hs | 13 +---- src/Dodge/Item/Weapon/Launcher.hs | 82 ++++++++++++++++++++++++----- src/Dodge/Item/Weapon/Remote.hs | 19 +++++++ src/Dodge/Item/Weapon/SprayGuns.hs | 2 +- src/Dodge/Movement/Turn.hs | 11 ++++ src/Geometry.hs | 1 + 11 files changed, 118 insertions(+), 31 deletions(-) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index ef3cebe44..f2d56c799 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -54,7 +54,9 @@ itemCombinations = , po [ELEPHANTGUN,HARDWARE,CAN] sniperRifle , po [BANGROD,PLATE,DRUM,MOTOR] machineGun - , p [p 3 TUBE,o HARDWARE] launcher + , p [p 2 TUBE,o HARDWARE] launcher + , po [MICROCHIP,TRANSMITTER,LAUNCHER] trackingLauncher + , po [MICROCHIP,TRANSMITTER,MINIDISPLAY,LAUNCHER] remoteLauncher , po [LIGHTER,PIPE,CAN] flameStick , po [FLAMESTICK,CAN,PUMP] blowTorch @@ -110,7 +112,7 @@ moduleCombinations = ] ) , ( ModTarget - , launcher : bulletWeapons + , trackingLauncher : launcher : bulletWeapons , [amod [MICROCHIP,CREATURESENSOR] "+CREATURETARGETING" (itTargeting .~ targetRBCreature) ,amod [MICROCHIP,PRISM] "+LASERTARGETING" (itTargeting .~ targetLaser) ,amod [MICROCHIP,TIN] "+POSTIONALTARGETING" (itTargeting .~ targetRBPress) @@ -120,7 +122,9 @@ moduleCombinations = , bulletWeapons , [amod [TELEPORTMODULE,MICROCHIP] "+DIRECTEDTELE" makeDirectedTele ,amod [MAGNET,MICROCHIP,HARDWARE] "+MAGNETTRAJECTORY" - ( (itConsumption . aoType . amBulTraj .~ MagnetTrajectory) ) + ( (itConsumption . aoType . amBulTraj .~ MagnetTrajectory) + . (itConsumption . aoType . amBulVel .~ V2 10 0) + ) ,amod [MICROCHIP,HARDWARE] "+FLECHETTETRAJECTORY" (itConsumption . aoType . amBulTraj .~ FlechetteTrajectory) ,amod [ANTIMATTER,HARDWARE] "+BEZIERTRAJECTORY" diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index 421ab1138..53a00efce 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -38,6 +38,7 @@ data CombineType | SNIPERRIFLE | MACHINEGUN | FLAMESTICK + | FLAMER | BLOWTORCH | FLAMETHROWER | AUTOGUN @@ -49,8 +50,9 @@ data CombineType | SONICGUN | TRACTORGUN | LAUNCHER + | TRACKINGLAUNCHER + | REMOTELAUNCHER | SPRAYER - | SQUIRTER | DRONELAUNCHER | GRENADE | REMOTEBOMB @@ -84,8 +86,11 @@ data CombineType | MAGNET | ANTIMATTER | PLATE + | TRANSMITTER | MICROCHIP | AIUNIT + | CAMERA + | MINIDISPLAY -- visual display unit | LED | NAILBOX | IRONBAR diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index 43ac73e46..b52ac8486 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -180,6 +180,7 @@ testInventory = IM.fromList $ zip [0..] , makeTypeCraftNum 3 PLANK , makeTypeCraftNum 1 MOTOR , makeTypeCraftNum 5 MICROCHIP + , makeTypeCraftNum 1 TRANSMITTER , makeTypeCraftNum 5 AIUNIT ] stackedInventory :: IM.IntMap Item diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 79b97cf40..98326964a 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -567,7 +567,7 @@ data ItemParams , _shellThrustDelay :: Int } | Refracting {_phaseV :: Float} - | BulletShooter + | BulletShooter -- this should possibly be moved into ammo type { _muzVel :: Float , _rifling :: Float , _bore :: Float diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index ac44376c8..d758ea6c3 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -33,7 +33,6 @@ defaultAimParams = AimParams , _aimZoom = ItZoom 20 0.2 1 , _aimStance = OneHand } - useAmmoParams :: Maybe Float -> Item -> Creature -> World -> World useAmmoParams vfact it cr w = w & particles .:~ aBulAt vfact diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index bee8ea53c..6016295c0 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -1,12 +1,9 @@ -module Dodge.Item.Weapon.Grenade - where +module Dodge.Item.Weapon.Grenade where import Dodge.Data import Dodge.Picture.Layer import Dodge.WorldEvent.Explosion --import Dodge.Item.Weapon.TriggerType import Dodge.Item.Weapon.Remote -import Dodge.Default ---import Dodge.Default.Weapon import Dodge.Base import Dodge.Zone import Dodge.SoundLogic @@ -199,14 +196,6 @@ moveRemoteBomb itid time pID w (\_ -> (,) mempty $ onLayer PtLayer $ uncurryV translate newPos $ remoteBombPic time) -setRemoteBombScope :: Int -> Prop -> World -> World -setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of - InInv cid invid - -> w' & creatures . ix cid . crInv . ix invid . itScope - . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid)) - & creatures . ix cid . crInv . ix invid . itUse . useAim . aimZoom - .~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}) - _ -> w' --defaultThrowable :: Item --defaultThrowable = grenade diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 552f83f9c..6af77e3a0 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -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 diff --git a/src/Dodge/Item/Weapon/Remote.hs b/src/Dodge/Item/Weapon/Remote.hs index 486f9f8c6..0c3806c61 100644 --- a/src/Dodge/Item/Weapon/Remote.hs +++ b/src/Dodge/Item/Weapon/Remote.hs @@ -1,8 +1,11 @@ module Dodge.Item.Weapon.Remote ( pointToItem , retireRemoteProj + , setRemoteScope + , setRemoteBombScope ) where import Dodge.Data +import Dodge.Default import Geometry import qualified Data.IntMap.Strict as IM @@ -31,3 +34,19 @@ retireRemoteProj resetFire itid t pjid w = setScope w . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid)) _ -> w' pos = fromMaybe (V2 0 0) $ w ^? props . ix pjid . pjPos + +setRemoteBombScope :: Int -> Prop -> World -> World +setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of + InInv cid invid + -> w' & creatures . ix cid . crInv . ix invid . itScope + . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid)) + & creatures . ix cid . crInv . ix invid . itUse . useAim . aimZoom + .~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}) + _ -> w' + +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' diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 1024730eb..ed5e710fc 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -90,7 +90,7 @@ flameWall = undefined flamer :: Item flamer = defaultAutoGun { _itName = "FLAMER" - , _itType = SQUIRTER + , _itType = FLAMER , _itConsumption = defaultAmmo { _ammoBaseMax = 250 , _ammoLoaded = 250 diff --git a/src/Dodge/Movement/Turn.hs b/src/Dodge/Movement/Turn.hs index 11b294b60..4e776babf 100644 --- a/src/Dodge/Movement/Turn.hs +++ b/src/Dodge/Movement/Turn.hs @@ -12,6 +12,17 @@ turnTo turnSpeed sp tp a vdir = unitVectorAtAngle a vToTarg = tp -.- sp +turnToAmount :: Float -> Point2 -> Point2 -> Float -> Float +turnToAmount turnSpeed sp tp a + | vToTarg == V2 0 0 = 0 + | angleVV vToTarg vdir <= turnSpeed + = diffAngles a (argV vToTarg) -- TODO check correctness + | isLHS (sp +.+ vdir) sp tp = negate turnSpeed + | otherwise = turnSpeed + where + vdir = unitVectorAtAngle a + vToTarg = tp -.- sp + vecTurnTo :: Float -> Point2 -> Point2 -> Point2 -> Point2 vecTurnTo turnSpeed sp tp vdir | angleVV vToTarg vdir <= turnSpeed diff --git a/src/Geometry.hs b/src/Geometry.hs index d4f919d25..639b1c6cb 100644 --- a/src/Geometry.hs +++ b/src/Geometry.hs @@ -156,6 +156,7 @@ isLeftOf :: Point2 -> Point2 -> Bool isLeftOf x y = isLeftOfA (argV x) (argV y) -- | Find the difference between two angles. -- Possibly not correct... +-- TODO write tests diffAngles :: Float -> Float -> Float diffAngles x y | diff > pi = diffAngles (x - 2*pi) y