This commit is contained in:
2025-07-05 23:41:28 +01:00
parent d6bdd0098b
commit 76cb03b07b
2 changed files with 62 additions and 47 deletions
+54 -30
View File
@@ -75,7 +75,7 @@ hammerCheck f pt loc cr w = case itemTriggerType loc of
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1 & cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpNoDelay{} -> f loc cr w & setwarming WarmUpNoDelay{} -> f loc cr w & setwarming
WarmUpCoolDown ws _ _ WarmUpCoolDown ws _ _
-- UNSAFE: -- UNSAFE:
| _wTime (_itParams $ it) < ws -> | _wTime (_itParams $ it) < ws ->
w & setwarming w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2) & soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2)
@@ -208,7 +208,7 @@ heldItemMuzzles = \case
& ix 0 . mzInaccuracy .~ 0 & ix 0 . mzInaccuracy .~ 0
BANGCONE -> [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 12] 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] 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)] 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 TORCH -> dbwMuzzles & ix 0 . mzPos .~ V2 10 0
VOLLEYGUN{} -> error "should get volleygun muzzles earlier" VOLLEYGUN{} -> error "should get volleygun muzzles earlier"
FLAMETHROWER -> flameMuzzles FLAMETHROWER -> flameMuzzles
@@ -498,7 +498,7 @@ applyRecoil loc cr =
+~ rotateV (_crDir cr + Q.qToAng q) (V2 ((- recoilAmount itm) / crMass (_crType cr)) 0) +~ rotateV (_crDir cr + Q.qToAng q) (V2 ((- recoilAmount itm) / crMass (_crType cr)) 0)
where where
itm = loc ^. locLDT . ldtValue . _1 itm = loc ^. locLDT . ldtValue . _1
(_,q) = locOrient loc cr (_, q) = locOrient loc cr
recoilAmount :: Item -> Float recoilAmount :: Item -> Float
recoilAmount itm recoilAmount itm
@@ -703,8 +703,9 @@ makeMuzzleFlare mz loc cr = case mz ^. mzFlareType of
) )
TeslaGunFlare -> cWorld . lWorld . lights .:~ LSParam (pos `v2z` 10) 100 (V3 0 0 1) TeslaGunFlare -> cWorld . lWorld . lights .:~ LSParam (pos `v2z` 10) 100 (V3 0 0 1)
where where
(V3 x y _,q) = locOrient loc cr (V3 x y _, q) =
`Q.comp` (_mzPos mz `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz)) 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) pos = _crPos cr + rotateV (_crDir cr) (V2 x y)
dir = _crDir cr + Q.qToAng q dir = _crDir cr + Q.qToAng q
oddcheck f w oddcheck f w
@@ -767,7 +768,7 @@ useLoadedAmmo loc cr (_, w) (Just (mz, x, magtree)) = (,) True $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz loc cr $ case _mzEffect mz of removeAmmoFromMag x mid cr . makeMuzzleFlare mz loc cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullets loc cr (mz, x, magtree) w MuzzleShootBullet -> shootBullets loc cr (mz, x, magtree) w
MuzzleLaser -> creatureShootLaser loc cr mz w MuzzleLaser -> creatureShootLaser loc cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w MuzzleTesla -> shootTeslaArc loc cr mz w
MuzzleTractor -> shootTractorBeam cr w MuzzleTractor -> shootTractorBeam cr w
MuzzleRLauncher -> createProjectileR loc magtree mz cr w MuzzleRLauncher -> createProjectileR loc magtree mz cr w
MuzzleGLauncher -> MuzzleGLauncher ->
@@ -779,7 +780,7 @@ useLoadedAmmo loc cr (_, w) (Just (mz, x, magtree)) = (,) True $
mz mz
cr cr
w w
MuzzleNozzle{} -> useGasParams mid mz (itm ^. _1) cr $ walkNozzle mz (itm ^. _1) cr w MuzzleNozzle{} -> useGasParams mid mz loc cr $ walkNozzle mz (itm ^. _1) cr w
MuzzleShatter -> shootShatter (itm ^. _1) cr w MuzzleShatter -> shootShatter (itm ^. _1) cr w
MuzzleDetector -> MuzzleDetector ->
itemDetectorEffect itemDetectorEffect
@@ -878,13 +879,17 @@ creatureShootLaser loc cr mz w =
(getLaserColor loc) (getLaserColor loc)
where where
itmtree = loc ^. locLDT itmtree = loc ^. locLDT
istree = fmap (\(x, _, _) -> x) itmtree istree = fmap (\(i, _, _) -> i) itmtree
itm = itmtree ^. ldtValue (V3 x y _, q) =
(moff, mrot) = heldItemOrient2D' itm cr (_mzPos mz) (_mzRot mz) locOrient loc cr
pos = _crPos cr + rotateV (_crDir cr) moff `Q.comp` ((_mzPos mz + V2 0 offset) `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz))
dir = _crDir cr + mrot + a pos = _crPos cr + rotateV (_crDir cr) (V2 x y)
dir = _crDir cr + Q.qToAng q + a
(a, g) = randomR (- inacc, inacc) $ _randGen w (a, g) = randomR (- inacc, inacc) $ _randGen w
inacc = _mzInaccuracy mz inacc = _mzInaccuracy mz
offset = case mz ^. mzRandomOffset of
0 -> 0
i -> fst . randomR (- i, i) $ _randGen w
shootLaser :: shootLaser ::
SoundOrigin -> SoundOrigin ->
@@ -985,8 +990,9 @@ shootBullets loc cr (mz, x, magtree) w = fromMaybe w $ do
shootBullet :: Bullet -> LocationLDT ItemLink OItem -> Creature -> Muzzle -> World -> World shootBullet :: Bullet -> LocationLDT ItemLink OItem -> Creature -> Muzzle -> World -> World
shootBullet bu loc cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w shootBullet bu loc cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
where where
(V3 x y _,q) = locOrient loc cr (V3 x y _, q) =
`Q.comp` ((_mzPos mz + V2 0 offset) `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz)) 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 itm = loc ^. locLDT . ldtValue . _1
bulpos = _crPos cr + rotateV (_crDir cr) (V2 x y) bulpos = _crPos cr + rotateV (_crDir cr) (V2 x y)
(a, g) = randomR (- inacc, inacc) $ _randGen w (a, g) = randomR (- inacc, inacc) $ _randGen w
@@ -1108,26 +1114,37 @@ mcUseHeld hit = case hit of
LASER -> mcShootLaser LASER -> mcShootLaser
_ -> mcShootAuto _ -> mcShootAuto
useGasParams :: Maybe Int -> Muzzle -> Item -> Creature -> World -> World useGasParams ::
useGasParams mmagid mz itm cr w = Maybe Int ->
Muzzle ->
LocationLDT ItemLink OItem ->
Creature ->
World ->
World
useGasParams mmagid mz loc cr w =
w w
& createGas gastype pressure pos dir cr & createGas gastype pressure pos dir cr
& randGen .~ g' & randGen .~ g'
where where
itm = loc ^. locLDT . ldtValue . _1
(pressure, g) = doGenFloat (_nzPressure $ _mzEffect mz) (_randGen w) (pressure, g) = doGenFloat (_nzPressure $ _mzEffect mz) (_randGen w)
gastype = fromMaybe (error "cannot find gas ammo") $ do gastype = fromMaybe (error "cannot find gas ammo") $ do
magid <- mmagid magid <- mmagid
hit <- itm ^? itType . ibtHeld hit <- itm ^? itType . ibtHeld
--fueltype <- cr ^? crInv . ix magid . itConsumables . magParams . ampCreateGas
fueltype <- cr ^? crInv . ix magid >>= magAmmoParams >>= (^? ampCreateGas) fueltype <- cr ^? crInv . ix magid >>= magAmmoParams >>= (^? ampCreateGas)
gasType hit fueltype gasType hit fueltype
--pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm) (V3 x y _, q) =
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz) (_mzRot mz) locOrient loc cr
pos = _crPos cr + rotateV (_crDir cr) moff `Q.comp` ((_mzPos mz + V2 0 offset) `v2z` 0, Q.axisAngle (V3 0 0 1) (_mzRot mz))
-- (moff, mrot) = heldItemOrient2D itm cr (_mzPos mz) (_mzRot mz)
pos = _crPos cr + rotateV (_crDir cr) (V2 x y)
(a, g') = randomR (- inacc, inacc) g (a, g') = randomR (- inacc, inacc) g
inacc = _mzInaccuracy mz inacc = _mzInaccuracy mz
--dir = _crDir cr + mrot + a + _nzCurrentWalkAngle (_mzEffect mz) offset = case mz ^. mzRandomOffset of
dir = _crDir cr + mrot + a + _nzAngle (_itParams itm) 0 -> 0
i -> fst . randomR (- i, i) $ _randGen w
-- dir = _crDir cr + mrot + a + _nzAngle (_itParams itm)
dir = _crDir cr + Q.qToAng q + a + _nzAngle (_itParams itm)
gasType :: HeldItemType -> GasFuel -> Maybe GasCreate gasType :: HeldItemType -> GasFuel -> Maybe GasCreate
gasType hit _ = case hit of gasType hit _ = case hit of
@@ -1203,17 +1220,24 @@ mcShootAuto itm mc w
dir = mc ^?! mcType . _McTurret . tuDir dir = mc ^?! mcType . _McTurret . tuDir
-- | assumes that the item is held -- | assumes that the item is held
shootTeslaArc :: OItem -> Creature -> Muzzle -> World -> World shootTeslaArc :: LocationLDT ItemLink OItem -> Creature -> Muzzle -> World -> World
shootTeslaArc itm cr mz w = shootTeslaArc loc cr mz w =
w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itParams .~ ip
& soundContinue (CrWeaponSound (_crID cr) 0) pos elecCrackleS (Just 2) & soundContinue (CrWeaponSound (_crID cr) 0) pos elecCrackleS (Just 2)
where where
-- use items item location instead -- use items item location instead
itRef = cr ^?! crManipulation . manObject . imRootSelectedItem -- unsafe!! TODO change -- itRef = cr ^?! crManipulation . manObject . imRootSelectedItem -- unsafe!! TODO change
(w', ip) = makeTeslaArc (_itParams (itm ^. _1)) pos dir w itm = loc ^. locLDT . ldtValue . _1
(moff, mrot) = heldItemOrient2D' itm cr (_mzPos mz) (_mzRot mz) invid = itm ^?! itLocation . ilInvID
pos = _crPos cr + rotateV (_crDir cr) moff (w', ip) = makeTeslaArc (itm ^. itParams) pos dir w
dir = _crDir cr + mrot (V3 x y _, q) =
locOrient loc cr
`Q.comp` ((_mzPos mz + V2 0 offset) `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
offset = case mz ^. mzRandomOffset of
0 -> 0
i -> fst . randomR (- i, i) $ _randGen w
determineProjectileTracking :: LDTree ItemLink Item -> LDTree ItemLink Item -> RocketHoming determineProjectileTracking :: LDTree ItemLink Item -> LDTree ItemLink Item -> RocketHoming
determineProjectileTracking magtree itmtree = determineProjectileTracking magtree itmtree =
+8 -17
View File
@@ -5,8 +5,6 @@ module Dodge.Item.HeldOffset (
twoFlatHRot, twoFlatHRot,
heldItemOffset, heldItemOffset,
heldItemRelativeOrient, heldItemRelativeOrient,
heldItemOrient2D,
heldItemOrient2D',
locOrient, locOrient,
handHandleOrient, handHandleOrient,
) where ) where
@@ -32,18 +30,7 @@ transToHandle itm = (-.-.- V3 x y 0)
where where
V2 x y = handlePos itm V2 x y = handlePos itm
heldItemOrient2D :: Item -> Creature -> Point2 -> Float -> (Point2, Float) heldItemRelativeOrient :: Item -> Creature -> Point3Q -> Point3Q
heldItemOrient2D itm cr p a = (V2 x y, argV . Q.qToV2 $ q)
where
(V3 x y _, q) = heldItemRelativeOrient itm cr (p `v2z` 0, Q.axisAngle (V3 0 0 1) a)
heldItemOrient2D' :: OItem -> Creature -> Point2 -> Float -> (Point2, Float)
heldItemOrient2D' (itm, _, (p1, q1)) cr p a = (V2 x y, argV . Q.qToV2 $ q)
where
(V3 x y _, q) = heldItemRelativeOrient itm cr (p1 + Q.rotate q1 (p `v2z` 0), q1 * Q.axisAngle (V3 0 0 1) a)
heldItemRelativeOrient ::
Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
heldItemRelativeOrient itm cr (p, q) heldItemRelativeOrient itm cr (p, q)
| Aiming{} <- _posture (_crStance cr) = | Aiming{} <- _posture (_crStance cr) =
(p + aimingWeaponZeroPos cr itm `v2z` shoulderHeight, Q.qID * q) (p + aimingWeaponZeroPos cr itm `v2z` shoulderHeight, Q.qID * q)
@@ -70,7 +57,9 @@ heldItemRelativeOrient itm cr (p, q)
sLen = _strideLength $ _crStance cr sLen = _strideLength $ _crStance cr
handleOrient :: LocationLDT ItemLink CItem -> Point3Q handleOrient :: LocationLDT ItemLink CItem -> Point3Q
handleOrient _ = (V3 (-3) 0 0, Q.qID) handleOrient loc = case loc ^. locLDT . ldtValue . _1 . itType of
HELD FLAMETHROWER -> (V3 (-1) 0 0, Q.qID)
_ -> (V3 (-3) 0 0, Q.qID)
-- note this is relative to the creature -- note this is relative to the creature
handOrient :: Creature -> AimStance -> Point3Q handOrient :: Creature -> AimStance -> Point3Q
@@ -93,8 +82,10 @@ handOrient cr = case cr ^. crStance . posture of
sLen = _strideLength $ _crStance cr sLen = _strideLength $ _crStance cr
locOrient :: LocationLDT ItemLink OItem -> Creature -> Point3Q locOrient :: LocationLDT ItemLink OItem -> Creature -> Point3Q
locOrient loc cr = handHandleOrient (fmap (\(x,y,_) -> (x,y)) loc) cr `Q.comp` locOrient loc cr =
(loc ^. locLDT . ldtValue . _3) handHandleOrient (fmap (\(x, y, _) -> (x, y)) loc) cr
`Q.comp` (loc ^. locLDT . ldtValue . _3)
-- heldItemRelativeOrient -- heldItemRelativeOrient
-- (locToTop loc ^. locLDT . ldtValue . _1) -- (locToTop loc ^. locLDT . ldtValue . _1)
-- cr -- cr