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