Improve creature turning wrt inertia

This commit is contained in:
2026-04-27 22:23:39 +01:00
parent f4c59612ea
commit 259325f81f
10 changed files with 206 additions and 160 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ beeCrit =
defaultCreature
& crName .~ "beeCrit"
& crHP .~ HP 100
& crType .~ BeeCrit 0 Nothing 0 0
& crType .~ BeeCrit 0 Nothing 0 0 0
& crFaction .~ ColorFaction yellow
& crStance . carriage .~ Flying 15
+1 -1
View File
@@ -74,7 +74,7 @@ followImpulse cid w = \case
MvForward -> crup $ crMvForward' (w ^. cWorld . lWorld)
MvTurnToward p ->
crup $
creatureTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir))
mvTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir))
where
clens = cWorld . lWorld . creatures . ix cid
cr = w ^?! cWorld . lWorld . creatures . ix cid
+22
View File
@@ -8,8 +8,10 @@ module Dodge.Creature.Impulse.Movement (
crMvForward,
crMvForward',
creatureTurnTo,
mvTurnToward,
) where
import Dodge.Creature.State.WalkCycle
import Dodge.Creature.MoveType
import Linear
import Control.Lens
@@ -117,3 +119,23 @@ creatureTurnToward p turnSpeed cr
where
vToTarg = p -.- cr ^. crPos . _xy
dirToTarget = argV vToTarg
mvTurnToward :: Point2 -> Float -> Creature -> Creature
mvTurnToward p' turnSpeed cr
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
-- | errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed =
| angleVV vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed =
cr & crDir .~ dirToTarget
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed
| otherwise = cr & crDir -~ turnSpeed
where
-- when flying, inertia is high enough that overturning can be usefull
p | Flying {} <- cr ^. crStance . carriage
= let v = flyInertia cr *^ (cr ^. crOldPos . _xy - cr ^. crOldOldPos . _xy)
-- u = normalize $ vNormal $ p' - cxy
--in p' - dot v u *^ u
in p' - v
| otherwise = p'
cxy = cr ^. crPos . _xy
vToTarg = p -.- cr ^. crPos . _xy
dirToTarget = argV vToTarg
+3 -1
View File
@@ -1,7 +1,9 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.State.WalkCycle (updateCarriage
,compressionScale) where
,compressionScale
, flyInertia
) where
import qualified Quaternion as Q
import Dodge.Creature.Radius
+12 -5
View File
@@ -133,12 +133,19 @@ isAnimate :: Creature -> Bool
{-# INLINE isAnimate #-}
isAnimate cr = case _crActionPlan cr of
Inanimate -> False
SlimeIntelligence -> False
SlimeIntelligence -> True
ActionPlan{} -> True
hasAutoDoorBody :: Creature -> Bool
hasAutoDoorBody cr = case cr ^. crHP of
HP {} -> True
CrIsCorpse {} -> True
CrDestroyed {} -> False
hasAutoDoorBody cr = crittype && notdestroyed
where
notdestroyed = case cr ^. crHP of
HP {} -> True
CrIsCorpse {} -> True
CrDestroyed {} -> False
crittype = case cr ^. crType of
SlimeCrit {} -> False
BeeCrit {} -> False
HiveCrit {} -> False
_ -> True
+16 -2
View File
@@ -3,9 +3,10 @@
module Dodge.Creature.Update (updateCreature) where
--import Dodge.WorldEvent.ThingsHit
import Dodge.Creature.Radius
import Dodge.Creature.MoveType
import Dodge.Base.Collide
import Data.List (sortOn)
import Dodge.Creature.Radius
import Dodge.Zoning.Creature
import Dodge.Creature.ChaseCrit
import Dodge.Creature.Damage
@@ -96,7 +97,7 @@ updateHiveCrit cr cid w
& tocr . crType . hiveGestation %~ (max 0 . subtract 1)
| otherwise = w
where
nbees = 10
nbees = 50
tocr = cWorld . lWorld . creatures . ix cid
nid = IM.newKey $ w ^. cWorld . lWorld . creatures
ncr = beeCrit & crPos .~ (cr ^. crPos + (0 & _xy +~ 25))
@@ -117,11 +118,24 @@ updateBeeCrit cr
updateAggroBee :: Creature -> Int -> World -> World
updateAggroBee cr cid w
| Mounted{} <- cr ^. crStance . carriage = w & tocr . crStance . carriage .~ Flying 0
| Just tcr <- listToMaybe . sortOn (distance cxy . (^. crPos . _xy)) . IM.elems . IM.filter istarget $ crsNearCirc cxy 100 w
, distance (tcr ^. crPos . _xy) (cr ^. crPos . _xy) < crRad (cr ^. crType) + crRad (tcr ^. crType) + 1
, nearZeroAngle (argV (tcr ^. crPos . _xy - cr ^. crPos . _xy) - cr ^. crDir) < pi / 2
, 0 <- cr ^?! crType . meleeCooldown
= w & tocr . crPos .~ (cr ^. crOldPos & _xy -~ 5 *^ unitVectorAtAngle (cr ^. crDir))
& tocr . crType . startStopMv .~ (cr ^?! to crMvType . mvPulseTime)
& cWorld . lWorld . creatures . ix (tcr ^. crID) . crDamage
.:~ Blunt 50 (cxy + crRad (cr ^. crType) *^ vdir) vdir (CrMeleeO (cr ^. crID))
& tocr . crType . meleeCooldown .~ 20
| Just tcr <- listToMaybe . sortOn (distance cxy . (^. crPos . _xy)) . IM.elems . IM.filter istarget $ crsNearCirc cxy 100 w = w & tocr . crActionPlan . apStrategy .~ CloseToMelee (tcr ^. crID)
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
| otherwise = w & tocr . crType . beeAggro -~ 1
& tocr . crActionPlan . apStrategy .~ Search
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
where
vdir = unitVectorAtAngle (cr ^. crDir)
cxy = cr ^. crPos . _xy
tocr = cWorld . lWorld . creatures . ix cid
istarget tcr = tcr ^. crID == 0
+1
View File
@@ -85,6 +85,7 @@ data CreatureType
, _beeHive :: Maybe Int
, _startStopMv :: Int
, _beeAggro :: Int
, _meleeCooldown :: Int
}
| HiveCrit
{ _hiveChildren :: IS.IntSet
+2 -4
View File
@@ -35,6 +35,7 @@ import NewInt
import RandomHelp
import qualified SDL
import ShortShow
import qualified Data.IntSet as IS
tocrs :: (IM.IntMap Creature
-> Const (Endo [String]) (IM.IntMap Creature))
@@ -42,10 +43,7 @@ tocrs :: (IM.IntMap Creature
tocrs = uvWorld . cWorld . lWorld . creatures
testStringInit :: Universe -> [String]
testStringInit u = u ^.. tocrs . ix 2 . crType . hiveChildren . to show
<> u ^.. tocrs . ix 3 . crStance . carriage . to show
<> u ^.. tocrs . ix 3 . crDir . to show
<> u ^.. tocrs . ix 3 . crActionPlan . apAction . to show
testStringInit u = u ^.. tocrs . ix 2 . crType . hiveChildren . to IS.size . to show
-- u ^.. tocrs . ix 1 . crPos . _xy . to show
-- <> u ^.. tocrs . ix 1 . crType . slimeCompression . to show
-- <> u ^.. tocrs . ix 1 . crType . slimeCompression . to norm . to show
+1 -1
View File
@@ -785,7 +785,7 @@ updateBeePheremone bp
| x <- bp ^. bpTimer
, x <= 0 = Nothing
| otherwise = Just $ bp & bpTimer -~ 1
& bpVel *~ 0.95
& bpVel *~ 0.90
& bpPos +~ (bp ^. bpVel)
updateDusts :: World -> World