Add pistolCrit file, tweak shell spin params

This commit is contained in:
2021-05-13 19:21:52 +02:00
parent 2402e1e868
commit eed7865192
7 changed files with 147 additions and 45 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
module Dodge.AIs module Dodge.AIs
( launcherAI ( chargeAI
, chargeAI
, dodgeAI , dodgeAI
, spawnerAI , spawnerAI
) where ) where
+2 -10
View File
@@ -2,6 +2,7 @@ module Dodge.Creature
( module Dodge.Creature ( module Dodge.Creature
, module Dodge.Creature.Inanimate , module Dodge.Creature.Inanimate
, launcherCrit , launcherCrit
, pistolCrit
) )
where where
import Dodge.Creature.Stance.Data import Dodge.Creature.Stance.Data
@@ -14,6 +15,7 @@ import Dodge.Creature.AlertLevel
import Dodge.Creature.SetTarget import Dodge.Creature.SetTarget
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Creature.LauncherCrit import Dodge.Creature.LauncherCrit
import Dodge.Creature.PistolCrit
import Dodge.Data import Dodge.Data
import Dodge.AIs import Dodge.AIs
import Dodge.Default import Dodge.Default
@@ -179,16 +181,6 @@ spreadGunCrit = defaultCreature
, _crState = defaultState {_goals = [[Init]]} , _crState = defaultState {_goals = [[Init]]}
, _crHP = 300 , _crHP = 300
} }
pistolCrit :: Creature
pistolCrit = defaultCreature
{ _crPict = basicCrPict red
, _crUpdate = stateUpdate (dodgeAI 150 200)
, _crInv = IM.fromList [(0,pistol),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crState = defaultState {_goals = [[InitGuard]]}
, _crHP = 500
}
autoCrit :: Creature autoCrit :: Creature
autoCrit = defaultCreature autoCrit = defaultCreature
{ _crPict = basicCrPict red { _crPict = basicCrPict red
+25 -18
View File
@@ -78,18 +78,22 @@ shootFirstMiss tcid w cr = StrategyActions (ShootAt tcid) acs
`DoActionThen` `DoActionThen`
LeadTarget (0,0) LeadTarget (0,0)
`DoActionThen` `DoActionThen`
(advanceShoot `DoActionWhileThen` lostest lostest `DoActionWhile`
$ DoReplicateThen advanceShoot 75 advanceShoot `DoActionThen`
$ DoImpulses [ChangeStrategy WatchAndWait] 75 `DoReplicate`
) advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
] ]
lostest (w,cr') = canSee (_crID cr') tcid w lostest (w,cr') = canSee (_crID cr') tcid w
advanceShoot = ImpulsesList [[UseItem, MoveForward 3]] advanceShoot = ImpulsesList [[UseItem, MoveForward 3]]
fleeTime :: Int -> World -> Creature -> Strategy fleeTime :: Int -> World -> Creature -> Strategy
fleeTime t w cr = StrategyActions Flee fleeTime t w cr = StrategyActions Flee
[ UseTargetCID FleeFrom `DoReplicateThen` t [ t `DoReplicate`
$ DoImpulses [ChangeStrategy WatchAndWait] UseTargetCID FleeFrom
`DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
] ]
aimThenShootStrat :: Int -> World -> Creature -> Strategy aimThenShootStrat :: Int -> World -> Creature -> Strategy
@@ -115,10 +119,10 @@ shootMoveStrat :: Point2 -> Int -> World -> Creature -> Strategy
shootMoveStrat moveV tcid _ _ = StrategyActions (ShootAt tcid) shootMoveStrat moveV tcid _ _ = StrategyActions (ShootAt tcid)
[ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction)) [ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction))
`DoActionThen` `DoActionThen`
(DoActionWhileThen advanceShoot lostest lostest `DoActionWhile`
. DoReplicateThen advanceShoot 75 75 `DoReplicate`
$ DoImpulses [ChangeStrategy WatchAndWait] advanceShoot `DoActionThen`
) DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow , AimAtCloseSlow
{ _targetID = tcid { _targetID = tcid
, _targetSeenAt = (0,0) -- hack , _targetSeenAt = (0,0) -- hack
@@ -135,10 +139,11 @@ shootAdvanceStrat :: Int -> World -> Creature -> Strategy
shootAdvanceStrat tcid _ _ = StrategyActions (ShootAt tcid) shootAdvanceStrat tcid _ _ = StrategyActions (ShootAt tcid)
[ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction)) [ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction))
`DoActionThen` `DoActionThen`
(DoActionWhileThen advanceShoot lostest lostest `DoActionWhile`
. DoReplicateThen advanceShoot 75 advanceShoot `DoActionThen`
$ DoImpulses [ChangeStrategy WatchAndWait] 75 `DoReplicate`
) advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow , AimAtCloseSlow
{ _targetID = tcid { _targetID = tcid
, _targetSeenAt = (0,0) -- hack , _targetSeenAt = (0,0) -- hack
@@ -183,10 +188,12 @@ shootAdvance w cr tcr as
&& cr ^? crInv . ix (_crInvSel cr) . wpReloadState == Just 0 = && cr ^? crInv . ix (_crInvSel cr) . wpReloadState == Just 0 =
[ DrawWeapon [ DrawWeapon
, DoImpulses [ChangeStrategy $ ShootAt $ _crID tcr] , DoImpulses [ChangeStrategy $ ShootAt $ _crID tcr]
, WaitThen 50 , 50 `WaitThen`
. DoActionWhileThen advanceShoot lostest lostest `DoActionWhile`
. DoReplicateThen advanceShoot 50 advanceShoot `DoActionThen`
$ DoImpulses [ChangeStrategy WatchAndWait] 50 `DoReplicate`
advanceShoot `DoActionThen`
DoImpulses [ChangeStrategy WatchAndWait]
, AimAtCloseSlow , AimAtCloseSlow
{ _targetID = _crID tcr { _targetID = _crID tcr
, _targetSeenAt = _crPos cr , _targetSeenAt = _crPos cr
+72
View File
@@ -0,0 +1,72 @@
module Dodge.Creature.PistolCrit
( pistolCrit
) 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 Data.Maybe
import qualified Data.IntMap.Strict as IM
import Control.Lens
pistolCrit :: Creature
pistolCrit = defaultCreature
{ _crPict = basicCrPict red
, _crUpdate = stateUpdate $ impulsiveAI $ composeInternalAIs
[ performActions
, watchUpdateStrat
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0) [chooseMovement cr w])
, (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,pistol),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crHP = 500
}
chooseMovement :: Creature -> World -> Action
chooseMovement cr w = undefined
retreatAction :: Creature -> Creature -> Action
retreatAction tcr cr =
[TurnToward retreatOffset 0.2]
`DoImpulsesAlongside`
NoAction
where
cpos = _crPos cr
tpos = _crPos tcr
retreatOffset =
let a | dist cpos tpos < 50 = 0
| isLeftOfA (_crDir cr) (argV $ tpos -.- cpos)
= -0.7
| otherwise = 0.7
in fromMaybe tpos $ intersectLineLine' cpos
(cpos +.+ rotateV a (tpos -.- cpos))
tpos
(tpos +.+ vNormal (cpos -.- tpos))
+15 -6
View File
@@ -68,7 +68,8 @@ followImpulse cr w imp = case imp of
DropItem -> undefined DropItem -> undefined
ChangeStrategy strat -> (id, cr & crActionPlan . crStrategy .~ strat) ChangeStrategy strat -> (id, cr & crActionPlan . crStrategy .~ strat)
AddGoal gl -> (id, cr & crActionPlan . crGoal %~ (gl :) ) AddGoal gl -> (id, cr & crActionPlan . crGoal %~ (gl :) )
ArbitraryCreatureImpulse f -> (id, f w cr) ArbitraryImpulseFunction f -> (id, f w cr)
ArbitraryImpulse f -> followImpulse cr w (f cr w)
ImpulseUseTargetCID f -> case cr ^? crTarget . _Just of ImpulseUseTargetCID f -> case cr ^? crTarget . _Just of
Just tcid -> followImpulse cr w (f tcid) Just tcid -> followImpulse cr w (f tcid)
_ -> (id,cr) _ -> (id,cr)
@@ -130,17 +131,18 @@ performAction cr w ac = case ac of
DoActionThen ac ac' -> case performAction cr w ac of DoActionThen ac ac' -> case performAction cr w ac of
(imps , Just ac'') -> (imps, Just (DoActionThen ac'' ac')) (imps , Just ac'') -> (imps, Just (DoActionThen ac'' ac'))
(imps , Nothing ) -> (imps, Just ac') (imps , Nothing ) -> (imps, Just ac')
DoActionWhile ac f DoActionWhile f ac -> performAction cr w $ DoActionWhilePartial ac f ac
| f (w,cr) -> (fst $ performAction cr w ac, Just $ DoActionWhile ac f) DoActionWhilePartial partAc f resetAc
| otherwise -> ([], Nothing) | f (w,cr) -> case performAction cr w partAc of
(imps, Just ac) -> (imps, Just $ DoActionWhilePartial ac f resetAc)
(imps, _) -> (imps, Just $ DoActionWhilePartial resetAc f resetAc)
| otherwise -> performAction cr w partAc
DoActionIfElse ac f ac' DoActionIfElse ac f ac'
| f (w,cr) -> performAction cr w ac | f (w,cr) -> performAction cr w ac
| otherwise -> performAction cr w ac' | otherwise -> performAction cr w ac'
DoActionWhileThen ac f ac' DoActionWhileThen ac f ac'
| f (w,cr) -> (fst $ performAction cr w ac, Just $ DoActionWhileThen ac f ac') | f (w,cr) -> (fst $ performAction cr w ac, Just $ DoActionWhileThen ac f ac')
| otherwise -> performAction cr w ac' | otherwise -> performAction cr w ac'
DoReplicateThen ac 0 ac' -> performAction cr w ac'
DoReplicateThen ac t ac' -> (fst $ performAction cr w ac, Just $ DoReplicateThen ac (t-1) ac')
DoActions [] -> ([], Nothing) DoActions [] -> ([], Nothing)
DoActions acs -> DoActions acs ->
let (imps, newAcs) = unzip $ map (performAction cr w) acs let (imps, newAcs) = unzip $ map (performAction cr w) acs
@@ -161,6 +163,13 @@ performAction cr w ac = case ac of
Just tcid -> performAction cr w (f tcid) Just tcid -> performAction cr w (f tcid)
_ -> ([],Nothing) _ -> ([],Nothing)
UseAheadPos f -> performAction cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr))) UseAheadPos f -> performAction cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
ArbitraryAction f -> performAction cr w (f cr w)
DoImpulsesAlongside sideImpulses mainAc -> undefined
DoReplicate t ac -> performAction cr w $ DoReplicatePartial ac t ac
DoReplicatePartial _ 0 ac' -> performAction cr w ac'
DoReplicatePartial ac t ac' -> case performAction cr w ac' of
(imps , Just ac'') -> (imps, Just $ DoReplicatePartial ac t ac'')
(imps , _) -> (imps, Just $ DoReplicatePartial ac (t-1) ac)
_ -> ([], Nothing) _ -> ([], Nothing)
where where
cpos = _crPos cr cpos = _crPos cr
+28 -6
View File
@@ -476,7 +476,8 @@ data Impulse
| MakeSound Int | MakeSound Int
| ChangeStrategy Strategy | ChangeStrategy Strategy
| AddGoal Goal | AddGoal Goal
| ArbitraryCreatureImpulse (World -> Creature -> Creature) | ArbitraryImpulseFunction (World -> Creature -> Creature)
| ArbitraryImpulse (Creature -> World -> Impulse)
| ImpulseUseTargetCID | ImpulseUseTargetCID
{_impulseUseTargetCID :: Int -> Impulse {_impulseUseTargetCID :: Int -> Impulse
} }
@@ -489,6 +490,8 @@ data Impulse
-- deriving (Eq,Ord,Show) -- deriving (Eq,Ord,Show)
infixr 9 `WaitThen` infixr 9 `WaitThen`
infixr 9 `DoActionThen` infixr 9 `DoActionThen`
infixr 9 `DoActionWhile`
infixr 9 `DoReplicate`
data Action data Action
= Attack = Attack
{_attackTargetID :: Int} {_attackTargetID :: Int}
@@ -535,8 +538,13 @@ data Action
,_waitThenAction :: Action ,_waitThenAction :: Action
} }
| DoActionWhile | DoActionWhile
{_doActionWhileAction :: Action {_doActionWhileCondition :: ( (World, Creature) -> Bool)
,_doActionWhileAction :: Action
}
| DoActionWhilePartial
{_doActionWhilePartial :: Action
,_doActionWhileCondition :: ( (World, Creature) -> Bool) ,_doActionWhileCondition :: ( (World, Creature) -> Bool)
,_doActionWhileAction :: Action
} }
| DoActionIfElse | DoActionIfElse
{_doActionIfElseIfAction :: Action {_doActionIfElseIfAction :: Action
@@ -561,10 +569,14 @@ data Action
| DoGuardActions | DoGuardActions
{_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)] {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)]
} }
| DoReplicateThen | DoReplicate
{_doReplicateThenDo :: Action {_doReplicateTimes :: Int
,_doReplicateThenTimes :: Int ,_doReplicateAction :: Action
,_doReplicateThenAfter :: Action }
| DoReplicatePartial
{_partialAction :: Action
,_doReplicateTimes :: Int
,_doReplicateAction :: Action
} }
| LeadTarget | LeadTarget
{_leadTargetBy :: Point2 {_leadTargetBy :: Point2
@@ -577,6 +589,16 @@ data Action
| UseAheadPos | UseAheadPos
{_useAheadPos :: Point2 -> Action {_useAheadPos :: Point2 -> Action
} }
| ArbitraryAction
{ _arbitraryAction :: Creature -> World -> Action }
| DoActionAlongside -- ^ Repeatedly perform a side action alongside a main action until the main action terminates
{_sideAction :: Action
,_mainAction :: Action
}
| DoImpulsesAlongside -- ^ Repeatedly perform impulses alongside a main action until the main action terminates
{_sideImpulses :: [Impulse]
,_mainAction :: Action
}
deriving (Generic) deriving (Generic)
-- deriving (Eq,Ord,Show) -- deriving (Eq,Ord,Show)
data Strategy data Strategy
+4 -3
View File
@@ -676,12 +676,12 @@ moveShell time i cid rot accel w
| time >= 20 = w | time >= 20 = w
& projectiles . ix i . pjPos %~ (+.+ vel) & projectiles . ix i . pjPos %~ (+.+ vel)
& projectiles . ix i . pjPict .~ pic & projectiles . ix i . pjPict .~ pic
& projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot (rotateV rot accel) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel)
| time > -99 = w | time > -99 = w
& projectiles . ix i . pjPos %~ (+.+ vel) & projectiles . ix i . pjPos %~ (+.+ vel)
& randGen .~ g & randGen .~ g
& projectiles . ix i . pjPict .~ pic & projectiles . ix i . pjPict .~ pic
& projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot (rotateV rot accel) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel)
& projectiles . ix i . pjVel %~ (\v -> accel +.+ frict *.* v) & projectiles . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
& soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250 & soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
& makeFlameletTimed (oldPos -.- vel) (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10 & makeFlameletTimed (oldPos -.- vel) (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
@@ -689,7 +689,7 @@ moveShell time i cid rot accel w
| time > -200 = w | time > -200 = w
& projectiles . ix i . pjPos %~ (+.+ vel) & projectiles . ix i . pjPos %~ (+.+ vel)
& projectiles . ix i . pjPict .~ pic & projectiles . ix i . pjPict .~ pic
& projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot (rotateV rot accel) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel)
| otherwise = doExplode | otherwise = doExplode
where where
doExplode = w doExplode = w
@@ -715,6 +715,7 @@ moveShell time i cid rot accel w
_ -> 0 _ -> 0
r1 = randInCirc 10 & evalState $ _randGen w r1 = randInCirc 10 & evalState $ _randGen w
smokeGen = makeSmokeCloudAt (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)) smokeGen = makeSmokeCloudAt (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))
rot' = rot * 0.995
normalizeAnglePi angle normalizeAnglePi angle
| normalizeAngle angle > pi = normalizeAngle angle - 2*pi | normalizeAngle angle > pi = normalizeAngle angle - 2*pi