69 lines
2.1 KiB
Haskell
69 lines
2.1 KiB
Haskell
module Dodge.Creature.ArmourChase
|
|
( armourChaseCrit
|
|
)
|
|
where
|
|
import Dodge.Base
|
|
import Dodge.Data
|
|
import Dodge.Default
|
|
import Dodge.Creature.State
|
|
import Dodge.Creature.State.Data
|
|
import Dodge.Creature.Rationality
|
|
import Dodge.Creature.ReaderUpdate
|
|
import Dodge.Creature.AlertLevel
|
|
import Dodge.Creature.Picture
|
|
import Dodge.Item.Equipment
|
|
import Dodge.Item.Consumable
|
|
import Picture
|
|
import Geometry
|
|
import FoldableHelp
|
|
|
|
import Data.Maybe
|
|
import qualified Data.IntMap.Strict as IM
|
|
import Control.Lens
|
|
import Control.Monad.Reader
|
|
|
|
armourChaseCrit :: Creature
|
|
armourChaseCrit = defaultCreature
|
|
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
|
watchUpdateStratR [] >=>
|
|
doStrategyActionsR >=>
|
|
performActionsR >=>
|
|
chaseTargetR (const . _crTarget) >=>
|
|
basicPerceptionUpdateR [0] >=>
|
|
targetYouWhenCognizantR >=>
|
|
flockACCR >=>
|
|
overrideMeleeCloseTargetR >=>
|
|
return . (crMeleeCooldown . _Just %~ max 0 . subtract 1)
|
|
, _crHP = 300
|
|
, _crPict = basicCrPict green
|
|
, _crInv = IM.fromList
|
|
[(0,frontArmour)
|
|
,(1,medkit 200)
|
|
]
|
|
, _crMeleeCooldown = Just 0
|
|
, _crGroup = ShieldGroup
|
|
}
|
|
|
|
flockACCR :: Creature -> Reader World Creature
|
|
flockACCR = reader . flockACC
|
|
|
|
flockACC :: Creature -> World -> Creature
|
|
flockACC cr w = fromMaybe cr $ mFlockACC cr w
|
|
|
|
mFlockACC :: Creature -> World -> Maybe Creature
|
|
mFlockACC cr w = do
|
|
tcr <- _crTarget cr
|
|
let tpos = _crPos tcr
|
|
cpos = _crPos cr
|
|
isFarACC cr' = _crGroup cr' == ShieldGroup && _crID cr' /= _crID cr
|
|
&& dist (_crPos cr') tpos > dist cpos tpos
|
|
-- && circOnSeg (_crPos cr') tpos cpos (_crRad cr + _crRad cr')
|
|
nearACCs = IM.filter isFarACC $ creaturesNearPointI 3 cpos w
|
|
acr <- safeMinimumOn (dist cpos . _crPos) nearACCs
|
|
let r = _crRad acr + _crRad cr + 10
|
|
horDir = normalizeV (vNormal (cpos -.- tpos))
|
|
horShift = if isLHS tpos cpos (_crPos acr)
|
|
then r *.* horDir
|
|
else negate r *.* horDir
|
|
return $ cr & crActionPlan . crImpulse .~ [MoveForward 2.5,TurnToward (tpos +.+ horShift) 0.05 ]
|