Refactor launcherCrit ai
This commit is contained in:
@@ -9,6 +9,7 @@ module Dodge.Creature.ActionRat
|
||||
, reloadOverride
|
||||
, reloadOverrideNoHolster
|
||||
, shootAdvanceStrat
|
||||
, shootMoveStrat
|
||||
, watchUpdateStrat
|
||||
, goToPostStrat
|
||||
, overrideInternal
|
||||
@@ -110,6 +111,26 @@ aimThenShootStrat tcid _ _ = StrategyActions (ShootAt tcid)
|
||||
lostest (w,cr') = canSee (_crID cr') tcid w
|
||||
advanceShoot = ImpulsesList [[UseItem, MoveForward 3]]
|
||||
|
||||
shootMoveStrat :: Point2 -> Int -> World -> Creature -> Strategy
|
||||
shootMoveStrat moveV tcid _ _ = StrategyActions (ShootAt tcid)
|
||||
[ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction))
|
||||
`DoActionThen`
|
||||
(DoActionWhileThen advanceShoot lostest
|
||||
. DoReplicateThen advanceShoot 75
|
||||
$ DoImpulses [ChangeStrategy WatchAndWait]
|
||||
)
|
||||
, AimAtCloseSlow
|
||||
{ _targetID = tcid
|
||||
, _targetSeenAt = (0,0) -- hack
|
||||
, _aimSpeed = 0.2
|
||||
, _slowAimSpeed = 0.01
|
||||
, _slowAimAngle = pi/8
|
||||
}
|
||||
]
|
||||
where
|
||||
lostest (w,cr') = canSee (_crID cr') tcid w
|
||||
advanceShoot = ImpulsesList [[UseItem, Move moveV]]
|
||||
|
||||
shootAdvanceStrat :: Int -> World -> Creature -> Strategy
|
||||
shootAdvanceStrat tcid _ _ = StrategyActions (ShootAt tcid)
|
||||
[ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction))
|
||||
|
||||
@@ -38,20 +38,7 @@ initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLam
|
||||
addLS = over lightSources (IM.insert i (lightAt (_crPos cr) i))
|
||||
|
||||
updateLamp :: Int -> CRUpdate
|
||||
updateLamp i w (f,g) cr = ((handleLS . f, g), internalUpdate)
|
||||
where
|
||||
handleLS w'
|
||||
| _crHP cr < 0 = explosionFlashAt cPos
|
||||
$ mkSoundBreakGlass cPos w' & lightSources %~ IM.delete i
|
||||
| otherwise = w' & lightSources . ix i . lsPos .~ cPos
|
||||
where
|
||||
cPos = _crPos cr
|
||||
internalUpdate
|
||||
| _crHP cr < 0 = Nothing
|
||||
| otherwise = fmap doDamage $ Just cr
|
||||
|
||||
updateLamp' :: Int -> CRUpdate
|
||||
updateLamp' i = unrandUpdate handleLS internalUpdate
|
||||
updateLamp i = unrandUpdate handleLS internalUpdate
|
||||
where
|
||||
handleLS cr w
|
||||
| _crHP cr < 0 = explosionFlashAt cPos
|
||||
@@ -63,7 +50,6 @@ updateLamp' i = unrandUpdate handleLS internalUpdate
|
||||
| _crHP cr < 0 = Nothing
|
||||
| otherwise = Just $ doDamage cr
|
||||
|
||||
|
||||
barrel :: Creature
|
||||
barrel = defaultInanimate
|
||||
{ _crUpdate = updateBarrel
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
module Dodge.Creature.LauncherCrit
|
||||
( launcherCrit
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.SetTarget
|
||||
import Dodge.Creature.Rationality
|
||||
import Dodge.Creature.AlertLevel
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
import Dodge.Item.Consumable
|
||||
import Geometry
|
||||
import Picture
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
launcherCrit :: Creature
|
||||
launcherCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ composeInternalAIs
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
-- [ (crHasTargetLOS, shootMoveStrat (0,3) 0)
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
, basicPerceptionUpdate [0]
|
||||
, doStrategyActions
|
||||
, reloadOverride
|
||||
, targetYouWhenCognizant
|
||||
, overrideInternal (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
$ \ _ -> crActionPlan . crStrategy .~ WatchAndWait
|
||||
]
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
, _crStrategy = StrategyActions WatchAndWait [StartSentinelPost]
|
||||
, _crGoal = []
|
||||
}
|
||||
, _crInv = IM.fromList [(0,launcher)]
|
||||
, _crInvSel = 0
|
||||
, _crRad = 10
|
||||
, _crState = defaultState
|
||||
, _crHP = 300
|
||||
}
|
||||
|
||||
retreatFire :: Action
|
||||
retreatFire = ImpulsesList ( [ [ UseItem ] ] ++ replicate 20 [ Turn 0.16 ])
|
||||
`DoActionThen`
|
||||
HolsterWeapon
|
||||
`DoActionThen`
|
||||
ImpulsesList ( replicate 30 [ MoveForward 3 ])
|
||||
`DoActionThen`
|
||||
DrawWeapon
|
||||
`DoActionThen`
|
||||
ImpulsesList ( [[UseItem]] ++ replicate 20 [ Turn $ negate 0.16 ] )
|
||||
`DoActionThen`
|
||||
HolsterWeapon
|
||||
`DoActionThen`
|
||||
ImpulsesList ( replicate 15 [ MoveForward 3 ] )
|
||||
`DoActionThen`
|
||||
DrawWeapon
|
||||
`DoActionThen`
|
||||
ImpulsesList (
|
||||
replicate 100 [UseItem, ImpulseUseTarget $ \tcr -> TurnToward (_crPos tcr) (pi/16) ] )
|
||||
`DoActionThen`
|
||||
20
|
||||
`WaitThen`
|
||||
HolsterWeapon
|
||||
`DoActionThen`
|
||||
ImpulsesList ( replicate 15 [ MoveForward 3 ] )
|
||||
`DoActionThen`
|
||||
DoImpulses [ChangeStrategy WatchAndWait]
|
||||
|
||||
|
||||
@@ -40,18 +40,18 @@ followImpulses
|
||||
followImpulses w (f,g) cr
|
||||
= (\(f''' ,cr) -> ((f''',g'),Just cr))
|
||||
$ foldr
|
||||
(\imp (f' , cr') -> let (f'', cr'') = followImpulse imp w cr' in (f'' . f', cr''))
|
||||
(\imp (f' , cr') -> let (f'', cr'') = followImpulse cr' w imp in (f'' . f', cr''))
|
||||
(f, cr)
|
||||
(_crImpulse $ _crActionPlan cr)
|
||||
where
|
||||
g' = snd $ next g
|
||||
|
||||
followImpulse
|
||||
:: Impulse
|
||||
:: Creature
|
||||
-> World
|
||||
-> Creature
|
||||
-> Impulse
|
||||
-> (World -> World , Creature)
|
||||
followImpulse imp w cr = case imp of
|
||||
followImpulse cr w imp = case imp of
|
||||
Move p -> (id, crMvBy p cr)
|
||||
MoveForward x -> (id, crMvForward x cr)
|
||||
Turn a -> (id, creatureTurn a cr)
|
||||
@@ -69,6 +69,13 @@ followImpulse imp w cr = case imp of
|
||||
ChangeStrategy strat -> (id, cr & crActionPlan . crStrategy .~ strat)
|
||||
AddGoal gl -> (id, cr & crActionPlan . crGoal %~ (gl :) )
|
||||
ArbitraryCreatureImpulse f -> (id, f w cr)
|
||||
ImpulseUseTargetCID f -> case cr ^? crTarget . _Just of
|
||||
Just tcid -> followImpulse cr w (f tcid)
|
||||
_ -> (id,cr)
|
||||
ImpulseUseTarget f -> case cr ^? crTarget . _Just of
|
||||
Just tcid -> followImpulse cr w (f $ _creatures w IM.! tcid)
|
||||
_ -> (id,cr)
|
||||
ImpulseUseAheadPos f -> followImpulse cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||
_ -> (id , cr)
|
||||
where
|
||||
cpos = _crPos cr
|
||||
@@ -153,6 +160,7 @@ performAction cr w ac = case ac of
|
||||
UseTargetCID f -> case cr ^? crTarget . _Just of
|
||||
Just tcid -> performAction cr w (f tcid)
|
||||
_ -> ([],Nothing)
|
||||
UseAheadPos f -> performAction cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||
_ -> ([], Nothing)
|
||||
where
|
||||
cpos = _crPos cr
|
||||
|
||||
@@ -86,7 +86,7 @@ velocity to carry across frames.
|
||||
crFriction :: Creature -> Point2 -> Point2
|
||||
crFriction cr vel = (0,0)
|
||||
|
||||
{- | In order to force a list, apply with seq -}
|
||||
{- | In order to force a list, apply with seq. -}
|
||||
forceSpine :: [a] -> ()
|
||||
forceSpine = foldr (const id) ()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user