Cleanup, move bullet spawn random offset to muzzle

This commit is contained in:
2025-07-05 20:55:24 +01:00
parent 164499fe4e
commit 7b9c1678f1
5 changed files with 34 additions and 83 deletions
-1
View File
@@ -286,7 +286,6 @@ updateAttachedItems itmtree cr =
chainLinkOrientation
chainLinkOrientation
(updateItemWithOrientation cr)
--(heldItemRelativeOrient (itmtree ^. ldtValue . _1) cr (0, Q.qID))
(handHandleOrient (LocLDT TopLDT itmtree) cr)
(LocLDT TopLDT itmtree)
+1 -1
View File
@@ -14,7 +14,7 @@ data Muzzle = Muzzle
, _mzFlareType :: FlareType
, _mzEffect :: MuzzleEffect
, _mzAmmoPerShot :: AmmoPerShot
-- , _mzFrame :: Int
, _mzRandomOffset :: Float
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
+25 -66
View File
@@ -164,22 +164,23 @@ heldItemMuzzles = \case
NoFlare
MuzzleShootBullet
(UseExactly 1)
0
| -- 0
a <- spreadAroundCenter i baseStickSpread
]
& ix 0 . mzFlareType .~ NoLightFlare
& ix (i `div` 2) . mzFlareType .~ BasicFlare
& ix (i -1) . mzFlareType .~ NoLightFlare
PISTOL -> [Muzzle (V2 10 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1)]
MACHINEPISTOL -> [Muzzle (V2 10 0) 0 0.3 0 MiniGunFlare MuzzleShootBullet (UseExactly 1)]
AUTOPISTOL -> [Muzzle (V2 10 0) 0 0 0 BasicFlare MuzzleShootBullet (UseExactly 1)]
SMG -> [Muzzle (V2 20 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1)]
PISTOL -> [Muzzle (V2 10 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
MACHINEPISTOL -> [Muzzle (V2 10 0) 0 0.3 0 MiniGunFlare MuzzleShootBullet (UseExactly 1) 0]
AUTOPISTOL -> [Muzzle (V2 10 0) 0 0 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
SMG -> [Muzzle (V2 20 0) 0 0.05 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
RIFLE -> dbwMuzzles & ix 0 . mzPos .~ V2 25 0
BURSTRIFLE -> dbwMuzzles & ix 0 . mzPos .~ V2 25 0 & ix 0 . mzInaccuracy .~ 0.05
MINIGUNX i ->
replicate
i
(Muzzle (V2 30 0) 0 0.05 0 NoFlare MuzzleShootBullet (UseExactly 1))
(Muzzle (V2 30 0) 0 0.05 0 NoFlare MuzzleShootBullet (UseExactly 1) 10)
& ix 0 . mzFlareType .~ MiniGunFlare
BANGROD ->
dbwMuzzles
@@ -205,9 +206,9 @@ heldItemMuzzles = \case
& ix 0 . mzPos .~ V2 30 0
& ix 0 . mzFlareType .~ HeavySmokeFlare
& ix 0 . mzInaccuracy .~ 0
BANGCONE -> [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15)]
BLUNDERBUSS -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15)]
GRAPECANNON _ -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15)]
BANGCONE -> [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 12]
BLUNDERBUSS -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 12]
GRAPECANNON i -> [Muzzle (V2 30 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) (12 + 4*fromIntegral i)]
TORCH -> dbwMuzzles & ix 0 . mzPos .~ V2 10 0
VOLLEYGUN{} -> error "should get volleygun muzzles earlier"
FLAMETHROWER -> flameMuzzles
@@ -229,6 +230,7 @@ heldItemMuzzles = \case
<*> pure NoFlare
<*> pure MuzzleRLauncher
<*> pure (UseExactly 1)
<*> pure 0
)
LASER ->
dbwMuzzles
@@ -282,7 +284,7 @@ heldItemMuzzles = \case
, _mzFlareType = NoFlare
, _mzEffect = MuzzleShootBullet
, _mzAmmoPerShot = UseExactly 1
-- , _mzFrame = 0
, _mzRandomOffset = 0
}
]
@@ -290,7 +292,7 @@ baseStickSpread :: Float
baseStickSpread = 0.2
dbwMuzzles :: [Muzzle]
dbwMuzzles = [Muzzle (V2 15 0) 0 0.01 0 BasicFlare MuzzleShootBullet (UseExactly 1)]
dbwMuzzles = [Muzzle (V2 15 0) 0 0.01 0 BasicFlare MuzzleShootBullet (UseExactly 1) 0]
flameMuzzles :: [Muzzle]
flameMuzzles =
@@ -306,6 +308,7 @@ flameMuzzles =
, _nzWalkSpeed = 0.01
}
(UseExactly 1)
0
]
vgunMuzzles :: Int -> [Muzzle]
@@ -316,7 +319,7 @@ vgunMuzzles i =
<*> pure BasicFlare
<*> pure MuzzleShootBullet
<*> pure (UseExactly 1)
-- <*> ZipList [0 .. i -1]
<*> pure 0
)
doHeldUseEffect :: LDTree ItemLink OItem -> Creature -> World -> World
@@ -696,11 +699,10 @@ makeMuzzleFlare mz loc cr = case mz ^. mzFlareType of
)
TeslaGunFlare -> cWorld . lWorld . lights .:~ LSParam (pos `v2z` 10) 100 (V3 0 0 1)
where
itmtree = loc ^. locLDT
itm = itmtree ^. ldtValue
(moff, mrot) = heldItemOrient2D' itm cr (_mzPos mz) (_mzRot mz)
pos = _crPos cr + rotateV (_crDir cr) moff
dir = _crDir cr + mrot
(V3 x y _,q) = locOrient loc cr
`Q.comp` (_mzPos mz `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz))
pos = _crPos cr + rotateV (_crDir cr) (V2 x y)
dir = _crDir cr + Q.qToAng q
oddcheck f w
| odd (w ^. cWorld . lWorld . lClock) = f w
| otherwise = w
@@ -979,59 +981,16 @@ shootBullets loc cr (mz, x, magtree) w = fromMaybe w $ do
shootBullet :: Bullet -> LocationLDT ItemLink OItem -> Creature -> Muzzle -> World -> World
shootBullet bu loc cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
where
(V3 x y _,q) = locOrient loc cr
`Q.comp` ((_mzPos mz + V2 0 offset) `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz))
itm = loc ^. locLDT . ldtValue . _1
bulpos = _crPos cr + rotateV (_crDir cr) moff
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
bulpos = _crPos cr + rotateV (_crDir cr) (V2 x y)
(a, g) = randomR (- inacc, inacc) $ _randGen w
dir = _crDir cr + mrot + a
dir = _crDir cr + Q.qToAng q + a
inacc = _mzInaccuracy mz
offset = case itemRandomOffset <$> itm ^? itType . ibtHeld of
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
_ -> 0
itemRandomOffset :: HeldItemType -> Float
itemRandomOffset = \case
BANGSTICK{} -> 0
REWINDER -> 0
TIMESTOPPER -> 0
TIMESCROLLER -> 0
PISTOL -> 0
MACHINEPISTOL -> 0
AUTOPISTOL -> 0
SMG -> 0
BANGCONE -> 12
BLUNDERBUSS -> 12
GRAPECANNON i -> 12 + 4 * fromIntegral i
MINIGUNX{} -> 10
VOLLEYGUN{} -> 0
RIFLE -> 0
ALTERIFLE -> 0
AUTORIFLE -> 0
BURSTRIFLE -> 0
BANGROD -> 0
ELEPHANTGUN -> 0
AMR -> 0
AUTOAMR -> 0
SNIPERRIFLE -> 0
FLAMESPITTER -> 0
FLAMETHROWER -> 0
FLAMETORRENT -> 0
FLAMEWALL -> 0
BLOWTORCH -> 0
SPARKGUN -> 0
TESLAGUN -> 0
LASER -> 0
TRACTORGUN -> 0
RLAUNCHER -> 0
RLAUNCHERX{} -> 0
GLAUNCHER -> 0
POISONSPRAYER -> 0
SHATTERGUN -> 0
TORCH -> 0
FLATSHIELD -> 0
KEYCARD{} -> 0
BLINKER -> 0
BLINKERUNSAFE -> 0
offset = case mz ^. mzRandomOffset of
0 -> 0
i -> fst . randomR (- i, i) $ _randGen w
makeBullet :: Bullet -> Item -> Point2 -> Float -> World -> World
makeBullet thebullet itm bulpos dir w =
+3 -15
View File
@@ -7,8 +7,7 @@ module Dodge.Item.HeldOffset (
heldItemRelativeOrient,
heldItemOrient2D,
heldItemOrient2D',
-- itemRelativeOrient,
locOrientation,
locOrient,
handHandleOrient,
) where
@@ -18,9 +17,7 @@ import Dodge.Data.ComposedItem
import Dodge.Data.Creature
import Dodge.Data.DoubleTree
import Dodge.Data.Machine
import Dodge.DoubleTree
import Dodge.Item.AimStance
import Dodge.Item.Orientation
import Geometry
import LensHelp
import qualified Quaternion as Q
@@ -95,8 +92,8 @@ handOrient cr = case cr ^. crStance . posture of
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
locOrientation :: LocationLDT ItemLink OItem -> Creature -> Point3Q
locOrientation loc cr = handHandleOrient (fmap (\(x,y,_) -> (x,y)) loc) cr `Q.comp`
locOrient :: LocationLDT ItemLink OItem -> Creature -> Point3Q
locOrient loc cr = handHandleOrient (fmap (\(x,y,_) -> (x,y)) loc) cr `Q.comp`
(loc ^. locLDT . ldtValue . _3)
-- heldItemRelativeOrient
-- (locToTop loc ^. locLDT . ldtValue . _1)
@@ -187,12 +184,3 @@ heldHandlePos = \case
KEYCARD{} -> V2 3 0
BLINKER -> V2 3 0
BLINKERUNSAFE -> V2 3 0
itemRelativeOrient ::
LocationLDT ItemLink Item ->
Creature ->
(Point3, Q.Quaternion Float) ->
(Point3, Q.Quaternion Float)
itemRelativeOrient loc cr =
heldItemRelativeOrient (locToTop loc ^. locLDT . ldtValue) cr
. orientLocation (V3 0 0 0, Q.qID) loc
+5
View File
@@ -13,12 +13,14 @@ module Quaternion (
qID,
qToV3,
qToV2,
qToAng,
rotateToZ,
vToQuat,
comp,
module Linear.Quaternion,
) where
import Geometry.Vector
import Data.Aeson
import Geometry.Data
import Geometry.Vector3D
@@ -52,6 +54,9 @@ qToV3 q = Q.rotate q (V3 1 0 0)
qToV2 :: Q.Quaternion Float -> Point2
qToV2 = (\(V3 x y _) -> V2 x y) . qToV3
qToAng :: Quaternion Float -> Float
qToAng = argV . qToV2
qID :: Q.Quaternion Float
qID = Q.axisAngle (V3 1 0 0) 0