Add randomness to multiple crab evasions
This commit is contained in:
@@ -106,7 +106,7 @@ tryEvadeSideways :: Creature -> World -> ActionUpdate
|
||||
tryEvadeSideways _ w = jumpleft -- (mv,mempty)
|
||||
where
|
||||
jumpleft = (mv,DoReplicate 5 (DoImpulses mv))
|
||||
mv = [Walk (V2 0 d)]
|
||||
mv = [Walk (V2 0 d),UpdateRandGen]
|
||||
d = evalState (takeOne [3,-3]) (w ^. randGen)
|
||||
|
||||
performAimAt :: Creature -> World -> Int -> Point2 -> ActionUpdate
|
||||
|
||||
@@ -41,8 +41,6 @@ crabCrit = defaultCreature
|
||||
& crType .~ CrabCrit
|
||||
{ _meleeCooldownL = 0
|
||||
, _meleeCooldownR = 0
|
||||
, _footForward = LeftForward
|
||||
, _strideAmount = 0
|
||||
, _dodgeCooldown = 0
|
||||
, _lFootPos = 0
|
||||
, _rFootPos = 0
|
||||
|
||||
@@ -23,6 +23,7 @@ import System.Random
|
||||
-- note SwitchToItem doesn't necessarily update the root item correctly
|
||||
followImpulse :: Int -> World -> Impulse -> World
|
||||
followImpulse cid w = \case
|
||||
UpdateRandGen -> w & randGen %~ (snd . (randomR (0::Int,0)))
|
||||
ImpulseNothing -> w
|
||||
RandomImpulse rimp ->
|
||||
let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w)
|
||||
|
||||
@@ -9,6 +9,7 @@ crMvType cr = case _crType cr of
|
||||
Avatar {} -> MvWalking 1.5
|
||||
ChaseCrit {} -> defaultChaseMvType & mvSpeed .~ 1.8
|
||||
CrabCrit {} -> defaultChaseMvType & mvSpeed .~ 0.5
|
||||
& mvTurnJit .~ 0.01
|
||||
HoverCrit {} -> defaultChaseMvType & mvSpeed .~ 0.16
|
||||
SwarmCrit -> defaultChaseMvType
|
||||
AutoCrit -> defaultAimMvType
|
||||
|
||||
@@ -85,12 +85,15 @@ drawChaseCrit w cr = mconcat
|
||||
|
||||
crabUpperBody :: World -> Creature -> Shape
|
||||
crabUpperBody _ cr = colorSH (_skinUpper cskin)
|
||||
$
|
||||
(overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI 5 $ polyCirc 4 12
|
||||
(
|
||||
overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI 5 $ polyCirc 4 10
|
||||
& each . _x *~ 0.6)
|
||||
)
|
||||
<> overPosSH (Q.apply lclawq) (upperPrismPolyHalfMI 4 $ rectNSWE 20 0 (-2) 2)
|
||||
<> overPosSH (Q.apply rclawq) (upperPrismPolyHalfMI 4 $ rectNSWE 0 (-20) (-2) 2)
|
||||
)
|
||||
<> colorSH (_skinHead cskin)
|
||||
--(overPosSH (Q.apply headq) (upperPrismPolyHalfMI 2 $ [V2 0 (-4), V2 2 (-2), 2, V2 0 4]))
|
||||
(overPosSH (Q.apply headq) (upperPrismPolyHalfMI 1 $ square 2))
|
||||
where
|
||||
-- i = fromIntegral (mod (w ^. cWorld . cClock) 100) / 100
|
||||
torsoq = (V3 0 0 10,Q.qid)
|
||||
@@ -104,6 +107,14 @@ crabUpperBody _ cr = colorSH (_skinUpper cskin)
|
||||
ratck = Q.axisAngle (V3 0 0 1) (0.5 * pi)
|
||||
rrest = Q.axisAngle (V3 1 0 0) (-1)
|
||||
rcool = 1 - min 10 (fromIntegral . _meleeCooldownR $ _crType cr) / 10
|
||||
headq = torsoq `Q.comp` (V3 0 0 5, Q.qid)
|
||||
-- headq = torsoq `Q.comp` (V3 0 0 5, (Q.qz aimrot ))
|
||||
-- cxy = cr ^. crPos . _xy
|
||||
-- aimrot = fromMaybe pi $ do
|
||||
-- i <- cr ^. crIntention . targetCr
|
||||
-- tcxy <- w ^? cWorld . lWorld . creatures . ix i . crPos . _xy
|
||||
-- guard $ hasLOSIndirect cxy tcxy w
|
||||
-- return $ argV (tcxy - cxy) - cr ^. crDir
|
||||
|
||||
|
||||
chaseUpperBody :: World -> Creature -> Shape
|
||||
@@ -178,12 +189,7 @@ crabFeet cr =
|
||||
f p q = q + 2 *^ (p - q)
|
||||
cdir = -cr ^. crDir
|
||||
cxy = cr ^. crPos . _xy
|
||||
-- sh x = translateSHxy x off aFoot <> translateSHxy (- x) (- off) aFoot
|
||||
afoot = upperPrismPolyST 10 $ polyCirc 3 2
|
||||
off = 10
|
||||
sLen = strideLength cr
|
||||
-- f i = 8 * (sLen - 2*i) / sLen
|
||||
-- f i = 8 * oneSmooth ((sLen - 2*i) / sLen)
|
||||
|
||||
deadFeet :: Creature -> Shape
|
||||
{-# INLINE deadFeet #-}
|
||||
|
||||
@@ -121,32 +121,33 @@ flockACC w cr = fromMaybe cr $ do
|
||||
else negate r *.* horDir
|
||||
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||
|
||||
crabActionUpdate :: World -> Creature -> Creature
|
||||
crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
|
||||
_ | Just tid <- meleel -> cr & crActionPlan . apAction
|
||||
crabActionUpdate :: Int -> World -> World
|
||||
crabActionUpdate cid w = case _apStrategy (_crActionPlan cr) of
|
||||
_ | Just tid <- meleel -> w & tocr . crActionPlan . apAction
|
||||
.~ DoImpulses [MeleeL tid] `DoActionThen`
|
||||
DoReplicate 10 NoAction
|
||||
-- & crType . meleeCooldownL .~ 20
|
||||
_ | Just tid <- meleer -> cr & crActionPlan . apAction
|
||||
_ | Just tid <- meleer -> w & tocr . crActionPlan . apAction
|
||||
.~ DoImpulses [MeleeR tid] `DoActionThen`
|
||||
DoReplicate 10 NoAction
|
||||
-- & crType . meleeCooldownR .~ 20
|
||||
WarningCry -> cr
|
||||
CloseToMelee tid | aimi tid -> cr & crActionPlan . apAction .~ EvadeAim
|
||||
& crType . dodgeCooldown .~ dc
|
||||
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
|
||||
WarningCry -> w
|
||||
CloseToMelee tid | aimi tid -> w & tocr . crActionPlan . apAction .~ EvadeAim
|
||||
& tocr . crType . dodgeCooldown .~ dc
|
||||
& randGen .~ g
|
||||
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> w
|
||||
Wander | Just tid <- cr ^? crIntention . targetCr . _Just
|
||||
, canSee tid (cr ^. crID) w -> cr & crActionPlan . apStrategy .~ CloseToMelee tid
|
||||
, canSee tid (cr ^. crID) w -> w & tocr . crActionPlan . apStrategy .~ CloseToMelee tid
|
||||
_ -> case cr ^? crIntention . mvToPoint . _Just of
|
||||
Just p
|
||||
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
|
||||
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
|
||||
w & tocr . crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
|
||||
| otherwise ->
|
||||
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||
& crActionPlan . apStrategy .~ Search
|
||||
& crIntention . mvToPoint .~ Nothing
|
||||
_ -> viewTarget w cr
|
||||
w & tocr . crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||
& tocr . crActionPlan . apStrategy .~ Search
|
||||
& tocr . crIntention . mvToPoint .~ Nothing
|
||||
_ -> w & tocr %~ viewTarget w
|
||||
where
|
||||
cr = w ^?! cWorld . lWorld . creatures . ix cid
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
meleel = do
|
||||
tid <- cr ^? crIntention . targetCr . _Just
|
||||
tcr <- w ^? cWorld . lWorld . creatures . ix tid
|
||||
@@ -171,8 +172,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
|
||||
&& (_crDir cr - argV (tpos -.- cpos)) >= 0
|
||||
&& cr ^?! crType . meleeCooldownL < 15
|
||||
return tid
|
||||
--dc = fst $ randomR (15,25) (w ^. randGen)
|
||||
dc = fst $ randomR (15,50) (w ^. randGen)
|
||||
(dc,g) = randomR (15,50) (w ^. randGen)
|
||||
notpath = \case
|
||||
Just NoAction -> False
|
||||
Just PathTo {} -> False
|
||||
@@ -180,6 +180,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
|
||||
_ -> True
|
||||
aimi tid = fromMaybe False $ do
|
||||
tcr <- w ^? cWorld . lWorld . creatures . ix tid
|
||||
hp <- cr ^? crHP . _HP
|
||||
Aiming <- tcr ^? crStance . posture
|
||||
let txy = tcr ^. crPos . _xy
|
||||
cxy = cr ^. crPos . _xy
|
||||
@@ -188,6 +189,7 @@ crabActionUpdate w cr = case _apStrategy (_crActionPlan cr) of
|
||||
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
|
||||
&& isWalkable txy cxy w
|
||||
&& diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1
|
||||
&& hp > 0
|
||||
|
||||
chaseCritMv :: World -> Creature -> Creature
|
||||
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
|
||||
|
||||
@@ -56,7 +56,7 @@ updateLivingCreature cr =
|
||||
over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
|
||||
CrabCrit{} -> \w ->
|
||||
crUpdate cid . performActions cid $
|
||||
over (cWorld . lWorld . creatures . ix cid) (crabCritInternal w) w
|
||||
(crabCritInternal cid) w
|
||||
AutoCrit {} -> crUpdate cid
|
||||
SwarmCrit {} -> crUpdate cid
|
||||
HoverCrit {} -> \w ->
|
||||
|
||||
@@ -47,6 +47,7 @@ data Impulse
|
||||
| AddGoal Goal
|
||||
| ImpulseUseTarget { _impulseUseTarget :: CrImp }
|
||||
| ImpulseNothing
|
||||
| UpdateRandGen
|
||||
deriving (Eq, Ord, Show) --Generic, Flat)
|
||||
|
||||
data RandImpulse
|
||||
|
||||
@@ -61,8 +61,6 @@ data CreatureType
|
||||
| CrabCrit
|
||||
{ _meleeCooldownL :: Int
|
||||
, _meleeCooldownR :: Int
|
||||
, _footForward :: FootForward
|
||||
, _strideAmount :: Float
|
||||
, _dodgeCooldown :: Int
|
||||
, _lFootPos :: Point2
|
||||
, _rFootPos :: Point2
|
||||
|
||||
@@ -13,6 +13,7 @@ data SoundOrigin
|
||||
| BackgroundSound
|
||||
| OnceSound
|
||||
| CrSound Int
|
||||
| CrFootSound Int Int
|
||||
| CrMouth Int
|
||||
| CrChasm Int
|
||||
| CrWeaponSound Int Int
|
||||
|
||||
+15
-13
@@ -26,20 +26,22 @@ chaseCritInternal w cr =
|
||||
, const (crVocalization %~ updateVocTimer)
|
||||
]
|
||||
|
||||
crabCritInternal :: World -> Creature -> Creature
|
||||
crabCritInternal w =
|
||||
(crVocalization %~ updateVocTimer)
|
||||
. (crType . meleeCooldownL %~ max 0 . subtract 1)
|
||||
. (crType . meleeCooldownR %~ max 0 . subtract 1)
|
||||
. (crType . dodgeCooldown %~ max 0 . subtract 1)
|
||||
. searchIfDamaged
|
||||
. targetYouWhenCognizant w
|
||||
. perceptionUpdate [0] w
|
||||
. crabActionUpdate w
|
||||
. setMvPosToTargetCr w
|
||||
. setViewPos w
|
||||
crabCritInternal :: Int -> World -> World
|
||||
crabCritInternal cid w =
|
||||
-- (crVocalization %~ updateVocTimer)
|
||||
(tocr %~ ((crType . meleeCooldownL %~ max 0 . subtract 1)))
|
||||
. (tocr %~ ((crType . meleeCooldownR %~ max 0 . subtract 1)))
|
||||
. (tocr %~ ((crType . dodgeCooldown %~ max 0 . subtract 1)))
|
||||
. (tocr %~ (searchIfDamaged))
|
||||
. (tocr %~ (targetYouWhenCognizant w))
|
||||
. (tocr %~ (perceptionUpdate [0] w))
|
||||
. crabActionUpdate cid
|
||||
. (tocr %~ (setMvPosToTargetCr w))
|
||||
. (tocr %~ (setViewPos w))
|
||||
-- . overrideMeleeCloseTarget w
|
||||
. doStrategyActions
|
||||
$ (tocr %~ doStrategyActions) w
|
||||
where
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
hoverCritInternal :: World -> Creature -> Creature
|
||||
hoverCritInternal w cr =
|
||||
|
||||
@@ -57,8 +57,8 @@ tutAnoTree = do
|
||||
foldMTRS
|
||||
[ tToBTree "TutStartRez" . return . cleatOnward <$> tutRezBox
|
||||
, corDoor
|
||||
-- , chasmSpitTerminal
|
||||
-- , corDoor
|
||||
, chasmSpitTerminal
|
||||
, corDoor
|
||||
, loadAmmoTut
|
||||
, corDoor
|
||||
, chasmSpitTerminal
|
||||
@@ -343,10 +343,10 @@ chasmSpitTerminal = do
|
||||
tToBTree "chasmTerm" $
|
||||
Node
|
||||
(addDoorToggleTerminal' i1 (PS 150 0) y')
|
||||
[ treePost [triggerDoorRoom i1, deadEndPSType (PutCrit chaseCrit)]
|
||||
[ treePost [triggerDoorRoom i1, deadEndPSType (PutCrit crabCrit)]
|
||||
--[ treePost [triggerDoorRoom i1, deadEndPSType (PutCrit hoverCrit)]
|
||||
--[ treePost [triggerDoorRoom i1, deadEndRoom]
|
||||
, treePost [triggerDoorRoom i1, deadEndPSType (PutCrit chaseCrit)]
|
||||
, treePost [triggerDoorRoom i1, deadEndPSType (PutCrit crabCrit)]
|
||||
, return $ cleatOnward $ triggerDoorRoom i1
|
||||
]
|
||||
where
|
||||
|
||||
+13
-9
@@ -371,20 +371,24 @@ muzzleWallCheck w cr = fromMaybe cr $ do
|
||||
_ -> Nothing
|
||||
|
||||
updateCreatureStrides :: World -> World
|
||||
updateCreatureStrides = cWorld . lWorld . creatures . each %~ updateCreatureStride
|
||||
updateCreatureStrides w = foldl' updateCreatureStride w (w ^. cWorld . lWorld . creatures)
|
||||
|
||||
updateCreatureStride :: Creature -> Creature
|
||||
updateCreatureStride cr
|
||||
updateCreatureStride :: World -> Creature -> World
|
||||
updateCreatureStride w cr
|
||||
| Walking <- cr ^. crStance . carriage
|
||||
, CrabCrit {} <- cr ^. crType
|
||||
= cr & crType . lFootPos %~ f (g 10)
|
||||
& crType . rFootPos %~ f (g (-10))
|
||||
= w & f (g 10) (cr ^?! crType . lFootPos) lFootPos
|
||||
& f (g (-10)) (cr ^?! crType . rFootPos) rFootPos
|
||||
| Walking <- cr ^. crStance . carriage
|
||||
, isJust $ cr ^? crType . strideAmount = cr & crType . strideAmount +~ d
|
||||
| otherwise = cr
|
||||
, isJust $ cr ^? crType . strideAmount = w & tocr . crType . strideAmount +~ d
|
||||
| otherwise = w
|
||||
where
|
||||
f p q | distance p q > 10 = p - 9 *^ signorm (q - p)
|
||||
| otherwise = q
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
cid = cr ^. crID
|
||||
f p q fp
|
||||
| distance p q > 10 = (tocr . crType . fp .~ (p - 9 *^ signorm (q - p)))
|
||||
. soundStart (CrFootSound cid 0) (p - 9 *^ signorm (q - p)) foot1S Nothing
|
||||
| otherwise = id
|
||||
g x = cr ^. crPos . _xy + x *^ vNormal (unitVectorAtAngle (cr ^. crDir))
|
||||
s = 2 * fromMaybe 1 (crMvType cr ^? mvSpeed)
|
||||
-- d = min s . norm $ cr ^. crPos - cr ^. crOldPos
|
||||
|
||||
Reference in New Issue
Block a user