Cleanup warnings
This commit is contained in:
@@ -9,25 +9,25 @@ module Dodge.Creature.Action
|
||||
import Dodge.Creature.Action.UseItem
|
||||
import Dodge.Creature.Action.Movement
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.State.Data
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.WorldEvent.Shockwave
|
||||
import Dodge.Data hiding (carriage)
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.WorldEvent
|
||||
--import Dodge.WorldEvent
|
||||
import Dodge.Inventory
|
||||
import Dodge.LightSources
|
||||
--import Dodge.LightSources
|
||||
import Geometry
|
||||
import Picture
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Control.Applicative
|
||||
--import Control.Monad
|
||||
--import Control.Applicative
|
||||
import Data.Maybe
|
||||
import Data.List
|
||||
--import Data.List
|
||||
import System.Random
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import qualified Data.Map as M
|
||||
--import qualified Data.Map as M
|
||||
|
||||
crStrafeLeft
|
||||
:: Float -- ^ Speed
|
||||
@@ -271,7 +271,7 @@ turnBy a n = over (creatures . ix n . crDir) (+ a)
|
||||
youDropItem :: World -> World
|
||||
youDropItem w = case yourItem w of
|
||||
NoItem -> w
|
||||
it -> rmSelectedInvItem (_yourID w)
|
||||
_ -> rmSelectedInvItem (_yourID w)
|
||||
. copyItemToFloor (you w) (_crInvSel $ you w)
|
||||
$ soundOnce putDownSound
|
||||
w
|
||||
@@ -287,9 +287,9 @@ copyItemToFloor cr i w = case _crInv cr IM.! i of
|
||||
where
|
||||
(rot, g) = randomR (-pi,pi) $ _randGen w
|
||||
offset = (_crRad cr + 2) *.* unitVectorAtAngle rot
|
||||
updateLocation w = case it ^? itID of
|
||||
Just (Just i) -> w & itemPositions . ix i .~ OnFloor flid
|
||||
_ -> w
|
||||
updateLocation w' = case it ^? itID of
|
||||
Just (Just i') -> w' & itemPositions . ix i' .~ OnFloor flid
|
||||
_ -> w'
|
||||
flid = newKey $ _floorItems w
|
||||
theflit = FlIt
|
||||
{_flIt = it
|
||||
|
||||
@@ -8,7 +8,7 @@ import Data.Maybe
|
||||
|
||||
retreatPointForFrom
|
||||
:: Float -> World -> Creature -> Point2 -> Maybe Point2
|
||||
retreatPointForFrom d w cr p
|
||||
retreatPointForFrom d _ cr p
|
||||
= listToMaybe
|
||||
. sortOn (dist cpos)
|
||||
$ divideCircle 10 p d
|
||||
|
||||
@@ -6,27 +6,32 @@ module Dodge.Creature.ActionRat
|
||||
, shootAdvance
|
||||
, shootFirstMiss
|
||||
, doStrategyActions
|
||||
, doStrategyActionsR
|
||||
, reloadOverride
|
||||
, reloadOverrideR
|
||||
, reloadOverrideNoHolster
|
||||
, shootAdvanceStrat
|
||||
, shootMoveStrat
|
||||
, watchUpdateStrat
|
||||
, watchUpdateStratR
|
||||
, goToPostStrat
|
||||
, overrideInternal
|
||||
, overrideInternalR
|
||||
, fleeTime
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--import Dodge.Base.Collide
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.Test
|
||||
import Geometry
|
||||
--import Geometry
|
||||
|
||||
import Data.List
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
|
||||
shootTargetWithStrat
|
||||
:: (Creature -> World -> Maybe Creature) -- ^ Function for determining target
|
||||
@@ -65,8 +70,9 @@ suppress w cr tcr as
|
||||
]
|
||||
| otherwise = as
|
||||
|
||||
-- This should be decomposed properly
|
||||
shootFirstMiss :: Int -> World -> Creature -> Strategy
|
||||
shootFirstMiss tcid w cr = StrategyActions (ShootAt tcid) acs
|
||||
shootFirstMiss tcid _ _ = StrategyActions (ShootAt tcid) acs
|
||||
where
|
||||
acs =
|
||||
[ DoActionIfElse NoAction crIsAiming (DoActionThen DrawWeapon (WaitThen 50 NoAction))
|
||||
@@ -88,7 +94,7 @@ shootFirstMiss tcid w cr = StrategyActions (ShootAt tcid) acs
|
||||
advanceShoot = ImpulsesList [[UseItem, MoveForward 3]]
|
||||
|
||||
fleeTime :: Int -> World -> Creature -> Strategy
|
||||
fleeTime t w cr = StrategyActions Flee
|
||||
fleeTime t _ _ = StrategyActions Flee
|
||||
[ t `DoReplicate`
|
||||
UseTargetCID FleeFrom
|
||||
`DoActionThen`
|
||||
@@ -110,9 +116,6 @@ aimThenShootStrat tcid _ _ = StrategyActions (ShootAt tcid)
|
||||
, _slowAimAngle = pi/8
|
||||
}
|
||||
]
|
||||
where
|
||||
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)
|
||||
@@ -165,7 +168,7 @@ goToPostStrat w cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of
|
||||
]
|
||||
_ -> WatchAndWait
|
||||
where
|
||||
sentinelGoal (SentinelAt p dir) = True
|
||||
sentinelGoal (SentinelAt _ _) = True
|
||||
sentinelGoal _ = False
|
||||
holsterIfAiming
|
||||
| crIsAiming (w,cr) = HolsterWeapon
|
||||
@@ -181,6 +184,16 @@ overrideInternal test update w cr
|
||||
| test (w,cr) = update w cr
|
||||
| otherwise = cr
|
||||
|
||||
overrideInternalR
|
||||
:: ((World , Creature) -> Bool)
|
||||
-> (World -> Creature -> Creature)
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
overrideInternalR test update cr = reader $ \w ->
|
||||
if test (w,cr)
|
||||
then update w cr
|
||||
else cr
|
||||
|
||||
shootAdvance :: World -> Creature -> Creature -> [Action] -> [Action]
|
||||
shootAdvance w cr tcr as
|
||||
| lostest (w,cr) && cr ^. crStance . posture /= Aiming
|
||||
@@ -205,33 +218,25 @@ shootAdvance w cr tcr as
|
||||
= [ HolsterWeapon ]
|
||||
| otherwise = as
|
||||
where
|
||||
lostest (w,cr') = canSee (_crID cr) (_crID tcr) w
|
||||
lostest (w',cr') = canSee (_crID cr') (_crID tcr) w'
|
||||
advanceShoot = ImpulsesList [[UseItem, MoveForward 3]]
|
||||
|
||||
applyNewStrategies
|
||||
:: World
|
||||
-> Creature
|
||||
-> Creature
|
||||
applyNewStrategies w cr = case cr ^? crActionPlan . crStrategy of
|
||||
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||
& crActionPlan . crStrategy .~ strat
|
||||
_ -> cr
|
||||
|
||||
doStrategyActions
|
||||
:: World
|
||||
-> Creature
|
||||
-> Creature
|
||||
doStrategyActions w cr = case cr ^? crActionPlan . crStrategy of
|
||||
doStrategyActions _ cr = case cr ^? crActionPlan . crStrategy of
|
||||
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||
& crActionPlan . crStrategy .~ strat
|
||||
_ -> cr
|
||||
|
||||
updateShoot
|
||||
:: World
|
||||
-> Creature
|
||||
-> Creature
|
||||
updateShoot w cr = case _crStrategy $ _crActionPlan cr of
|
||||
WatchAndWait -> undefined
|
||||
doStrategyActionsR
|
||||
:: Creature
|
||||
-> Reader World Creature
|
||||
doStrategyActionsR cr = return $ case cr ^? crActionPlan . crStrategy of
|
||||
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||
& crActionPlan . crStrategy .~ strat
|
||||
_ -> cr
|
||||
|
||||
reloadOverride
|
||||
:: World
|
||||
@@ -245,7 +250,21 @@ reloadOverride _ cr
|
||||
where
|
||||
reloadActions =
|
||||
[ HolsterWeapon
|
||||
, WaitThen 1 $ DoActionWhileThen NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
, WaitThen 1 $ DoActionWhileInterrupt NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
|
||||
reloadOverrideR
|
||||
:: Creature
|
||||
-> Reader World Creature
|
||||
reloadOverrideR cr
|
||||
| cr ^? crInv . ix (_crInvSel cr) . wpLoadedAmmo == Just 0
|
||||
&& cr ^. crStance . posture == Aiming
|
||||
= return $ cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
|
||||
| otherwise = return $ cr
|
||||
where
|
||||
reloadActions =
|
||||
[ HolsterWeapon
|
||||
, WaitThen 1 $ DoActionWhileInterrupt NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
|
||||
reloadOverrideNoHolster
|
||||
@@ -259,7 +278,7 @@ reloadOverrideNoHolster _ cr
|
||||
| otherwise = cr
|
||||
where
|
||||
reloadActions =
|
||||
[ DoActionWhileThen NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
[ DoActionWhileInterrupt NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
|
||||
watchUpdateStrat
|
||||
@@ -272,6 +291,15 @@ watchUpdateStrat fs w cr = case cr ^? crActionPlan . crStrategy of
|
||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
_ -> cr
|
||||
|
||||
watchUpdateStratR
|
||||
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
watchUpdateStratR fs cr = reader $ \w -> case cr ^? crActionPlan . crStrategy of
|
||||
Just WatchAndWait -> cr
|
||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
_ -> cr
|
||||
|
||||
listGuard :: ([(a -> Bool, b)] , b) -> a -> b
|
||||
listGuard ( (test,y):ps, z ) x
|
||||
| test x = y
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
module Dodge.Creature.AutoCrit
|
||||
( autoCrit
|
||||
) 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 Dodge.RandomHelp
|
||||
|
||||
--import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
--import System.Random
|
||||
|
||||
autoCrit :: Creature
|
||||
autoCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||
performActionsR
|
||||
>=> watchUpdateStratR
|
||||
[ (crHasTargetLOS, shootAdvanceStrat 0)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
>=> (overrideInternalR (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
$ \ _ -> crActionPlan . crStrategy .~ WatchAndWait)
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
, _crStrategy = StrategyActions WatchAndWait [StartSentinelPost]
|
||||
, _crGoal = []
|
||||
}
|
||||
, _crInv = IM.fromList [(0,autoGun),(1,medkit 100)]
|
||||
, _crInvSel = 0
|
||||
, _crRad = 10
|
||||
, _crHP = 300
|
||||
}
|
||||
@@ -2,7 +2,7 @@ module Dodge.Creature.ImpulseRat
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.State.Data
|
||||
import Geometry
|
||||
|
||||
@@ -120,15 +120,14 @@ chaseTargetR targFunc cr = reader $ \w -> case targFunc cr w of
|
||||
Nothing -> cr
|
||||
Just crTarg -> cr & crActionPlan . crImpulse .~ chaseTarg cr crTarg
|
||||
|
||||
|
||||
overrideMeleeCloseTarget :: World -> Creature -> Creature
|
||||
overrideMeleeCloseTarget w cr = case _crTarget cr of
|
||||
overrideMeleeCloseTarget _ cr = case _crTarget cr of
|
||||
Nothing -> cr
|
||||
Just tcr
|
||||
| _crMeleeCooldown cr == Just 0
|
||||
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
|
||||
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
|
||||
-> cr & crActionPlan . crStrategy .~ StrategyActions MeleeStrike [DoImpulses [Melee (_crID tcr)]]
|
||||
-> cr & crActionPlan . crAction .~ [DoImpulses [Melee (_crID tcr)]]
|
||||
| otherwise -> cr
|
||||
where
|
||||
cpos = _crPos cr
|
||||
@@ -136,16 +135,21 @@ overrideMeleeCloseTarget w cr = case _crTarget cr of
|
||||
overrideMeleeCloseTargetR
|
||||
:: Creature
|
||||
-> Reader World Creature
|
||||
overrideMeleeCloseTargetR cr = reader $ \w -> case _crTarget cr of
|
||||
Nothing -> cr
|
||||
Just tcr
|
||||
| _crMeleeCooldown cr == Just 0
|
||||
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
|
||||
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
|
||||
-> cr & crActionPlan . crStrategy .~ StrategyActions MeleeStrike [DoImpulses [Melee (_crID tcr)]]
|
||||
| otherwise -> cr
|
||||
overrideMeleeCloseTargetR cr = return $ maybe cr (tryMeleeAttack cr) (_crTarget cr)
|
||||
|
||||
tryMeleeAttack :: Creature -> Creature -> Creature
|
||||
tryMeleeAttack cr tcr
|
||||
| _crMeleeCooldown cr == Just 0
|
||||
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
|
||||
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
|
||||
= cr & crActionPlan . crStrategy .~ StrategyActions MeleeStrike meleeActions
|
||||
| otherwise = cr
|
||||
where
|
||||
cpos = _crPos cr
|
||||
meleeActions =
|
||||
[DoImpulses [Melee (_crID tcr)]
|
||||
`DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||
]
|
||||
|
||||
chaseTarg' :: Point2 -> Creature -> Creature -> [Impulse]
|
||||
chaseTarg' p cr crT
|
||||
|
||||
@@ -4,7 +4,7 @@ Inanimate objects such as lamps, barrels, etc
|
||||
module Dodge.Creature.Inanimate
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
--import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Picture.Layer
|
||||
@@ -19,6 +19,7 @@ import Picture
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
defaultInanimate :: Creature
|
||||
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
|
||||
|
||||
lamp :: Creature
|
||||
|
||||
@@ -7,15 +7,15 @@ import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--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.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
import Dodge.Item.Consumable
|
||||
import Geometry
|
||||
--import Dodge.Item.Consumable
|
||||
--import Geometry
|
||||
import Picture
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
|
||||
@@ -6,24 +6,23 @@ import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--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.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
import Dodge.Item.Consumable
|
||||
import Geometry
|
||||
import Picture
|
||||
import Dodge.RandomHelp
|
||||
--import Dodge.RandomHelp
|
||||
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.State
|
||||
import System.Random
|
||||
|
||||
--import Control.Monad.State
|
||||
--import System.Random
|
||||
|
||||
ltAutoCrit :: Creature
|
||||
ltAutoCrit = defaultCreature
|
||||
@@ -31,7 +30,7 @@ ltAutoCrit = defaultCreature
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ composeInternalAIs
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) DrawWeapon
|
||||
,DoActionThen
|
||||
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||
|
||||
@@ -8,7 +8,7 @@ module Dodge.Creature.Picture
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
--import Dodge.Creature.AlertLevel.Data
|
||||
import Dodge.Picture.Layer
|
||||
import Picture
|
||||
import Geometry
|
||||
@@ -52,14 +52,14 @@ basicCrPict col cr = pictures
|
||||
Nothing -> False
|
||||
Just x -> x > 5
|
||||
|
||||
drawAwakeLevel
|
||||
:: Creature
|
||||
-> Picture
|
||||
drawAwakeLevel cr = case cr ^? crAttentionDir of
|
||||
Just (AttentiveTo [0]) -> setPos . color red $ circleSolid 5
|
||||
_ -> setPos . color blue $ circleSolid 5
|
||||
where
|
||||
setPos = translate 0 (_crRad cr)
|
||||
--drawAwakeLevel
|
||||
-- :: Creature
|
||||
-- -> Picture
|
||||
--drawAwakeLevel cr = case cr ^? crAttentionDir of
|
||||
-- Just (AttentiveTo [0]) -> setPos . color red $ circleSolid 5
|
||||
-- _ -> setPos . color blue $ circleSolid 5
|
||||
-- where
|
||||
-- setPos = translate 0 (_crRad cr)
|
||||
|
||||
drawEquipment
|
||||
:: Creature
|
||||
@@ -70,4 +70,5 @@ drawEquipment cr = pictures $ map f $ IM.toList (_crInv cr)
|
||||
Just g | (cr ^? crStance . posture) == Just Aiming -> g cr i
|
||||
_ -> blank
|
||||
|
||||
circLine :: Float -> Picture
|
||||
circLine x = line [(0,0),(x,0)]
|
||||
|
||||
@@ -6,12 +6,12 @@ import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--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.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
import Dodge.Item.Consumable
|
||||
import Geometry
|
||||
@@ -22,24 +22,24 @@ import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.State
|
||||
import System.Random
|
||||
--import System.Random
|
||||
|
||||
pistolCrit :: Creature
|
||||
pistolCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ composeInternalAIs
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0) [DoActionIf (not . crIsAiming) DrawWeapon,chooseMovement cr w])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
, basicPerceptionUpdate [0]
|
||||
, doStrategyActions
|
||||
, reloadOverride
|
||||
, targetYouWhenCognizant
|
||||
, overrideInternal (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
$ \ _ -> crActionPlan . crStrategy .~ WatchAndWait
|
||||
]
|
||||
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||
performActionsR
|
||||
>=> watchUpdateStratR
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) DrawWeapon,chooseMovement cr w])
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
>=> overrideInternalR (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
( \ _ -> crActionPlan . crStrategy .~ WatchAndWait )
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
|
||||
@@ -3,7 +3,7 @@ module Dodge.Creature.Rationality
|
||||
import Dodge.Data
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Creature.Action.UseItem
|
||||
--import Dodge.Creature.Action.UseItem
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.SoundLogic
|
||||
@@ -15,8 +15,6 @@ import System.Random
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
|
||||
-- Alternatives would probably be a very good fit for actions...
|
||||
|
||||
composeInternalAIs
|
||||
:: [World -> Creature -> Creature]
|
||||
-> World
|
||||
@@ -40,13 +38,14 @@ impulsiveAI
|
||||
-> ((World -> World,StdGen), Maybe Creature)
|
||||
impulsiveAI impF w (f,g) = followImpulses w (f,g) . impF w
|
||||
|
||||
-- needs cleanup
|
||||
followImpulses
|
||||
:: World
|
||||
-> (World -> World,StdGen)
|
||||
-> Creature
|
||||
-> ((World -> World,StdGen), Maybe Creature)
|
||||
followImpulses w (f,g) cr
|
||||
= (\(f''' ,cr) -> ((f''',g'),Just cr))
|
||||
= (\(f''' ,cr') -> ((f''',g'),Just cr'))
|
||||
$ foldr
|
||||
(\imp (f' , cr') -> let (f'', cr'') = followImpulse cr' w imp in (f'' . f', cr''))
|
||||
(f, cr)
|
||||
@@ -68,9 +67,9 @@ followImpulse cr w imp = case imp of
|
||||
ChangePosture post -> (id, cr & crStance . posture .~ post)
|
||||
UseItem -> (crUseItem cr, cr)
|
||||
SwitchToItem i -> (id, cr & crInvSel .~ i)
|
||||
Melee crID ->
|
||||
(hitCr crID
|
||||
, crMvBy (10 *.* normalizeV (posFromID crID -.- cpos)) $ cr & crMeleeCooldown ?~ 20) -- randomise cooldown?
|
||||
Melee cid ->
|
||||
(hitCr cid
|
||||
, crMvBy (10 *.* normalizeV (posFromID cid -.- cpos)) $ cr & crMeleeCooldown ?~ 20) -- randomise cooldown?
|
||||
RandomTurn a -> (id, creatureTurn (rr a) cr)
|
||||
MakeSound sid -> ( soundOnceOrigin sid (CrSound (_crID cr)) (_crPos cr) , cr )
|
||||
DropItem -> undefined
|
||||
@@ -101,18 +100,6 @@ actionUpdateAI
|
||||
-> Creature
|
||||
actionUpdateAI actF w c = performActions w $ actF w c
|
||||
|
||||
performActionR :: Creature -> Reader World Creature
|
||||
performActionR cr = reader $ \w -> performActions w cr
|
||||
|
||||
watchUpdateStratR
|
||||
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
||||
-> Creature
|
||||
-> Reader World Creature
|
||||
watchUpdateStratR fs cr = case cr ^? crActionPlan . crStrategy of
|
||||
Just WatchAndWait -> reader $ \w -> cr
|
||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||
_ -> reader $ \_ -> cr
|
||||
|
||||
listGuard :: ([(a -> Bool, b)] , b) -> a -> b
|
||||
listGuard ( (test,y):ps, z ) x
|
||||
| test x = y
|
||||
@@ -126,6 +113,10 @@ performActions w cr = cr
|
||||
where
|
||||
(iss, mayas) = unzip $ map (performAction cr w) $ cr ^. crActionPlan . crAction
|
||||
|
||||
performActionsR :: Creature -> Reader World Creature
|
||||
performActionsR cr = reader $ \w -> performActions w cr
|
||||
|
||||
|
||||
{- | Performing an action means that a creature has some impulses for a frame, and
|
||||
updates or deletes the action itself. -}
|
||||
performAction
|
||||
@@ -154,24 +145,24 @@ performAction cr w ac = case ac of
|
||||
DoImpulses imps -> (imps, Nothing)
|
||||
DrawWeapon -> ([ChangePosture Aiming, MakeSound pickUpSound] , Nothing)
|
||||
HolsterWeapon -> ([ChangePosture AtEase, MakeSound putDownSound] , Nothing)
|
||||
DoActionThen ac ac' -> case performAction cr w ac of
|
||||
(imps , Just ac'') -> (imps, Just (DoActionThen ac'' ac'))
|
||||
(imps , Nothing ) -> (imps, Just ac')
|
||||
DoActionWhile f ac -> performAction cr w $ DoActionWhilePartial ac f ac
|
||||
DoActionThen fsta afta -> case performAction cr w fsta of
|
||||
(imps , Just nxta) -> (imps, Just (DoActionThen nxta afta))
|
||||
(imps , Nothing ) -> (imps, Just afta)
|
||||
DoActionWhile f repa -> performAction cr w $ DoActionWhilePartial repa f repa
|
||||
DoActionWhilePartial partAc f resetAc
|
||||
| f (w,cr) -> case performAction cr w partAc of
|
||||
(imps, Just ac) -> (imps, Just $ DoActionWhilePartial ac f resetAc)
|
||||
(imps, Just nxta) -> (imps, Just $ DoActionWhilePartial nxta f resetAc)
|
||||
(imps, _) -> (imps, Just $ DoActionWhilePartial resetAc f resetAc)
|
||||
| otherwise -> performAction cr w partAc
|
||||
DoActionIf f ac
|
||||
| f (w,cr) -> performAction cr w ac
|
||||
DoActionIf f ifa
|
||||
| f (w,cr) -> performAction cr w ifa
|
||||
| otherwise -> ([],Nothing)
|
||||
DoActionIfElse ac f ac'
|
||||
| f (w,cr) -> performAction cr w ac
|
||||
| otherwise -> performAction cr w ac'
|
||||
DoActionWhileThen ac f ac'
|
||||
| f (w,cr) -> (fst $ performAction cr w ac, Just $ DoActionWhileThen ac f ac')
|
||||
| otherwise -> performAction cr w ac'
|
||||
DoActionIfElse ifa f elsea
|
||||
| f (w,cr) -> performAction cr w ifa
|
||||
| otherwise -> performAction cr w elsea
|
||||
DoActionWhileInterrupt repa f afta
|
||||
| f (w,cr) -> (fst $ performAction cr w repa, Just $ DoActionWhileInterrupt repa f afta)
|
||||
| otherwise -> performAction cr w afta
|
||||
DoActions [] -> ([], Nothing)
|
||||
DoActions acs ->
|
||||
let (imps, newAcs) = unzip $ map (performAction cr w) acs
|
||||
|
||||
@@ -7,6 +7,7 @@ import Dodge.Data
|
||||
import Dodge.Creature.AlertLevel.Data
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
{- | Assumes that you are id 0: if creature is cognizant of you, sets you as target -}
|
||||
targetYouWhenCognizant
|
||||
@@ -16,3 +17,9 @@ targetYouWhenCognizant
|
||||
targetYouWhenCognizant w cr = case cr ^? crAwarenessLevel . ix 0 of
|
||||
Just (Cognizant _) -> cr & crTarget ?~ _creatures w IM.! 0
|
||||
_ -> cr & crTarget .~ Nothing
|
||||
|
||||
targetYouWhenCognizantR :: Creature -> Reader World Creature
|
||||
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crAwarenessLevel . ix 0 of
|
||||
-- Just (Cognizant _) -> cr & crTarget ?~ _creatures w IM.! 0
|
||||
Just (Cognizant _) -> cr {_crTarget = Just $! _creatures w IM.! 0}
|
||||
_ -> cr & crTarget .~ Nothing
|
||||
|
||||
@@ -6,47 +6,45 @@ import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
--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.Creature.State.Data
|
||||
import Dodge.Item.Weapon
|
||||
import Dodge.Item.Consumable
|
||||
import Geometry
|
||||
import Picture
|
||||
import Dodge.RandomHelp
|
||||
--import Dodge.RandomHelp
|
||||
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.State
|
||||
import System.Random
|
||||
|
||||
import Control.Monad
|
||||
--import System.Random
|
||||
|
||||
spreadGunCrit :: Creature
|
||||
spreadGunCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ composeInternalAIs
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) DrawWeapon
|
||||
,DoActionThen
|
||||
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
, basicPerceptionUpdate [0]
|
||||
, doStrategyActions
|
||||
, reloadOverride
|
||||
, targetYouWhenCognizant
|
||||
, overrideInternal (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
$ \ _ -> crActionPlan . crStrategy .~ WatchAndWait
|
||||
]
|
||||
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||
performActionsR
|
||||
>=> watchUpdateStratR
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
[DoActionIf (not . crIsAiming) DrawWeapon
|
||||
,DoActionThen
|
||||
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovement)
|
||||
(DoImpulses [ChangeStrategy WatchAndWait])
|
||||
]
|
||||
)
|
||||
, (crAwayFromPost, goToPostStrat)
|
||||
]
|
||||
>=> basicPerceptionUpdateR [0]
|
||||
>=> doStrategyActionsR
|
||||
>=> reloadOverrideR
|
||||
>=> targetYouWhenCognizantR
|
||||
>=> (overrideInternalR (onBoth (&&) crHasTarget (crStratConMatches (GetTo (0,0))))
|
||||
$ \ _ -> crActionPlan . crStrategy .~ WatchAndWait)
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
|
||||
+23
-29
@@ -6,27 +6,25 @@ import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.RandomHelp
|
||||
import Dodge.WorldEvent
|
||||
import Dodge.WallCreatureCollisions
|
||||
--import Dodge.WallCreatureCollisions
|
||||
import Dodge.Creature.Action
|
||||
import Geometry
|
||||
import Picture
|
||||
|
||||
import Data.List
|
||||
import Data.Char
|
||||
import Data.Maybe
|
||||
--import Data.Char
|
||||
--import Data.Maybe
|
||||
import Data.Function
|
||||
import Control.Lens
|
||||
import Control.Applicative
|
||||
--import Control.Applicative
|
||||
import Control.Monad.State
|
||||
import Control.Monad
|
||||
import qualified SDL
|
||||
import qualified SDL.Mixer as Mix
|
||||
--import Control.Monad
|
||||
--import qualified SDL
|
||||
--import qualified SDL.Mixer as Mix
|
||||
import System.Random
|
||||
import qualified Data.Set as S
|
||||
--import qualified Data.Set as S
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import qualified Data.Map as M
|
||||
import Foreign.ForeignPtr
|
||||
import Control.Concurrent
|
||||
--import qualified Data.Map as M
|
||||
|
||||
type CRUpdate = World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature)
|
||||
|
||||
@@ -45,15 +43,15 @@ stateUpdate u w (f,g) cr =
|
||||
, fmap (updateReloadCounter . doDamage . crAutoReload) $ crOrCorpse =<< maybeCr
|
||||
)
|
||||
where
|
||||
crOrCorpse cr
|
||||
| cr ^. crHP > 0 = Just cr
|
||||
crOrCorpse cr'
|
||||
| cr' ^. crHP > 0 = Just cr'
|
||||
| otherwise = Nothing
|
||||
deathEff
|
||||
| cr ^.crHP > 0 = id
|
||||
| otherwise = stopSoundFrom (CrWeaponSound (_crID cr))
|
||||
. over decorations addCorpse
|
||||
. dropByState cr
|
||||
crBeforeDeath = colCrWall w cr
|
||||
--crBeforeDeath = colCrWall w cr
|
||||
addCorpse = insertNewKey
|
||||
$ uncurry translate (_crOldPos cr)
|
||||
$ rotate (_crDir cr)
|
||||
@@ -75,7 +73,7 @@ Given a creature and a velocity, applies friction to that creature and evaluates
|
||||
velocity to carry across frames.
|
||||
-}
|
||||
crFriction :: Creature -> Point2 -> Point2
|
||||
crFriction cr vel = (0,0)
|
||||
crFriction _ _ = (0,0)
|
||||
|
||||
doDamage :: Creature -> Creature
|
||||
doDamage cr = set (crState . crDamage) []
|
||||
@@ -84,9 +82,6 @@ doDamage cr = set (crState . crDamage) []
|
||||
dams = _crDamage $ _crState cr
|
||||
damagedCr = snd $ _crApplyDamage cr dams cr
|
||||
|
||||
sumDamage :: Creature -> DamageType -> Int -> Int
|
||||
sumDamage cr dm x = x + _dmAmount dm
|
||||
|
||||
movementSideEff :: Creature -> World -> World
|
||||
movementSideEff cr w
|
||||
| hasJetPack
|
||||
@@ -178,18 +173,17 @@ updateBarrel
|
||||
-> (World -> World,StdGen)
|
||||
-> Creature
|
||||
-> ((World -> World , StdGen), Maybe Creature)
|
||||
updateBarrel w (f,g) cr
|
||||
updateBarrel _ (f,g) cr
|
||||
| _crHP cr > 0 = ((f, g), newCr)
|
||||
| otherwise = ((f, g), Nothing)
|
||||
where
|
||||
damages = _crDamage $ _crState cr
|
||||
newCr = Just $ doDamage cr
|
||||
|
||||
-- it is easy to leave off the "f" here
|
||||
-- should find some better way of doing all this that is less prone to error
|
||||
updateExpBarrel ::
|
||||
World -> (World -> World,StdGen) -> Creature -> ((World -> World , StdGen), Maybe Creature)
|
||||
updateExpBarrel w (f,g) cr
|
||||
updateExpBarrel _ (f,g) cr
|
||||
| _crHP cr > 0 = ((f . foldr (.) id pierceSparks . hiss, g'), newCr)
|
||||
| otherwise = ((f . makeExplosionAt (_crPos cr) . stopSounds , g'), Nothing)
|
||||
where
|
||||
@@ -205,13 +199,13 @@ updateExpBarrel w (f,g) cr
|
||||
poss = _piercedPoints $ _crSpState $ _crState cr
|
||||
--newCr = Just $ doDamage $ applyFuseDamage cr -- $ foldr perforate cr damages
|
||||
newCr = Just $ applyFuseDamage $ set (crState . crDamage) [] $ damToExpBarrel damages cr
|
||||
perforate :: DamageType -> Creature -> Creature
|
||||
perforate (Piercing amount sp int ep) cr = over (crState . crSpState . piercedPoints)
|
||||
((:) $ int -.- _crPos cr) cr
|
||||
perforate _ cr = cr
|
||||
applyFuseDamage cr = over crHP (\hp -> hp - length (_piercedPoints
|
||||
$ _crSpState $ _crState cr))
|
||||
cr
|
||||
--perforate :: DamageType -> Creature -> Creature
|
||||
--perforate (Piercing amount sp int ep) cr = over (crState . crSpState . piercedPoints)
|
||||
-- ((:) $ int -.- _crPos cr) cr
|
||||
--perforate _ cr = cr
|
||||
applyFuseDamage cr' = over crHP (subtract $ length (_piercedPoints
|
||||
$ _crSpState $ _crState cr'))
|
||||
cr'
|
||||
hiss | null poss = id
|
||||
| otherwise = soundMultiFrom [BarrelHiss 0,BarrelHiss 1] 41 50 1
|
||||
stopSounds = stopSoundFrom (BarrelHiss 0) . stopSoundFrom (BarrelHiss 1)
|
||||
@@ -224,7 +218,7 @@ damToExpBarrel ds cr = foldr damToExpBarrel' (foldr damToExpBarrel' cr pierceDam
|
||||
isPierce _ = False
|
||||
|
||||
damToExpBarrel' :: DamageType -> Creature -> Creature
|
||||
damToExpBarrel' (Piercing amount sp int ep) cr
|
||||
damToExpBarrel' (Piercing amount _ int _) cr
|
||||
= over (crState . crSpState . piercedPoints) ((:) $ int -.- _crPos cr)
|
||||
$ over crHP (\hp -> hp - div amount 200) cr
|
||||
damToExpBarrel' PoisonDam {} cr = cr
|
||||
|
||||
@@ -4,7 +4,7 @@ module Dodge.Creature.State.Data
|
||||
where
|
||||
import Geometry
|
||||
import Dodge.Data.DamageType
|
||||
import Dodge.Creature.Stance.Data
|
||||
--import Dodge.Creature.Stance.Data
|
||||
import Picture.Data
|
||||
|
||||
import Control.Lens
|
||||
|
||||
@@ -5,27 +5,25 @@ module Dodge.Creature.SwarmCrit
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.ActionRat
|
||||
--import Dodge.Creature.Test
|
||||
--import Dodge.Creature.ActionRat
|
||||
import Dodge.Creature.ImpulseRat
|
||||
import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.SetTarget
|
||||
--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 Dodge.Picture.Layer
|
||||
import Geometry
|
||||
--import Geometry
|
||||
import Picture
|
||||
import Dodge.RandomHelp
|
||||
--import Dodge.RandomHelp
|
||||
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
--import Data.Maybe
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Control.Monad.State
|
||||
import System.Random
|
||||
--import Control.Monad.State
|
||||
--import System.Random
|
||||
|
||||
swarmCrit :: Creature
|
||||
swarmCrit = defaultCreature
|
||||
|
||||
@@ -12,4 +12,4 @@ unrandUpdate
|
||||
-> (Creature -> Maybe Creature)
|
||||
-> CRUpdate
|
||||
{-# INLINE unrandUpdate #-}
|
||||
unrandUpdate h cF w (f,g) cr = ( ( h cr . f , g) , cF cr )
|
||||
unrandUpdate h cF _ (f,g) cr = ( ( h cr . f , g) , cF cr )
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module Dodge.Creature.YourControl
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
--import Dodge.Base
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.State.Data
|
||||
--import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.Update.UsingInput
|
||||
import Dodge.Config.KeyConfig
|
||||
@@ -43,7 +43,7 @@ wasdWithAiming w speed i cr
|
||||
mov = rotateV (negate $ _crDir cr - _cameraRot w) mov'
|
||||
isAiming = _posture (_crStance cr) == Aiming
|
||||
isMoving = mov' /= (0,0)
|
||||
mouseDir = case w ^? creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
mouseDir = case w ^? creatures . ix i . crInv . ix (_crInvSel (_creatures w IM.! i))
|
||||
. itAttachment of
|
||||
Just (Just ItScope{_scopePos = p}) -> normalizeAngle $ argV
|
||||
$ p +.+ 2 / _cameraZoom w
|
||||
@@ -67,9 +67,9 @@ wasdComp ks w = f $ foldr ( (+.+) . wasdM w ) (0,0) ks
|
||||
|
||||
{- | Set posture according to mouse presses. -}
|
||||
mouseActionsCr :: S.Set SDL.MouseButton -> Creature -> Creature
|
||||
mouseActionsCr keys
|
||||
mouseActionsCr pkeys
|
||||
| rbPressed = crStance . posture .~ Aiming
|
||||
| otherwise = crStance . posture .~ AtEase
|
||||
where
|
||||
lbPressed = SDL.ButtonLeft `S.member` keys
|
||||
rbPressed = SDL.ButtonRight `S.member` keys
|
||||
--lbPressed = SDL.ButtonLeft `S.member` pkeys
|
||||
rbPressed = SDL.ButtonRight `S.member` pkeys
|
||||
|
||||
Reference in New Issue
Block a user