Add crab crit, rethink Action datatype slightly

This commit is contained in:
2026-04-07 15:29:02 +01:00
parent 35d169b585
commit f0e568e694
25 changed files with 606 additions and 465 deletions
+1
View File
@@ -179,6 +179,7 @@ crHeight cr = case cr ^. crHP of
HoverCrit {} -> 10
ChaseCrit {} -> 25
Avatar {} -> 25
CrabCrit {} -> 25
_ -> error "Need to define crHeight for this crType"
CrIsCorpse{} -> Just 5
CrDestroyed{} -> Nothing
+40 -33
View File
@@ -45,9 +45,9 @@ performActions cid w =
iss
where
cr = w ^?! cWorld . lWorld . creatures . ix cid
(iss, mayas) = foldMap (performAction cr w) $ cr ^. crActionPlan . apAction
(iss, mayas) = fromMaybe ([],NoAction) $ performAction cr w <$> cr ^? crActionPlan . apAction
type ActionUpdate = ([Impulse], [Action])
type ActionUpdate = ([Impulse], Action)
{- | Performing an action on a frame creates an ActionUpdate:
gives impulses and updates/deletes the action itself.
@@ -55,54 +55,61 @@ type ActionUpdate = ([Impulse], [Action])
performAction :: Creature -> World -> Action -> ActionUpdate
performAction cr w ac = case ac of
AimAt tcid p -> performAimAt cr w tcid p
WaitThen 0 newAc -> ([], [newAc])
WaitThen t newAc -> ([], [WaitThen (t -1) newAc])
ImpulsesList (xs : xss) -> (xs, [ImpulsesList xss])
ImpulsesList _ -> ([], mempty)
DoImpulses imps -> (imps, mempty)
DoActionThen fsta afta -> case performAction cr w fsta of -- NOTE this only does ONE continuation action
(imps, nxta : _) -> (imps, [DoActionThen nxta afta])
(imps, []) -> (imps, [afta])
WaitThen 0 newAc -> ([], newAc)
WaitThen t newAc -> ([], WaitThen (t -1) newAc)
ImpulsesList (xs : xss) a -> performAction cr w a & _1 <>~ xs
& _2 %~ ImpulsesList xss
ImpulsesList _ a -> performAction cr w a
DoImpulses imps -> (imps, NoAction)
DoActionThen fsta afta -> case performAction cr w fsta of
(imps, NoAction) -> (imps, afta)
(imps, nxta) -> (imps, DoActionThen nxta afta)
DoActionWhile f act -> performAction cr w $ DoActionWhilePartial act f act
DoActionWhilePartial partAc f resetAc
| doWdCrBl f w cr -> case performAction cr w partAc of
(imps, nxta : _) -> (imps, [DoActionWhilePartial nxta f resetAc])
(imps, []) -> (imps, [DoActionWhilePartial resetAc f resetAc])
(imps, NoAction) -> (imps, DoActionWhilePartial resetAc f resetAc)
(imps, nxta ) -> (imps, DoActionWhilePartial nxta f resetAc)
| otherwise -> performAction cr w partAc
DoActionIf f ifa
| doWdCrBl f w cr -> performAction cr w ifa
| otherwise -> ([], mempty)
| otherwise -> ([], NoAction)
DoActionIfElse ifa f elsea
| doWdCrBl f w cr -> performAction cr w ifa
| otherwise -> performAction cr w elsea
DoActionWhileInterrupt repa f afta
| doWdCrBl f w cr -> (fst $ performAction cr w repa, [DoActionWhileInterrupt repa f afta])
| doWdCrBl f w cr -> (fst $ performAction cr w repa, DoActionWhileInterrupt repa f afta)
| otherwise -> performAction cr w afta
DoActions [] -> ([], mempty)
DoActions acs ->
let (imps, newAcs) = foldMap (performAction cr w) acs
in (imps, newAcs)
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], mempty)
-- DoActions [] -> ([], NoAction)
-- DoActions acs ->
-- let (imps, newAcs) = foldMap (performAction cr w) acs
-- in (imps, newAcs)
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], NoAction)
PathTo p a -> performPathTo a cr w p
EvadeAim _ _ 0 -> (mempty,NoAction)
EvadeAim p a i -> tryEvadeSideways cr w p a i
TurnToPoint p -> performTurnToA cr p
LeadTarget p -> fromMaybe ([], mempty) $ do
LeadTarget p -> fromMaybe ([], NoAction) $ do
i <- cr ^? crIntention . targetCr . _Just
tcr <- w ^? cWorld . lWorld . creatures . ix i
return ([TurnTo (tcr ^. crPos . _xy +.+ rotateV (_crDir tcr) p)], mempty)
return ([TurnTo (tcr ^. crPos . _xy +.+ rotateV (_crDir tcr) p)], NoAction)
UseSelf f -> performAction cr w $ doCrAc f cr
ArbitraryAction f -> performAction cr w (doCrWdAc f cr w)
DoImpulsesAlongside sideImp mainAc -> case performAction cr w mainAc of
(imp, [nxtac]) -> (sideImp ++ imp, [DoImpulsesAlongside sideImp nxtac])
(imp, _) -> (sideImp ++ imp, mempty)
DoImpulsesAlongside sideImp mainAc -> performAction cr w mainAc & _1 <>~ sideImp
DoReplicate t nxtac -> performAction cr w $ DoReplicatePartial nxtac t nxtac
DoReplicatePartial _ 0 pac -> performAction cr w pac
DoReplicatePartial startac t partac -> case performAction cr w partac of
(imps, [nextac]) -> (imps, [DoReplicatePartial startac t nextac])
(imps, _) -> (imps, [DoReplicatePartial startac (t -1) startac])
NoAction -> ([], mempty)
(imps, NoAction) -> (imps, DoReplicatePartial startac (t -1) startac)
(imps, nextac) -> (imps, DoReplicatePartial startac t nextac)
NoAction -> ([], NoAction)
tryEvadeSideways :: Creature -> World -> Point2 -> Float -> Int -> ActionUpdate
tryEvadeSideways _ _ p a i = jumpleft -- (mv,mempty)
where
jumpleft = (mv,EvadeAim p a (i-1))
mv = [Move (V2 0 3)]
performAimAt :: Creature -> World -> Int -> Point2 -> ActionUpdate
performAimAt cr w tcid p = ([TurnToward tpos aimSp], [AimAt tcid tpos])
performAimAt cr w tcid p = ([TurnToward tpos aimSp], AimAt tcid tpos)
where
cdir = _crDir cr
cpos = cr ^. crPos . _xy
@@ -121,20 +128,20 @@ crPathing cr = case cr ^. crStance . carriage of
performPathTo :: Action -> Creature -> World -> Point2 -> ActionUpdate
performPathTo a cr w p
| dist cpos p <= crRad (cr ^. crType) = mempty
| dist cpos p <= crRad (cr ^. crType) = (mempty,NoAction)
| fst (crPathing cr) cpos p w = gotowards p
| otherwise = case uncurry pointTowardsImpulse' (crPathing cr) cpos p w of
Just q -> gotowards q
_ -> ([], [a])
_ -> ([], a)
where
gotowards q = ( [MvTurnToward q, MvForward, RandomTurn jit] , [PathTo p a])
gotowards q = ( [MvTurnToward q, MvForward, RandomTurn jit] , PathTo p a)
cpos = cr ^. crPos . _xy
jit = _mvTurnJit $ crMvType cr
performTurnToA :: Creature -> Point2 -> ActionUpdate
performTurnToA cr p
| angleVV cdirv dirv < 0.1 = mempty
| otherwise = ([MvTurnToward p, RandomTurn jit], [TurnToPoint p])
| angleVV cdirv dirv < 0.1 = (mempty,NoAction)
| otherwise = ([MvTurnToward p, RandomTurn jit], TurnToPoint p)
where
cpos = cr ^. crPos . _xy
cdirv = unitVectorAtAngle (_crDir cr)
+1 -1
View File
@@ -22,7 +22,7 @@ flockArmourChaseCrit =
-- ]
, _crActionPlan =
ActionPlan
{ _apAction = []
{ _apAction = NoAction
, _apStrategy = FollowImpulses
, _apGoal = [Kill 0]
}
+8
View File
@@ -1,6 +1,7 @@
module Dodge.Creature.ChaseCrit (
smallChaseCrit,
invisibleChaseCrit,
crabCrit,
chaseCrit,
hoverCrit,
) where
@@ -32,6 +33,13 @@ chaseCrit =
& crHP .~ HP 150
& crFaction .~ ColorFaction green
crabCrit :: Creature
crabCrit = defaultCreature
& crName .~ "chaseCrit"
& crHP .~ HP 350
& crType .~ CrabCrit 0 LeftForward 0 0
& crFaction .~ ColorFaction red
hoverCrit :: Creature
hoverCrit =
defaultCreature
+1
View File
@@ -6,6 +6,7 @@ crMass :: CreatureType -> Float
crMass = \case
Avatar {} -> 10
ChaseCrit {} -> 10
CrabCrit {} -> 10
HoverCrit {} -> 5
SwarmCrit -> 2
AutoCrit -> 10
+1
View File
@@ -9,6 +9,7 @@ crMaterial :: CreatureType -> Material
crMaterial = \case
Avatar{_avatarMaterial = mt} -> mt
ChaseCrit {} -> Flesh
CrabCrit {} -> Flesh
HoverCrit {} -> Metal
SwarmCrit -> Flesh
AutoCrit -> Flesh
+1
View File
@@ -7,6 +7,7 @@ crMaxHP :: CreatureType -> Int
crMaxHP = \case
Avatar {} -> 15000
ChaseCrit {} -> 150
CrabCrit {} -> 350
HoverCrit {} -> 100
SwarmCrit -> 50
AutoCrit -> 100
+1
View File
@@ -8,6 +8,7 @@ crMvType :: Creature -> CrMvType
crMvType cr = case _crType cr of
Avatar {} -> MvWalking 1.5
ChaseCrit {} -> defaultChaseMvType & mvSpeed .~ 1.8
CrabCrit {} -> defaultChaseMvType & mvSpeed .~ 1
HoverCrit {} -> defaultChaseMvType & mvSpeed .~ 0.16
SwarmCrit -> defaultChaseMvType
AutoCrit -> defaultAimMvType
+6 -9
View File
@@ -21,12 +21,8 @@ import Linear
import RandomHelp
import Sound.Data
perceptionUpdate ::
-- | List of creature ids that may direct attention and awareness
[Int] ->
World ->
Creature ->
Creature
-- | The [Int] is a list of creature ids that may direct attention and awareness
perceptionUpdate :: [Int] -> World -> Creature -> Creature
perceptionUpdate is w = rememberSounds w . basicAwarenessUpdate w . basicAttentionUpdate is w
{- | Update a creatures awareness based upon the creatures' current direction
@@ -55,9 +51,9 @@ basicAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of
return $
(crActionPlan . apStrategy .~ WarningCry) .
(crActionPlan . apAction
.~ [ImpulsesList (crImpulsesOnCognizant w cr)
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
])
.~ ImpulsesList (crImpulsesOnCognizant w cr)
(AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy))
)
crImpulsesOnCognizant :: World -> Creature -> [[Impulse]]
crImpulsesOnCognizant w cr = case cr ^. crType of
@@ -65,6 +61,7 @@ crImpulsesOnCognizant w cr = case cr ^. crType of
<> [[ChangeStrategy $ CloseToMelee 0]]
HoverCrit {} | Just sid <- cognizantVoc w cr -> [Bark sid]:
[[ChangeStrategy $ CloseToMelee 0]]
CrabCrit {} -> [[ChangeStrategy $ CloseToMelee 0]]
_ | Just sid <- cognizantVoc w cr -> [Bark sid]: replicate 5 [RandomImpulse $ RandImpulseCircMove 1]
_ -> replicate 5 [RandomImpulse $ RandImpulseCircMove 3]
+33
View File
@@ -9,6 +9,7 @@ module Dodge.Creature.Picture (
deadFeet,
drawChaseCrit,
drawHoverCrit,
drawCrabCrit,
) where
import Dodge.Base.Collide
@@ -65,6 +66,14 @@ drawHoverCrit cr = colorSH (_skinHead cskin)
f a = tpq `Q.comp` (1 & _xy .~ rotateV a 5, Q.qid)
tpq = (V3 0 0 0, Q.qid)
drawCrabCrit :: World -> Creature -> Shape
drawCrabCrit w cr = mconcat
[ crabUpperBody w cr
, colorSH (_skinLower cskin) $ crabFeet cr
]
where
cskin = crShape $ _crType cr
drawChaseCrit :: World -> Creature -> Shape
drawChaseCrit w cr = mconcat
[ chaseUpperBody w cr
@@ -74,6 +83,16 @@ drawChaseCrit w cr = mconcat
cskin = crShape $ _crType cr
rotmdir = rotateSH (_crMvDir cr - _crDir cr)
crabUpperBody :: World -> Creature -> Shape
crabUpperBody _ cr = colorSH (_skinUpper cskin)
(overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI 5 $ polyCirc 4 12
& each . _x *~ 0.6)
)
where
torsoq = (V3 0 0 10,Q.qid)
cskin = crShape $ _crType cr
chaseUpperBody :: World -> Creature -> Shape
chaseUpperBody w cr = colorSH (_skinUpper cskin)
(overPosSH (Q.apply torsoq) (upperPrismPolyHalfMI tz $ polyCirc 3 12
@@ -126,6 +145,20 @@ feet cr = case (cr ^? crType . strideAmount,cr ^? crType . footForward) of
-- f i = 8 * (sLen - 2*i) / sLen
f i = 8 * oneSmooth ((sLen - 2*i) / sLen)
crabFeet :: Creature -> Shape
{-# INLINE crabFeet #-}
crabFeet cr = case (cr ^? crType . strideAmount,cr ^? crType . footForward) of
(Just sa,Just LeftForward) -> sh (f sa)
(Just sa,Just RightForward) -> sh (-f sa)
_ -> sh 0
where
sh x = translateSHxy x off aFoot <> translateSHxy (- x) (- off) aFoot
aFoot = upperPrismPolyST 10 $ polyCirc 3 2
off = 10
sLen = strideLength cr
-- f i = 8 * (sLen - 2*i) / sLen
f i = 8 * oneSmooth ((sLen - 2*i) / sLen)
deadFeet :: Creature -> Shape
{-# INLINE deadFeet #-}
deadFeet = feet
+1
View File
@@ -9,6 +9,7 @@ crRad :: CreatureType -> Float
crRad = \case
Avatar {} -> 10
ChaseCrit {} -> 10
CrabCrit {} -> 10
HoverCrit {} -> 8
SwarmCrit -> 2
AutoCrit -> 10
+76 -34
View File
@@ -1,6 +1,6 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.ReaderUpdate (
doStrategyActions,
setTargetMv,
targetYouWhenCognizant,
overrideMeleeCloseTarget,
watchUpdateStrat,
@@ -9,7 +9,8 @@ module Dodge.Creature.ReaderUpdate (
-- goToTarget,
flockACC,
chaseCritMv,
setMvPos,
crabCritMv,
setMvPosToTargetCr,
setViewPos,
hoverCritMv,
) where
@@ -45,19 +46,18 @@ tryMeleeAttack cr tcr
&& dist tpos cpos < crRad (cr ^. crType) + crRad (tcr ^. crType) + 5
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4 =
cr & crActionPlan . apAction
.~ [ DoImpulses [Melee $ _crID tcr] `DoActionThen`
.~ DoImpulses [Melee $ _crID tcr] `DoActionThen`
DoReplicate 10 NoAction
`DoActionThen` DoImpulses
[ChangeStrategy (CloseToMelee $ _crID tcr)]
]
& crActionPlan . apStrategy .~ MeleeStrike
-- `DoActionThen` DoImpulses
-- [ChangeStrategy (CloseToMelee $ _crID tcr)]
-- & crActionPlan . apStrategy .~ MeleeStrike
| otherwise = cr
where
cpos = cr ^. crPos . _xy
tpos = tcr ^. crPos . _xy
setMvPos :: World -> Creature -> Creature
setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
setMvPosToTargetCr :: World -> Creature -> Creature
setMvPosToTargetCr w cr = cr & crIntention . mvToPoint .~ mpos
where
int = _crIntention cr
mtpos = do
@@ -81,17 +81,17 @@ attentionViewPoint w cr = do
guard $ visionCheck cr (tcr ^. crPos . _xy) > 0
tcr ^? crPos . _xy
setTargetMv ::
-- | Function for determining target
(World -> Creature -> Maybe Creature) ->
World ->
Creature ->
Creature
setTargetMv targFunc w cr =
maybe
cr
(\ctarg -> cr & crIntention . mvToPoint ?~ (ctarg ^. crPos . _xy))
(targFunc w cr)
--setTargetMv ::
-- -- | Function for determining target
-- (World -> Creature -> Maybe Creature) ->
-- World ->
-- Creature ->
-- Creature
--setTargetMv targFunc w cr =
-- maybe
-- cr
-- (\ctarg -> cr & crIntention . mvToPoint ?~ (ctarg ^. crPos . _xy))
-- (targFunc w cr)
-- ugly
flockACC :: World -> Creature -> Creature
@@ -120,48 +120,88 @@ flockACC w cr = fromMaybe cr $ do
else negate r *.* horDir
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
crabCritMv :: World -> Creature -> Creature
crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
CloseToMelee tid | Just (p,a) <- aimi tid -> cr & crActionPlan . apAction .~ EvadeAim p a 3
& crType . dodgeCooldown .~ 20
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ Search
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
aimi tid = do
tcr <- w ^? cWorld . lWorld . creatures . ix tid
Aiming <- tcr ^? crStance . posture
let txy = tcr ^. crPos . _xy
cxy = cr ^. crPos . _xy
0 <- cr ^? crType . dodgeCooldown
guard $ hasLOS cxy txy w
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
return (txy, tcr ^. crDir)
chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
MeleeStrike -> cr
CloseToMelee cid
| VocReady == (cr ^. crVocalization) ->
cr
& crActionPlan . apAction
.:~ ImpulsesList
.~ ImpulsesList
( [Bark soundid] :
replicate numjits [RandomImpulse thejitter]
++ [[ChangeStrategy (CloseToMelee cid)]]
)
) NoAction
& resetCrVocCoolDown w
& crActionPlan . apStrategy .~ WarningCry
where
thejitter = RandImpulseCircMove 3
soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
numjits = fst $ randomR (15, 25) (_randGen w)
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ WatchAndWait
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
hoverCritMv :: World -> Creature -> Creature
hoverCritMv w cr = case _apStrategy (_crActionPlan cr) of
WarningCry -> cr
MeleeStrike -> cr
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
cr & crActionPlan . apAction .~ bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
& crActionPlan . apStrategy .~ WatchAndWait
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
where
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
_ -> True
--goToTarget :: World -> Creature -> Creature
--goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
@@ -173,23 +213,25 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
Just p
| hasLOSIndirect p (cr ^. crPos . _xy) w ->
cr
& crActionPlan . apAction .~ [TurnToPoint p]
& crActionPlan . apAction .~ TurnToPoint p
& crIntention . viewPoint .~ Nothing
& crActionPlan . apStrategy .~ Investigate
| otherwise ->
cr & crActionPlan . apAction %~ replaceNullWith (PathTo p (DoImpulses [ChangeStrategy Wander]))
-- cr & crActionPlan . apAction %~ replaceNullWith (PathTo p (DoImpulses [ChangeStrategy Wander]))
cr & crActionPlan . apAction .~ PathTo p (DoImpulses [ChangeStrategy Wander])
& crActionPlan . apStrategy .~ Investigate
Nothing -> cr
replaceNullWith :: a -> [a] -> [a]
replaceNullWith x [] = [x]
replaceNullWith _ xs = xs
--replaceNullWith :: a -> [a] -> [a]
--replaceNullWith x [] = [x]
--replaceNullWith _ xs = xs
doStrategyActions :: Creature -> Creature
doStrategyActions cr = case cr ^? crActionPlan . apStrategy of
Just (StrategyActions strat acs) ->
cr
& crActionPlan . apAction .~ acs
-- & crActionPlan . apAction .~ acs
& crActionPlan . apAction .~ head acs
& crActionPlan . apStrategy .~ strat
_ -> cr
+1
View File
@@ -9,6 +9,7 @@ crShape :: CreatureType -> CreatureShape
crShape = \case
Avatar{} -> Humanoid (greyN 0.9) (lightx4 black) (greyN 0.3)
ChaseCrit {} -> Humanoid (greyN 0.9) (lightx4 green) (greyN 0.3)
CrabCrit {} -> Humanoid (greyN 0.9) (lightx4 red) (greyN 0.3)
HoverCrit {} -> Humanoid (greyN 0.9) (light blue) (greyN 0.3)
SwarmCrit -> Humanoid (greyN 0.9) (lightx4 yellow) (greyN 0.3)
AutoCrit -> Humanoid (greyN 0.9) (lightx4 red) (greyN 0.3)
+3
View File
@@ -25,6 +25,7 @@ crDexterity cr = case cr ^. crType of
AutoCrit -> 46
BarrelCrit {} -> 0
LampCrit {} -> 0
_ -> 46
crStrength :: Creature -> Int
crStrength cr = case cr ^. crType of
@@ -35,11 +36,13 @@ crStrength cr = case cr ^. crType of
AutoCrit -> 46
BarrelCrit {} -> 0
LampCrit {} -> 0
_ -> 46
crIntelligence :: Creature -> Int
crIntelligence cr = case cr ^. crType of
Avatar { _avIntelligence = x } -> x
ChaseCrit {} -> 20
CrabCrit {} -> 20
HoverCrit {} -> 20
SwarmCrit -> 20
AutoCrit -> 20
+3
View File
@@ -54,6 +54,9 @@ updateLivingCreature cr =
ChaseCrit{} -> \w ->
crUpdate cid . performActions cid $
over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
CrabCrit{} -> \w ->
crUpdate cid . performActions cid $
over (cWorld . lWorld . creatures . ix cid) (crabCritInternal w) w
AutoCrit {} -> crUpdate cid
SwarmCrit {} -> crUpdate cid
HoverCrit {} -> \w ->
+2
View File
@@ -26,6 +26,7 @@ crWarningSounds cr = case cr ^. crType of
, seagullCry1S
, seagullCry2S
]
CrabCrit {} -> mempty
HoverCrit {} -> mempty
SwarmCrit -> mempty
AutoCrit -> mempty
@@ -36,6 +37,7 @@ crDeathSounds :: Creature -> DeathType -> [SoundID]
crDeathSounds cr dt = case cr ^. crType of
Avatar{} -> mempty
ChaseCrit{} -> defaultDeathSounds dt
CrabCrit{} -> defaultDeathSounds dt
HoverCrit{} -> hoverDeathSounds dt
SwarmCrit -> mempty
AutoCrit -> mempty
+1 -1
View File
@@ -34,5 +34,5 @@ shootFirstMiss :: Action
shootFirstMiss =
LeadTarget (V2 30 50)
`DoActionThen` DoImpulses [UseItem]
`DoActionThen` (WdCrBlfromCrBl CrCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0), DoImpulses [UseItem]])
-- `DoActionThen` (WdCrBlfromCrBl CrCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0), DoImpulses [UseItem]])
`DoActionThen` 20 `WaitThen` holsterWeapon
+6 -5
View File
@@ -15,7 +15,7 @@ data ActionPlan
= Inanimate
| ActionPlan
{ -- _apImpulse :: [Impulse] -- done per frame
_apAction :: [Action] -- updated per frame, likely persist across frames
_apAction :: Action -- updated per frame, likely persist across frames
, _apStrategy :: Strategy -- current strategy
, _apGoal :: [Goal] -- particular ordered goals
}
@@ -68,8 +68,9 @@ data Action
, _targetSeenAt :: Point2
}
| PathTo { _pathToPoint :: Point2, _pathFailAction :: Action }
| EvadeAim {_enemyPos :: Point2, _enemyDir :: Float, _acTimer :: Int}
| TurnToPoint { _turnToPoint :: Point2 }
| ImpulsesList { _impulsesListList :: [[Impulse]] }
| ImpulsesList { _impulsesListList :: [[Impulse]], _acAction :: Action }
| DoImpulses { _doImpulsesList :: [Impulse] }
| WaitThen
{ _waitThenTimer :: Int
@@ -98,7 +99,7 @@ data Action
, _doActionWhileThenCondition :: WdCrBl
, _doActionWhileThenThen :: Action
}
| DoActions { _doActionsList :: [Action] }
-- | DoActions { _doActionsList :: [Action] }
| DoActionThen
{ _doActionThenFirst :: Action
, _doActionThenSecond :: Action
@@ -140,9 +141,9 @@ data Strategy
| CloseToMelee {_meleeTarget :: Int}
| StrategyActions Strategy [Action]
| GetTo Point2
| Reload
-- | Reload
| Flee
| MeleeStrike
-- | MeleeStrike
| Search
deriving (Eq, Ord, Show) --Generic, Flat)
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
+5
View File
@@ -58,6 +58,11 @@ data CreatureType
, _footForward :: FootForward
, _strideAmount :: Float
}
| CrabCrit {_meleeCooldown :: Int
, _footForward :: FootForward
, _strideAmount :: Float
, _dodgeCooldown :: Int
}
| HoverCrit {_meleeCooldown :: Int}
| SwarmCrit
| AutoCrit
+1 -1
View File
@@ -43,7 +43,7 @@ defaultCreature =
, _posture = AtEase
}
, _crVocalization = VocReady
, _crActionPlan = ActionPlan [] (StrategyActions WatchAndWait [StartSentinelPost]) [LiveLongAndProsper]
, _crActionPlan = ActionPlan NoAction (StrategyActions WatchAndWait [StartSentinelPost]) [LiveLongAndProsper]
, _crPerception = defaultPerceptionState
, _crMemory = defaultCreatureMemory
, _crFaction = NoFaction
+17 -2
View File
@@ -1,5 +1,6 @@
module Dodge.Humanoid (
chaseCritInternal,
crabCritInternal,
hoverCritInternal,
) where
@@ -16,7 +17,7 @@ chaseCritInternal w cr =
[ const doStrategyActions
, overrideMeleeCloseTarget
, setViewPos
, setMvPos
, setMvPosToTargetCr
, chaseCritMv
, perceptionUpdate [0]
, targetYouWhenCognizant
@@ -25,6 +26,20 @@ chaseCritInternal w cr =
, const (crVocalization %~ updateVocTimer)
]
crabCritInternal :: World -> Creature -> Creature
crabCritInternal w =
(crVocalization %~ updateVocTimer)
. (crType . meleeCooldown %~ max 0 . subtract 1)
. (crType . dodgeCooldown %~ max 0 . subtract 1)
. searchIfDamaged
. targetYouWhenCognizant w
. perceptionUpdate [0] w
. crabCritMv w
. setMvPosToTargetCr w
. setViewPos w
. overrideMeleeCloseTarget w
. doStrategyActions
hoverCritInternal :: World -> Creature -> Creature
hoverCritInternal w cr =
foldl'
@@ -33,7 +48,7 @@ hoverCritInternal w cr =
[ const doStrategyActions
, overrideMeleeCloseTarget
, setViewPos
, setMvPos
, setMvPosToTargetCr
, hoverCritMv
, perceptionUpdate [0]
, targetYouWhenCognizant
+1
View File
@@ -119,6 +119,7 @@ drawCreature w m cr = translateSP (_crPos cr) . rotateSP (_crDir cr) $
Avatar {} -> basicCrPict m cr
SwarmCrit -> basicCrPict m cr
AutoCrit -> basicCrPict m cr
CrabCrit {} -> noPic $ drawCrabCrit w cr
HoverCrit{} -> noPic $ drawHoverCrit cr
barrelShape :: SPic
+16 -7
View File
@@ -2,6 +2,7 @@
module Dodge.Room.Tutorial where
import Dodge.Item.Held.Stick
import Dodge.Creature.ChaseCrit
import Control.Monad
import Data.Foldable
@@ -427,6 +428,10 @@ tutLight = do
)
_ -> Nothing
crabRoom :: State LayoutVars Room
crabRoom = (putSingleLight =<< roomNgon 6 150)
<&> rmPmnts .:~ psPtPl (PS 100 0) (PutCrit crabCrit)
loadAmmoTut :: State LayoutVars (MetaTree Room String)
loadAmmoTut = do
i <- nextLayoutInt
@@ -445,14 +450,16 @@ loadAmmoTut = do
=<< join (takeOne [roomNgon 6 80, roomRectAutoLights 100 100])
-- =<< join (takeOne [roomNgon 6 80])
droom <- distributerRoom BulletAmmo (10 ^ (4::Int))
ncrits <- takeOne [1,1,2,2,2,3]
croom <- roomCCrits ncrits
croom <- crabRoom
wep <- takeOne [burstRifle,smg]
return $
tToBTree "loadAmmoTest" $
treePost
[ amrm & rmPmnts .:~ sps (PS 50 0) (PutFlIt (drumMag & itConsumables ?~ 90))
[ croom
, door
, amrm & rmPmnts .:~ sps (PS 50 0) (PutFlIt (drumMag & itConsumables ?~ 90))
, triggerDoorRoom i
, wprm & rmPmnts .:~ sps (PS 50 0) (PutFlIt burstRifle)
, wprm & rmPmnts .:~ sps (PS 50 0) (PutFlIt wep)
, triggerDoorRoom j
, droom
, door
@@ -478,11 +485,13 @@ putSingleLight rm = do
, (V2 0 y', V2 x y')
]
return $ rmPmnts .:~ uncurry spanLightI ps
RoomNgon{_rmngonSize = x} -> do
y <- takeOne [21, -21]
return $ rmPmnts .:~ spanLightI (V2 (-x) y) (V2 x y)
RoomNgon{} -> do
let p = rm ^?! rmPolys . ix 0 . ix 0
return $ rmPmnts .:~ spanLightI p (-p)
return . f $ removeLights rm
tutHub :: State LayoutVars (MetaTree Room String)
tutHub = do
(is, wbp) <- setTreeInts =<< critsRoom 1
+2 -9
View File
@@ -41,15 +41,8 @@ tocrs :: (IM.IntMap Creature
tocrs = uvWorld . cWorld . lWorld . creatures
testStringInit :: Universe -> [String]
testStringInit u =
[ show $ inverseSelNumPos (u ^. uvConfig) invDP
(u ^. uvWorld . input . mousePos) (u ^. uvWorld . hud . diSections)
, show $ do
(i',xs) <- IM.lookupMax (u ^. uvWorld . hud . diSections)
(j',_) <- xs ^. ssItems . to IM.lookupMax
return (i',j')
]
testStringInit u = u ^.. tocrs . ix 1 . crActionPlan . apStrategy . to show
<> u ^.. tocrs . ix 1 . crActionPlan . apAction . to show
-- where
-- tocr = uvWorld . cWorld . lWorld . creatures . ix 0
-- f = fromMaybe 0