Tweak melee movement
This commit is contained in:
@@ -25,7 +25,7 @@ import Linear
|
||||
-- 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)))
|
||||
UpdateRandGen -> w & randGen %~ (snd . randomR (0::Int,1))
|
||||
ImpulseNothing -> w
|
||||
RandomImpulse rimp ->
|
||||
let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w)
|
||||
@@ -43,11 +43,8 @@ followImpulse cid w = \case
|
||||
ChangePosture post -> crup $ crStance . posture .~ post
|
||||
UseItem -> undefined
|
||||
-- SwitchToItem i -> crup $ crManipulation . manObject .~ SelectedItem (NInt i) (NInt i) mempty
|
||||
Melee cid' ->
|
||||
hitCr cid' $
|
||||
crup
|
||||
( crMvAbsolute (w ^. cWorld . lWorld) (10 *.* normalizeV (posFromID cid' -.- cpos)) . (crType . meleeCooldown .~ 20)
|
||||
)
|
||||
Melee tid ->
|
||||
hitCr tid $ crup $ meleeMovement w tid . (crType . meleeCooldown .~ 20)
|
||||
MeleeL cid' ->
|
||||
hitCrd (-pi/2) cid' $
|
||||
crup
|
||||
@@ -100,6 +97,16 @@ followImpulse cid w = \case
|
||||
, Inertial 0 (posFromID i) (50 * unitVectorAtAngle (cr ^. crDir + a)) (CrMeleeO cid)
|
||||
]
|
||||
|
||||
meleeMovement :: World -> Int -> Creature -> Creature
|
||||
meleeMovement w tid cr = case cr ^. crType of
|
||||
HoverCrit {} -> fromMaybe cr $ do
|
||||
txy <- w ^? cWorld . lWorld . creatures . ix tid . crPos . _xy
|
||||
return $ crMvAbsolute (w ^. cWorld . lWorld) (5 *^ normalizeV (cr ^. crPos . _xy - txy)) cr
|
||||
ChaseCrit {} -> fromMaybe cr $ do
|
||||
txy <- w ^? cWorld . lWorld . creatures . ix tid . crPos . _xy
|
||||
return $ crMvAbsolute (w ^. cWorld . lWorld) (5 *^ normalizeV (txy - cr ^. crPos . _xy)) cr
|
||||
_ -> cr
|
||||
|
||||
setBeeRandomMovement :: Int -> World -> World
|
||||
setBeeRandomMovement cid w = fromMaybe w $ do
|
||||
mff <- w ^? cWorld . lWorld . creatures . ix cid . crType . beeRandomMovement
|
||||
|
||||
@@ -28,20 +28,12 @@ p is the movement translation vector, will be made relative to creature directio
|
||||
crMvBy :: Point2 -> LWorld -> Creature -> Creature
|
||||
crMvBy p lw cr = crMvAbsolute lw (rotateV (_crDir cr) p) cr
|
||||
|
||||
crWalk ::
|
||||
-- | Movement translation vector, will be made relative to creature direction
|
||||
Point2 ->
|
||||
LWorld ->
|
||||
Creature ->
|
||||
Creature
|
||||
-- | p is the movement translation vector, made relative to creature direction
|
||||
crWalk :: Point2 -> LWorld -> Creature -> Creature
|
||||
crWalk p lw cr = crWalkAbsolute lw (rotateV (_crDir cr) p) cr
|
||||
|
||||
crMvByNoStride ::
|
||||
-- | Movement translation vector, will be made relative to creature direction
|
||||
Point2 ->
|
||||
LWorld ->
|
||||
Creature ->
|
||||
Creature
|
||||
-- | p is the movement translation vector, made relative to creature direction
|
||||
crMvByNoStride :: Point2 -> LWorld -> Creature -> Creature
|
||||
crMvByNoStride p lw cr = crMvAbsoluteNoStride lw (rotateV (_crDir cr) p) cr
|
||||
|
||||
crMvAbsolute :: LWorld -> Point2 -> Creature -> Creature
|
||||
@@ -50,7 +42,7 @@ crMvAbsolute lw p' cr =
|
||||
& crPos . _xy +~ p
|
||||
& crMvDir .~ argV (p + cr ^. crOldPos . _xy - cr ^. crOldOldPos . _xy)
|
||||
where
|
||||
p = strengthFactor (getCrMoveSpeed lw cr) *.* p'
|
||||
p = strengthFactor (getCrMoveSpeed lw cr) *^ p'
|
||||
|
||||
crWalkAbsolute :: LWorld -> Point2 -> Creature -> Creature
|
||||
crWalkAbsolute lw p' cr
|
||||
|
||||
@@ -132,14 +132,10 @@ decreaseAwareness (Cognizant 0) = Just $ Suspicious 1000
|
||||
decreaseAwareness (Cognizant x) = Just $ Cognizant $ x - 50
|
||||
|
||||
{- | Given a fixed group of creatures, direct attention to those of them that
|
||||
- are in view.
|
||||
are in view.
|
||||
The ints are ids of creatures that may attract this creature's attention
|
||||
-}
|
||||
basicAttentionUpdate ::
|
||||
-- | Creatures that may attract this creature's attention
|
||||
[Int] ->
|
||||
World ->
|
||||
Creature ->
|
||||
Creature
|
||||
basicAttentionUpdate :: [Int] -> World -> Creature -> Creature
|
||||
basicAttentionUpdate cids w cr =
|
||||
cr & crPerception . cpAttention
|
||||
.~ AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||
|
||||
@@ -45,7 +45,7 @@ tryMeleeAttack cr tcr
|
||||
| _meleeCooldown (_crType cr) == 0
|
||||
&& Just (_crID tcr) == cr ^? crActionPlan . apStrategy . meleeTarget
|
||||
&& dist tpos cpos < crRad (cr ^. crType) + crRad (tcr ^. crType) + 5
|
||||
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4 =
|
||||
&& abs (_crDir cr - argV (tpos - cpos)) < pi / 4 =
|
||||
cr & crActionPlan . apAction
|
||||
.~ DoImpulses [Melee $ _crID tcr] `DoActionThen`
|
||||
DoReplicate 10 NoAction
|
||||
|
||||
@@ -70,9 +70,8 @@ updateLivingCreature cr = case cr ^. crType of
|
||||
CrabCrit{} -> crUpdate cid . performActions cid . crabCritInternal cid
|
||||
AutoCrit{} -> crUpdate cid
|
||||
SwarmCrit{} -> crUpdate cid
|
||||
HoverCrit{} -> \w ->
|
||||
crUpdate cid . performActions cid . hoverCritHoverSound cr $
|
||||
over (cWorld . lWorld . creatures . ix cid) (hoverCritInternal w) w
|
||||
HoverCrit{} -> crUpdate cid . performActions cid . hoverCritHoverSound cr .
|
||||
updateHoverCrit cid
|
||||
SlinkCrit{} -> slinkCritUpdate cid
|
||||
SlimeCrit{} -> slimeCritUpdate cid
|
||||
BeeCrit{} -> crUpdate cid . performActions cid . updateBeeFromPheremones cr cid . updateBeeCrit cr cid
|
||||
@@ -151,6 +150,9 @@ updateAggroBee cr cid w
|
||||
|
||||
-- do bees need to be able to see slime targets?
|
||||
-- if no path can be made, reset harvest action
|
||||
-- this should all be simplified
|
||||
-- should count how many are mounted on an individual slime, try for a different
|
||||
-- slime if too many
|
||||
updateCalmBee :: Creature -> Int -> World -> World
|
||||
updateCalmBee cr cid w
|
||||
| Just hcr <- gethive
|
||||
@@ -160,7 +162,7 @@ updateCalmBee cr cid w
|
||||
| Just x <- cr ^? crType . beeSlime
|
||||
, x < 0.5
|
||||
, Just ReturnToHive <- cr ^? crActionPlan . apStrategy
|
||||
= w & tocr . crActionPlan . apAction .~ NoAction
|
||||
= w & tocr . crActionPlan . apStrategy .~ Search
|
||||
| Just hcr <- gethive
|
||||
, Just _ <- cr ^? crStance . carriage . mountID
|
||||
, Just x <- cr ^? crType . beeSlime
|
||||
@@ -169,7 +171,7 @@ updateCalmBee cr cid w
|
||||
& tocr . crStance . carriage .~ Flying 0
|
||||
& tocr . crActionPlan . apStrategy .~ ReturnToHive
|
||||
| Just mid <- cr ^? crStance . carriage . mountID
|
||||
, mountshakeoff mid = w -- & tocr . crActionPlan . apStrategy .~ Search
|
||||
, mountshakeoff mid = w
|
||||
& tocr . crStance . carriage .~ Flying 0
|
||||
& tocr . crActionPlan . apStrategy .~ Search
|
||||
| Just hcr <- gethive
|
||||
@@ -193,11 +195,13 @@ updateCalmBee cr cid w
|
||||
& tocr . crActionPlan . apAction .~ NoAction
|
||||
| Just (tcr,_) <- gettarg = w
|
||||
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
|
||||
| Just (SearchTimed 0) <- cr ^? crActionPlan . apStrategy = w & tocr . crActionPlan . apStrategy .~ Search
|
||||
| Just PathTo{} <- cr ^? crActionPlan . apAction = w
|
||||
& tocr . crActionPlan . apStrategy . searchTimer %~ (max 0 . subtract 1)
|
||||
| otherwise = w
|
||||
& tocr . crActionPlan . apAction .~ PathTo (cxy + p) NoAction
|
||||
& randGen .~ g
|
||||
& tocr . crActionPlan . apStrategy .~ Search
|
||||
& randGen .~ g
|
||||
& tocr . crActionPlan . apStrategy .~ SearchTimed 200
|
||||
where
|
||||
(p,g) = runState (randOnCirc 150) (w ^. randGen)
|
||||
cxy = cr ^. crPos . _xy
|
||||
|
||||
@@ -151,6 +151,7 @@ data Strategy
|
||||
| Flee
|
||||
-- | MeleeStrike
|
||||
| Search
|
||||
| SearchTimed {_searchTimer :: Int}
|
||||
| ReturnToHive
|
||||
| HarvestFrom {_harvestTarget :: Int}
|
||||
| StrategyInt {_strategyInt :: Int}
|
||||
|
||||
+29
-34
@@ -1,35 +1,32 @@
|
||||
module Dodge.Humanoid (
|
||||
updateChaseCrit,
|
||||
crabCritInternal,
|
||||
hoverCritInternal,
|
||||
updateHoverCrit,
|
||||
) where
|
||||
|
||||
import Data.Foldable
|
||||
import Dodge.Creature
|
||||
import Dodge.Data.World
|
||||
import LensHelp
|
||||
|
||||
updateChaseCrit :: Int -> World -> World
|
||||
updateChaseCrit cid w =
|
||||
(tocr . crVocalization %~ updateVocTimer)
|
||||
. (tocr . crType . meleeCooldown %~ max 0 . subtract 1)
|
||||
. (tocr %~ searchIfDamaged)
|
||||
. (tocr %~ targetYouWhenCognizant w)
|
||||
. (tocr %~ perceptionUpdate [0] w)
|
||||
. (tocr %~ chaseCritMv w)
|
||||
. (tocr %~ setMvPosToTargetCr w)
|
||||
. (tocr %~ setViewPos w)
|
||||
. (tocr %~ overrideMeleeCloseTarget w)
|
||||
. (tocr %~ doStrategyActions)
|
||||
$ w
|
||||
updateChaseCrit cid w = w
|
||||
& (tocr %~ doStrategyActions)
|
||||
& (tocr %~ overrideMeleeCloseTarget w)
|
||||
& (tocr %~ setViewPos w)
|
||||
& (tocr %~ setMvPosToTargetCr w)
|
||||
& (tocr %~ chaseCritMv w)
|
||||
& (tocr %~ perceptionUpdate [0] w)
|
||||
& (tocr %~ targetYouWhenCognizant w)
|
||||
& (tocr %~ searchIfDamaged)
|
||||
& (tocr . crType . meleeCooldown %~ max 0 . subtract 1)
|
||||
& (tocr . crVocalization %~ updateVocTimer)
|
||||
where
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
|
||||
crabCritInternal :: Int -> World -> World
|
||||
crabCritInternal cid w =
|
||||
-- (crVocalization %~ updateVocTimer)
|
||||
(tocr %~ (crType . meleeCooldownL %~ max 0 . subtract 1))
|
||||
-- (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)
|
||||
@@ -38,27 +35,25 @@ crabCritInternal cid w =
|
||||
. crabActionUpdate cid
|
||||
. (tocr %~ setMvPosToTargetCr w)
|
||||
. (tocr %~ setViewPos w)
|
||||
-- . overrideMeleeCloseTarget w
|
||||
-- . overrideMeleeCloseTarget w
|
||||
$ (tocr %~ doStrategyActions) w
|
||||
where
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
hoverCritInternal :: World -> Creature -> Creature
|
||||
hoverCritInternal w cr =
|
||||
foldl'
|
||||
(\c f -> f w c)
|
||||
cr
|
||||
[ const doStrategyActions
|
||||
, overrideMeleeCloseTarget
|
||||
, setViewPos
|
||||
, setMvPosToTargetCr
|
||||
, hoverCritMv
|
||||
, perceptionUpdate [0]
|
||||
, targetYouWhenCognizant
|
||||
, const searchIfDamaged
|
||||
, const (crType . meleeCooldown %~ max 0 . subtract 1)
|
||||
, const (crVocalization %~ updateVocTimer)
|
||||
]
|
||||
updateHoverCrit :: Int -> World -> World
|
||||
updateHoverCrit cid w = w
|
||||
& tocr %~ doStrategyActions
|
||||
& tocr %~ overrideMeleeCloseTarget w
|
||||
& tocr %~ setViewPos w
|
||||
& tocr %~ setMvPosToTargetCr w
|
||||
& tocr %~ hoverCritMv w
|
||||
& tocr %~ perceptionUpdate [0] w
|
||||
& tocr %~ targetYouWhenCognizant w
|
||||
& tocr %~ searchIfDamaged
|
||||
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
|
||||
& tocr . crVocalization %~ updateVocTimer
|
||||
where
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
updateVocTimer :: Vocalization -> Vocalization
|
||||
updateVocTimer VocTimer{_vcTime = x, _vcMaxTime = y} | x < y = VocTimer (x + 1) y
|
||||
|
||||
@@ -43,7 +43,7 @@ tocrs :: (IM.IntMap Creature
|
||||
tocrs = uvWorld . cWorld . lWorld . creatures
|
||||
|
||||
testStringInit :: Universe -> [String]
|
||||
testStringInit u = u ^.. tocrs . each . crActionPlan . apStrategy . to show
|
||||
testStringInit _ = mempty -- u ^.. tocrs . each . crActionPlan . apStrategy . 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
|
||||
|
||||
Reference in New Issue
Block a user