From 60e5e6ecae7859db3ab7c9fc6067fc4063469d8e Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 1 May 2023 14:01:27 +0100 Subject: [PATCH] Add extra warning cries to chaseCrits --- src/Dodge/Bullet.hs | 2 -- src/Dodge/Creature/ChaseCrit.hs | 2 +- src/Dodge/Creature/Impulse.hs | 4 ++-- src/Dodge/Creature/Perception.hs | 2 +- src/Dodge/Creature/ReaderUpdate.hs | 18 +++++++++++++++--- src/Dodge/Creature/Vocalization.hs | 11 +++++++---- src/Dodge/Data/Creature/Misc.hs | 2 +- src/Dodge/Debug.hs | 2 ++ src/Dodge/Default/Item/Use/Consumption.hs | 2 +- src/Dodge/Humanoid.hs | 1 + src/Dodge/Item/Held/Rod.hs | 2 +- src/Dodge/Item/Weapon/Bullet.hs | 12 ++++++------ src/Dodge/Path.hs | 1 - src/Dodge/Update.hs | 2 +- 14 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/Dodge/Bullet.hs b/src/Dodge/Bullet.hs index e25f0514f..4f03727bf 100644 --- a/src/Dodge/Bullet.hs +++ b/src/Dodge/Bullet.hs @@ -29,8 +29,6 @@ updateBullet w bu = case _buDelayFraction bu of mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet) mvBullet x w bu --- | magV (_buVel bu) < 1 = (w, Nothing) --- | _buTimer bu <= 0 = (endspawn w, Nothing) | magV (_buVel bu) < 1 || _buTimer bu <= 0 = (endspawn w, Nothing) | otherwise = second (fmap updateBulVel) diff --git a/src/Dodge/Creature/ChaseCrit.hs b/src/Dodge/Creature/ChaseCrit.hs index dbd328849..8de24e666 100644 --- a/src/Dodge/Creature/ChaseCrit.hs +++ b/src/Dodge/Creature/ChaseCrit.hs @@ -56,5 +56,5 @@ chaseCritVocalization = , seagullCry1S , seagullCry2S ] - 50 + (50,100) 0 diff --git a/src/Dodge/Creature/Impulse.hs b/src/Dodge/Creature/Impulse.hs index db633f076..fe2d40318 100644 --- a/src/Dodge/Creature/Impulse.hs +++ b/src/Dodge/Creature/Impulse.hs @@ -39,7 +39,7 @@ followImpulse cr w imp = case imp of RandomImpulse rimp -> let (newimp, newgen) = runState (doRandImpulse rimp) (_randGen w) in first ((randGen .~ newgen) .) $ followImpulse cr w newimp - Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown cr) + Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown w cr) Move p -> crup $ crMvBy p cr MoveForward x -> crup $ crMvForward x cr Turn a -> crup $ creatureTurn a cr @@ -83,6 +83,6 @@ followImpulse cr w imp = case imp of rr a = randomR (- a, a) $ _randGen w hitCr i = ( cWorld . lWorld . creatures . ix i . crState . csDamage - .:~ Damage BLUNT 100 cpos (posFromID i) (posFromID i) (PushBackDamage 3) + .:~ Damage BLUNT 100 cpos (posFromID i) (posFromID i) (PushBackDamage 5) ) . soundStart (CrSound cid) cpos hitS Nothing diff --git a/src/Dodge/Creature/Perception.hs b/src/Dodge/Creature/Perception.hs index c8b5161db..8214b9093 100644 --- a/src/Dodge/Creature/Perception.hs +++ b/src/Dodge/Creature/Perception.hs @@ -80,7 +80,7 @@ chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of oldAwareness = _cpAwareness $ _crPerception cr newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness - thejitter = RandImpulseCircMove 2 + thejitter = RandImpulseCircMove 3 maybeBark | becomesCognizant -- && randBool && cr ^? crVocalization . vcCoolDown == Just 0 = diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index b339bfb48..98670fd4c 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -14,12 +14,13 @@ module Dodge.Creature.ReaderUpdate ( setViewPos, ) where +import RandomHelp import Dodge.Creature.Perception import qualified IntMapHelp as IM import Data.List (sortOn) import Control.Applicative -import Control.Lens -import Control.Monad +import LensHelp +--import Control.Monad import Data.Bifunctor import Data.Maybe import Dodge.Base @@ -114,11 +115,22 @@ chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of StrategyActions _ _ -> cr WarningCry -> cr MeleeStrike -> cr + CloseToMelee cid | Just 0 == (cr ^? crVocalization . vcCoolDown) + -> cr & crActionPlan . apAction + .:~ ImpulsesList ( [Bark soundid] : replicate numjits [RandomImpulse thejitter] + ++ [[ChangeStrategy (CloseToMelee cid)]]) + & crVocalization . vcCoolDown .~ 10 + & crActionPlan . apStrategy .~ WarningCry + where + thejitter = RandImpulseCircMove 3 + soundid = evalState (takeOne (_vcWarnings (_crVocalization cr))) (_randGen w) + numjits = fst $ randomR (15, 25) (_randGen w) _ -> case cr ^? crIntention . mvToPoint . _Just of Just p | dist (_crPos cr) p > _crRad cr -> cr & crActionPlan . apAction .~ [PathTo p] | otherwise -> - cr & crActionPlan . apAction .~ [bfsThenReturn 500] + cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]] + & crActionPlan . apStrategy .~ WatchAndWait & crIntention . mvToPoint .~ Nothing _ -> viewTarget w cr diff --git a/src/Dodge/Creature/Vocalization.hs b/src/Dodge/Creature/Vocalization.hs index 1ed0a015a..5c36a49f6 100644 --- a/src/Dodge/Creature/Vocalization.hs +++ b/src/Dodge/Creature/Vocalization.hs @@ -1,15 +1,18 @@ module Dodge.Creature.Vocalization where import Control.Lens -import Dodge.Data.Creature +import Dodge.Data.World import Sound.Data +import System.Random vocalizationTest :: Creature -> Maybe SoundID vocalizationTest cr = case cr ^? crVocalization . vcCoolDown of Just 0 -> Just $ _vcSound $ _crVocalization cr _ -> Nothing -resetCrVocCoolDown :: Creature -> Creature -resetCrVocCoolDown cr = case cr ^? crVocalization . vcMaxCoolDown of - Just i -> cr & crVocalization . vcCoolDown .~ i +resetCrVocCoolDown :: World -> Creature -> Creature +resetCrVocCoolDown w cr = case cr ^? crVocalization . vcMaxCoolDown of + Just (i,j) -> cr & crVocalization . vcCoolDown .~ x + where + x = fst $ randomR (i,j) (_randGen w) Nothing -> cr diff --git a/src/Dodge/Data/Creature/Misc.hs b/src/Dodge/Data/Creature/Misc.hs index 99fc92fe3..8874c378a 100644 --- a/src/Dodge/Data/Creature/Misc.hs +++ b/src/Dodge/Data/Creature/Misc.hs @@ -29,7 +29,7 @@ data Vocalization | Vocalization { _vcSound :: SoundID , _vcWarnings :: [SoundID] - , _vcMaxCoolDown :: Int + , _vcMaxCoolDown :: (Int, Int) , _vcCoolDown :: Int } deriving (Eq, Ord, Show, Read) --Generic, Flat) diff --git a/src/Dodge/Debug.hs b/src/Dodge/Debug.hs index 3c903dcff..5d772f5a2 100644 --- a/src/Dodge/Debug.hs +++ b/src/Dodge/Debug.hs @@ -70,6 +70,8 @@ debugSelectCreatureList cid u = (u ^? uvWorld . cWorld . lWorld . creatures . ix cid . crMemory) , debugList "Strategy" (u ^? uvWorld . cWorld . lWorld . creatures . ix cid . crActionPlan . apStrategy) + , debugList "Vocalization" + (u ^? uvWorld . cWorld . lWorld . creatures . ix cid . crVocalization) ] diff --git a/src/Dodge/Default/Item/Use/Consumption.hs b/src/Dodge/Default/Item/Use/Consumption.hs index 463f5b9c2..b3705f398 100644 --- a/src/Dodge/Default/Item/Use/Consumption.hs +++ b/src/Dodge/Default/Item/Use/Consumption.hs @@ -16,7 +16,7 @@ defaultLoadable = } defaultBulletLoadable :: HeldConsumption -defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBullet +defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBulletAmmo defaultLeftLoadable :: LeftConsumption defaultLeftLoadable = AutoRecharging 10 10 100 100 diff --git a/src/Dodge/Humanoid.hs b/src/Dodge/Humanoid.hs index 96ba8fa5d..973dda764 100644 --- a/src/Dodge/Humanoid.hs +++ b/src/Dodge/Humanoid.hs @@ -23,6 +23,7 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of , targetYouWhenCognizant , const searchIfDamaged , const (crMeleeCooldown %~ max 0 . subtract 1) + , const (crVocalization . vcCoolDown %~ max 0 . subtract 1) ] cr SpreadGunAI -> diff --git a/src/Dodge/Item/Held/Rod.hs b/src/Dodge/Item/Held/Rod.hs index f440c4c7e..54d4d2542 100644 --- a/src/Dodge/Item/Held/Rod.hs +++ b/src/Dodge/Item/Held/Rod.hs @@ -40,7 +40,7 @@ bangRod = & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} & itUse . heldAim . aimHandlePos .~ 5 & itUse . heldAim . aimMuzPos .~ 30 - & itUse . heldConsumption . laAmmoType .~ hvBullet + & itUse . heldConsumption . laAmmoType .~ hvBulletAmmo elephantGun :: Item elephantGun = diff --git a/src/Dodge/Item/Weapon/Bullet.hs b/src/Dodge/Item/Weapon/Bullet.hs index ff56ada30..ca72c5105 100644 --- a/src/Dodge/Item/Weapon/Bullet.hs +++ b/src/Dodge/Item/Weapon/Bullet.hs @@ -1,6 +1,6 @@ module Dodge.Item.Weapon.Bullet ( - basicBullet, - hvBullet, + basicBulletAmmo, + hvBulletAmmo, defaultBullet, ) where @@ -8,8 +8,8 @@ import Dodge.Data.Item.Use.Consumption.Ammo import Control.Lens import Geometry.Data -basicBullet :: AmmoType -basicBullet = +basicBulletAmmo :: AmmoType +basicBulletAmmo = BulletAmmo { _amString = "BASIC" , _amBullet = defaultBullet @@ -37,8 +37,8 @@ basicBulDams = [ Damage PIERCING 100 0 0 0 $ PushBackDamage 2 ] -hvBullet :: AmmoType -hvBullet = +hvBulletAmmo :: AmmoType +hvBulletAmmo = BulletAmmo { _amString = "HVBULLET" , _amBullet = diff --git a/src/Dodge/Path.hs b/src/Dodge/Path.hs index 5bd8e49ed..b76882481 100644 --- a/src/Dodge/Path.hs +++ b/src/Dodge/Path.hs @@ -58,7 +58,6 @@ makePathBetweenPs a b w = mapMaybe (lab $ w ^. cWorld . pathGraph) <$> makePathB bfsNodePoints :: Int -> World -> [Point2] bfsNodePoints n w = mapMaybe (lab g) $ bfs n g where - --g = _pathGraph (_cWorld w) g = w ^. cWorld . pathGraph pointTowardsImpulse :: Point2 -> Point2 -> World -> Maybe Point2 diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index dba8c5eb2..21ab4b91c 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -295,7 +295,7 @@ advanceScrollAmount u = updatePastWorlds :: World -> World --updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 100 . ((w ^. cWorld . lWorld) :)) -updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 300 . ((w ^. cWorld . lWorld) :)) +updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 600 . ((w ^. cWorld . lWorld) :)) doWorldEvents :: World -> World doWorldEvents w =