Start removing Reader monad from internal creature update
This commit is contained in:
@@ -89,7 +89,7 @@ longCrit :: Creature
|
|||||||
longCrit = defaultCreature
|
longCrit = defaultCreature
|
||||||
{ _crPict = basicCrPict red
|
{ _crPict = basicCrPict red
|
||||||
-- , _crUpdate = stateUpdate sniperAI
|
-- , _crUpdate = stateUpdate sniperAI
|
||||||
, _crUpdate = stateUpdate $ impulsiveAIR $ sentinelFireTypeR $ const shootTillEmpty
|
, _crUpdate = stateUpdate' $ impulsiveAI $ sentinelFireType $ const shootTillEmpty
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
, _crAction = []
|
, _crAction = []
|
||||||
@@ -109,7 +109,7 @@ multGunCrit = defaultCreature
|
|||||||
, _crInvSel = 0
|
, _crInvSel = 0
|
||||||
, _crRad = 10
|
, _crRad = 10
|
||||||
, _crHP = 300
|
, _crHP = 300
|
||||||
, _crUpdate = stateUpdate $ impulsiveAIR $ sentinelExtraWatchUpdate
|
, _crUpdate = stateUpdate' $ impulsiveAI $ sentinelExtraWatchUpdate
|
||||||
[ ( not . crHasAmmo
|
[ ( not . crHasAmmo
|
||||||
, \_ _ -> StrategyActions Reload reloadActions
|
, \_ _ -> StrategyActions Reload reloadActions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,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 = stateUpdate $ impulsiveAIR sentinelAI
|
, _crUpdate = stateUpdate' $ impulsiveAI sentinelAI
|
||||||
, _crActionPlan = ActionPlan
|
, _crActionPlan = ActionPlan
|
||||||
{ _crImpulse = []
|
{ _crImpulse = []
|
||||||
, _crAction = []
|
, _crAction = []
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
module Dodge.Creature.SentinelAI
|
module Dodge.Creature.SentinelAI
|
||||||
( sentinelAI
|
( sentinelAI
|
||||||
, sentinelFireType
|
, sentinelFireType
|
||||||
, sentinelFireTypeR
|
|
||||||
, sentinelExtraWatchUpdate
|
, sentinelExtraWatchUpdate
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Dodge.Creature.ChainUpdates
|
||||||
import Dodge.Base.Collide
|
import Dodge.Base.Collide
|
||||||
import Dodge.Creature.Test
|
import Dodge.Creature.Test
|
||||||
import Dodge.Creature.Volition
|
import Dodge.Creature.Volition
|
||||||
@@ -16,11 +16,10 @@ import Geometry.Data
|
|||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad
|
|
||||||
import Control.Monad.Reader
|
|
||||||
|
|
||||||
sentinelAI :: Creature -> Reader World Creature
|
sentinelAI :: World -> Creature -> Creature
|
||||||
sentinelAI = sentinelExtraWatchUpdate
|
sentinelAI w = reloadOverride .
|
||||||
|
sentinelExtraWatchUpdate
|
||||||
[ (crHasTargetLOS
|
[ (crHasTargetLOS
|
||||||
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
|
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
|
||||||
[ DoActionIf
|
[ DoActionIf
|
||||||
@@ -35,22 +34,15 @@ sentinelAI = sentinelExtraWatchUpdate
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
>=> reloadOverrideR
|
w
|
||||||
where
|
where
|
||||||
advanceShoot = DoImpulses [UseItem, MoveForward 3]
|
advanceShoot = DoImpulses [UseItem, MoveForward 3]
|
||||||
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 = chainCreatureUpdatesLR
|
sentinelFireType f = chainCreatureUpdatesLR
|
||||||
@@ -79,46 +71,22 @@ sentinelFireType f = chainCreatureUpdatesLR
|
|||||||
, _targetSeenAt = V2 0 0 -- hack
|
, _targetSeenAt = V2 0 0 -- hack
|
||||||
}
|
}
|
||||||
|
|
||||||
sentinelFireTypeR
|
|
||||||
:: (Int -> Action)
|
|
||||||
-> Creature
|
|
||||||
-> Reader World Creature
|
|
||||||
sentinelFireTypeR f = performActionsR
|
|
||||||
>=> watchUpdateStratR
|
|
||||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
|
||||||
[ drawwp `DoActionThen` f 0 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]
|
|
||||||
, aiming
|
|
||||||
]
|
|
||||||
)
|
|
||||||
, (crAwayFromPost, goToPostStrat)
|
|
||||||
]
|
|
||||||
>=> perceptionUpdate [0]
|
|
||||||
>=> doStrategyActionsR
|
|
||||||
>=> reloadOverrideR
|
|
||||||
>=> targetYouWhenCognizantR
|
|
||||||
>=> overrideInternalRRR
|
|
||||||
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
|
|
||||||
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
|
|
||||||
where
|
|
||||||
drawwp = DoActionIfElse NoAction crIsAiming (DoActionThen drawWeapon (WaitThen 50 NoAction))
|
|
||||||
aiming = AimAt
|
|
||||||
{ _targetID = 0
|
|
||||||
, _targetSeenAt = V2 0 0 -- hack
|
|
||||||
}
|
|
||||||
|
|
||||||
sentinelExtraWatchUpdate
|
sentinelExtraWatchUpdate
|
||||||
:: [((World, Creature) -> Bool , World -> Creature -> Strategy)]
|
:: [((World, Creature) -> Bool , World -> Creature -> Strategy)]
|
||||||
|
-> World
|
||||||
-> Creature
|
-> Creature
|
||||||
-> Reader World Creature
|
-> Creature
|
||||||
sentinelExtraWatchUpdate xs = performActionsR
|
sentinelExtraWatchUpdate xs = chainCreatureUpdatesLR
|
||||||
>=> watchUpdateStratR
|
[ Left performActions
|
||||||
|
, Left $ watchUpdateStrat
|
||||||
( xs ++ [(crAwayFromPost, goToPostStrat)] )
|
( xs ++ [(crAwayFromPost, goToPostStrat)] )
|
||||||
>=> perceptionUpdate [0]
|
, Left $ perceptionUpdate' [0]
|
||||||
>=> doStrategyActionsR
|
, Right doStrategyActions
|
||||||
>=> targetYouWhenCognizantR
|
, Left targetYouWhenCognizant
|
||||||
>=> overrideInternalRRR
|
, Right $ overrideInternal
|
||||||
(\cr -> (&&) <$> crHasTargetR cr <*> crStratConMatchesR (GetTo (V2 0 0)) cr)
|
(\cr -> crHasTarget' cr && crStratConMatches' (GetTo (V2 0 0)) cr)
|
||||||
(pure . (crActionPlan . crStrategy .~ WatchAndWait))
|
(crActionPlan . crStrategy .~ WatchAndWait)
|
||||||
|
]
|
||||||
|
|
||||||
--shootAtAdvance :: Int -> [Action]
|
--shootAtAdvance :: Int -> [Action]
|
||||||
--shootAtAdvance tcid =
|
--shootAtAdvance tcid =
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
module Dodge.Placement.Instance.Turret where
|
module Dodge.Placement.Instance.Turret where
|
||||||
import Color
|
import Color
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Reloading
|
--import Dodge.Reloading
|
||||||
import Dodge.Creature.State
|
import Dodge.Creature.State
|
||||||
import Dodge.Creature.Impulse
|
import Dodge.Creature.Impulse
|
||||||
import Dodge.Creature.Picture
|
import Dodge.Creature.Picture
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Creature.Impulse.UseItem
|
--import Dodge.Creature.Impulse.UseItem
|
||||||
import Dodge.FloorItem
|
import Dodge.FloorItem
|
||||||
import Dodge.Wall.Delete
|
import Dodge.Wall.Delete
|
||||||
import Dodge.WorldEvent.Explosion
|
import Dodge.WorldEvent.Explosion
|
||||||
@@ -43,6 +43,7 @@ lasTurret = Turret
|
|||||||
, _tuMCrID = Nothing
|
, _tuMCrID = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- this needs a major cleanup
|
||||||
updateTurret :: Float -> Machine -> World -> World
|
updateTurret :: Float -> Machine -> World -> World
|
||||||
updateTurret rotSpeed mc w
|
updateTurret rotSpeed mc w
|
||||||
| _mcHP mc < 1 = w & machines %~ IM.delete mcid
|
| _mcHP mc < 1 = w & machines %~ IM.delete mcid
|
||||||
@@ -72,7 +73,7 @@ updateTurret rotSpeed mc w
|
|||||||
& crPict .~ (\cr _ _ -> drawCrEquipment cr)
|
& crPict .~ (\cr _ _ -> drawCrEquipment cr)
|
||||||
-- & crPict .~ basicCrPict red
|
-- & crPict .~ basicCrPict red
|
||||||
-- & crUpdate .~ (\cr -> crUpCrUp stepReloading cr . invSideEff cr)
|
-- & crUpdate .~ (\cr -> crUpCrUp stepReloading cr . invSideEff cr)
|
||||||
& crUpdate .~ stateUpdate' (\cr w -> followImpulses w cr)
|
& crUpdate .~ stateUpdate' (\cr w'' -> followImpulses w'' cr)
|
||||||
& crStance . posture .~ Aiming
|
& crStance . posture .~ Aiming
|
||||||
Just cid -> w'
|
Just cid -> w'
|
||||||
& creatures . ix cid . crPos .~ mcpos
|
& creatures . ix cid . crPos .~ mcpos
|
||||||
|
|||||||
Reference in New Issue
Block a user