Make _targetCr an Int id rather than a full creature
This commit is contained in:
@@ -125,10 +125,10 @@ performAction cr w ac = case ac of
|
|||||||
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], Nothing)
|
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], Nothing)
|
||||||
PathTo p -> performPathTo cr w p
|
PathTo p -> performPathTo cr w p
|
||||||
TurnToPoint p -> performTurnToA cr p
|
TurnToPoint p -> performTurnToA cr p
|
||||||
LeadTarget p -> case cr ^? crIntention . targetCr . _Just of
|
LeadTarget p -> fromMaybe ([],Nothing) $ do
|
||||||
Just tcr -> ([TurnTo (tcr ^. crPos . _xy +.+ rotateV (_crDir tcr) p)], Nothing)
|
i <- cr ^? crIntention . targetCr . _Just
|
||||||
_ -> ([], Nothing)
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
UseTarget f -> performAction cr w $ doMCrAc f $ cr ^? crIntention . targetCr . _Just
|
return $ ([TurnTo (tcr ^. crPos . _xy +.+ rotateV (_crDir tcr) p)], Nothing)
|
||||||
UseSelf f -> performAction cr w $ doCrAc f cr
|
UseSelf f -> performAction cr w $ doCrAc f cr
|
||||||
UseAheadPos f -> performAction cr w (doP2Ac f (cr ^. crPos . _xy +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
UseAheadPos f -> performAction cr w (doP2Ac f (cr ^. crPos . _xy +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||||
UseMvTargetPos f -> performAction cr w $ doMP2Ac f $ _mvToPoint $ _crIntention cr
|
UseMvTargetPos f -> performAction cr w $ doMP2Ac f $ _mvToPoint $ _crIntention cr
|
||||||
|
|||||||
+26
-22
@@ -1,5 +1,6 @@
|
|||||||
module Dodge.Creature.Boid where
|
module Dodge.Creature.Boid where
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
import Linear
|
import Linear
|
||||||
import Dodge.Creature.Radius
|
import Dodge.Creature.Radius
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@@ -176,9 +177,10 @@ swarmUsingCenter ::
|
|||||||
World ->
|
World ->
|
||||||
Creature ->
|
Creature ->
|
||||||
Creature
|
Creature
|
||||||
swarmUsingCenter updT upd w cr = case _targetCr $ _crIntention cr of
|
swarmUsingCenter updT upd w cr = fromMaybe (upd cenp cr) $ do
|
||||||
Nothing -> upd cenp cr
|
i <- _targetCr $ _crIntention cr
|
||||||
Just tcr -> updT tcr cenp cr
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
return $ updT tcr cenp cr
|
||||||
where
|
where
|
||||||
cid = _crID cr
|
cid = _crID cr
|
||||||
cenp = _crGroupCenter $ _creatureGroups (_lWorld (_cWorld w)) IM.! _crGroupID (_crGroup $ _creatures (_lWorld (_cWorld w)) IM.! cid)
|
cenp = _crGroupCenter $ _creatureGroups (_lWorld (_cWorld w)) IM.! _crGroupID (_crGroup $ _creatures (_lWorld (_cWorld w)) IM.! cid)
|
||||||
@@ -191,9 +193,10 @@ flockChaseTarget ::
|
|||||||
World ->
|
World ->
|
||||||
Creature ->
|
Creature ->
|
||||||
Creature
|
Creature
|
||||||
flockChaseTarget updT upd w cr = case _targetCr $ _crIntention cr of
|
flockChaseTarget updT upd w cr = fromMaybe (upd crs cr) $ do
|
||||||
Nothing -> upd crs cr
|
i <- _targetCr $ _crIntention cr
|
||||||
Just tcr -> updT tcr crs cr
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
return $ updT tcr crs cr
|
||||||
where
|
where
|
||||||
is = _swarm $ _crGroup cr
|
is = _swarm $ _crGroup cr
|
||||||
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
|
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
|
||||||
@@ -213,18 +216,18 @@ flockPointTarget f targFunc w cr = case targFunc cr w of
|
|||||||
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
|
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
|
||||||
p = f crTarg crs cr
|
p = f crTarg crs cr
|
||||||
|
|
||||||
flockToPointUsing ::
|
--flockToPointUsing ::
|
||||||
(Creature -> Point2 -> Creature -> Point2) ->
|
-- (Creature -> Point2 -> Creature -> Point2) ->
|
||||||
(Point2 -> Creature -> Creature -> [Impulse]) ->
|
-- (Point2 -> Creature -> Creature -> [Impulse]) ->
|
||||||
Creature ->
|
-- Creature ->
|
||||||
Reader World Creature
|
-- Reader World Creature
|
||||||
flockToPointUsing pf mvf cr = reader $ \w -> case _targetCr $ _crIntention cr of
|
--flockToPointUsing pf mvf cr = reader $ \w -> case _targetCr $ _crIntention cr of
|
||||||
Nothing -> cr
|
-- Nothing -> cr
|
||||||
Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
|
-- Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
|
||||||
where
|
-- where
|
||||||
cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
|
-- cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
|
||||||
-- crGroupCenter $ _creatureGroups (_cWorld w) IM.! _crGroupID (_crGroup cr)
|
-- -- crGroupCenter $ _creatureGroups (_cWorld w) IM.! _crGroupID (_crGroup cr)
|
||||||
ptarg = pf tcr cenp cr
|
-- ptarg = pf tcr cenp cr
|
||||||
|
|
||||||
flockToPointUsing' ::
|
flockToPointUsing' ::
|
||||||
(Creature -> Point2 -> Creature -> Point2) ->
|
(Creature -> Point2 -> Creature -> Point2) ->
|
||||||
@@ -232,12 +235,13 @@ flockToPointUsing' ::
|
|||||||
World ->
|
World ->
|
||||||
Creature ->
|
Creature ->
|
||||||
Creature
|
Creature
|
||||||
flockToPointUsing' pf mvf w cr = case _targetCr $ _crIntention cr of
|
flockToPointUsing' pf mvf w cr = fromMaybe cr $ do
|
||||||
Nothing -> cr
|
i <- _targetCr $ _crIntention cr
|
||||||
Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
let ptarg = pf tcr cenp cr
|
||||||
|
return $ cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
|
||||||
where
|
where
|
||||||
cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
|
cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
|
||||||
ptarg = pf tcr cenp cr
|
|
||||||
|
|
||||||
flockFunc ::
|
flockFunc ::
|
||||||
(Creature -> Point2 -> Creature -> Point2) ->
|
(Creature -> Point2 -> Creature -> Point2) ->
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
module Dodge.Creature.Impulse (impulsiveAIBefore) where
|
module Dodge.Creature.Impulse (impulsiveAIBefore) where
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
import Linear
|
import Linear
|
||||||
import NewInt
|
import NewInt
|
||||||
import Dodge.Creature.MoveType
|
import Dodge.Creature.MoveType
|
||||||
@@ -64,12 +65,14 @@ followImpulse cr w imp = case imp of
|
|||||||
ArbitraryImpulseFunction f -> crup $ doWdCrCr f w cr
|
ArbitraryImpulseFunction f -> crup $ doWdCrCr f w cr
|
||||||
ArbitraryImpulse f -> followImpulse cr w (doCrWdImp f cr w)
|
ArbitraryImpulse f -> followImpulse cr w (doCrWdImp f cr w)
|
||||||
ArbitraryImpulseEffect f -> (doCrWdWd f cr, cr)
|
ArbitraryImpulseEffect f -> (doCrWdWd f cr, cr)
|
||||||
ImpulseUseTargetCID f -> case cr ^? crIntention . targetCr . _Just of
|
ImpulseUseTargetCID f -> fromMaybe (crup cr) $ do
|
||||||
Just tcr -> followImpulse cr w (doIntImp f $ _crID tcr)
|
i <- cr ^? crIntention . targetCr . _Just
|
||||||
_ -> crup cr
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
ImpulseUseTarget f -> case cr ^? crIntention . targetCr . _Just of
|
return $ followImpulse cr w (doIntImp f $ _crID tcr)
|
||||||
Just tcr -> followImpulse cr w (doCrImp f tcr)
|
ImpulseUseTarget f -> fromMaybe (crup cr) $ do
|
||||||
_ -> crup cr
|
i <- cr ^? crIntention . targetCr . _Just
|
||||||
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
return $ followImpulse cr w (doCrImp f tcr)
|
||||||
ImpulseUseAheadPos f -> followImpulse cr w (doP2Imp f (cr ^. crPos . _xy +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
ImpulseUseAheadPos f -> followImpulse cr w (doP2Imp f (cr ^. crPos . _xy +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||||
MvForward -> crup $ crMvForward speed (w ^. cWorld . lWorld) cr
|
MvForward -> crup $ crMvForward speed (w ^. cWorld . lWorld) cr
|
||||||
MvTurnToward p ->
|
MvTurnToward p ->
|
||||||
|
|||||||
@@ -5,19 +5,19 @@ module Dodge.Creature.Perception (
|
|||||||
visionCheck,
|
visionCheck,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad
|
|
||||||
import Dodge.Creature.Radius
|
|
||||||
import Linear
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
|
import Control.Monad
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Dodge.Base.Collide
|
import Dodge.Base.Collide
|
||||||
|
import Dodge.Creature.Radius
|
||||||
import Dodge.Creature.Vocalization
|
import Dodge.Creature.Vocalization
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import Dodge.FloatFunction
|
import Dodge.FloatFunction
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Geometry.Vector
|
import Geometry.Vector
|
||||||
import qualified IntMapHelp as IM
|
import qualified IntMapHelp as IM
|
||||||
|
import Linear
|
||||||
import RandomHelp
|
import RandomHelp
|
||||||
import Sound.Data
|
import Sound.Data
|
||||||
|
|
||||||
@@ -48,17 +48,18 @@ basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of
|
|||||||
& maybeBark
|
& maybeBark
|
||||||
where
|
where
|
||||||
oldAwareness = _cpAwareness $ _crPerception cr
|
oldAwareness = _cpAwareness $ _crPerception cr
|
||||||
newAwareness
|
newAwareness =
|
||||||
= (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
(IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||||
oldAwareness
|
oldAwareness
|
||||||
becomesCognizant
|
becomesCognizant =
|
||||||
= any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
||||||
thejitter = [RandomImpulse $ RandImpulseCircMove 1]
|
thejitter = [RandomImpulse $ RandImpulseCircMove 1]
|
||||||
maybeBark = fromMaybe id $ do
|
maybeBark = fromMaybe id $ do
|
||||||
guard becomesCognizant
|
guard becomesCognizant
|
||||||
sid <- vocalizationTest cr
|
sid <- vocalizationTest cr
|
||||||
return $ crActionPlan . apAction
|
return $
|
||||||
.~ [ ImpulsesList ( [Bark sid] : replicate 5 thejitter) ]
|
crActionPlan . apAction
|
||||||
|
.~ [ImpulsesList ([Bark sid] : replicate 5 thejitter)]
|
||||||
|
|
||||||
-- TODO fold in randgen update, requires that this is a world to world function
|
-- TODO fold in randgen update, requires that this is a world to world function
|
||||||
chaseCritAwarenessUpdate :: World -> Creature -> Creature
|
chaseCritAwarenessUpdate :: World -> Creature -> Creature
|
||||||
@@ -73,26 +74,29 @@ chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of
|
|||||||
& maybeBark
|
& maybeBark
|
||||||
where
|
where
|
||||||
oldAwareness = _cpAwareness $ _crPerception cr
|
oldAwareness = _cpAwareness $ _crPerception cr
|
||||||
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
newAwareness =
|
||||||
oldAwareness
|
(IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||||
becomesCognizant = any isCognizant
|
oldAwareness
|
||||||
$ IM.unionWith cogRaised oldAwareness newAwareness
|
becomesCognizant =
|
||||||
|
any isCognizant $
|
||||||
|
IM.unionWith cogRaised oldAwareness newAwareness
|
||||||
thejitter = [RandomImpulse $ RandImpulseCircMove 3]
|
thejitter = [RandomImpulse $ RandImpulseCircMove 3]
|
||||||
maybeBark
|
maybeBark = fromMaybe id $ do
|
||||||
| becomesCognizant -- && randBool
|
guard $ becomesCognizant
|
||||||
&& cr ^? crVocalization . vcCoolDown == Just 0 =
|
guard $ cr ^? crVocalization . vcCoolDown == Just 0
|
||||||
let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
|
let soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
|
||||||
numjits = fst $ randomR (15, 25) (_randGen w)
|
numjits = fst $ randomR (15, 25) (_randGen w)
|
||||||
in (crActionPlan . apStrategy .~ WarningCry)
|
return $
|
||||||
. (crActionPlan . apAction .~
|
(crActionPlan . apStrategy .~ WarningCry)
|
||||||
[ ImpulsesList
|
. ( crActionPlan . apAction
|
||||||
( [Bark soundid] :
|
.~ [ ImpulsesList
|
||||||
replicate numjits thejitter
|
( [Bark soundid] :
|
||||||
++ [[ChangeStrategy $ CloseToMelee 0]]
|
replicate numjits thejitter
|
||||||
)
|
++ [[ChangeStrategy $ CloseToMelee 0]]
|
||||||
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
|
)
|
||||||
])
|
, AimAt 0 (w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy)
|
||||||
| otherwise = id
|
]
|
||||||
|
)
|
||||||
|
|
||||||
cogRaised :: Awareness -> Awareness -> Awareness
|
cogRaised :: Awareness -> Awareness -> Awareness
|
||||||
cogRaised Suspicious{} Cognizant{} = Cognizant 100
|
cogRaised Suspicious{} Cognizant{} = Cognizant 100
|
||||||
@@ -153,7 +157,6 @@ visionCheck cr tpos = doFloatFloat (_viFOV vi) ang * doFloatFloat (_viDist vi) d
|
|||||||
dirvec = unitVectorAtAngle (_crDir cr)
|
dirvec = unitVectorAtAngle (_crDir cr)
|
||||||
ang = angleVV dirvec (tpos - (cpos - crRad (cr ^. crType) *^ dirvec))
|
ang = angleVV dirvec (tpos - (cpos - crRad (cr ^. crType) *^ dirvec))
|
||||||
d = dist tpos cpos
|
d = dist tpos cpos
|
||||||
|
|
||||||
|
|
||||||
awakeLevelPerception :: Creature -> Float
|
awakeLevelPerception :: Creature -> Float
|
||||||
awakeLevelPerception cr = case _cpVigilance $ _crPerception cr of
|
awakeLevelPerception cr = case _cpVigilance $ _crPerception cr of
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ import LensHelp
|
|||||||
import Linear
|
import Linear
|
||||||
import RandomHelp
|
import RandomHelp
|
||||||
|
|
||||||
overrideMeleeCloseTarget :: Creature -> Creature
|
overrideMeleeCloseTarget :: World -> Creature -> Creature
|
||||||
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
overrideMeleeCloseTarget w cr = maybe cr (tryMeleeAttack cr) $ do
|
||||||
|
i <- _targetCr $ _crIntention cr
|
||||||
|
w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
|
||||||
tryMeleeAttack :: Creature -> Creature -> Creature
|
tryMeleeAttack :: Creature -> Creature -> Creature
|
||||||
tryMeleeAttack cr tcr
|
tryMeleeAttack cr tcr
|
||||||
@@ -58,7 +60,8 @@ setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
|
|||||||
where
|
where
|
||||||
int = _crIntention cr
|
int = _crIntention cr
|
||||||
mtpos = do
|
mtpos = do
|
||||||
tpos <- (^. crPos . _xy) <$> _targetCr int
|
i <- int ^. targetCr
|
||||||
|
tpos <- w ^? cWorld . lWorld . creatures . ix i . crPos . _xy
|
||||||
guard $ hasLOSIndirect (cr ^. crPos . _xy) tpos w
|
guard $ hasLOSIndirect (cr ^. crPos . _xy) tpos w
|
||||||
return tpos
|
return tpos
|
||||||
mpos = mtpos <|> _mvToPoint int
|
mpos = mtpos <|> _mvToPoint int
|
||||||
@@ -90,29 +93,29 @@ setTargetMv targFunc w cr =
|
|||||||
|
|
||||||
-- ugly
|
-- ugly
|
||||||
flockACC :: World -> Creature -> Creature
|
flockACC :: World -> Creature -> Creature
|
||||||
flockACC w cr = case cr ^? crIntention . targetCr . _Just of
|
flockACC w cr = fromMaybe cr $ do
|
||||||
Nothing -> cr
|
i <- cr ^. crIntention . targetCr
|
||||||
Just tcr ->
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
let tpos = tcr ^. crPos . _xy
|
let tpos = tcr ^. crPos . _xy
|
||||||
cpos = cr ^. crPos . _xy
|
cpos = cr ^. crPos . _xy
|
||||||
isFarACC cr' =
|
isFarACC cr' =
|
||||||
_crGroup cr' == _crGroup cr
|
_crGroup cr' == _crGroup cr
|
||||||
&& _crID cr' /= _crID cr
|
&& _crID cr' /= _crID cr
|
||||||
&& dist (cr' ^. crPos . _xy) tpos > dist cpos tpos
|
&& dist (cr' ^. crPos . _xy) tpos > dist cpos tpos
|
||||||
macr =
|
macr =
|
||||||
safeMinimumOn (dist cpos . (^. crPos . _xy))
|
safeMinimumOn (dist cpos . (^. crPos . _xy))
|
||||||
. filter isFarACC
|
. filter isFarACC
|
||||||
$ crsNearCirc cpos 50 w
|
$ crsNearCirc cpos 50 w
|
||||||
in case macr of
|
return $ case macr of
|
||||||
Nothing -> cr
|
Nothing -> cr
|
||||||
Just acr ->
|
Just acr ->
|
||||||
let r = crRad (acr ^. crType) + crRad (cr ^. crType) + 10
|
let r = crRad (acr ^. crType) + crRad (cr ^. crType) + 10
|
||||||
horDir = normalizeV (vNormal (cpos -.- tpos))
|
horDir = normalizeV (vNormal (cpos -.- tpos))
|
||||||
horShift =
|
horShift =
|
||||||
if isLHS tpos cpos (acr ^. crPos . _xy)
|
if isLHS tpos cpos (acr ^. crPos . _xy)
|
||||||
then r *.* horDir
|
then r *.* horDir
|
||||||
else negate r *.* horDir
|
else negate r *.* horDir
|
||||||
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||||
|
|
||||||
chaseCritMv :: World -> Creature -> Creature
|
chaseCritMv :: World -> Creature -> Creature
|
||||||
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
|
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
|
||||||
@@ -203,7 +206,7 @@ targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
|||||||
Just (Cognizant _) ->
|
Just (Cognizant _) ->
|
||||||
(w ^?! cWorld . lWorld . creatures . ix 0)
|
(w ^?! cWorld . lWorld . creatures . ix 0)
|
||||||
`seq` cr
|
`seq` cr
|
||||||
& crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
|
& crIntention . targetCr ?~ 0
|
||||||
& crPerception . cpVigilance .~ Vigilant
|
& crPerception . cpVigilance .~ Vigilant
|
||||||
_ -> cr & crIntention . targetCr .~ Nothing
|
_ -> cr & crIntention . targetCr .~ Nothing
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ sentinelAI =
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
-- w
|
|
||||||
where
|
where
|
||||||
advanceShoot = DoImpulses [UseItem, MoveForward 3]
|
advanceShoot = DoImpulses [UseItem, MoveForward 3]
|
||||||
tcid cr = _crID <$> _targetCr (_crIntention cr)
|
tcid cr = _targetCr (_crIntention cr)
|
||||||
lostest = WdCrLOSTarget -- w' cr = maybe False (\cid -> canSee (_crID cr) cid w') (tcid cr)
|
lostest = WdCrLOSTarget -- w' cr = maybe False (\cid -> canSee (_crID cr) cid w') (tcid cr)
|
||||||
|
|
||||||
--chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
|
--chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
|
||||||
|
|||||||
@@ -6,11 +6,7 @@ import Dodge.Data.World
|
|||||||
--import MaybeHelp
|
--import MaybeHelp
|
||||||
|
|
||||||
-- | Assumes that you are id 0: if creature is cognizant of you, sets you as target
|
-- | Assumes that you are id 0: if creature is cognizant of you, sets you as target
|
||||||
targetYouWhenCognizant ::
|
targetYouWhenCognizant :: World -> Creature -> Creature
|
||||||
World ->
|
targetYouWhenCognizant _ cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
||||||
Creature ->
|
Just (Cognizant _) -> cr & crIntention . targetCr ?~ 0
|
||||||
Creature
|
|
||||||
targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
|
||||||
--Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures (_cWorld w) IM.! 0
|
|
||||||
Just (Cognizant _) -> cr & crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
|
|
||||||
_ -> cr & crIntention . targetCr .~ Nothing
|
_ -> cr & crIntention . targetCr .~ Nothing
|
||||||
|
|||||||
@@ -66,14 +66,16 @@ crHasTarget :: Creature -> Bool
|
|||||||
crHasTarget cr = isJust $ cr ^? crIntention . targetCr . _Just
|
crHasTarget cr = isJust $ cr ^? crIntention . targetCr . _Just
|
||||||
|
|
||||||
crHasTargetLOS :: World -> Creature -> Bool
|
crHasTargetLOS :: World -> Creature -> Bool
|
||||||
crHasTargetLOS w cr = case cr ^? crIntention . targetCr . _Just of
|
crHasTargetLOS w cr = fromMaybe False $ do
|
||||||
Just i -> crCanSeeCr i (w, cr)
|
i <- cr ^. crIntention . targetCr
|
||||||
Nothing -> False
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
return $ crCanSeeCr tcr (w, cr)
|
||||||
|
|
||||||
crSafeDistFromTarg :: Float -> Creature -> Bool
|
crSafeDistFromTarg :: World -> Float -> Creature -> Bool
|
||||||
crSafeDistFromTarg d cr = case cr ^? crIntention . targetCr . _Just of
|
crSafeDistFromTarg w d cr = fromMaybe True $ do
|
||||||
Just tcr -> dist (cr ^. crPos . _xy) (tcr ^. crPos . _xy) > d
|
i <- cr ^? crIntention . targetCr . _Just
|
||||||
Nothing -> True
|
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||||
|
return $ dist (cr ^. crPos . _xy) (tcr ^. crPos . _xy) > d
|
||||||
|
|
||||||
crStratConMatches :: Strategy -> Creature -> Bool
|
crStratConMatches :: Strategy -> Creature -> Bool
|
||||||
crStratConMatches strat cr = strat == _apStrategy (_crActionPlan cr)
|
crStratConMatches strat cr = strat == _apStrategy (_crActionPlan cr)
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ doWdCrBl wcb = case wcb of
|
|||||||
maybe
|
maybe
|
||||||
False
|
False
|
||||||
(\cid -> canSee (_crID cr) cid w)
|
(\cid -> canSee (_crID cr) cid w)
|
||||||
(_crID <$> _targetCr (_crIntention cr))
|
(_targetCr (_crIntention cr))
|
||||||
WdCrSafeDistFromTarget x -> \_ -> crSafeDistFromTarg x -- currently ignores walls etc
|
WdCrSafeDistFromTarget x -> \w -> crSafeDistFromTarg w x -- currently ignores walls etc
|
||||||
|
|
||||||
doCrBl :: CrBl -> Creature -> Bool
|
doCrBl :: CrBl -> Creature -> Bool
|
||||||
doCrBl cb = case cb of
|
doCrBl cb = case cb of
|
||||||
@@ -55,18 +55,14 @@ doCrBl cb = case cb of
|
|||||||
CrIsAiming -> crIsAiming
|
CrIsAiming -> crIsAiming
|
||||||
CrIsAnimate -> isAnimate
|
CrIsAnimate -> isAnimate
|
||||||
|
|
||||||
doMCrAc :: MCrAc -> Maybe Creature -> Action
|
|
||||||
doMCrAc mca = case mca of
|
|
||||||
MCrNoAction -> const ActionNothing
|
|
||||||
|
|
||||||
doCrAc :: CrAc -> Creature -> Action
|
doCrAc :: CrAc -> Creature -> Action
|
||||||
doCrAc ca = case ca of
|
doCrAc ca = case ca of
|
||||||
CrTurnAround -> \cr -> TurnToPoint
|
CrTurnAround -> \cr -> TurnToPoint
|
||||||
(cr ^. crPos . _xy -.- 10 *.* unitVectorAtAngle (_crDir cr))
|
(cr ^. crPos . _xy -.- 10 *.* unitVectorAtAngle (_crDir cr))
|
||||||
CrFleeFromTarget -> fleeFromTarget
|
-- CrFleeFromTarget -> fleeFromTarget
|
||||||
|
|
||||||
fleeFromTarget :: Creature -> Action
|
--fleeFromTarget :: Creature -> Action
|
||||||
fleeFromTarget cr = fleeFrom cr (_targetCr (_crIntention cr))
|
--fleeFromTarget cr = fleeFrom cr (_targetCr (_crIntention cr))
|
||||||
|
|
||||||
doP2Ac :: P2Ac -> Point2 -> Action
|
doP2Ac :: P2Ac -> Point2 -> Action
|
||||||
doP2Ac p2a = case p2a of
|
doP2Ac p2a = case p2a of
|
||||||
|
|||||||
@@ -149,9 +149,6 @@ data Action
|
|||||||
}
|
}
|
||||||
| NoAction
|
| NoAction
|
||||||
| StartSentinelPost
|
| StartSentinelPost
|
||||||
| UseTarget
|
|
||||||
{ _useTarget :: MCrAc
|
|
||||||
}
|
|
||||||
| UseSelf
|
| UseSelf
|
||||||
{ _useSelf :: CrAc
|
{ _useSelf :: CrAc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ data CrHP
|
|||||||
| CrIsPitted
|
| CrIsPitted
|
||||||
|
|
||||||
data Intention = Intention
|
data Intention = Intention
|
||||||
{ _targetCr :: Maybe Creature
|
{ _targetCr :: Maybe Int
|
||||||
, _mvToPoint :: Maybe Point2
|
, _mvToPoint :: Maybe Point2
|
||||||
, _viewPoint :: Maybe Point2
|
, _viewPoint :: Maybe Point2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,9 @@ data CrBl
|
|||||||
| CrIsAnimate
|
| CrIsAnimate
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|
||||||
data MCrAc = MCrNoAction
|
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
|
||||||
|
|
||||||
data CrAc
|
data CrAc
|
||||||
= CrTurnAround
|
= CrTurnAround
|
||||||
| CrFleeFromTarget
|
-- | CrFleeFromTarget
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|
||||||
data P2Ac = P2NoAction
|
data P2Ac = P2NoAction
|
||||||
@@ -70,7 +67,6 @@ deriveJSON defaultOptions ''CrImp
|
|||||||
deriveJSON defaultOptions ''P2Imp
|
deriveJSON defaultOptions ''P2Imp
|
||||||
deriveJSON defaultOptions ''CrBl
|
deriveJSON defaultOptions ''CrBl
|
||||||
deriveJSON defaultOptions ''WdCrBl
|
deriveJSON defaultOptions ''WdCrBl
|
||||||
deriveJSON defaultOptions ''MCrAc
|
|
||||||
deriveJSON defaultOptions ''CrAc
|
deriveJSON defaultOptions ''CrAc
|
||||||
deriveJSON defaultOptions ''P2Ac
|
deriveJSON defaultOptions ''P2Ac
|
||||||
deriveJSON defaultOptions ''MP2Ac
|
deriveJSON defaultOptions ''MP2Ac
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ updateHumanoid cr = case cr ^?! crType of
|
|||||||
humanoidAIList
|
humanoidAIList
|
||||||
[ const doStrategyActions
|
[ const doStrategyActions
|
||||||
, performActions
|
, performActions
|
||||||
, const overrideMeleeCloseTarget
|
, overrideMeleeCloseTarget
|
||||||
, setViewPos
|
, setViewPos
|
||||||
, setMvPos
|
, setMvPos
|
||||||
, chaseCritMv
|
, chaseCritMv
|
||||||
|
|||||||
Reference in New Issue
Block a user