Cleanup
This commit is contained in:
@@ -69,7 +69,7 @@ spawnerCrit = defaultCreature
|
|||||||
miniGunCrit :: Creature
|
miniGunCrit :: Creature
|
||||||
miniGunCrit = defaultCreature
|
miniGunCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
, _crUpdate = stateUpdate $ impulsiveAI $
|
, _crUpdate = stateUpdate' $ impulsiveAI' $
|
||||||
sentinelFireType (const shootTillEmpty)
|
sentinelFireType (const shootTillEmpty)
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module Dodge.Creature.Impulse
|
module Dodge.Creature.Impulse
|
||||||
( impulsiveAIR
|
( impulsiveAIR
|
||||||
, impulsiveAI
|
, impulsiveAI
|
||||||
|
, impulsiveAI'
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Creature.Vocalization
|
import Dodge.Creature.Vocalization
|
||||||
@@ -20,31 +21,29 @@ impulsiveAIR
|
|||||||
-> Creature
|
-> Creature
|
||||||
-> World
|
-> World
|
||||||
-> (World -> World , Maybe Creature)
|
-> (World -> World , Maybe Creature)
|
||||||
impulsiveAIR impf cr w = bimap id Just $ followImpulses w . ($ w) . runReader $ impf cr
|
impulsiveAIR impf cr w = second Just $ followImpulses w . ($ w) . runReader $ impf cr
|
||||||
|
|
||||||
impulsiveAI :: (World -> Creature -> Creature)
|
impulsiveAI :: (World -> Creature -> Creature)
|
||||||
-> Creature
|
-> Creature
|
||||||
-> World
|
-> World
|
||||||
-> (World -> World , Maybe Creature)
|
-> (World -> World , Maybe Creature)
|
||||||
impulsiveAI impf cr w = bimap id Just $ followImpulses w $ impf w cr
|
impulsiveAI impf cr w = second Just $ followImpulses w $ impf w cr
|
||||||
|
|
||||||
followImpulses
|
impulsiveAI' :: (World -> Creature -> Creature)
|
||||||
:: World
|
|
||||||
-> Creature
|
-> Creature
|
||||||
|
-> World
|
||||||
-> (World -> World , Creature)
|
-> (World -> World , Creature)
|
||||||
followImpulses w cr
|
impulsiveAI' impf cr w = followImpulses w $ impf w cr
|
||||||
= foldr
|
|
||||||
|
followImpulses :: World -> Creature -> (World -> World, Creature)
|
||||||
|
followImpulses w cr = foldr
|
||||||
foldf
|
foldf
|
||||||
(id, cr)
|
(id, cr)
|
||||||
(_crImpulse $ _crActionPlan cr)
|
(_crImpulse $ _crActionPlan cr)
|
||||||
where
|
where
|
||||||
foldf imp (f,cr') = first ( . f) $ followImpulse cr' w imp
|
foldf imp (f,cr') = first ( . f) $ followImpulse cr' w imp
|
||||||
|
|
||||||
followImpulse
|
followImpulse :: Creature -> World -> Impulse -> (World -> World , Creature)
|
||||||
:: Creature
|
|
||||||
-> World
|
|
||||||
-> Impulse
|
|
||||||
-> (World -> World , Creature)
|
|
||||||
followImpulse cr w imp = case imp of
|
followImpulse cr w imp = case imp of
|
||||||
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown cr)
|
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown cr)
|
||||||
Move p -> (id, crMvBy p cr)
|
Move p -> (id, crMvBy p cr)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ updateBarrel cr
|
|||||||
-- should generate the sparks externally using new random generators
|
-- should generate the sparks externally using new random generators
|
||||||
updateExpBarrel :: Creature -> World -> World
|
updateExpBarrel :: Creature -> World -> World
|
||||||
updateExpBarrel cr w
|
updateExpBarrel cr w
|
||||||
| _crHP cr > 0 = foldr (.) id pierceSparks $ hiss w & creatures . at (_crID cr) .~ newCr
|
| _crHP cr > 0 = foldr ($) (hiss w & creatures . at (_crID cr) .~ newCr) pierceSparks
|
||||||
| otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & creatures . at (_crID cr) .~ Nothing
|
| otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & creatures . at (_crID cr) .~ Nothing
|
||||||
where
|
where
|
||||||
g = _randGen w
|
g = _randGen w
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
module Dodge.Creature.Lamp
|
||||||
|
( lamp
|
||||||
|
, colorLamp
|
||||||
|
) where
|
||||||
|
import Dodge.Data
|
||||||
|
import Dodge.Default
|
||||||
|
import Dodge.Creature.Picture
|
||||||
|
import Dodge.LightSource
|
||||||
|
import Dodge.WorldEvent.Flash
|
||||||
|
import Dodge.WorldEvent.Sound
|
||||||
|
import Dodge.Creature.State
|
||||||
|
import Geometry
|
||||||
|
import Picture
|
||||||
|
import Polyhedra
|
||||||
|
import qualified IntMapHelp as IM
|
||||||
|
import LensHelp
|
||||||
|
|
||||||
|
colorLamp
|
||||||
|
:: Point3 -- color of lamp
|
||||||
|
-> Float -- height of lamp
|
||||||
|
-> Creature
|
||||||
|
colorLamp col h = defaultInanimate
|
||||||
|
{ _crUpdate = initialiseColorLamp col h
|
||||||
|
, _crHP = 100
|
||||||
|
, _crPict = picAtCrPosNoRot (lampCrPic h)
|
||||||
|
, _crRad = 3
|
||||||
|
, _crMass = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
lamp :: Float -> Creature
|
||||||
|
lamp h = defaultInanimate
|
||||||
|
{ _crUpdate = initialiseLamp h
|
||||||
|
, _crHP = 100
|
||||||
|
, _crPict = picAtCrPosNoRot (lampCrPic h)
|
||||||
|
, _crRad = 3
|
||||||
|
, _crMass = 3
|
||||||
|
}
|
||||||
|
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
|
||||||
|
|
||||||
|
initialiseLamp :: Float -> Creature -> World -> World
|
||||||
|
initialiseLamp = initialiseColorLamp 0.75
|
||||||
|
|
||||||
|
initialiseColorLamp :: Point3 -> Float -> Creature -> World -> World
|
||||||
|
initialiseColorLamp col h cr w = w
|
||||||
|
& lightSources . at lsid ?~ lsColPosID col (addZ h $ _crPos cr) lsid
|
||||||
|
& creatures . ix (_crID cr) . crUpdate .~ updateLamp h lsid
|
||||||
|
where
|
||||||
|
lsid = IM.newKey $ _lightSources w
|
||||||
|
|
||||||
|
updateLamp :: Float -> Int -> Creature -> World -> World
|
||||||
|
updateLamp h i cr w
|
||||||
|
| _crHP cr < 0 = w
|
||||||
|
& explosionFlashAt cpos
|
||||||
|
& mkSoundBreakGlass cpos
|
||||||
|
& lightSources . at i .~ Nothing
|
||||||
|
& creatures . at cid .~ Nothing
|
||||||
|
| otherwise = w
|
||||||
|
& lightSources . ix i . lsParam . lsPos .~ addZ h cpos
|
||||||
|
& creatures . ix cid %~ doDamage
|
||||||
|
where
|
||||||
|
cpos = _crPos cr
|
||||||
|
cid = _crID cr
|
||||||
@@ -121,14 +121,14 @@ doStrategyActionsR cr = return $ case cr ^? crActionPlan . crStrategy of
|
|||||||
& crActionPlan . crStrategy .~ strat
|
& crActionPlan . crStrategy .~ strat
|
||||||
_ -> cr
|
_ -> cr
|
||||||
|
|
||||||
doStrategyActions :: World -> Creature -> Creature
|
doStrategyActions :: 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
|
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
|
||||||
& crActionPlan . crStrategy .~ strat
|
& crActionPlan . crStrategy .~ strat
|
||||||
_ -> cr
|
_ -> cr
|
||||||
|
|
||||||
reloadOverride :: World -> Creature -> Creature
|
reloadOverride :: Creature -> Creature
|
||||||
reloadOverride w cr
|
reloadOverride 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
|
||||||
= cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
|
= cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
|
||||||
@@ -163,10 +163,9 @@ overrideInternalRRR test update cr = do
|
|||||||
overrideInternal
|
overrideInternal
|
||||||
:: (Creature -> Bool)
|
:: (Creature -> Bool)
|
||||||
-> (Creature -> Creature)
|
-> (Creature -> Creature)
|
||||||
-> World
|
|
||||||
-> Creature
|
-> Creature
|
||||||
-> Creature
|
-> Creature
|
||||||
overrideInternal test update w cr
|
overrideInternal test update cr
|
||||||
| test cr = update cr
|
| test cr = update cr
|
||||||
| otherwise = cr
|
| otherwise = cr
|
||||||
|
|
||||||
|
|||||||
@@ -41,13 +41,21 @@ 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)
|
||||||
|
|
||||||
chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
|
--chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
|
||||||
chainCreatureUpdates ls w cr = foldr (\f -> f w) cr ls
|
--chainCreatureUpdates ls w cr = foldr (\f -> f w) cr ls
|
||||||
|
|
||||||
|
chainCreatureUpdatesLR
|
||||||
|
:: [Either (World -> Creature -> Creature) (Creature -> Creature)]
|
||||||
|
-> World -> Creature -> Creature
|
||||||
|
chainCreatureUpdatesLR ls w cr = foldr unf cr ls
|
||||||
|
where
|
||||||
|
unf (Left g) = g w
|
||||||
|
unf (Right g) = g
|
||||||
|
|
||||||
sentinelFireType :: (Int -> Action) -> World -> Creature -> Creature
|
sentinelFireType :: (Int -> Action) -> World -> Creature -> Creature
|
||||||
sentinelFireType f = chainCreatureUpdates
|
sentinelFireType f = chainCreatureUpdatesLR
|
||||||
[ performActions
|
[ Left performActions
|
||||||
, watchUpdateStrat
|
, Left $ watchUpdateStrat
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||||
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
||||||
, aiming
|
, aiming
|
||||||
@@ -55,13 +63,13 @@ sentinelFireType f = chainCreatureUpdates
|
|||||||
)
|
)
|
||||||
, (crAwayFromPost, goToPostStrat)
|
, (crAwayFromPost, goToPostStrat)
|
||||||
]
|
]
|
||||||
, perceptionUpdate' [0]
|
, Left $ perceptionUpdate' [0]
|
||||||
, doStrategyActions
|
, Right doStrategyActions
|
||||||
, reloadOverride
|
, Right reloadOverride
|
||||||
, targetYouWhenCognizant
|
, Left targetYouWhenCognizant
|
||||||
, overrideInternal
|
, Right $ overrideInternal
|
||||||
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||||
((crActionPlan . crStrategy .~ WatchAndWait))
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module Dodge.Creature.State
|
module Dodge.Creature.State
|
||||||
( stateUpdate
|
( stateUpdate
|
||||||
|
, stateUpdate'
|
||||||
, stateUpdateDamage
|
, stateUpdateDamage
|
||||||
, doDamage
|
, doDamage
|
||||||
, clearDamage
|
, clearDamage
|
||||||
@@ -45,6 +46,10 @@ stateUpdate :: CRUpdate -> Creature -> World -> World
|
|||||||
stateUpdate f cr w = let (fw,mcr) = stateUpdateDamage doDamage f cr w
|
stateUpdate f cr w = let (fw,mcr) = stateUpdateDamage doDamage f cr w
|
||||||
in fw $ w & creatures . at (_crID cr) .~ mcr
|
in fw $ w & creatures . at (_crID cr) .~ mcr
|
||||||
|
|
||||||
|
stateUpdate' :: CRUpdate' -> Creature -> World -> World
|
||||||
|
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) ->
|
||||||
@@ -64,6 +69,25 @@ stateUpdateDamage damageupdate u cr w = case u (updateMovement cr) w of
|
|||||||
$ uncurryV translate (_crOldPos cr)
|
$ uncurryV translate (_crOldPos cr)
|
||||||
$ rotate (_crDir cr)
|
$ rotate (_crDir cr)
|
||||||
(_crCorpse cr)
|
(_crCorpse cr)
|
||||||
|
stateUpdateDamage' :: (Creature -> Creature) -> CRUpdate' -> CRUpdate
|
||||||
|
stateUpdateDamage' damageupdate u cr w = case u (updateMovement cr) w of
|
||||||
|
(f, upcr) ->
|
||||||
|
( invSideEff upcr . movementSideEff cr . deathEff . f
|
||||||
|
, (stepReloading . damageupdate) <$> crOrCorpse upcr
|
||||||
|
)
|
||||||
|
where
|
||||||
|
crOrCorpse cr'
|
||||||
|
| cr' ^. crHP > 0 = Just cr'
|
||||||
|
| otherwise = Nothing
|
||||||
|
deathEff
|
||||||
|
| cr ^.crHP > 0 = id
|
||||||
|
| otherwise = stopSoundFrom (CrWeaponSound (_crID cr) 0)
|
||||||
|
. over decorations addCorpse
|
||||||
|
. dropByState cr
|
||||||
|
addCorpse = IM.insertNewKey
|
||||||
|
$ uncurryV translate (_crOldPos cr)
|
||||||
|
$ rotate (_crDir cr)
|
||||||
|
(_crCorpse cr)
|
||||||
-- | Drop items according to the creature state.
|
-- | Drop items according to the creature state.
|
||||||
dropByState :: Creature -> World -> World
|
dropByState :: Creature -> World -> World
|
||||||
dropByState cr w = foldr (copyInvItemToFloor cr) w is
|
dropByState cr w = foldr (copyInvItemToFloor cr) w is
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ module Dodge.Creature.Update
|
|||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
|
||||||
|
unrandUpdate :: (Creature -> World -> World) -> (Creature -> Maybe Creature) -> CRUpdate
|
||||||
unrandUpdate
|
|
||||||
:: (Creature -> World -> World)
|
|
||||||
-> (Creature -> Maybe Creature)
|
|
||||||
-> CRUpdate
|
|
||||||
{-# INLINE unrandUpdate #-}
|
{-# INLINE unrandUpdate #-}
|
||||||
unrandUpdate h cF cr _ = ( (h cr) , cF cr )
|
unrandUpdate h cF cr _ = ( h cr , cF cr )
|
||||||
|
|||||||
+4
-2
@@ -53,6 +53,8 @@ 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)
|
||||||
type CRUpdate = Creature -> World -> (World -> World, Maybe Creature)
|
type CRUpdate = Creature -> World -> (World -> World, Maybe Creature)
|
||||||
|
type CRUpdate' = Creature -> World -> (World -> World, Creature)
|
||||||
|
|
||||||
data Universe = Universe
|
data Universe = Universe
|
||||||
{ _uvWorld :: World
|
{ _uvWorld :: World
|
||||||
, _preloadData :: PreloadData
|
, _preloadData :: PreloadData
|
||||||
@@ -78,7 +80,7 @@ data World = World
|
|||||||
, _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
|
||||||
@@ -109,7 +111,7 @@ data World = World
|
|||||||
, _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)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- | stopgap module, making creature update simpler
|
||||||
|
-- should probably end up removed after further refactoring
|
||||||
|
module Dodge.RemoveCreatureEndo
|
||||||
|
(
|
||||||
|
toCrUpdate'
|
||||||
|
)where
|
||||||
|
import Dodge.Data
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
|
toCrUpdate' :: (Creature -> World -> (World -> World, Maybe Creature))
|
||||||
|
-> Creature
|
||||||
|
-> World
|
||||||
|
-> World
|
||||||
|
toCrUpdate' f cr w = let (fw,mcr) = f cr w
|
||||||
|
in fw $ w & creatures . at (_crID cr) .~ mcr
|
||||||
Reference in New Issue
Block a user