From 7ca9afeb5ff0d4d02b560e5ebe262701a6c623bb Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 7 Apr 2022 10:06:39 +0100 Subject: [PATCH] Implement dual laser tesla --- src/Dodge/Combine/Combinations.hs | 5 +++- src/Dodge/Data.hs | 6 ++-- src/Dodge/Item/Location.hs | 21 +++++++++++--- src/Dodge/Item/Weapon/BatteryGuns.hs | 43 +++++++++++++++++----------- src/Dodge/Item/Weapon/Launcher.hs | 39 +++++++------------------ src/Dodge/Item/Weapon/Remote.hs | 6 +--- 6 files changed, 62 insertions(+), 58 deletions(-) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 7890b8a37..72f242984 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -148,7 +148,10 @@ moduleCombinations = , ( ModDualBeam , [lasGunDual] , [amod [INCENDIARYMODULE] "+INCENDIARY" (itParams . lasBeam .~ BeamCombine flameBeamCombine) - ,amod [STATICMODULE] "+STATIC" (itParams . lasBeam .~ BeamCombine teslaBeamCombine) + ,amod [STATICMODULE] "+STATIC" + ( (itParams . lasBeam .~ BeamCombine teslaBeamCombine) + . (itParams . subParams .~ Just teslaParams) + ) ,amod [TRANSFORMER] "+SPLIT" (itParams . lasBeam .~ BeamCombine splitBeamCombine) ] ) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 594234e5d..6867ca865 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -520,15 +520,12 @@ data Beam = Beam , _bmFirstPoints :: [Point2] , _bmRange :: Float , _bmPhaseV :: Float + , _bmOrigin :: Maybe Int , _bmType :: BeamType } data BeamType = BeamCombine {_beamCombine :: (Point2 , (Point2,Point2,Beam) , (Point2,Point2,Beam)) -> World -> World} - | BeamItemParamsCombine - {_beamCombine :: (Point2 , (Point2,Point2,Beam) , (Point2,Point2,Beam)) -> World -> World - ,_beamItemParams :: ItemParams - } | BeamSimple {- Objects without ids. @@ -682,6 +679,7 @@ data ItemParams , _lasCycle :: Int , _lasDamage :: Int , _lasBeam :: BeamType + , _subParams :: Maybe ItemParams } | Attracting {_attractionPower :: Point2} | BulletShooter diff --git a/src/Dodge/Item/Location.hs b/src/Dodge/Item/Location.hs index 3b0b92982..3fdda6f45 100644 --- a/src/Dodge/Item/Location.hs +++ b/src/Dodge/Item/Location.hs @@ -5,11 +5,11 @@ import qualified IntMapHelp as IM import Control.Lens import Data.Maybe -setHeldItemPos :: Creature -> World -> World -setHeldItemPos cr = fst . getHeldItemPos cr +setHeldItemLoc :: Creature -> World -> World +setHeldItemLoc cr = fst . getHeldItemLoc cr -getHeldItemPos :: Creature -> World -> (World,Int) -getHeldItemPos cr w = case maybeitid of +getHeldItemLoc :: Creature -> World -> (World,Int) +getHeldItemLoc cr w = case maybeitid of Nothing -> ( w & creatures . ix cid . crInv . ix j . itID ?~ newitid & itemPositions %~ IM.insert newitid (InInv cid j) @@ -21,3 +21,16 @@ getHeldItemPos cr w = case maybeitid of newitid = IM.newKey $ _itemPositions w maybeitid = cr ^? crInv . ix j . itID . _Just itid = fromMaybe newitid maybeitid + +getItem :: Int -> World -> Maybe Item +getItem itid w = do + itpos <- w ^? itemPositions . ix itid + case itpos of + OnFloor flitid -> w ^? floorItems . ix flitid . flIt + InInv cid invid -> w ^? creatures . ix cid . crInv . ix invid + +pointToItem :: Applicative f => + ItemPos -> (Item -> f Item) -> World -> f World +pointToItem (InInv cid invid) = creatures . ix cid . crInv . ix invid +pointToItem (OnFloor flid) = floorItems . ix flid . flIt + diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index bdbafb155..2d2b31253 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -9,6 +9,7 @@ module Dodge.Item.Weapon.BatteryGuns , lasGunPulse , sparkGun , teslaGun + , teslaParams , tractorGun , lasRayAt , flameBeamCombine @@ -17,6 +18,7 @@ module Dodge.Item.Weapon.BatteryGuns ) where import Dodge.Data import Dodge.Item.Weapon.LaserPath +import Dodge.Item.Location import Dodge.Creature.HandPos import Dodge.Particle.TeslaArc import Dodge.Particle.Flame @@ -93,13 +95,15 @@ teslaGun = defaultBatteryGun } , _dimSPic = teslaGunPic } - , _itParams = Arcing - { _currentArc = Nothing - , _arcSize = 20 - , _arcNumber = 10 - , _newArcStep = defaultArcStep - , _previousArcEffect = NoPreviousArcEffect - } + , _itParams = teslaParams + } +teslaParams :: ItemParams +teslaParams = Arcing + { _currentArc = Nothing + , _arcSize = 20 + , _arcNumber = 10 + , _newArcStep = defaultArcStep + , _previousArcEffect = NoPreviousArcEffect } teslaGunPic :: Item -> SPic teslaGunPic _ = noPic $ colorSH blue $ @@ -228,6 +232,7 @@ lasGunDual = lasGun , _lasCycle = 0 , _lasDamage = 11 , _lasBeam = BeamCombine lasBeamCombine + , _subParams = Nothing } & itUse .~ (ruseInstant shootDualLaser NoHammer [ ammoCheckI @@ -483,10 +488,11 @@ shootLaser it cr = instantParticles .:~ lasRayAt (_lasColor $ _itParams it) dam dam = _lasDamage $ _itParams it shootDualLaser :: Item -> Creature -> World -> World -shootDualLaser it cr w = w - & newBeams . positronBeams .:~ dualRayAt (_lasBeam $ _itParams it) w (_lasColor $ _itParams it) dam phasev posl dirl - & newBeams . electronBeams .:~ basicBeamAt w (_lasColor2 $ _itParams it) dam phasev posr dirr +shootDualLaser it cr w = w' + & newBeams . positronBeams .:~ dualRayAt (_lasBeam $ _itParams it) itid w (_lasColor $ _itParams it) dam phasev posl dirl + & newBeams . electronBeams .:~ basicBeamAt itid w (_lasColor2 $ _itParams it) dam phasev posr dirr where + (w',itid) = getHeldItemLoc cr w dir = _crDir cr pos = _crPos cr +.+ aimlength *.* unitVectorAtAngle dir aimlength = aimingMuzzlePos cr it @@ -509,8 +515,8 @@ drawBeam bm = setLayer 1 $ pictures col = _bmColor bm ps = _bmFirstPoints bm -basicBeamAt :: World -> Color -> Int -> Float -> Point2 -> Float -> Beam -basicBeamAt w col dam phasev pos dir = Beam +basicBeamAt :: Int -> World -> Color -> Int -> Float -> Point2 -> Float -> Beam +basicBeamAt itid w col dam phasev pos dir = Beam { _bmDraw = drawBeam , _bmPos = pos , _bmDir = dir @@ -520,13 +526,14 @@ basicBeamAt w col dam phasev pos dir = Beam , _bmColor = col , _bmPoints = pos:ps , _bmFirstPoints = [] + , _bmOrigin = Just itid , _bmType = BeamCombine $ const id } where (_,ps) = reflectLaserAlong phasev [] pos (pos +.+ 800 *.* unitVectorAtAngle dir) w -dualRayAt :: BeamType -> World -> Color -> Int -> Float -> Point2 -> Float -> Beam -dualRayAt bt w col dam phasev pos dir = basicBeamAt w col dam phasev pos dir +dualRayAt :: BeamType -> Int -> World -> Color -> Int -> Float -> Point2 -> Float -> Beam +dualRayAt bt itid w col dam phasev pos dir = basicBeamAt itid w col dam phasev pos dir & bmType .~ bt flameBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam)) @@ -550,10 +557,14 @@ splitBeamCombine (p,(a,b,_),(x,y,_)) teslaBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam)) -> World -> World teslaBeamCombine (p,(a,b,bm),(x,y,_)) w - = w' + = w' & pointToItem (_itemPositions w IM.! itid) . itParams . subParams ?~ ip where + itid = fromJust $ _bmOrigin bm dir = argV (normalizeV (b-.-a)+.+normalizeV (y-.-x)) - (w',ip) = shootTeslaArc' (_beamItemParams $ _bmType bm) p dir w + (w',ip) = shootTeslaArc' (fromJust . _subParams $ _itParams it) p dir w + it = case getItem itid w of + Nothing -> error "tried to get item use teslaBeamCombine that doesn't exist" + Just itm -> itm lasRayAt :: Color -> Int -> Float -> Point2 -> Float -> Particle lasRayAt col dam phasev pos dir = LaserParticle diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 783d3acb7..cd763786b 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -8,6 +8,7 @@ import Dodge.Data import Dodge.Default import Dodge.Default.Weapon import Dodge.Item.Weapon.InventoryDisplay +import Dodge.Item.Location import Dodge.SoundLogic.LoadSound import Dodge.WorldEvent.Explosion import Dodge.Item.Weapon.Shell @@ -294,25 +295,17 @@ remoteLauncher = launcher -- TODO consider allowing tweaking rocket speed fireRemoteShell :: Item -> Creature -> World -> World -fireRemoteShell it cr w = setLocation - $ set (creatures . ix cid . crInv . ix j . itUse . rUse) +fireRemoteShell it cr w = set (creatures . ix cid . crInv . ix j . itUse . rUse) (\_ _ -> explodeRemoteRocket itid i) $ set (creatures . ix cid . crInv . ix j . itName) remoteLauncherName - $ addRemRocket w + $ addRemRocket w' where + (w',itid) = getHeldItemLoc cr w i = IM.newKey $ _props w cid = _crID cr addRemRocket = makeShell it cr $ \pj -> decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj 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 moveRemoteShell :: Int -> Int -> Prop -> World -> World moveRemoteShell cid itid pj w @@ -372,25 +365,15 @@ explodeRemoteRocket itid pjid w = w thepj = _props w IM.! pjid fireTrackingShell :: Item -> Creature -> World -> World -fireTrackingShell it cr w = setLocation - $ addTrackRocket w +fireTrackingShell it cr w = addTrackRocket w' where - cid = _crID cr + (w',itid) = getHeldItemLoc cr w addTrackRocket = makeShell it cr $ \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 - 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 + . pjThrust thrustdelay pj + . reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj + . decTimMvVel pj + . pjTrack itid thrustdelay pj + . moveShell pj spinamount = _shellSpinAmount params thrustdelay = _shellThrustDelay params spindrag = _shellSpinDrag params diff --git a/src/Dodge/Item/Weapon/Remote.hs b/src/Dodge/Item/Weapon/Remote.hs index 0c3806c61..db8f0e387 100644 --- a/src/Dodge/Item/Weapon/Remote.hs +++ b/src/Dodge/Item/Weapon/Remote.hs @@ -7,16 +7,12 @@ module Dodge.Item.Weapon.Remote import Dodge.Data import Dodge.Default import Geometry +import Dodge.Item.Location import qualified Data.IntMap.Strict as IM import Control.Lens import Data.Maybe -pointToItem :: Applicative f => - ItemPos -> (Item -> f Item) -> World -> f World -pointToItem (InInv cid invid) = creatures . ix cid . crInv . ix invid -pointToItem (OnFloor flid) = floorItems . ix flid . flIt - retireRemoteProj :: (Item -> Creature -> World -> World) -> Int -> Int -> Int -> World -> World retireRemoteProj resetFire itid 0 pjid w = w