Cleanup, trying to diagnose space leak in crit update
This commit is contained in:
@@ -11,7 +11,6 @@ module Dodge.Creature
|
|||||||
, smallChaseCrit
|
, smallChaseCrit
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Creature.State.Data
|
import Dodge.Creature.State.Data
|
||||||
--import Dodge.Item.Weapon.Grenade
|
--import Dodge.Item.Weapon.Grenade
|
||||||
import Dodge.Item.Weapon.Booster
|
import Dodge.Item.Weapon.Booster
|
||||||
@@ -70,7 +69,7 @@ spawnerCrit = defaultCreature
|
|||||||
miniGunCrit :: Creature
|
miniGunCrit :: Creature
|
||||||
miniGunCrit = defaultCreature
|
miniGunCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
, _crUpdate = stateUpdate $ impulsiveAI $
|
||||||
sentinelFireType (const shootTillEmpty)
|
sentinelFireType (const shootTillEmpty)
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
@@ -78,7 +77,9 @@ miniGunCrit = defaultCreature
|
|||||||
, _crStrategy = StrategyActions WatchAndWait [StartSentinelPost]
|
, _crStrategy = StrategyActions WatchAndWait [StartSentinelPost]
|
||||||
, _crGoal = []
|
, _crGoal = []
|
||||||
}
|
}
|
||||||
, _crInv = IM.fromList [(0,miniGun)]
|
, _crInv = IM.fromList [(0,autoRifle & itConsumption . ammoLoaded .~ 1000)]
|
||||||
|
-- , _crInv = IM.fromList [(0,miniGun')]
|
||||||
|
-- , _crInv = IM.fromList [(0,autoRifle)]
|
||||||
, _crInvSel = 0
|
, _crInvSel = 0
|
||||||
, _crRad = 10
|
, _crRad = 10
|
||||||
, _crState = defaultState
|
, _crState = defaultState
|
||||||
@@ -89,7 +90,7 @@ longCrit :: Creature
|
|||||||
longCrit = defaultCreature
|
longCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
-- , _crUpdate = stateUpdate sniperAI
|
-- , _crUpdate = stateUpdate sniperAI
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $ sentinelFireType $ const shootTillEmpty
|
, _crUpdate = stateUpdate $ impulsiveAIR $ sentinelFireTypeR $ const shootTillEmpty
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
, _crAction = []
|
, _crAction = []
|
||||||
@@ -109,7 +110,7 @@ multGunCrit = defaultCreature
|
|||||||
, _crInvSel = 0
|
, _crInvSel = 0
|
||||||
, _crRad = 10
|
, _crRad = 10
|
||||||
, _crHP = 300
|
, _crHP = 300
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $ sentinelExtraWatchUpdate
|
, _crUpdate = stateUpdate $ impulsiveAIR $ sentinelExtraWatchUpdate
|
||||||
[ ( not . crHasAmmo
|
[ ( not . crHasAmmo
|
||||||
, \_ _ -> StrategyActions Reload reloadActions
|
, \_ _ -> StrategyActions Reload reloadActions
|
||||||
)
|
)
|
||||||
@@ -150,7 +151,7 @@ startCr = defaultCreature
|
|||||||
, _crMvDir = pi/2
|
, _crMvDir = pi/2
|
||||||
, _crID = 0
|
, _crID = 0
|
||||||
, _crPict = basicCrPict black
|
, _crPict = basicCrPict black
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate yourControl
|
, _crUpdate = stateUpdate yourControl
|
||||||
, _crRad = 10
|
, _crRad = 10
|
||||||
, _crMass = 10
|
, _crMass = 10
|
||||||
, _crHP = 1000
|
, _crHP = 1000
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
-}
|
-}
|
||||||
module Dodge.Creature.Action
|
module Dodge.Creature.Action
|
||||||
( performActionsR
|
( performActionsR
|
||||||
|
, performActions
|
||||||
, stripNoItems
|
, stripNoItems
|
||||||
, setMinInvSize
|
, setMinInvSize
|
||||||
, dropUnselected
|
, dropUnselected
|
||||||
@@ -91,11 +92,7 @@ performTurnToA cr p
|
|||||||
{- | Performing an action means that a creature has some impulses for a frame, and
|
{- | Performing an action means that a creature has some impulses for a frame, and
|
||||||
updates or deletes the action itself.
|
updates or deletes the action itself.
|
||||||
-- doAction -}
|
-- doAction -}
|
||||||
performAction
|
performAction :: Creature -> World -> Action -> OutAction
|
||||||
:: Creature
|
|
||||||
-> World
|
|
||||||
-> Action
|
|
||||||
-> OutAction
|
|
||||||
performAction cr w ac = case ac of
|
performAction cr w ac = case ac of
|
||||||
AimAt tcid p -> performAimAt cr w tcid p
|
AimAt tcid p -> performAimAt cr w tcid p
|
||||||
WaitThen 0 newAc -> ([] , Just newAc)
|
WaitThen 0 newAc -> ([] , Just newAc)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module Dodge.Creature.ArmourChase
|
|||||||
( armourChaseCrit
|
( armourChaseCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.State
|
import Dodge.Creature.State
|
||||||
import Dodge.Creature.ReaderUpdate
|
import Dodge.Creature.ReaderUpdate
|
||||||
@@ -20,7 +19,7 @@ import Control.Monad.Reader
|
|||||||
|
|
||||||
armourChaseCrit :: Creature
|
armourChaseCrit :: Creature
|
||||||
armourChaseCrit = defaultCreature
|
armourChaseCrit = defaultCreature
|
||||||
{ _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
watchUpdateStratR [] >=>
|
watchUpdateStratR [] >=>
|
||||||
doStrategyActionsR >=>
|
doStrategyActionsR >=>
|
||||||
performActionsR >=>
|
performActionsR >=>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module Dodge.Creature.AutoCrit
|
|||||||
( autoCrit
|
( autoCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.SentinelAI
|
import Dodge.Creature.SentinelAI
|
||||||
@@ -22,7 +21,7 @@ import qualified Data.IntMap.Strict as IM
|
|||||||
autoCrit :: Creature
|
autoCrit :: Creature
|
||||||
autoCrit = defaultCreature
|
autoCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR sentinelAI
|
, _crUpdate = stateUpdate $ impulsiveAIR sentinelAI
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
, _crAction = []
|
, _crAction = []
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ module Dodge.Creature.ChaseCrit
|
|||||||
,chaseCrit
|
,chaseCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.ReaderUpdate
|
import Dodge.Creature.ReaderUpdate
|
||||||
@@ -34,7 +33,7 @@ smallChaseCrit = chaseCrit
|
|||||||
}
|
}
|
||||||
chaseCrit :: Creature
|
chaseCrit :: Creature
|
||||||
chaseCrit = defaultCreature
|
chaseCrit = defaultCreature
|
||||||
{ _crUpdate = toCrUpdate $ stateUpdate $ --dummyUpdate
|
{ _crUpdate = stateUpdate $ --dummyUpdate
|
||||||
impulsiveAIR $
|
impulsiveAIR $
|
||||||
doStrategyActionsR >=>
|
doStrategyActionsR >=>
|
||||||
performActionsR >=>
|
performActionsR >=>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Dodge.Creature.Impulse
|
module Dodge.Creature.Impulse
|
||||||
( impulsiveAIR
|
( impulsiveAIR
|
||||||
)
|
, impulsiveAI
|
||||||
where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Creature.Vocalization
|
import Dodge.Creature.Vocalization
|
||||||
import Dodge.Creature.Impulse.Movement
|
import Dodge.Creature.Impulse.Movement
|
||||||
@@ -13,15 +13,20 @@ import qualified Data.IntMap.Strict as IM
|
|||||||
import System.Random
|
import System.Random
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
import Data.Monoid
|
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
|
|
||||||
impulsiveAIR
|
impulsiveAIR
|
||||||
:: (Creature -> Reader World Creature)
|
:: (Creature -> Reader World Creature)
|
||||||
-> Creature
|
-> Creature
|
||||||
-> World
|
-> World
|
||||||
-> (Endo World , Maybe Creature)
|
-> (World -> World , Maybe Creature)
|
||||||
impulsiveAIR impf cr w = bimap Endo Just $ followImpulses w . ($ w) . runReader $ impf cr
|
impulsiveAIR impf cr w = bimap id Just $ followImpulses w . ($ w) . runReader $ impf cr
|
||||||
|
|
||||||
|
impulsiveAI :: (World -> Creature -> Creature)
|
||||||
|
-> Creature
|
||||||
|
-> World
|
||||||
|
-> (World -> World , Maybe Creature)
|
||||||
|
impulsiveAI impf cr w = bimap id Just $ followImpulses w $ impf w cr
|
||||||
|
|
||||||
followImpulses
|
followImpulses
|
||||||
:: World
|
:: World
|
||||||
|
|||||||
+12
-105
@@ -3,13 +3,12 @@
|
|||||||
Inanimate objects such as lamps, barrels, etc
|
Inanimate objects such as lamps, barrels, etc
|
||||||
-}
|
-}
|
||||||
module Dodge.Creature.Inanimate
|
module Dodge.Creature.Inanimate
|
||||||
( lamp
|
( barrel
|
||||||
, colorLamp
|
|
||||||
, barrel
|
|
||||||
, explosiveBarrel
|
, explosiveBarrel
|
||||||
|
, module Dodge.Creature.Lamp
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
import Dodge.Creature.Lamp
|
||||||
import Dodge.WorldEvent.Explosion
|
import Dodge.WorldEvent.Explosion
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
--import Dodge.Creature.Stance.Data
|
--import Dodge.Creature.Stance.Data
|
||||||
@@ -17,100 +16,21 @@ import Dodge.Picture.Layer
|
|||||||
import Dodge.Particle.Spark
|
import Dodge.Particle.Spark
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.State
|
import Dodge.Creature.State
|
||||||
import Dodge.LightSource
|
|
||||||
import Dodge.WorldEvent.Flash
|
|
||||||
import Dodge.WorldEvent.Sound
|
|
||||||
import Dodge.Creature.Update
|
|
||||||
import Picture
|
import Picture
|
||||||
import qualified IntMapHelp as IM
|
import qualified IntMapHelp as IM
|
||||||
import Geometry
|
import Geometry
|
||||||
--import Geometry.Data
|
--import Geometry.Data
|
||||||
--import Geometry.Vector3D
|
--import Geometry.Vector3D
|
||||||
import Polyhedra
|
|
||||||
import Shape
|
import Shape
|
||||||
import Dodge.SoundLogic
|
import Dodge.SoundLogic
|
||||||
|
|
||||||
import System.Random
|
import System.Random
|
||||||
import Data.List
|
import Data.List
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.Monoid
|
|
||||||
|
|
||||||
defaultInanimate :: Creature
|
|
||||||
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
|
|
||||||
|
|
||||||
colorLamp
|
|
||||||
:: Point3 -- color of lamp
|
|
||||||
-> Float -- height of lamp
|
|
||||||
-> Creature
|
|
||||||
colorLamp col h = defaultInanimate
|
|
||||||
{ _crUpdate = toCrUpdate $ initialiseColorLamp col h
|
|
||||||
, _crHP = 100
|
|
||||||
, _crPict = picAtCrPosNoRot (lampCrPic h)
|
|
||||||
, _crRad = 3
|
|
||||||
, _crMass = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
lamp :: Float -> Creature
|
|
||||||
lamp h = defaultInanimate
|
|
||||||
{ _crUpdate = toCrUpdate $ initialiseLamp h
|
|
||||||
, _crHP = 100
|
|
||||||
, _crPict = picAtCrPosNoRot (lampCrPic h)
|
|
||||||
, _crRad = 3
|
|
||||||
, _crMass = 3
|
|
||||||
}
|
|
||||||
-- it is not clear that any of the attempts with Foldl help at all here
|
|
||||||
lampCrPic :: Float -> Picture
|
|
||||||
lampCrPic h = pictures
|
|
||||||
[ setLayer 1 (setDepth h . color white $ circleSolid 3)
|
|
||||||
, concatMap (polyToTris . map f) $ boxXYZnobase 5 5 (h-1)
|
|
||||||
]
|
|
||||||
where
|
|
||||||
f pos = Verx (pos -.-.- V3 2.5 2.5 0) blue [] 0 polyNum
|
|
||||||
|
|
||||||
--lTriFold :: a -> a -> L.Fold a [a]
|
|
||||||
--lTriFold s x = L.Fold (f s) (x,[]) snd
|
|
||||||
-- where
|
|
||||||
-- f s' (x1,l) x2 = (x2,s':x1:x2:l)
|
|
||||||
--
|
|
||||||
--preTriFold :: (a -> b) -> [a] -> [b]
|
|
||||||
--preTriFold f (s:x:xs) = L.fold (L.premap f $ lTriFold (f s) (f x)) xs
|
|
||||||
--preTriFold _ _ = []
|
|
||||||
--
|
|
||||||
--polyToTriFold :: [a] -> [a]
|
|
||||||
--polyToTriFold (s:x:xs) = L.fold (lTriFold s x) xs
|
|
||||||
--polyToTriFold _ = []
|
|
||||||
|
|
||||||
initialiseLamp :: Float -> CRUpdate
|
|
||||||
initialiseLamp = initialiseColorLamp 0.75
|
|
||||||
|
|
||||||
initialiseColorLamp :: Point3 -> Float -> CRUpdate
|
|
||||||
initialiseColorLamp col h cr _ = ( Endo addLS , Just $ cr & crUpdate .~ toCrUpdate (updateLamp h i))
|
|
||||||
where
|
|
||||||
i = _crID cr
|
|
||||||
addLS w = w
|
|
||||||
& lightSources %~ IM.insert lsid (lsColPosID col (V3 x y h) lsid)
|
|
||||||
& creatures . ix i . crUpdate .~ toCrUpdate (updateLamp h lsid)
|
|
||||||
where
|
|
||||||
lsid = IM.newKey $ _lightSources w
|
|
||||||
(V2 x y) = _crPos cr
|
|
||||||
|
|
||||||
updateLamp :: Float -> Int -> CRUpdate
|
|
||||||
updateLamp h i = unrandUpdate handleLS internalUpdate
|
|
||||||
where
|
|
||||||
handleLS cr w
|
|
||||||
| _crHP cr < 0 = explosionFlashAt cPos
|
|
||||||
$ mkSoundBreakGlass cPos w & lightSources %~ IM.delete i
|
|
||||||
| otherwise = w & lightSources . ix i . lsParam . lsPos .~ f cPos
|
|
||||||
where
|
|
||||||
cPos = _crPos cr
|
|
||||||
f (V2 x y) = V3 x y h
|
|
||||||
internalUpdate cr
|
|
||||||
| _crHP cr < 0 = Nothing
|
|
||||||
| otherwise = Just $ doDamage cr
|
|
||||||
|
|
||||||
barrel :: Creature
|
barrel :: Creature
|
||||||
barrel = defaultInanimate
|
barrel = defaultInanimate
|
||||||
{ _crUpdate = toCrUpdate updateBarrel
|
{ _crUpdate = updateBarrel
|
||||||
, _crHP = 500
|
, _crHP = 500
|
||||||
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures
|
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures
|
||||||
[ color orange $ circleSolid 10
|
[ color orange $ circleSolid 10
|
||||||
@@ -125,7 +45,7 @@ barrel = defaultInanimate
|
|||||||
|
|
||||||
explosiveBarrel :: Creature
|
explosiveBarrel :: Creature
|
||||||
explosiveBarrel = defaultInanimate
|
explosiveBarrel = defaultInanimate
|
||||||
{ _crUpdate = toCrUpdate updateExpBarrel
|
{ _crUpdate = updateExpBarrel
|
||||||
, _crHP = 400
|
, _crHP = 400
|
||||||
, _crPict = shapeAtCrPos
|
, _crPict = shapeAtCrPos
|
||||||
. colorSH orange
|
. colorSH orange
|
||||||
@@ -137,24 +57,16 @@ explosiveBarrel = defaultInanimate
|
|||||||
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||||
,_crApplyDamage = \_ c -> (id, c)
|
,_crApplyDamage = \_ c -> (id, c)
|
||||||
}
|
}
|
||||||
updateBarrel
|
updateBarrel :: Creature -> World -> World
|
||||||
:: Creature
|
updateBarrel cr
|
||||||
-> World
|
| _crHP cr > 0 = creatures . ix (_crID cr) %~ doDamage
|
||||||
-> (Endo World, Maybe Creature)
|
| otherwise = creatures . at (_crID cr) .~ Nothing
|
||||||
updateBarrel cr _
|
|
||||||
| _crHP cr > 0 = (Endo id, newCr)
|
|
||||||
| otherwise = (Endo id, Nothing)
|
|
||||||
where
|
|
||||||
newCr = Just $ doDamage cr
|
|
||||||
|
|
||||||
-- should generate the sparks externally using new random generators
|
-- should generate the sparks externally using new random generators
|
||||||
updateExpBarrel
|
updateExpBarrel :: Creature -> World -> World
|
||||||
:: Creature
|
|
||||||
-> World
|
|
||||||
-> (Endo World, Maybe Creature)
|
|
||||||
updateExpBarrel cr w
|
updateExpBarrel cr w
|
||||||
| _crHP cr > 0 = (Endo $ foldr (.) id pierceSparks . hiss, newCr)
|
| _crHP cr > 0 = foldr (.) id pierceSparks $ hiss w & creatures . at (_crID cr) .~ newCr
|
||||||
| otherwise = (Endo $ makeExplosionAt (_crPos cr) . stopSounds , Nothing)
|
| otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & creatures . at (_crID cr) .~ Nothing
|
||||||
where
|
where
|
||||||
g = _randGen w
|
g = _randGen w
|
||||||
damages = _crDamage $ _crState cr
|
damages = _crDamage $ _crState cr
|
||||||
@@ -166,12 +78,7 @@ updateExpBarrel cr w
|
|||||||
colids = randomRs (0,11) g
|
colids = randomRs (0,11) g
|
||||||
times = randomRs (2,5) g
|
times = randomRs (2,5) g
|
||||||
poss = _piercedPoints $ _crSpState $ _crState cr
|
poss = _piercedPoints $ _crSpState $ _crState cr
|
||||||
--newCr = Just $ doDamage $ applyFuseDamage cr -- $ foldr perforate cr damages
|
|
||||||
newCr = Just $ applyFuseDamage $ set (crState . crDamage) [] $ damToExpBarrel damages cr
|
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' = cr' & crHP %~
|
applyFuseDamage cr' = cr' & crHP %~
|
||||||
subtract (length . _piercedPoints . _crSpState $ _crState cr')
|
subtract (length . _piercedPoints . _crSpState $ _crState cr')
|
||||||
hiss | null poss = id
|
hiss | null poss = id
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ module Dodge.Creature.LauncherCrit
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.Test
|
import Dodge.Creature.Test
|
||||||
@@ -25,7 +24,7 @@ import Control.Monad.Reader
|
|||||||
launcherCrit :: Creature
|
launcherCrit :: Creature
|
||||||
launcherCrit = defaultCreature
|
launcherCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
performActionsR
|
performActionsR
|
||||||
>=> watchUpdateStratR
|
>=> watchUpdateStratR
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module Dodge.Creature.LtAutoCrit
|
|||||||
( ltAutoCrit
|
( ltAutoCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.Impulse
|
import Dodge.Creature.Impulse
|
||||||
@@ -30,7 +29,7 @@ import Control.Monad.Reader
|
|||||||
ltAutoCrit :: Creature
|
ltAutoCrit :: Creature
|
||||||
ltAutoCrit = defaultCreature
|
ltAutoCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
performActionsR
|
performActionsR
|
||||||
>=> watchUpdateStratR
|
>=> watchUpdateStratR
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
--{-# LANGUAGE TupleSections #-}
|
--{-# LANGUAGE TupleSections #-}
|
||||||
module Dodge.Creature.Perception
|
module Dodge.Creature.Perception
|
||||||
( perceptionUpdate
|
( perceptionUpdate
|
||||||
|
, perceptionUpdate'
|
||||||
, newSounds
|
, newSounds
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
@@ -29,6 +30,33 @@ perceptionUpdate is cr = basicAttentionUpdate is cr
|
|||||||
>>= basicAwarenessUpdate
|
>>= basicAwarenessUpdate
|
||||||
>>= rememberSounds
|
>>= rememberSounds
|
||||||
|
|
||||||
|
perceptionUpdate'
|
||||||
|
:: [Int] -- ^ List of creature ids that may direct attention and awareness
|
||||||
|
-> World
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
perceptionUpdate' is w cr = rememberSounds' w $ basicAwarenessUpdate' $ basicAttentionUpdate' is w cr
|
||||||
|
|
||||||
|
{- | Update a creatures awareness based upon the creatures' current direction
|
||||||
|
of attention -}
|
||||||
|
basicAwarenessUpdate'
|
||||||
|
:: Creature
|
||||||
|
-> Creature
|
||||||
|
basicAwarenessUpdate' cr = case _crAttentionDir $ _crPerception cr of
|
||||||
|
AttentiveTo is -> cr
|
||||||
|
& crPerception . crAwarenessLevel
|
||||||
|
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||||
|
& maybeBark
|
||||||
|
where
|
||||||
|
oldAwareness = _crAwarenessLevel $ _crPerception cr
|
||||||
|
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
|
||||||
|
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
||||||
|
maybeBark | becomesCognizant = case vocalizationTest cr of
|
||||||
|
Just sid -> crActionPlan . crImpulse .~ [Bark sid]
|
||||||
|
Nothing -> id
|
||||||
|
| otherwise = id
|
||||||
|
Fixated i -> cr & crPerception . crAwarenessLevel
|
||||||
|
%~ ( IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
|
||||||
{- | Update a creatures awareness based upon the creatures' current direction
|
{- | Update a creatures awareness based upon the creatures' current direction
|
||||||
of attention -}
|
of attention -}
|
||||||
basicAwarenessUpdate
|
basicAwarenessUpdate
|
||||||
@@ -84,6 +112,16 @@ basicAttentionUpdate cids cr = do
|
|||||||
pure $ cr & crPerception . crAttentionDir .~
|
pure $ cr & crPerception . crAttentionDir .~
|
||||||
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||||
|
|
||||||
|
{- | Given a fixed group of creatures, direct attention to those of them that
|
||||||
|
- are in view. -}
|
||||||
|
basicAttentionUpdate'
|
||||||
|
:: [Int] -- ^ Creatures that may attract this creature's attention
|
||||||
|
-> World
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
basicAttentionUpdate' cids w cr = cr & crPerception . crAttentionDir .~
|
||||||
|
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||||
|
|
||||||
newExtraAwareness
|
newExtraAwareness
|
||||||
:: Creature -- ^ source creature
|
:: Creature -- ^ source creature
|
||||||
-> World
|
-> World
|
||||||
@@ -119,6 +157,9 @@ rememberSounds cr = do
|
|||||||
sList <- asks newSounds
|
sList <- asks newSounds
|
||||||
return $ cr & crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) sList)
|
return $ cr & crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) sList)
|
||||||
-- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0]
|
-- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0]
|
||||||
|
--
|
||||||
|
rememberSounds' :: World -> Creature -> Creature
|
||||||
|
rememberSounds' w cr = cr & crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) (newSounds w))
|
||||||
|
|
||||||
soundIsClose :: Creature -> (Point2,Float) -> Bool
|
soundIsClose :: Creature -> (Point2,Float) -> Bool
|
||||||
soundIsClose cr (pos,vol) = vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr))
|
soundIsClose cr (pos,vol) = vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr))
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module Dodge.Creature.PistolCrit
|
|||||||
( pistolCrit
|
( pistolCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.Test
|
import Dodge.Creature.Test
|
||||||
@@ -30,7 +29,7 @@ import Control.Monad.State
|
|||||||
pistolCrit :: Creature
|
pistolCrit :: Creature
|
||||||
pistolCrit = defaultCreature
|
pistolCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
performActionsR
|
performActionsR
|
||||||
>=> watchUpdateStratR
|
>=> watchUpdateStratR
|
||||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
{- | Functions updating a creature in a Reader World environment -}
|
{- | Functions updating a creature in a Reader World environment -}
|
||||||
module Dodge.Creature.ReaderUpdate
|
module Dodge.Creature.ReaderUpdate
|
||||||
( doStrategyActionsR
|
( doStrategyActionsR
|
||||||
|
, doStrategyActions
|
||||||
, setTargetMv
|
, setTargetMv
|
||||||
, targetYouWhenCognizantR
|
, targetYouWhenCognizantR
|
||||||
|
, targetYouWhenCognizant
|
||||||
, overrideMeleeCloseTargetR
|
, overrideMeleeCloseTargetR
|
||||||
, watchUpdateStratR
|
, watchUpdateStratR
|
||||||
|
, watchUpdateStrat
|
||||||
, reloadOverrideR
|
, reloadOverrideR
|
||||||
|
, reloadOverride
|
||||||
, overrideInternalRRR
|
, overrideInternalRRR
|
||||||
|
, overrideInternal
|
||||||
, goToTarget
|
, goToTarget
|
||||||
, flockACCR
|
, flockACCR
|
||||||
, setMvPos
|
, setMvPos
|
||||||
@@ -110,17 +115,31 @@ replaceNullWith :: a -> [a] -> [a]
|
|||||||
replaceNullWith x [] = [x]
|
replaceNullWith x [] = [x]
|
||||||
replaceNullWith _ xs = xs
|
replaceNullWith _ xs = xs
|
||||||
|
|
||||||
doStrategyActionsR
|
doStrategyActionsR :: Creature -> Reader World Creature
|
||||||
:: Creature
|
|
||||||
-> Reader World Creature
|
|
||||||
doStrategyActionsR cr = return $ case cr ^? crActionPlan . crStrategy of
|
doStrategyActionsR cr = return $ case cr ^? crActionPlan . crStrategy of
|
||||||
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||||
& crActionPlan . crStrategy .~ strat
|
& crActionPlan . crStrategy .~ strat
|
||||||
_ -> cr
|
_ -> cr
|
||||||
|
|
||||||
reloadOverrideR
|
doStrategyActions :: World -> Creature -> Creature
|
||||||
:: Creature
|
doStrategyActions w cr = case cr ^? crActionPlan . crStrategy of
|
||||||
-> Reader World Creature
|
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||||
|
& crActionPlan . crStrategy .~ strat
|
||||||
|
_ -> cr
|
||||||
|
|
||||||
|
reloadOverride :: World -> Creature -> Creature
|
||||||
|
reloadOverride w cr
|
||||||
|
| cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded == Just 0
|
||||||
|
&& cr ^. crStance . posture == Aiming
|
||||||
|
= cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
|
||||||
|
| otherwise = cr
|
||||||
|
where
|
||||||
|
reloadActions =
|
||||||
|
[ holsterWeapon
|
||||||
|
, WaitThen 1 $ DoActionWhileInterrupt NoAction crIsReloading (DoImpulses [ChangeStrategy WatchAndWait])
|
||||||
|
]
|
||||||
|
|
||||||
|
reloadOverrideR :: Creature -> Reader World Creature
|
||||||
reloadOverrideR cr
|
reloadOverrideR cr
|
||||||
| cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded == Just 0
|
| cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded == Just 0
|
||||||
&& cr ^. crStance . posture == Aiming
|
&& cr ^. crStance . posture == Aiming
|
||||||
@@ -141,6 +160,16 @@ overrideInternalRRR test update cr = do
|
|||||||
b <- test cr
|
b <- test cr
|
||||||
if b then update cr else pure cr
|
if b then update cr else pure cr
|
||||||
|
|
||||||
|
overrideInternal
|
||||||
|
:: (Creature -> Bool)
|
||||||
|
-> (Creature -> Creature)
|
||||||
|
-> World
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
overrideInternal test update w cr
|
||||||
|
| test cr = update cr
|
||||||
|
| otherwise = cr
|
||||||
|
|
||||||
watchUpdateStratR
|
watchUpdateStratR
|
||||||
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
||||||
-> Creature
|
-> Creature
|
||||||
@@ -150,6 +179,16 @@ watchUpdateStratR fs cr = reader $ \w -> case cr ^? crActionPlan . crStrategy of
|
|||||||
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
& crActionPlan . crStrategy .~ listGuard (fs, \_ _ -> WatchAndWait) (w, cr) w cr
|
||||||
_ -> cr
|
_ -> cr
|
||||||
|
|
||||||
|
watchUpdateStrat
|
||||||
|
:: [ ((World, Creature) -> Bool, World -> Creature -> Strategy) ]
|
||||||
|
-> World
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
watchUpdateStrat fs w cr = 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 :: ([(a -> Bool, b)] , b) -> a -> b
|
||||||
listGuard ( (test,y):ps, z ) x
|
listGuard ( (test,y):ps, z ) x
|
||||||
| test x = y
|
| test x = y
|
||||||
@@ -160,3 +199,8 @@ targetYouWhenCognizantR :: Creature -> Reader World Creature
|
|||||||
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crPerception . crAwarenessLevel . ix 0 of
|
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crPerception . crAwarenessLevel . ix 0 of
|
||||||
Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0
|
Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0
|
||||||
_ -> cr & crIntention . targetCr .~ Nothing
|
_ -> cr & crIntention . targetCr .~ Nothing
|
||||||
|
|
||||||
|
targetYouWhenCognizant :: World -> Creature -> Creature
|
||||||
|
targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 of
|
||||||
|
Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0
|
||||||
|
_ -> cr & crIntention . targetCr .~ Nothing
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module Dodge.Creature.SentinelAI
|
module Dodge.Creature.SentinelAI
|
||||||
( sentinelAI
|
( sentinelAI
|
||||||
, sentinelFireType
|
, sentinelFireType
|
||||||
|
, sentinelFireTypeR
|
||||||
, sentinelExtraWatchUpdate
|
, sentinelExtraWatchUpdate
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -40,11 +41,40 @@ sentinelAI = sentinelExtraWatchUpdate
|
|||||||
tcid cr = _crID <$> _targetCr (_crIntention cr)
|
tcid cr = _crID <$> _targetCr (_crIntention cr)
|
||||||
lostest (w,cr) = maybe False (\cid -> canSee (_crID cr) cid w) (tcid cr)
|
lostest (w,cr) = maybe False (\cid -> canSee (_crID cr) cid w) (tcid cr)
|
||||||
|
|
||||||
sentinelFireType
|
chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
|
||||||
|
chainCreatureUpdates ls w cr = foldr (\f -> f w) cr ls
|
||||||
|
|
||||||
|
sentinelFireType :: (Int -> Action) -> World -> Creature -> Creature
|
||||||
|
sentinelFireType f = chainCreatureUpdates
|
||||||
|
[ performActions
|
||||||
|
, watchUpdateStrat
|
||||||
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
|
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||||
|
, aiming
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, (crAwayFromPost, goToPostStrat)
|
||||||
|
]
|
||||||
|
, perceptionUpdate' [0]
|
||||||
|
, doStrategyActions
|
||||||
|
, reloadOverride
|
||||||
|
, targetYouWhenCognizant
|
||||||
|
, overrideInternal
|
||||||
|
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||||
|
((crActionPlan . crStrategy .~ WatchAndWait))
|
||||||
|
]
|
||||||
|
where
|
||||||
|
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
||||||
|
aiming = AimAt
|
||||||
|
{ _targetID = 0
|
||||||
|
, _targetSeenAt = V2 0 0 -- hack
|
||||||
|
}
|
||||||
|
|
||||||
|
sentinelFireTypeR
|
||||||
:: (Int -> Action)
|
:: (Int -> Action)
|
||||||
-> Creature
|
-> Creature
|
||||||
-> Reader World Creature
|
-> Reader World Creature
|
||||||
sentinelFireType f = performActionsR
|
sentinelFireTypeR f = performActionsR
|
||||||
>=> watchUpdateStratR
|
>=> watchUpdateStratR
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module Dodge.Creature.SpreadGunCrit
|
|||||||
( spreadGunCrit
|
( spreadGunCrit
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.Test
|
import Dodge.Creature.Test
|
||||||
@@ -31,7 +30,7 @@ import Control.Monad
|
|||||||
spreadGunCrit :: Creature
|
spreadGunCrit :: Creature
|
||||||
spreadGunCrit = defaultCreature
|
spreadGunCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
, _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
performActionsR
|
performActionsR
|
||||||
>=> watchUpdateStratR
|
>=> watchUpdateStratR
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import Control.Monad.State
|
|||||||
import System.Random
|
import System.Random
|
||||||
--import qualified Data.Set as S
|
--import qualified Data.Set as S
|
||||||
--import qualified Data.Map as M
|
--import qualified Data.Map as M
|
||||||
import Data.Monoid
|
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import qualified Data.Vector.Mutable as MV
|
import qualified Data.Vector.Mutable as MV
|
||||||
|
|
||||||
@@ -42,13 +41,14 @@ import qualified Data.Vector.Mutable as MV
|
|||||||
-- the creature before or after it has moved?
|
-- the creature before or after it has moved?
|
||||||
-- currently invSideEffects are applied after the creature moves, to correctly
|
-- currently invSideEffects are applied after the creature moves, to correctly
|
||||||
-- update shield positions
|
-- update shield positions
|
||||||
stateUpdate :: CRUpdate -> CRUpdate
|
stateUpdate :: CRUpdate -> Creature -> World -> World
|
||||||
stateUpdate = stateUpdateDamage doDamage
|
stateUpdate f cr w = let (fw,mcr) = stateUpdateDamage doDamage f cr w
|
||||||
|
in fw $ w & creatures . at (_crID cr) .~ mcr
|
||||||
|
|
||||||
stateUpdateDamage :: (Creature -> Creature) -> CRUpdate -> CRUpdate
|
stateUpdateDamage :: (Creature -> Creature) -> CRUpdate -> CRUpdate
|
||||||
stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
|
stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
|
||||||
(f, maybeCr) ->
|
(f, maybeCr) ->
|
||||||
( Endo $ invSideEff (fromMaybe cr maybeCr) . movementSideEff cr . deathEff . appEndo f
|
( invSideEff (fromMaybe cr maybeCr) . movementSideEff cr . deathEff . f
|
||||||
, fmap (stepReloading . damageupdate) $ crOrCorpse =<< maybeCr
|
, fmap (stepReloading . damageupdate) $ crOrCorpse =<< maybeCr
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ module Dodge.Creature.SwarmCrit
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.RemoveCreatureEndo
|
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.Creature.Boid
|
import Dodge.Creature.Boid
|
||||||
@@ -19,7 +18,7 @@ import Control.Monad.Reader
|
|||||||
|
|
||||||
swarmCrit :: Creature
|
swarmCrit :: Creature
|
||||||
swarmCrit = defaultCreature
|
swarmCrit = defaultCreature
|
||||||
{ _crUpdate = toCrUpdate $ stateUpdate $ impulsiveAIR $
|
{ _crUpdate = stateUpdate $ impulsiveAIR $
|
||||||
flockToPointUsing (encircleDistP 100) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
|
flockToPointUsing (encircleDistP 100) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
|
||||||
>=> return . (crMeleeCooldown %~ max 0 . subtract 1)
|
>=> return . (crMeleeCooldown %~ max 0 . subtract 1)
|
||||||
>=> perceptionUpdate [0]
|
>=> perceptionUpdate [0]
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ crIsAimingR cr = return $ _posture (_crStance cr) == Aiming
|
|||||||
crHasTarget :: (World,Creature) -> Bool
|
crHasTarget :: (World,Creature) -> Bool
|
||||||
crHasTarget (_,cr) = isJust $ cr ^? crIntention . targetCr . _Just
|
crHasTarget (_,cr) = isJust $ cr ^? crIntention . targetCr . _Just
|
||||||
|
|
||||||
|
crHasTarget' :: Creature -> Bool
|
||||||
|
crHasTarget' cr = isJust $ cr ^? crIntention . targetCr . _Just
|
||||||
|
|
||||||
crHasTargetR :: Creature -> Reader World Bool
|
crHasTargetR :: Creature -> Reader World Bool
|
||||||
crHasTargetR cr = return $ isJust $ cr ^? crIntention . targetCr . _Just
|
crHasTargetR cr = return $ isJust $ cr ^? crIntention . targetCr . _Just
|
||||||
|
|
||||||
@@ -94,6 +97,9 @@ crSafeDistFromTargR d cr = return $ case cr ^? crIntention . targetCr . _Just of
|
|||||||
crStratConMatches :: Strategy -> (World,Creature) -> Bool
|
crStratConMatches :: Strategy -> (World,Creature) -> Bool
|
||||||
crStratConMatches strat (_,cr) = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
crStratConMatches strat (_,cr) = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||||
|
|
||||||
|
crStratConMatches' :: Strategy -> Creature -> Bool
|
||||||
|
crStratConMatches' strat cr = eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||||
|
|
||||||
crStratConMatchesR :: Strategy -> Creature -> Reader World Bool
|
crStratConMatchesR :: Strategy -> Creature -> Reader World Bool
|
||||||
crStratConMatchesR strat cr = return $ eqConstr strat (_crStrategy $ _crActionPlan cr)
|
crStratConMatchesR strat cr = return $ eqConstr strat (_crStrategy $ _crActionPlan cr)
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ module Dodge.Creature.Update
|
|||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
|
||||||
import Data.Monoid
|
|
||||||
|
|
||||||
unrandUpdate
|
unrandUpdate
|
||||||
:: (Creature -> World -> World)
|
:: (Creature -> World -> World)
|
||||||
-> (Creature -> Maybe Creature)
|
-> (Creature -> Maybe Creature)
|
||||||
-> CRUpdate
|
-> CRUpdate
|
||||||
{-# INLINE unrandUpdate #-}
|
{-# INLINE unrandUpdate #-}
|
||||||
unrandUpdate h cF cr _ = ( Endo (h cr) , cF cr )
|
unrandUpdate h cF cr _ = ( (h cr) , cF cr )
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ import Control.Lens
|
|||||||
import qualified SDL
|
import qualified SDL
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import Data.Monoid
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
{- | The AI equivalent for your control. -}
|
{- | The AI equivalent for your control. -}
|
||||||
yourControl
|
yourControl
|
||||||
:: Creature
|
:: Creature
|
||||||
-> World
|
-> World
|
||||||
-> (Endo World, Maybe Creature)
|
-> (World -> World, Maybe Creature)
|
||||||
yourControl cr w =
|
yourControl cr w =
|
||||||
( Endo updateUsingInput
|
( updateUsingInput
|
||||||
, Just . mouseActionsCr (_mouseButtons w) $ wasdWithAiming w speed 0 cr
|
, Just . mouseActionsCr (_mouseButtons w) $ wasdWithAiming w speed 0 cr
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
speed = _mvSpeed $ _crMvType cr
|
speed = _mvSpeed $ _crMvType cr
|
||||||
|
|
||||||
{- | Turn key presses into creature movement. -}
|
{- | Turn key presses into creature movement. -}
|
||||||
wasdWithAiming
|
wasdWithAiming
|
||||||
:: World
|
:: World
|
||||||
|
|||||||
+19
-21
@@ -52,8 +52,7 @@ import qualified Data.IntSet as IS
|
|||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import SDL (Scancode, MouseButton)
|
import SDL (Scancode, MouseButton)
|
||||||
import Data.Monoid
|
type CRUpdate = Creature -> World -> (World -> World, Maybe Creature)
|
||||||
type CRUpdate = Creature -> World -> (Endo World, Maybe Creature)
|
|
||||||
data Universe = Universe
|
data Universe = Universe
|
||||||
{ _uvWorld :: World
|
{ _uvWorld :: World
|
||||||
, _preloadData :: PreloadData
|
, _preloadData :: PreloadData
|
||||||
@@ -63,13 +62,13 @@ data Universe = Universe
|
|||||||
, _config :: Configuration
|
, _config :: Configuration
|
||||||
}
|
}
|
||||||
data World = World
|
data World = World
|
||||||
{ _keys :: !(S.Set Scancode)
|
{ _keys :: S.Set Scancode
|
||||||
, _mouseButtons :: !(S.Set MouseButton)
|
, _mouseButtons :: S.Set MouseButton
|
||||||
, _mousePos :: !Point2
|
, _mousePos :: Point2
|
||||||
, _cameraCenter :: !Point2
|
, _cameraCenter :: Point2
|
||||||
, _cameraRot :: !Float
|
, _cameraRot :: Float
|
||||||
, _cameraZoom :: !Float
|
, _cameraZoom :: Float
|
||||||
, _cameraViewFrom :: !Point2
|
, _cameraViewFrom :: Point2
|
||||||
, _creatures :: IM.IntMap Creature
|
, _creatures :: IM.IntMap Creature
|
||||||
, _creaturesZone :: Zone (IM.IntMap Creature)
|
, _creaturesZone :: Zone (IM.IntMap Creature)
|
||||||
, _creatureGroups :: IM.IntMap CrGroupParams
|
, _creatureGroups :: IM.IntMap CrGroupParams
|
||||||
@@ -78,8 +77,8 @@ data World = World
|
|||||||
, _cloudsZone :: Zone [Cloud]
|
, _cloudsZone :: Zone [Cloud]
|
||||||
, _props :: IM.IntMap Prop
|
, _props :: IM.IntMap Prop
|
||||||
, _instantParticles :: [Particle]
|
, _instantParticles :: [Particle]
|
||||||
, _particles :: ![Particle]
|
, _particles :: [Particle]
|
||||||
, _walls :: !(IM.IntMap Wall)
|
, _walls :: (IM.IntMap Wall)
|
||||||
, _doors :: IM.IntMap Door
|
, _doors :: IM.IntMap Door
|
||||||
, _machines :: IM.IntMap Machine
|
, _machines :: IM.IntMap Machine
|
||||||
, _magnets :: IM.IntMap Magnet
|
, _magnets :: IM.IntMap Magnet
|
||||||
@@ -92,7 +91,7 @@ data World = World
|
|||||||
, _randGen :: StdGen
|
, _randGen :: StdGen
|
||||||
, _testString :: World -> [String]
|
, _testString :: World -> [String]
|
||||||
, _modifications :: IM.IntMap Modification
|
, _modifications :: IM.IntMap Modification
|
||||||
, _yourID :: !Int
|
, _yourID :: Int
|
||||||
, _worldEvents :: World -> World
|
, _worldEvents :: World -> World
|
||||||
, _delayedEvents :: [(Int,World -> World)]
|
, _delayedEvents :: [(Int,World -> World)]
|
||||||
, _pressPlates :: IM.IntMap PressPlate
|
, _pressPlates :: IM.IntMap PressPlate
|
||||||
@@ -102,16 +101,16 @@ data World = World
|
|||||||
, _decorations :: IM.IntMap Picture
|
, _decorations :: IM.IntMap Picture
|
||||||
, _foregroundShape :: Shape
|
, _foregroundShape :: Shape
|
||||||
, _corpses :: Zone [Corpse]
|
, _corpses :: Zone [Corpse]
|
||||||
, _clickMousePos :: !Point2
|
, _clickMousePos :: Point2
|
||||||
, _pathGraph :: ~(Gr Point2 Float)
|
, _pathGraph :: ~(Gr Point2 Float)
|
||||||
, _pathGraphP :: ~[(Point2,Point2)]
|
, _pathGraphP :: ~[(Point2,Point2)]
|
||||||
, _pathPoints :: ~(IM.IntMap (IM.IntMap [(Int,Point2)]))
|
, _pathPoints :: ~(IM.IntMap (IM.IntMap [(Int,Point2)]))
|
||||||
, _carteDisplay :: !Bool
|
, _carteDisplay :: Bool
|
||||||
, _carteCenter :: !Point2
|
, _carteCenter :: Point2
|
||||||
, _carteZoom :: !Float
|
, _carteZoom :: Float
|
||||||
, _carteRot :: !Float
|
, _carteRot :: Float
|
||||||
, _lightSources :: !(IM.IntMap LightSource)
|
, _lightSources :: (IM.IntMap LightSource)
|
||||||
, _tempLightSources :: ![TempLightSource]
|
, _tempLightSources :: [TempLightSource]
|
||||||
, _closeObjects :: [Either FloorItem Button]
|
, _closeObjects :: [Either FloorItem Button]
|
||||||
, _seenLocations :: IM.IntMap (World -> Point2,String)
|
, _seenLocations :: IM.IntMap (World -> Point2,String)
|
||||||
, _selLocation :: Int
|
, _selLocation :: Int
|
||||||
@@ -229,7 +228,6 @@ data Creature = Creature
|
|||||||
, _crTwist :: Float
|
, _crTwist :: Float
|
||||||
, _crID :: Int
|
, _crID :: Int
|
||||||
, _crPict :: Creature -> Configuration -> World -> SPic
|
, _crPict :: Creature -> Configuration -> World -> SPic
|
||||||
--, _crUpdate :: Creature -> World -> (Endo World, Maybe Creature)
|
|
||||||
, _crUpdate :: Creature -> World -> World
|
, _crUpdate :: Creature -> World -> World
|
||||||
, _crRad :: Float
|
, _crRad :: Float
|
||||||
, _crMass :: Float
|
, _crMass :: Float
|
||||||
@@ -246,7 +244,7 @@ data Creature = Creature
|
|||||||
, _crApplyDamage :: [DamageType] -> Creature -> (World -> World,Creature)
|
, _crApplyDamage :: [DamageType] -> Creature -> (World -> World,Creature)
|
||||||
, _crStance :: Stance
|
, _crStance :: Stance
|
||||||
, _crActionPlan :: ActionPlan
|
, _crActionPlan :: ActionPlan
|
||||||
, _crMeleeCooldown :: !Int
|
, _crMeleeCooldown :: Int
|
||||||
, _crPerception :: PerceptionState
|
, _crPerception :: PerceptionState
|
||||||
, _crMemory :: MemoryState
|
, _crMemory :: MemoryState
|
||||||
, _crVocalization :: Vocalization
|
, _crVocalization :: Vocalization
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ applyTerminalString :: String -> Universe -> Universe
|
|||||||
applyTerminalString "NOCLIP" w = w & config . debug_noclip %~ not
|
applyTerminalString "NOCLIP" w = w & config . debug_noclip %~ not
|
||||||
applyTerminalString "LOADME" w = w & uvWorld . creatures . ix 0 . crInv .~ stackedInventory
|
applyTerminalString "LOADME" w = w & uvWorld . creatures . ix 0 . crInv .~ stackedInventory
|
||||||
& uvWorld . creatures . ix 0 . crInvCapacity .~ 50
|
& uvWorld . creatures . ix 0 . crInvCapacity .~ 50
|
||||||
applyTerminalString "GODON" u = u & uvWorld . creatures . ix 0 . crUpdate .~ toCrUpdate (stateUpdateDamage clearDamage yourControl)
|
applyTerminalString "GODON" u = u & uvWorld . creatures . ix 0 . crUpdate .~ toCrUpdate' (stateUpdateDamage clearDamage yourControl)
|
||||||
applyTerminalString "GODOFF" u = u & uvWorld . creatures . ix 0 . crUpdate .~ toCrUpdate (stateUpdate yourControl)
|
applyTerminalString "GODOFF" u = u & uvWorld . creatures . ix 0 . crUpdate .~ stateUpdate yourControl
|
||||||
applyTerminalString "LOADTEST" w = w & uvWorld . creatures . ix 0 . crInv .~ testInventory
|
applyTerminalString "LOADTEST" w = w & uvWorld . creatures . ix 0 . crInv .~ testInventory
|
||||||
& uvWorld . creatures . ix 0 . crInvCapacity .~ 50
|
& uvWorld . creatures . ix 0 . crInvCapacity .~ 50
|
||||||
applyTerminalString "LM" w = applyTerminalString "LOADME" w
|
applyTerminalString "LM" w = applyTerminalString "LOADME" w
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ defaultCreature = Creature
|
|||||||
, _crMvDir = 0
|
, _crMvDir = 0
|
||||||
, _crTwist = 0
|
, _crTwist = 0
|
||||||
, _crID = 1
|
, _crID = 1
|
||||||
, _crPict = \_ _ _ -> (,) mempty blank
|
, _crPict = \_ _ _ -> mempty
|
||||||
, _crUpdate = const id
|
, _crUpdate = const id
|
||||||
, _crRad = 10
|
, _crRad = 10
|
||||||
, _crMass = 10
|
, _crMass = 10
|
||||||
@@ -60,6 +60,8 @@ defaultCreature = Creature
|
|||||||
, _crGroup = LoneWolf
|
, _crGroup = LoneWolf
|
||||||
, _crMvType = defaultAimMvType
|
, _crMvType = defaultAimMvType
|
||||||
}
|
}
|
||||||
|
defaultInanimate :: Creature
|
||||||
|
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
|
||||||
|
|
||||||
defaultCreatureMemory :: MemoryState
|
defaultCreatureMemory :: MemoryState
|
||||||
defaultCreatureMemory = MemoryState
|
defaultCreatureMemory = MemoryState
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module Dodge.Item.Weapon.BulletGun.Cane
|
|||||||
, autoRifle
|
, autoRifle
|
||||||
, assaultRifle
|
, assaultRifle
|
||||||
, miniGun
|
, miniGun
|
||||||
|
, miniGun'
|
||||||
) where
|
) where
|
||||||
import Dodge.Item.Weapon.BulletGun.Clip
|
import Dodge.Item.Weapon.BulletGun.Clip
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -185,6 +186,8 @@ assaultRifle = repeater
|
|||||||
, withMuzFlareI
|
, withMuzFlareI
|
||||||
, withRecoilI 50
|
, withRecoilI 50
|
||||||
]
|
]
|
||||||
|
miniGun' :: Item
|
||||||
|
miniGun' = miniGun & itConsumption . ammoLoaded .~ 0
|
||||||
miniGun :: Item
|
miniGun :: Item
|
||||||
miniGun = defaultAutoGun
|
miniGun = defaultAutoGun
|
||||||
{ _itName = "MINIGUN"
|
{ _itName = "MINIGUN"
|
||||||
|
|||||||
Reference in New Issue
Block a user