Work on bee movement

This commit is contained in:
2026-05-02 22:08:06 +01:00
parent b827827951
commit aef3671063
4 changed files with 27 additions and 12 deletions
+22 -9
View File
@@ -116,7 +116,7 @@ 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
| Just tcr <- atarget
, 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
@@ -125,16 +125,18 @@ updateAggroBee cr cid w
& 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)
| Just tcr <- atarget = w & tocr . crActionPlan . apStrategy .~ CloseToMelee (tcr ^. crID)
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
| Just PathTo{} <- cr ^? crActionPlan . apAction = w & tocr . crType . beeAggro -~ 1
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
| otherwise = w & tocr . crType . beeAggro -~ 1
& tocr . crActionPlan . apStrategy .~ Search
& tocr . crActionPlan . apAction .~ PathTo (cxy + p) NoAction
& tocr . crType . meleeCooldown %~ (max 0 . subtract 1)
& randGen .~ g
where
(p,g) = runState (randOnCirc 150) (w ^. randGen)
atarget = listToMaybe . sortOn (distance cxy . (^.crPos._xy)) . IM.elems . IM.filter istarget $ crsNearCirc cxy 100 w
vdir = unitVectorAtAngle (cr ^. crDir)
cxy = cr ^. crPos . _xy
tocr = cWorld . lWorld . creatures . ix cid
@@ -154,21 +156,27 @@ updateCalmBee cr cid w
| Just hcr <- gethive
, distance (cr ^. crPos . _xy) (hcr ^. crPos . _xy) < 30
, Just x <- cr ^? crType . beeSlime
, x >= 0.5
= w & tocr . crType . beeSlime -~ 0.5
, x >= 0.5 = w & tocr . crType . beeSlime -~ 0.5
| Just x <- cr ^? crType . beeSlime
, x < 0.5
, Just ReturnToHive <- cr ^? crActionPlan . apStrategy
= w & tocr . crActionPlan . apAction .~ NoAction
| Just hcr <- gethive
, Just _ <- cr ^? crStance . carriage . mountID
, Just x <- cr ^? crType . beeSlime
, x >= 15
= w & tocr . crActionPlan . apAction .~ PathTo (hcr ^. crPos . _xy) NoAction
& 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 . crActionPlan . apStrategy .~ Search
& tocr . crStance . carriage .~ Flying 0
& tocr . crActionPlan . apStrategy .~ Search
| Just hcr <- gethive
, Just x <- cr ^? crType . beeSlime
, x >= 15
= w & tocr . crActionPlan . apAction .~ PathTo (hcr ^. crPos . _xy) NoAction
& tocr . crActionPlan . apStrategy .~ ReturnToHive
| Nothing <- cr ^? crActionPlan . apStrategy . harvestTarget
, Just tcr <- listToMaybe . sortOn (distance cxy . (^. crPos . _xy)) . IM.elems . IM.filter istarget $ crsNearCirc cxy 100 w =
w & tocr . crActionPlan . apStrategy .~ HarvestFrom (tcr ^. crID)
@@ -177,7 +185,7 @@ updateCalmBee cr cid w
& tocr . crType . beeSlime +~ sspeed
& cWorld . lWorld . creatures . ix tid . crType . slimeRad %~ (sqrt . subtract sspeed . (^(2::Int)))
| Just (tcr,ti) <- gettarg
, distance (cr ^. crPos . _xy) (tcr ^. crPos . _xy) < 0.9*crRad (tcr ^. crType)
, distance (cr ^. crPos . _xy) (tcr ^. crPos . _xy) < 0.8*crRad (tcr ^. crType)
, Just r <- tcr ^? crType . slimeRad
, Just d <- tcr ^? crType . slimeCompression
= w
@@ -185,8 +193,13 @@ updateCalmBee cr cid w
& tocr . crActionPlan . apAction .~ NoAction
| Just (tcr,_) <- gettarg = w
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
| otherwise = w & tocr . crActionPlan . apStrategy .~ Search
| Just PathTo{} <- cr ^? crActionPlan . apAction = w
| otherwise = w
& tocr . crActionPlan . apAction .~ PathTo (cxy + p) NoAction
& randGen .~ g
& tocr . crActionPlan . apStrategy .~ Search
where
(p,g) = runState (randOnCirc 150) (w ^. randGen)
cxy = cr ^. crPos . _xy
mountshakeoff mid = fromMaybe True $ do
mcr <- w ^? cWorld . lWorld . creatures . ix mid
+2
View File
@@ -151,7 +151,9 @@ data Strategy
| Flee
-- | MeleeStrike
| Search
| ReturnToHive
| HarvestFrom {_harvestTarget :: Int}
| StrategyInt {_strategyInt :: Int}
deriving (Eq, Ord, Show) --Generic, Flat)
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
+2 -2
View File
@@ -377,8 +377,8 @@ chasmSpitTerminal = do
return $
tToBTree "chasmTerm" $
Node
(addDoorToggleTerminal' i1 (PS 150 0) y'
& rmPmnts .:~ (sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 150 100)
(addDoorToggleTerminal' i1 (PS 150 0) y'
-- & rmPmnts .:~ (sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 150 100)
)
[ treePost [triggerDoorRoom i1, deadEndPSType cr]
, treePost [triggerDoorRoom i1, deadEndPSType cr]
+1 -1
View File
@@ -43,7 +43,7 @@ tocrs :: (IM.IntMap Creature
tocrs = uvWorld . cWorld . lWorld . creatures
testStringInit :: Universe -> [String]
testStringInit u = u ^.. tocrs . ix 2 . crType . hiveChildren . to IS.size . to show
testStringInit u = 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