Work on bee movement
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
module Dodge.Creature.Update (updateCreature) where
|
||||
|
||||
--import Dodge.WorldEvent.ThingsHit
|
||||
import Data.List (sortOn)
|
||||
import Dodge.Creature.Radius
|
||||
import Dodge.Zoning.Creature
|
||||
import Dodge.Creature.ChaseCrit
|
||||
@@ -37,6 +38,7 @@ import qualified Quaternion as Q
|
||||
import RandomHelp
|
||||
import Shape
|
||||
import ShapePicture.Data
|
||||
import qualified Data.IntSet as IS
|
||||
|
||||
-- Should separate out creature movement from other parts here
|
||||
-- allow for knockbacks etc to be determined as well as intended movements
|
||||
@@ -81,18 +83,19 @@ updateLivingCreature cr = case cr ^. crType of
|
||||
|
||||
updateHiveCrit :: Creature -> Int -> World -> World
|
||||
updateHiveCrit cr cid w
|
||||
| Just x <- cr ^? crType . hiveChildren . to length
|
||||
, x < 10
|
||||
| Just x <- cr ^? crType . hiveChildren . to IS.size
|
||||
, x < nbees
|
||||
, Just y <- cr ^? crType . hiveGestation
|
||||
, y == 0 = w
|
||||
& tocr . crType . hiveChildren .:~ nid
|
||||
& tocr . crType . hiveChildren %~ IS.insert nid
|
||||
& tocr . crType . hiveGestation .~ 50
|
||||
& cWorld . lWorld . creatures . at nid ?~ ncr
|
||||
| Just x <- cr ^? crType . hiveChildren . to length
|
||||
, x < 10 = w
|
||||
| Just x <- cr ^? crType . hiveChildren . to IS.size
|
||||
, x < nbees = w
|
||||
& tocr . crType . hiveGestation %~ (max 0 . subtract 1)
|
||||
| otherwise = w
|
||||
where
|
||||
nbees = 10
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
nid = IM.newKey $ w ^. cWorld . lWorld . creatures
|
||||
ncr = beeCrit & crPos .~ (cr ^. crPos + (0 & _xy +~ 25))
|
||||
@@ -107,32 +110,37 @@ updateBeeCrit cr cid w
|
||||
, x >= 0.5
|
||||
= w & tocr . crType . beeSlime -~ 0.5
|
||||
| Just hcr <- gethive
|
||||
, Just mid <- cr ^? crStance . carriage . mountID
|
||||
, Just _ <- cr ^? crStance . carriage . mountID
|
||||
, Just x <- cr ^? crType . beeSlime
|
||||
, x >= 15 || mountshakeoff mid
|
||||
, x >= 15
|
||||
= w & tocr . crActionPlan . apAction .~ PathTo (hcr ^. crPos . _xy) NoAction
|
||||
& tocr . crStance . carriage .~ Flying 0
|
||||
| Just mid <- cr ^? crStance . carriage . mountID
|
||||
, mountshakeoff mid = w & tocr . crActionPlan . apStrategy .~ Search
|
||||
& tocr . crStance . carriage .~ Flying 0
|
||||
| Just hcr <- gethive
|
||||
, Just x <- cr ^? crType . beeSlime
|
||||
, x >= 15
|
||||
= w & tocr . crActionPlan . apAction .~ PathTo (hcr ^. crPos . _xy) NoAction
|
||||
| Nothing <- cr ^? crActionPlan . apStrategy . harvestTarget
|
||||
, Just tcr <- find isslime $ crsNearCirc (cr ^. crPos . _xy) 100 w =
|
||||
, Just tcr <- listToMaybe . sortOn (distance cxy . (^. crPos . _xy)) . IM.elems . IM.filter istarget $ crsNearCirc (cr ^. crPos . _xy) 100 w =
|
||||
w & tocr . crActionPlan . apStrategy .~ HarvestFrom (tcr ^. crID)
|
||||
| Just (tcr,ti) <- gettarg
|
||||
, distance (cr ^. crPos . _xy) (tcr ^. crPos . _xy) < 0.5*crRad (tcr ^. crType)
|
||||
, Just r <- tcr ^? crType . slimeRad
|
||||
, Just d <- tcr ^? crType . slimeCompression
|
||||
= w
|
||||
& tocr . crStance . carriage .~ Mounted ti (cr ^. crPos - tcr ^. crPos & _xy %~ compressionScale (vNormal ((1/r) *^d)))
|
||||
| Just tid <- cr ^? crStance . carriage . mountID
|
||||
, Just SlimeCrit{} <- w ^? cWorld . lWorld . creatures . ix tid . crType = 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)
|
||||
, Just r <- tcr ^? crType . slimeRad
|
||||
, Just d <- tcr ^? crType . slimeCompression
|
||||
= w
|
||||
& tocr . crStance . carriage .~ Mounted ti (cr ^. crPos - tcr ^. crPos & _xy %~ compressionScale (vNormal ((1/r) *^d)))
|
||||
& tocr . crActionPlan . apAction .~ NoAction
|
||||
| Just (tcr,_) <- gettarg = w
|
||||
& tocr . crActionPlan . apAction .~ PathTo (tcr ^. crPos . _xy) NoAction
|
||||
| otherwise = w & tocr . crActionPlan . apStrategy .~ Search
|
||||
where
|
||||
cxy = cr ^. crPos . _xy
|
||||
mountshakeoff mid = fromMaybe True $ do
|
||||
mcr <- w ^? cWorld . lWorld . creatures . ix mid
|
||||
SlimeCrit {_slimeSplitTimer = x} <- mcr ^? crType
|
||||
@@ -148,9 +156,9 @@ updateBeeCrit cr cid w
|
||||
i <- cr ^? crType . beeHive . _Just
|
||||
w ^? cWorld . lWorld . creatures . ix i
|
||||
tocr = cWorld . lWorld . creatures . ix cid
|
||||
isslime tcr = case tcr ^. crType of
|
||||
SlimeCrit {} -> True
|
||||
_ -> False
|
||||
istarget tcr = fromMaybe False $ do
|
||||
r <- tcr ^? crType . slimeRad
|
||||
return $ r > 12
|
||||
|
||||
slimeCritUpdate :: Int -> World -> World
|
||||
slimeCritUpdate cid w
|
||||
@@ -323,11 +331,19 @@ checkDeath' cr w = case cr ^. crHP of
|
||||
& dropAll cr -- the order of these is possibly important
|
||||
& stopSoundFrom (CrWeaponSound (_crID cr) 0)
|
||||
& corpseOrGib cr
|
||||
& crEffectsOnDeath cr
|
||||
& tocr . crStance . carriage %~ toDeathCarriage
|
||||
_ -> w
|
||||
where
|
||||
tocr = cWorld . lWorld . creatures . ix (_crID cr)
|
||||
|
||||
crEffectsOnDeath :: Creature -> World -> World
|
||||
crEffectsOnDeath cr w = case cr ^. crType of
|
||||
BeeCrit {_beeHive = mhid} -> fromMaybe w $ do
|
||||
hid <- mhid
|
||||
return $ w & cWorld . lWorld . creatures . ix hid . crType . hiveChildren %~ IS.delete (cr ^. crID)
|
||||
_ -> w
|
||||
|
||||
startDeathTimer :: Creature -> Creature
|
||||
startDeathTimer cr = cr & crDeathTimer ?~ case cr ^. crType of
|
||||
HoverCrit{} -> 0
|
||||
|
||||
Reference in New Issue
Block a user