Start ai cleanup

This commit is contained in:
2021-09-05 22:27:31 +01:00
parent 68ba11aa91
commit e366698064
19 changed files with 352 additions and 489 deletions
+31 -46
View File
@@ -6,8 +6,8 @@ import Dodge.Creature.Test
import Dodge.Creature.Volition
import Dodge.Creature.ReaderUpdate
import Dodge.Creature.ActionRat
import Dodge.Creature.Action
--import Dodge.Creature.ChooseTarget
import Dodge.Creature.Rationality
import Dodge.Creature.AlertLevel
--import Dodge.Creature.State
--import Dodge.Creature.State.Data
@@ -20,34 +20,28 @@ import Data.Maybe
import Control.Lens
import Control.Monad
import Control.Monad.Reader
--import System.Random
sentinelAI :: Creature -> Reader World Creature
sentinelAI = sentinelExtraWatchUpdate
[ (crHasTargetLOS
, \ _ cr ->
let lostest (w,cr') = canSee (_crID cr') tcid w
advanceShoot = ImpulsesList [[UseItem, MoveForward 3]]
tcid = _crID $ fromJust $ _crTarget cr
in StrategyActions (ShootAt tcid)
[ DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
`DoActionThen`
lostest `DoActionWhile`
advanceShoot `DoActionThen`
75 `DoReplicate`
advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow
{ _targetID = tcid
, _targetSeenAt = V2 0 0 -- hack
, _aimSpeed = 0.2
, _slowAimSpeed = 0.01
, _slowAimAngle = pi/8
}
]
)
]
[ (crHasTargetLOS
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
[ DoActionIf
(not . crIsAiming)
(drawWeapon `DoActionThen` (50 `WaitThen` NoAction))
`DoActionThen` lostest
`DoActionWhile` advanceShoot
`DoActionThen` 75
`DoReplicate` advanceShoot
`DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
, AimAt { _targetID = fromJust $ tcid cr , _targetSeenAt = V2 0 0 }
]
)
]
>=> reloadOverrideR
where
advanceShoot = DoImpulses [UseItem, MoveForward 3]
tcid cr = _crID <$> _crTarget cr
lostest (w,cr) = maybe False (\cid -> canSee (_crID cr) cid w) (tcid cr)
sentinelFireType
:: (Int -> Action)
@@ -57,7 +51,8 @@ sentinelFireType f = performActionsR
>=> watchUpdateStratR
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
, aiming]
, aiming
]
)
, (crAwayFromPost, goToPostStrat)
]
@@ -65,17 +60,14 @@ sentinelFireType f = performActionsR
>=> doStrategyActionsR
>=> reloadOverrideR
>=> targetYouWhenCognizantR
>=> overrideInternalR
(onBoth (&&) crHasTarget (crStratConMatches (GetTo (V2 0 0))))
(\ _ -> crActionPlan . crStrategy .~ WatchAndWait)
>=> overrideInternalRRR
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
where
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
aiming = AimAtCloseSlow
aiming = AimAt
{ _targetID = 0
, _targetSeenAt = V2 0 0 -- hack
, _aimSpeed = 0.2
, _slowAimSpeed = 0.01
, _slowAimAngle = pi/8
}
sentinelExtraWatchUpdate
@@ -84,14 +76,13 @@ sentinelExtraWatchUpdate
-> Reader World Creature
sentinelExtraWatchUpdate xs = performActionsR
>=> watchUpdateStratR
( xs ++ [(crAwayFromPost, goToPostStrat)] )
( xs ++ [(crAwayFromPost, goToPostStrat)] )
>=> basicPerceptionUpdateR [0]
>=> doStrategyActionsR
-- >=> reloadOverrideR
>=> targetYouWhenCognizantR
>=> overrideInternalR (onBoth (&&) crHasTarget (crStratConMatches (GetTo (V2 0 0))))
(\ _ -> crActionPlan . crStrategy .~ WatchAndWait)
>=> overrideInternalRRR
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
shootAtAdvance :: Int -> [Action]
shootAtAdvance tcid =
@@ -102,12 +93,9 @@ shootAtAdvance tcid =
75 `DoReplicate`
advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow
, AimAt
{ _targetID = tcid
, _targetSeenAt = V2 0 0 -- hack
, _aimSpeed = 0.2
, _slowAimSpeed = 0.01
, _slowAimAngle = pi/8
}
]
where
@@ -123,12 +111,9 @@ shootAtWhileContinueTime tcid _ _ = StrategyActions (ShootAt tcid)
75 `DoReplicate`
advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow
, AimAt
{ _targetID = tcid
, _targetSeenAt = V2 0 0 -- hack
, _aimSpeed = 0.2
, _slowAimSpeed = 0.01
, _slowAimAngle = pi/8
}
]
where