Add random generator update when creature does random turn
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
module Dodge.Creature.Impulse
|
module Dodge.Creature.Impulse
|
||||||
( impulsiveAI'
|
( impulsiveAIBefore
|
||||||
, followThenClearImpulses
|
, followThenClearImpulses
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -25,9 +25,9 @@ impulsiveAIBeforeAfter startup endup cr w = w' & creatures . ix (_crID cr) .~ en
|
|||||||
w' = g w
|
w' = g w
|
||||||
(g,cr') = impulsiveAI startup cr w
|
(g,cr') = impulsiveAI startup cr w
|
||||||
|
|
||||||
impulsiveAI' :: (World -> Creature -> Creature)
|
impulsiveAIBefore :: (World -> Creature -> Creature)
|
||||||
-> Creature -> World -> World
|
-> Creature -> World -> World
|
||||||
impulsiveAI' f cr w = g w & creatures . ix (_crID cr) .~ cr'
|
impulsiveAIBefore f cr w = g w & creatures . ix (_crID cr) .~ cr'
|
||||||
where
|
where
|
||||||
(g,cr') = impulsiveAI f cr w
|
(g,cr') = impulsiveAI f cr w
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ followImpulse cr w imp = case imp of
|
|||||||
SwitchToItem i -> crup $ cr & crInvSel .~ i
|
SwitchToItem i -> crup $ cr & crInvSel .~ i
|
||||||
Melee cid' -> (hitCr cid'
|
Melee cid' -> (hitCr cid'
|
||||||
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
|
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
|
||||||
RandomTurn a -> crup $ creatureTurn (rr a) cr
|
RandomTurn a -> (randGen .~ snd (rr a), creatureTurn (fst $ rr a) cr)
|
||||||
MakeSound sid -> ( soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing , cr )
|
MakeSound sid -> ( soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing , cr )
|
||||||
DropItem -> undefined
|
DropItem -> undefined
|
||||||
ChangeStrategy strat -> crup $ cr & crActionPlan . crStrategy .~ strat
|
ChangeStrategy strat -> crup $ cr & crActionPlan . crStrategy .~ strat
|
||||||
@@ -86,7 +86,7 @@ followImpulse cr w imp = case imp of
|
|||||||
cdir = _crDir cr
|
cdir = _crDir cr
|
||||||
cid = _crID cr
|
cid = _crID cr
|
||||||
posFromID cid' = _crPos $ _creatures w IM.! cid'
|
posFromID cid' = _crPos $ _creatures w IM.! cid'
|
||||||
rr a = fst $ randomR (-a,a) $ _randGen w
|
rr a = randomR (-a,a) $ _randGen w
|
||||||
hitCr i = (creatures . ix i . crState . crDamage
|
hitCr i = (creatures . ix i . crState . crDamage
|
||||||
.:~ Damage Blunt 100 cpos (posFromID i) (posFromID i) NoDamageEffect
|
.:~ Damage Blunt 100 cpos (posFromID i) (posFromID i) NoDamageEffect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ import Dodge.Creature.ChainUpdates
|
|||||||
|
|
||||||
defaultImpulsive :: [World -> Creature -> Creature]
|
defaultImpulsive :: [World -> Creature -> Creature]
|
||||||
-> Creature -> World -> World
|
-> Creature -> World -> World
|
||||||
defaultImpulsive = stateUpdate . impulsiveAI' . chainCreatureUpdates
|
defaultImpulsive = stateUpdate . impulsiveAIBefore . chainCreatureUpdates
|
||||||
|
|||||||
+89
-1
@@ -1061,7 +1061,95 @@ data Action
|
|||||||
}
|
}
|
||||||
deriving (Generic)
|
deriving (Generic)
|
||||||
instance Show Action where
|
instance Show Action where
|
||||||
show _ = "AnAction"
|
show act = case act of
|
||||||
|
AimAt
|
||||||
|
{_targetID = tid
|
||||||
|
,_targetSeenAt = p
|
||||||
|
} -> "AimAt tid:"++show tid++" seenAt:"++show p
|
||||||
|
PathTo
|
||||||
|
{_pathToPoint = p
|
||||||
|
} -> "PathTo:"++show p
|
||||||
|
TurnToA
|
||||||
|
{_turnToAPoint = p
|
||||||
|
} -> "TurnToA:"++show p
|
||||||
|
---- | PickupItem
|
||||||
|
---- {_pickupItemID :: Int
|
||||||
|
---- }
|
||||||
|
ImpulsesList
|
||||||
|
{_impulsesListList = iss
|
||||||
|
} -> "ImpulsesList:"++show iss
|
||||||
|
DoImpulses
|
||||||
|
{_doImpulsesList = is
|
||||||
|
} -> "DoImpulses:"++show is
|
||||||
|
WaitThen
|
||||||
|
{_waitThenTimer = i
|
||||||
|
,_waitThenAction = a
|
||||||
|
} -> "WaitThen timer:"++show i++" act:"++show a
|
||||||
|
DoActionWhile
|
||||||
|
{_doActionWhileCondition = _
|
||||||
|
,_doActionWhileAction = a
|
||||||
|
} -> "DoActionWhile (function) act:"++show a
|
||||||
|
DoActionWhilePartial
|
||||||
|
{_doActionWhilePartial = partact
|
||||||
|
,_doActionWhileCondition = _
|
||||||
|
,_doActionWhileAction = a
|
||||||
|
} -> "DoActionWhilePartial partAct:"++show partact++" resetAct:"++show a
|
||||||
|
DoActionIf
|
||||||
|
{_doActionIfCondition = _
|
||||||
|
,_doActionIfAction = a
|
||||||
|
} -> "DoActionIf act:"++show a
|
||||||
|
DoActionIfElse
|
||||||
|
{_doActionIfElseIfAction = ifa
|
||||||
|
,_doActionIfElseCondition = _
|
||||||
|
,_doActionIfElseElseAction = elsea
|
||||||
|
} -> "DoActionIfElse ifa:"++show ifa++" elsea:"++show elsea
|
||||||
|
DoActionWhileInterrupt
|
||||||
|
{_doActionWhileThenDo = whilea
|
||||||
|
,_doActionWhileThenCondition = _
|
||||||
|
,_doActionWhileThenThen = thena
|
||||||
|
} -> "DoActionWhileInterrupt whilea:" ++show whilea++" interrupta:"++show thena
|
||||||
|
DoActions
|
||||||
|
{_doActionsList = as
|
||||||
|
} -> "DoActions " ++ foldMap show as
|
||||||
|
DoActionThen
|
||||||
|
{_doActionThenFirst = a1
|
||||||
|
,_doActionThenSecond = a2
|
||||||
|
} -> "DoActionThen " ++ show a1 ++ " then:" ++ show a2
|
||||||
|
---- | DoGuardActions
|
||||||
|
---- {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)]
|
||||||
|
---- }
|
||||||
|
DoReplicate
|
||||||
|
{_doReplicateTimes = i
|
||||||
|
,_doReplicateAction = a
|
||||||
|
} -> "DoReplicate times:" ++ show i ++ " act:"++ show a
|
||||||
|
DoReplicatePartial
|
||||||
|
{_partialAction = pa
|
||||||
|
,_doReplicateTimes = i
|
||||||
|
,_doReplicateAction = ra
|
||||||
|
} -> "DoReplicatePartial pa:" ++ show pa ++ " times:" ++ show i ++ " reset:"++ show ra
|
||||||
|
LeadTarget
|
||||||
|
{_leadTargetBy = p
|
||||||
|
} -> "LeadTarget by:"++ show p
|
||||||
|
NoAction -> "NoAction"
|
||||||
|
StartSentinelPost -> "StartSentinelPost"
|
||||||
|
UseTarget
|
||||||
|
{_useTarget = _
|
||||||
|
} -> "UseTarget func"
|
||||||
|
UseSelf
|
||||||
|
{_useSelf = _
|
||||||
|
} -> "UseSelf func"
|
||||||
|
UseAheadPos
|
||||||
|
{_useAheadPos = _
|
||||||
|
} -> "UseAheadPos func"
|
||||||
|
UseMvTargetPos
|
||||||
|
{_useMvTargetPos = _
|
||||||
|
} -> "UseMvTargetPos func"
|
||||||
|
ArbitraryAction {} -> "ArbitraryAction func"
|
||||||
|
DoImpulsesAlongside
|
||||||
|
{_sideImpulses = is
|
||||||
|
,_mainAction = a
|
||||||
|
} -> "DoImpulsesAlongside sideImpulses:"++show is ++ " mainA:"++show a
|
||||||
|
|
||||||
-- deriving (Eq,Ord,Show)
|
-- deriving (Eq,Ord,Show)
|
||||||
data Strategy
|
data Strategy
|
||||||
= Flank Int
|
= Flank Int
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import Sound.Data
|
|||||||
import Geometry
|
import Geometry
|
||||||
import LensHelp
|
import LensHelp
|
||||||
|
|
||||||
|
--import System.Random
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
--import Data.Function
|
--import Data.Function
|
||||||
@@ -45,6 +46,7 @@ updateUniverse u = case _menuLayers u of
|
|||||||
{- | The update step. -}
|
{- | The update step. -}
|
||||||
functionalUpdate :: Configuration -> World -> World
|
functionalUpdate :: Configuration -> World -> World
|
||||||
functionalUpdate cfig w = checkEndGame
|
functionalUpdate cfig w = checkEndGame
|
||||||
|
-- . updateRandGen
|
||||||
. (worldClock +~ 1)
|
. (worldClock +~ 1)
|
||||||
. doRewind
|
. doRewind
|
||||||
. updateDistortions
|
. updateDistortions
|
||||||
@@ -83,6 +85,10 @@ functionalUpdate cfig w = checkEndGame
|
|||||||
where
|
where
|
||||||
(x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl
|
(x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl
|
||||||
|
|
||||||
|
-- hack
|
||||||
|
--updateRandGen :: World -> World
|
||||||
|
--updateRandGen = randGen %~ (snd . (uniform :: StdGen -> (Int,StdGen)))
|
||||||
|
|
||||||
doRewind :: World -> World
|
doRewind :: World -> World
|
||||||
doRewind w = case _maybeWorld w of
|
doRewind w = case _maybeWorld w of
|
||||||
Just' w' -> w' & timeFlow .~ RewindingLastFrame
|
Just' w' -> w' & timeFlow .~ RewindingLastFrame
|
||||||
|
|||||||
Reference in New Issue
Block a user