Files
loop/src/Dodge/Item/Weapon/AmmoParams.hs
T
2022-07-13 11:26:13 +01:00

84 lines
2.7 KiB
Haskell

module Dodge.Item.Weapon.AmmoParams
( ruseAmmoParams
, useAmmoParams
, fractionLoadedAmmo
, fractionLoadedAmmo2
) where
import Dodge.Data
import Dodge.Base
import Dodge.Particle.Bullet.Spawn
import Dodge.Creature.HandPos
import Dodge.Movement.Turn
import Dodge.Default.AimParams
import Geometry
import LensHelp
import Data.Maybe
--import Control.Lens
ruseAmmoParams :: ItemUse
ruseAmmoParams = RightUse
{ _rUse = useAmmoParams Nothing
, _useDelay = FixedRate {_rateMax = 10, _rateTime = 0}
, _useMods = []
, _useHammer = HammerUp
, _useAim = defaultAimParams
, _heldScroll = \_ _ -> id
}
--defaultAimParams :: AimParams
--defaultAimParams = AimParams
-- { _aimWeight = 0
-- , _aimRange = 0
-- , _aimZoom = ItZoom 20 0.2 1
-- , _aimStance = OneHand
-- , _aimHandlePos = 10
-- , _aimMuzPos = 20
-- }
useAmmoParams :: Maybe Float -> Item -> Creature -> World -> World
useAmmoParams vfact it cr w = w & instantParticles .:~ aBulAt
vfact
thetraj -- extra update
Nothing -- color (default)
sp
(rotateV dir (muzvel *.* _amBulVel bultype)) -- vel
(_rifling $ _itParams it) -- drag
(_amBulEff bultype)
(_amBulWth bultype)
where
sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir
dir = _crDir cr
bultype = _laAmmoType $ _itConsumption it
muzvel = _muzVel $ _itParams it
muzlength = aimingMuzzlePos cr it
thetraj = case _amBulTraj bultype of
BasicBulletTrajectory -> id
MagnetTrajectory -> fromMaybe id $ do
tpos <- it ^? itTargeting . tgPos . _Just
return $ \pt -> pt & ptVel .+.+~ 5 *.* normalizeV (tpos -.- head (_ptTrail pt))
FlechetteTrajectory -> fromMaybe id $ do
tpos <- it ^? itTargeting . tgPos . _Just
return $ \pt -> pt & ptVel %~ vecTurnTo 0.2 (head $ _ptTrail pt) tpos
BezierTrajectory -> fromMaybe id $ do
tpos <- it ^? itTargeting . tgPos . _Just
let bf t = bQuadToF (sp,mouseWorldPos w,tpos) $ (100 - t) * 0.05
return $ \pt -> pt
& ptVel .~ bf (fromIntegral $ _ptTimer pt - 1) -.- bf (fromIntegral $ _ptTimer pt)
---- this shouldn't really be used
loadedAmmo :: Item -> Int
loadedAmmo = _laLoaded . _itConsumption
-- | _laTransfer (_itConsumption it) == NoTransfer = _laLoaded (_itConsumption it)
-- | otherwise = 0
fractionLoadedAmmo :: Item -> Float
fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (itmaxammo it)
where
itmaxammo = _laMax . _itConsumption
fractionLoadedAmmo2 :: Item -> Float
fractionLoadedAmmo2 it = 1 -
(1 - fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it))**2
where
itMaxAmmo = _laMax . _itConsumption