Allow turrets to fire bullets, only good for testing for now
This commit is contained in:
+33
-18
@@ -7,6 +7,7 @@ module Dodge.HeldUse (
|
||||
mcUseHeld,
|
||||
) where
|
||||
|
||||
import Dodge.Item.Weapon.Bullet
|
||||
import Color
|
||||
import Control.Monad
|
||||
import Data.Maybe
|
||||
@@ -458,36 +459,39 @@ shootBullet ::
|
||||
World
|
||||
shootBullet itmtree cr (mz, x, magtree) w = fromMaybe w $ do
|
||||
thebullet <- getBulletType itmtree magtree mz cr w
|
||||
return $ foldl' (&) w (replicate x (makeBullet thebullet (itmtree ^. ldtValue) cr mz))
|
||||
return $ foldl' (&) w (replicate x (makeBullet' thebullet (itmtree ^. ldtValue) cr mz))
|
||||
|
||||
makeBullet' :: Bullet -> Item -> Creature -> Muzzle -> World -> World
|
||||
makeBullet' bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
|
||||
where
|
||||
bulpos = _crPos cr + rotateV (_crDir cr) moff
|
||||
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
|
||||
(a, g) = randomR (- inacc, inacc) $ _randGen w
|
||||
dir = _crDir cr + mrot + a
|
||||
inacc = _mzInaccuracy mz
|
||||
offset = case itm ^? itUse . heldParams . randomOffset of
|
||||
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
|
||||
_ -> 0
|
||||
|
||||
-- & makeMuzzleSmoke mz itm cr
|
||||
|
||||
-- the random generator is not updated here, not sure if that is a problem
|
||||
makeBullet :: Bullet -> Item -> Creature -> Muzzle -> World -> World
|
||||
makeBullet thebullet itm cr mz w =
|
||||
w & randGen .~ g
|
||||
makeBullet :: Bullet -> Item -> Point2 -> Float -> World -> World
|
||||
makeBullet thebullet itm bulpos dir w =
|
||||
w & randGen .~ g''
|
||||
& cWorld . lWorld . instantBullets
|
||||
.:~ ( thebullet
|
||||
& buPos .~ bulpos
|
||||
-- & buTrajectory .~ BasicBulletTrajectory
|
||||
& buVel %~ (rotateV dir . (muzvel *.*))
|
||||
& buDrag *~ drag
|
||||
)
|
||||
where
|
||||
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
|
||||
bulpos = _crPos cr + rotateV (_crDir cr) moff
|
||||
(a, g'') = randomR (- inacc, inacc) $ _randGen w
|
||||
inacc = _mzInaccuracy mz
|
||||
g = _randGen w
|
||||
(drag, g') = case _rifling (_heldParams $ _itUse itm) of
|
||||
ConstFloat x -> (x, g'')
|
||||
UniRandFloat x y -> randomR (x, y) g''
|
||||
(muzvel, g) = case _muzVel $ _heldParams $ _itUse itm of
|
||||
ConstFloat x -> (x, g)
|
||||
UniRandFloat x y -> randomR (x, y) g
|
||||
(muzvel, g'') = case _muzVel $ _heldParams $ _itUse itm of
|
||||
ConstFloat x -> (x, g')
|
||||
UniRandFloat x y -> randomR (x, y) g'
|
||||
dir = _crDir cr + mrot + a
|
||||
offset = case itm ^? itUse . heldParams . randomOffset of
|
||||
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
|
||||
_ -> 0
|
||||
|
||||
mcUseHeld :: HeldItemType -> Item -> Machine -> World -> World
|
||||
mcUseHeld hit = case hit of
|
||||
@@ -555,7 +559,18 @@ mcShootLaser _ mc = cWorld . lWorld . lasers .:~ lasRayAt yellow dam phasev pos
|
||||
dam = 11
|
||||
|
||||
mcShootAuto :: Item -> Machine -> World -> World
|
||||
mcShootAuto _ _ = id
|
||||
mcShootAuto itm mc w
|
||||
| Just (FixedRate x 0) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay
|
||||
= w & cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
|
||||
. itUse . heldDelay . rateTime .~ x
|
||||
& makeBullet defaultBullet itm pos dir
|
||||
| otherwise
|
||||
= w & cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
|
||||
. itUse . heldDelay . rateTime -~ 1
|
||||
where
|
||||
pos = _mcPos mc +.+ 20 *.* unitVectorAtAngle dir
|
||||
dir = mc ^?! mcType . _McTurret . tuDir
|
||||
|
||||
|
||||
-- | assumes that the item is held
|
||||
shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World
|
||||
|
||||
Reference in New Issue
Block a user