Improve awareness

This commit is contained in:
2021-09-05 23:58:35 +01:00
parent e366698064
commit 86311c5d41
24 changed files with 121 additions and 397 deletions
+33 -22
View File
@@ -1,10 +1,14 @@
{- | Actions performed by creatures within the world
-}
module Dodge.Creature.Action
-- ( module Dodge.Creature.Action
-- , module Dodge.Creature.Action.UseItem
-- , module Dodge.Creature.Action.Movement
-- )
( performActionsR
, startReloadingWeapon
, blinkAction
, crAutoReload
, copyItemToFloor
, youDropItem
, pickUpItem
)
where
import Dodge.Creature.Stance.Data
import Dodge.WorldEvent.Shockwave
@@ -39,6 +43,28 @@ performActions w cr = cr
performActionsR :: Creature -> Reader World Creature
performActionsR cr = reader $ \w -> performActions w cr
type OutAction = ( [Impulse] , Maybe Action )
performAimAt :: Creature -> World -> Int -> Point2 -> OutAction
performAimAt cr w tcid p = ([TurnToward tpos aimSp], Just $ AimAt tcid tpos)
where
cdir = _crDir cr
cpos = _crPos cr
canSee' = canSee (_crID cr) tcid w
aimSp = case cr ^? crMvType . mvAimSpeed of
Just f -> f $ safeAngleVV (unitVectorAtAngle cdir) (tpos - cpos)
Nothing -> error "creature without aiming type"
tpos | canSee' = _crPos (_creatures w IM.! tcid)
| otherwise = p
performPathTo :: Creature -> World -> Point2 -> OutAction
performPathTo cr w p
| dist cpos p < 5 = ([], Nothing)
| hasLOS cpos p w = ([MvTurnToward p,MvForward] , Just (PathTo p))
| otherwise = ([], Nothing)
where
cpos = _crPos cr
{- | Performing an action means that a creature has some impulses for a frame, and
updates or deletes the action itself.
-- doAction -}
@@ -46,17 +72,9 @@ performAction
:: Creature
-> World
-> Action
-> ( [Impulse] , Maybe Action )
-> OutAction
performAction cr w ac = case ac of
AimAt tcid p
-> ([TurnToward tpos aimSp], Just $ AimAt tcid tpos)
where
canSee' = canSee (_crID cr) tcid w
aimSp = case cr ^? crMvType . mvAimSpeed of
Just f -> f $ safeAngleVV (unitVectorAtAngle cdir) (tpos - cpos)
Nothing -> error "creature without aiming type"
tpos | canSee' = _crPos (_creatures w IM.! tcid)
| otherwise = p
AimAt tcid p -> performAimAt cr w tcid p
WaitThen 0 newAc -> ([] , Just newAc)
WaitThen t newAc -> ([] , Just (WaitThen (t-1) newAc))
ImpulsesList (xs:xss) -> (xs, Just $ ImpulsesList xss)
@@ -85,10 +103,7 @@ performAction cr w ac = case ac of
let (imps, newAcs) = unzip $ map (performAction cr w) acs
in (concat imps, Just . DoActions $ catMaybes newAcs)
StartSentinelPost -> ([AddGoal $ SentinelAt (_crPos cr) (_crDir cr)], Nothing)
PathTo p
| dist cpos p < 5 -> ([], Nothing)
| hasLOS cpos p w -> ([MvTurnToward p,MvForward] , Just (PathTo p))
| otherwise -> ([], Nothing)
PathTo p -> performPathTo cr w p
LeadTarget p -> case cr ^? crTarget . _Just of
Just tcr -> ([TurnTo (_crPos tcr +.+ rotateV (_crDir tcr) p)], Nothing)
_ -> ([], Nothing)
@@ -106,10 +121,6 @@ performAction cr w ac = case ac of
(imps , Just nac) -> (imps, Just $ DoReplicatePartial sac t nac)
(imps , _) -> (imps, Just $ DoReplicatePartial sac (t-1) sac)
NoAction -> ([],Nothing)
-- _ -> ([], Nothing)
where
cpos = _crPos cr
cdir = _crDir cr
startReloadingWeapon
:: Creature