Start refactoring hand/item handle orientation

This commit is contained in:
2025-07-05 11:50:25 +01:00
parent d8e811c050
commit 5ddfc83f09
4 changed files with 108 additions and 79 deletions
+28 -23
View File
@@ -128,7 +128,7 @@ heldEffectMuzzles :: LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles loc cr w =
setusetime . doHeldUseEffect t cr
. uncurry (applyCME (_ldtValue t ^. _1) cr)
. foldl' (useLoadedAmmo t cr) (False, w)
. foldl' (useLoadedAmmo loc cr) (False, w)
$ loadedmuzzles
where
t = loc ^. locLDT
@@ -680,8 +680,8 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
, Just (mz, usedammo, mag)
)
makeMuzzleFlare :: Muzzle -> LDTree ItemLink OItem -> Creature -> World -> World
makeMuzzleFlare mz itmtree cr = case mz ^. mzFlareType of
makeMuzzleFlare :: Muzzle -> LocationLDT ItemLink OItem -> Creature -> World -> World
makeMuzzleFlare mz loc cr = case mz ^. mzFlareType of
NoFlare -> id
BasicFlare -> basicMuzFlare pos dir
NoLightFlare -> muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
@@ -690,12 +690,13 @@ makeMuzzleFlare mz itmtree cr = case mz ^. mzFlareType of
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
HeavySmokeFlare -> basicMuzFlare pos dir
LasGunFlare ->
flareCircleAt (getLaserColor $ fmap (^. _1) itmtree) 0.8 (pos `v2z` 20)
flareCircleAt (getLaserColor loc) 0.8 (pos `v2z` 20)
. ( cWorld . lWorld . lights
.:~ LSParam (pos `v2z` 10) 100 (xyzV4 $ getLaserColor $ fmap (^. _1) itmtree)
.:~ LSParam (pos `v2z` 10) 100 (xyzV4 $ getLaserColor loc)
)
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
@@ -735,7 +736,7 @@ getLaserPhaseV = const 1
getLaserDamage :: LDTree ItemLink Item -> LaserType
getLaserDamage = const (DamageLaser 11)
getLaserColor :: LDTree ItemLink Item -> Color
getLaserColor :: LocationLDT ItemLink OItem -> Color
getLaserColor = const yellow
basicMuzFlare :: Point2 -> Float -> World -> World
@@ -750,19 +751,19 @@ isAmmoIntLink i (AmmoInLink j _) = i == j
isAmmoIntLink _ _ = False
useLoadedAmmo ::
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
Creature ->
(Bool, World) ->
Maybe (Muzzle, Int, LDTree ItemLink OItem) ->
(Bool, World)
useLoadedAmmo _ _ (cme, w) Nothing = (cme, w)
useLoadedAmmo itmtree cr (_, w) (Just (mz, x, magtree)) = (,) True $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itmtree cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullets itmtree cr (mz, x, magtree) w
MuzzleLaser -> creatureShootLaser itmtree cr mz w
useLoadedAmmo loc cr (_, w) (Just (mz, x, magtree)) = (,) True $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz loc cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullets loc cr (mz, x, magtree) w
MuzzleLaser -> creatureShootLaser loc cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam cr w
MuzzleRLauncher -> createProjectileR itmtree magtree mz cr w
MuzzleRLauncher -> createProjectileR loc magtree mz cr w
MuzzleGLauncher ->
createProjectile
(itmtree ^. ldtValue . _3)
@@ -787,6 +788,7 @@ useLoadedAmmo itmtree cr (_, w) (Just (mz, x, magtree)) = (,) True $
MuzzleStopper -> useStopWatch (itm ^. _1) cr w
MuzzleScroller -> useTimeScrollGun (itm ^. _1) cr w
where
itmtree = loc ^. locLDT
mid = magtree ^? ldtValue . _1 . itLocation . ilInvID
itm = itmtree ^. ldtValue
@@ -853,12 +855,12 @@ tractorBeamAt pos outpos dir power =
d = unitVectorAtAngle dir * power
creatureShootLaser ::
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
Creature ->
Muzzle ->
World ->
World
creatureShootLaser itmtree cr mz w =
creatureShootLaser loc cr mz w =
w
& randGen .~ g
& shootLaser
@@ -867,8 +869,9 @@ creatureShootLaser itmtree cr mz w =
(getLaserPhaseV istree)
pos
dir
(getLaserColor istree)
(getLaserColor loc)
where
itmtree = loc ^. locLDT
istree = fmap (\(x, _, _) -> x) itmtree
itm = itmtree ^. ldtValue
(moff, mrot) = heldItemOrient2D' itm cr (_mzPos mz) (_mzRot mz)
@@ -964,18 +967,19 @@ magAmmoParams itm = case itm ^. itType of
-- _ -> 0
shootBullets ::
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
Creature ->
(Muzzle, Int, LDTree ItemLink OItem) ->
World ->
World
shootBullets itmtree cr (mz, x, magtree) w = fromMaybe w $ do
shootBullets loc cr (mz, x, magtree) w = fromMaybe w $ do
thebullet <- getBulletType $ fmap (^. _1) magtree
return $ foldl' (&) w (replicate x (shootBullet thebullet (itmtree ^. ldtValue . _1) cr mz))
return $ foldl' (&) w (replicate x (shootBullet thebullet loc cr mz))
shootBullet :: Bullet -> Item -> Creature -> Muzzle -> World -> World
shootBullet bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
shootBullet :: Bullet -> LocationLDT ItemLink OItem -> Creature -> Muzzle -> World -> World
shootBullet bu loc cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
where
itm = loc ^. locLDT . ldtValue . _1
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
@@ -1263,15 +1267,15 @@ determineProjectileTracking magtree itmtree =
return $ HomeUsingTargeting (targetingtree ^. ldtValue . itID)
createProjectileR ::
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
LDTree ItemLink OItem ->
Muzzle ->
Creature ->
World ->
World
createProjectileR itmtree magtree =
createProjectileR loc magtree =
createProjectile
(itmtree ^. ldtValue . _3)
(loc ^. locLDT . ldtValue . _3)
( Rocket
(determineProjectileTracking (fmap (^. _1) magtree) $ fmap (^. _1) itmtree)
smoke
@@ -1279,6 +1283,7 @@ createProjectileR itmtree magtree =
magtree
(getPJStabiliser $ fmap (^. _1) itmtree)
where
itmtree = loc ^. locLDT
smoke
| isJust $ lookup SmokeReducerLink (magtree ^. ldtLeft) = Just ReducedRocketSmoke
| otherwise = Nothing
+23
View File
@@ -71,6 +71,29 @@ heldItemRelativeOrient itm cr (p, q)
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
handleOrient :: LocationLDT ItemLink OItem -> Point3Q
handleOrient _ = (V3 3 0 0, Q.qID)
-- note this is relative to the creature
handOrient :: Creature -> AimStance -> Point3Q
handOrient cr = case cr ^. crStance . posture of
Aiming -> \case
TwoHandUnder -> (V3 1 0 shoulderHeight, Q.qID)
TwoHandOver -> (V3 0 0 shoulderHeight, Q.qID)
OneHand -> (V3 13 (-2) shoulderHeight, Q.qID)
TwoHandFlat -> (V3 13 0 shoulderHeight, Q.qID)
AtEase -> \case
OneHand -> (V3 (10 + walkhandp) (-7) 15, Q.qID)
TwoHandFlat -> (V3 10 0 15, Q.axisAngle (V3 0 0 1) $ twoFlatHRot cr)
TwoHandUnder -> (V3 10 0 15, Q.axisAngle (V3 0 0 1) (strideRot cr + 1.2))
TwoHandOver -> (V3 10 0 15, Q.axisAngle (V3 0 0 1) (strideRot cr + 1.2))
where
walkhandp = case cr ^? crStance . carriage of
Just (Walking x LeftForward) -> f x * 50 -2
_ -> - 2
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
locOrientation :: LocationLDT ItemLink OItem -> Creature -> Point3Q
locOrientation loc cr =
heldItemRelativeOrient
+3 -3
View File
@@ -242,9 +242,9 @@ heldPositionInfo = aimStanceInfo . itemBaseStance
aimStanceInfo :: AimStance -> String
aimStanceInfo as = case as of
TwoHandUnder -> "It is held in two hands and tucked under the shoulder."
TwoHandOver -> "It is held in two hands and over the shoulder."
TwoHandFlat -> "It is held in two hands at its sides."
TwoHandUnder -> "It is held using two hands, tucked under the shoulder."
TwoHandOver -> "It is held using two hands, resting over the shoulder."
TwoHandFlat -> "It is held using two hands in front of the body."
OneHand -> "It is held in one hand."
itmEquipSiteInfo :: Item -> String