Cleanup launchers

This commit is contained in:
2022-03-02 08:36:16 +00:00
parent b3ba0697b4
commit be1fda266a
7 changed files with 44 additions and 60 deletions
+3
View File
@@ -100,6 +100,9 @@ allWalls = IM.unions . concatMap IM.elems . IM.elems . _znObjects . _wallsZone
creatureNearPoint :: Point2 -> World -> Maybe Creature creatureNearPoint :: Point2 -> World -> Maybe Creature
creatureNearPoint p = L.fold (L.minimumOn (dist p . _crPos)) . creaturesNearPoint p creatureNearPoint p = L.fold (L.minimumOn (dist p . _crPos)) . creaturesNearPoint p
creatureNearPointI :: Int -> Point2 -> World -> Maybe Creature
creatureNearPointI n p = L.fold (L.minimumOn (dist p . _crPos)) . creaturesNearPointI n p
creaturesNearPoint :: Point2 -> World -> IM.IntMap Creature creaturesNearPoint :: Point2 -> World -> IM.IntMap Creature
creaturesNearPoint p w = IM.unions creaturesNearPoint p w = IM.unions
[f b $ f a $ _znObjects $ _creaturesZone w | a<-[x-1,x,x+1] , b<-[y-1,y,y+1]] [f b $ f a $ _znObjects $ _creaturesZone w | a<-[x-1,x,x+1] , b<-[y-1,y,y+1]]
+1 -1
View File
@@ -42,7 +42,7 @@ followImpulse cr w imp = case imp of
TurnToward p a -> crup $ creatureTurnToward p a cr TurnToward p a -> crup $ creatureTurnToward p a cr
TurnTo p -> crup $ creatureTurnTo p cr TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (tryUseItem cr, cr) UseItem -> (useItem cr, cr)
SwitchToItem i -> crup $ cr & crInvSel .~ i SwitchToItem i -> crup $ cr & crInvSel .~ i
Melee cid' -> (hitCr cid' Melee cid' -> (hitCr cid'
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20) , crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
+3 -3
View File
@@ -1,5 +1,5 @@
module Dodge.Creature.Impulse.UseItem module Dodge.Creature.Impulse.UseItem
( tryUseItem ( useItem
, useLeftItem , useLeftItem
) where ) where
import Dodge.Data import Dodge.Data
@@ -9,8 +9,8 @@ import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
tryUseItem :: Creature -> World -> World useItem :: Creature -> World -> World
tryUseItem cr' w = fromMaybe w $ do useItem cr' w = fromMaybe w $ do
cr <- w ^? creatures . ix (_crID cr') cr <- w ^? creatures . ix (_crID cr')
it <- cr ^? crInv . ix (_crInvSel cr) it <- cr ^? crInv . ix (_crInvSel cr)
return $ itemEffect cr it w return $ itemEffect cr it w
+3 -2
View File
@@ -154,9 +154,10 @@ targetRBPressUpdate _ _ w t
targetRBCreatureUpdate :: Item -> Creature -> World -> Targeting -> Targeting targetRBCreatureUpdate :: Item -> Creature -> World -> Targeting -> Targeting
targetRBCreatureUpdate _ _ w t targetRBCreatureUpdate _ _ w t
| SDL.ButtonRight `S.member` _mouseButtons w = t & updatePos | SDL.ButtonRight `S.member` _mouseButtons w && isJust (t ^? tgID . _Just)
= t & updatePos
& tgActive .~ True & tgActive .~ True
| otherwise = t & tgID .~ fmap _crID (creatureNearPoint mwp w) | otherwise = t & tgID .~ fmap _crID (creatureNearPointI 3 mwp w)
& updatePos & updatePos
& tgActive .~ False & tgActive .~ False
where where
+28 -48
View File
@@ -44,12 +44,13 @@ launcher = defaultGun
, _amString = "EXPLOSIVE SHELL" , _amString = "EXPLOSIVE SHELL"
, _amPjDraw = drawShell , _amPjDraw = drawShell
} }
, _ammoBaseMax = 30 , _ammoBaseMax = 1
, _ammoLoaded = 30 , _ammoLoaded = 1
, _reloadTime = 80 , _reloadTime = 80
} }
, _itUse = ruseRate 20 aRocketWithItemParams upHammer , _itUse = ruseRate 20 fireLauncher upHammer
[ ammoCheckI [ hammerCheckI
, ammoCheckI
, useTimeCheck , useTimeCheck
, withSoundStart tap4S , withSoundStart tap4S
, useAmmoAmount 1 , useAmmoAmount 1
@@ -154,19 +155,18 @@ doThrust pj w = w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w (sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _randGen w r1 = randInCirc 10 & evalState $ _randGen w
aRocketWithItemParams :: Item -> Creature -> World -> World fireLauncher :: Item -> Creature -> World -> World
aRocketWithItemParams it cr w = over props addShell w fireLauncher it cr w = addShell w
where where
i = IM.newKey $ _props w
params = _itParams it params = _itParams it
spindrag = _shellSpinDrag params spindrag = _shellSpinDrag params
spinamount = _shellSpinAmount params spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params thrustdelay = _shellThrustDelay params
addShell = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj addShell = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj . pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj . reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj . decTimMvVel pj
. moveShell pj . moveShell pj
moveShell :: Prop -- ^ Projectile id moveShell :: Prop -- ^ Projectile id
-> World -> World
@@ -181,13 +181,12 @@ moveShell pj w
where where
time = _pjTimer pj time = _pjTimer pj
doExplode = w doExplode = w
& projectileExplosion oldPos & _pjPayload pj oldPos
& stopSoundFrom (ShellSound i) & stopSoundFrom (ShellSound i)
& props %~ IM.delete i & props %~ IM.delete i
i = _pjID pj i = _pjID pj
oldPos = _pjPos pj oldPos = _pjPos pj
vel = _pjVel pj vel = _pjVel pj
projectileExplosion = _pjPayload pj
newPos = oldPos +.+ vel newPos = oldPos +.+ vel
reduceSpinBy :: Float -> Prop -> World -> World reduceSpinBy :: Float -> Prop -> World -> World
@@ -257,35 +256,16 @@ trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin
trackingLauncher :: Item trackingLauncher :: Item
trackingLauncher = launcher trackingLauncher = launcher
{ _itName = "ROCKO-TRACK" & itName .~ "ROCKO-TRACK"
, _itType = TRACKINGLAUNCHER & itType .~ TRACKINGLAUNCHER
, _itUse = ruseRate 10 fireTrackingLauncher upHammer & itUse . rUse .~ fireTrackingLauncher
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
}
remoteLauncher :: Item remoteLauncher :: Item
remoteLauncher = launcher remoteLauncher = launcher
{ _itName = "ROCKO-REMOTE" & itName .~ "ROCKO-REMOTE"
, _itType = REMOTELAUNCHER & itType .~ REMOTELAUNCHER
, _itUse = ruseRate 10 fireRemoteLauncher upHammer & itUse . rUse .~ fireRemoteLauncher
[ ammoCheckI & itScope .~ RemoteScope (V2 0 0) 1 True
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
, _itScope = RemoteScope (V2 0 0) 1 True
}
& itConsumption . aoType . amPjDraw .~ drawRemoteShell & itConsumption . aoType . amPjDraw .~ drawRemoteShell
-- TODO consider allowing tweaking rocket speed -- TODO consider allowing tweaking rocket speed
@@ -294,11 +274,11 @@ fireRemoteLauncher it cr w = setLocation
$ set (creatures . ix cid . crInv . ix j . itUse . rUse) $ set (creatures . ix cid . crInv . ix j . itUse . rUse)
(\_ _ -> explodeRemoteRocket itid i) (\_ _ -> explodeRemoteRocket itid i)
$ set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET" $ set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET"
$ over props addRemRocket w $ addRemRocket w
where where
i = IM.newKey $ _props w i = IM.newKey $ _props w
cid = _crID cr cid = _crID cr
addRemRocket = makeShell i it cr $ \pj -> addRemRocket = makeShell it cr $ \pj ->
decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
j = _crInvSel cr j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w newitid = IM.newKey $ _itemPositions w
@@ -368,11 +348,10 @@ explodeRemoteRocket itid pjid w
fireTrackingLauncher :: Item -> Creature -> World -> World fireTrackingLauncher :: Item -> Creature -> World -> World
fireTrackingLauncher it cr w = setLocation fireTrackingLauncher it cr w = setLocation
$ over props addTrackRocket w $ addTrackRocket w
where where
i = IM.newKey $ _props w
cid = _crID cr cid = _crID cr
addTrackRocket = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj addTrackRocket = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj . pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj . reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj . decTimMvVel pj
@@ -392,8 +371,8 @@ fireTrackingLauncher it cr w = setLocation
spindrag = _shellSpinDrag params spindrag = _shellSpinDrag params
params = _itParams it params = _itParams it
makeShell :: Int -> Item -> Creature -> (Prop -> World -> World) -> IM.IntMap Prop -> IM.IntMap Prop makeShell :: Item -> Creature -> (Prop -> World -> World) -> World -> World
makeShell i it cr theupdate = IM.insert i Shell makeShell it cr theupdate w = w & props %~ IM.insert i Shell
{ _pjPos = pos { _pjPos = pos
, _pjZ = 20 , _pjZ = 20
, _pjStartPos = pos , _pjStartPos = pos
@@ -408,6 +387,7 @@ makeShell i it cr theupdate = IM.insert i Shell
, _pjTimer = 50 , _pjTimer = 50
} }
where where
i = IM.newKey $ _props w
dir = _crDir cr dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0) pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
am = _itConsumption it am = _itConsumption it
+5 -5
View File
@@ -1,4 +1,8 @@
module Dodge.Reloading where module Dodge.Reloading
( stepReloading
, startReloadingWeapon
, crStopReloading
) where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
--import qualified Data.IntMap.Strict as IM --import qualified Data.IntMap.Strict as IM
@@ -6,7 +10,6 @@ import Dodge.Base
--import Data.Maybe --import Data.Maybe
import Control.Lens import Control.Lens
startReloadingWeapon :: Creature -> World -> Maybe World startReloadingWeapon :: Creature -> World -> Maybe World
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr)) startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr))
icTryStartReloading icTryStartReloading
@@ -23,9 +26,6 @@ icTryStartReloading it
crStopReloading :: Creature -> Creature crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing' crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
crUpCrUp :: (Creature -> Creature) -> Creature -> World -> World
crUpCrUp f cr = creatures . ix (_crID cr) %~ f
stepReloading :: Creature -> Creature stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
Just 0 -> cr & crInv . ix isel %~ doload Just 0 -> cr & crInv . ix isel %~ doload
+1 -1
View File
@@ -18,7 +18,7 @@ updateUsingInput w = if _carteDisplay w
updatePressedButtons :: S.Set MouseButton -> World -> World updatePressedButtons :: S.Set MouseButton -> World -> World
updatePressedButtons pkeys w updatePressedButtons pkeys w
| lbPressed && rbPressed && inTopInv = tryUseItem (you w) w | lbPressed && rbPressed && inTopInv = useItem (you w) w
| lbPressed && | lbPressed &&
(inTopInv || _timeFlow w == RewindingLastFrame) (inTopInv || _timeFlow w == RewindingLastFrame)
= useLeftItem (_yourID w) w = useLeftItem (_yourID w) w