Fix scope rotation after torque

This commit is contained in:
2023-05-28 16:22:54 +01:00
parent 24939094c6
commit 9283ae187f
7 changed files with 39 additions and 41 deletions
+10 -16
View File
@@ -2,8 +2,6 @@ module Dodge.Creature.YourControl (
yourControl, yourControl,
) where ) where
import Dodge.Creature.Impulse.UseItem
import Dodge.Hotkey
import Control.Monad import Control.Monad
import Data.Foldable import Data.Foldable
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
@@ -11,8 +9,10 @@ import Data.Maybe
import Dodge.Base.Coordinate import Dodge.Base.Coordinate
import Dodge.Base.You import Dodge.Base.You
import Dodge.Creature.Impulse.Movement import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Impulse.UseItem
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Data.World import Dodge.Data.World
import Dodge.Hotkey
import Dodge.InputFocus import Dodge.InputFocus
import Dodge.WASD import Dodge.WASD
import Geometry import Geometry
@@ -92,8 +92,9 @@ tryAssignHotkey w sc = fromMaybe w $ do
itid <- cr ^? crManipulation . manObject . inInventory . ispItem itid <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc) return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
-- | Turn key presses into creature movement. {- | Turn key presses into creature movement.
-- | note the order of operation, setting the posture first--this prevents the twist fire bug | note the order of operation, setting the posture first--this prevents the twist fire bug
-}
wasdWithAiming :: wasdWithAiming ::
World -> World ->
-- | Base speed -- | Base speed
@@ -115,16 +116,11 @@ wasdWithAiming w speed cr
addAnyTwist = fromMaybe id $ do addAnyTwist = fromMaybe id $ do
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
let currenttwistamount = cr ^. crTwist case (astance, cr ^. crTwist) of
case (astance, currenttwistamount) of
(TwoHandUnder, 0) -> (TwoHandUnder, 0) ->
return $ return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
(crTwist .~ twistamount * pi)
. (crDir -~ twistamount * pi)
(TwoHandOver, 0) -> (TwoHandOver, 0) ->
return $ return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
(crTwist .~ twistamount * pi)
. (crDir -~ twistamount * pi)
_ -> Nothing _ -> Nothing
theMovement theMovement
| movDir == V2 0 0 = id | movDir == V2 0 0 = id
@@ -154,11 +150,10 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
-- | Set posture according to mouse presses. -- | Set posture according to mouse presses.
mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature
mouseActionsCr pkeys cr mouseActionsCr pkeys cr
| rbPressed && noaction = | SDL.ButtonRight `M.member` pkeys && noaction =
cr & crStance . posture .~ Aiming cr & crStance . posture .~ Aiming
| otherwise = cr & crStance . posture .~ AtEase | otherwise = cr & crStance . posture .~ AtEase
where where
rbPressed = SDL.ButtonRight `M.member` pkeys
noaction = fromMaybe True $ do noaction = fromMaybe True $ do
theaction <- cr ^? crManipulation . manObject . inInventory . iselAction theaction <- cr ^? crManipulation . manObject . inInventory . iselAction
return $ theaction == NoInvSelAction return $ theaction == NoInvSelAction
@@ -167,8 +162,7 @@ pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World
pressedMBEffectsTopInventory pkeys w pressedMBEffectsTopInventory pkeys w
| isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = useItemRightClick (you w) w | isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = useItemRightClick (you w) w
| isDown SDL.ButtonLeft && inTopInv = useItemLeftClick (you w) w | isDown SDL.ButtonLeft && inTopInv = useItemLeftClick (you w) w
| isDown SDL.ButtonMiddle = | isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation
w & wCam . camRot -~ rotation
| otherwise = w | otherwise = w
where where
inTopInv = case w ^. hud . hudElement of inTopInv = case w ^. hud . hudElement of
-2
View File
@@ -85,5 +85,3 @@ defaultConsumable =
& itUse .~ ConsumeUse CDoNothing 1 & itUse .~ ConsumeUse CDoNothing 1
& itInvColor .~ blue & itInvColor .~ blue
defaultItZoom :: ItZoom
defaultItZoom = ItZoom 20 0.2 1
+11 -3
View File
@@ -9,10 +9,18 @@ defaultAimParams =
{ _aimWeight = 0 { _aimWeight = 0
, _aimTurnSpeed = 1 , _aimTurnSpeed = 1
, _aimRange = 0 , _aimRange = 0
, _aimZoom = ItZoom 20 0.2 1 , _aimZoom = defaultItZoom
, _aimStance = OneHand , _aimStance = OneHand
--, _aimHandlePos = 10 , --, _aimHandlePos = 10
, _aimHandlePos = V2 3 0 _aimHandlePos = V2 3 0
, _aimMuzzles = [Muzzle (V2 20 0) 0 0] , _aimMuzzles = [Muzzle (V2 20 0) 0 0]
-- , _aimMuzPos = 20 -- , _aimMuzPos = 20
} }
defaultItZoom :: ItZoom
defaultItZoom =
ItZoom
{ _izMax = 20
, _izMin = 0.2
, _izFac = 1
}
+1 -12
View File
@@ -39,25 +39,14 @@ defaultBangCane =
volleyGun :: Int -> Item volleyGun :: Int -> Item
volleyGun i = volleyGun i =
defaultBangCane defaultBangCane
& itUse . heldDelay . rateMax .~ 6
& itUse . heldMods .~ VolleyGunMod & itUse . heldMods .~ VolleyGunMod
& itUse . heldAim . aimWeight .~ 6 & itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimRange .~ 1 & itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
-- & itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3] & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3]
& itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i
& itParams & itParams . torqueAfter .~ 0.15 + 0.05 * fromIntegral i
.~ BulletShooter
{ _muzVel = 0.8
, _rifling = 0.9
, _bore = 2
, _recoil = 50
, _torqueAfter = 0.1
, _randomOffset = 0
}
& itParams . torqueAfter .~ 0.48 + 0.2 * fromIntegral i
& itType . iyBase .~ HELD (VOLLEYGUN i) & itType . iyBase .~ HELD (VOLLEYGUN i)
rifle :: Item rifle :: Item
-1
View File
@@ -49,7 +49,6 @@ elephantGun =
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0.05 & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0.05
& itUse . heldMods .~ ElephantGunMod & itUse . heldMods .~ ElephantGunMod
& itParams . recoil .~ 50 & itParams . recoil .~ 50
& itParams . torqueAfter .~ 0.1
amr :: Item amr :: Item
amr = amr =
+7
View File
@@ -2,9 +2,11 @@ module Dodge.Item.Location (
pointerToItemLocation, pointerToItemLocation,
getItem, getItem,
pointerToItem, pointerToItem,
pointerYourItem,
) where ) where
import Control.Lens import Control.Lens
import Data.Maybe
import Dodge.Data.World import Dodge.Data.World
getItem :: Int -> World -> Maybe Item getItem :: Int -> World -> Maybe Item
@@ -26,6 +28,11 @@ pointerToItemLocation (InInv cid invid) = cWorld . lWorld . creatures . ix cid .
pointerToItemLocation (OnFloor flid) = cWorld . lWorld . floorItems . ix flid . flIt pointerToItemLocation (OnFloor flid) = cWorld . lWorld . floorItems . ix flid . flIt
pointerToItemLocation _ = const pure pointerToItemLocation _ = const pure
pointerYourItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem
Just $ pointerToItemLocation (InInv 0 itinvid) f w
pointerToItem :: pointerToItem ::
Applicative f => Applicative f =>
Item -> Item ->
+9 -6
View File
@@ -59,6 +59,7 @@ module Dodge.Item.Weapon.TriggerType (
blCheck, blCheck,
) where ) where
import Dodge.Item.Location
import Dodge.Creature.HandPos import Dodge.Creature.HandPos
import Data.Foldable import Data.Foldable
import Data.Maybe import Data.Maybe
@@ -202,16 +203,16 @@ withWarmUp ::
withWarmUp soundID f item cr w withWarmUp soundID f item cr w
| curWarmUp < maxWarmUp && crWeaponReady cr = | curWarmUp < maxWarmUp && crWeaponReady cr =
w w
& pointerToItem . itUse . heldDelay . warmTime +~ 2 & pointertoitem . itUse . heldDelay . warmTime +~ 2
& soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2) & soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2)
| otherwise = | otherwise =
w w
& pointerToItem . itUse . heldDelay . warmTime .~ maxWarmUp & pointertoitem . itUse . heldDelay . warmTime .~ maxWarmUp
& f item cr & f item cr
where where
cid = _crID cr cid = _crID cr
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef pointertoitem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef
curWarmUp = _warmTime . _heldDelay $ _itUse item curWarmUp = _warmTime . _heldDelay $ _itUse item
maxWarmUp = _warmMax . _heldDelay $ _itUse item maxWarmUp = _warmMax . _heldDelay $ _itUse item
@@ -411,7 +412,7 @@ shootL ::
World World
shootL f item cr w shootL f item cr w
| fireCondition = | fireCondition =
f item cr w & pointerToItem f item cr w & cWorld . lWorld . creatures . ix cid . crInv . ix invid
%~ ( itUseCharge 1 %~ ( itUseCharge 1
. (itUse . leftDelay . rateTime .~ _rateMax (_leftDelay (_itUse item))) . (itUse . leftDelay . rateTime .~ _rateMax (_leftDelay (_itUse item)))
) )
@@ -420,7 +421,6 @@ shootL f item cr w
where where
cid = _crID cr cid = _crID cr
invid = _ipInvID $ _itLocation item invid = _ipInvID $ _itLocation item
pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix invid
fireCondition = fireCondition =
_rateTime (_leftDelay (_itUse item)) == 0 _rateTime (_leftDelay (_itUse item)) == 0
&& _arLoaded (_leftConsumption (_itUse item)) > 0 && _arLoaded (_leftConsumption (_itUse item)) > 0
@@ -587,13 +587,16 @@ torqueBeforeAtLeast minTorque exTorque feff item cr w
withTorqueAfter :: ChainEffect withTorqueAfter :: ChainEffect
withTorqueAfter feff item cr w withTorqueAfter feff item cr w
-- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w -- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w
| cid == 0 = set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w | cid == 0 = rotateScope . set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w
where where
cid = _crID cr cid = _crID cr
(rot, g) = randomR (- torque, torque) $ _randGen w (rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? itParams . torqueAfter torque = fromMaybe 0 $ item ^? itParams . torqueAfter
--rotateScope = cWorld . lWorld . creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
sideEffectOnFrame :: sideEffectOnFrame ::
Int -> Int ->
(Item -> Creature -> WdWd) -> (Item -> Creature -> WdWd) ->