diff --git a/src/Dodge/Creature/Impulse.hs b/src/Dodge/Creature/Impulse.hs index 93932513e..83259aa36 100644 --- a/src/Dodge/Creature/Impulse.hs +++ b/src/Dodge/Creature/Impulse.hs @@ -1,6 +1,6 @@ {-# LANGUAGE TupleSections #-} module Dodge.Creature.Impulse - ( impulsiveAI' + ( impulsiveAIBefore , followThenClearImpulses ) where import Dodge.Data @@ -25,9 +25,9 @@ impulsiveAIBeforeAfter startup endup cr w = w' & creatures . ix (_crID cr) .~ en w' = g w (g,cr') = impulsiveAI startup cr w -impulsiveAI' :: (World -> Creature -> Creature) +impulsiveAIBefore :: (World -> Creature -> Creature) -> 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 (g,cr') = impulsiveAI f cr w @@ -60,7 +60,7 @@ followImpulse cr w imp = case imp of SwitchToItem i -> crup $ cr & crInvSel .~ i Melee cid' -> (hitCr cid' , 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 ) DropItem -> undefined ChangeStrategy strat -> crup $ cr & crActionPlan . crStrategy .~ strat @@ -86,7 +86,7 @@ followImpulse cr w imp = case imp of cdir = _crDir cr cid = _crID cr 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 .:~ Damage Blunt 100 cpos (posFromID i) (posFromID i) NoDamageEffect ) diff --git a/src/Dodge/Creature/Update.hs b/src/Dodge/Creature/Update.hs index 2c9f90f4c..34927ac62 100644 --- a/src/Dodge/Creature/Update.hs +++ b/src/Dodge/Creature/Update.hs @@ -6,4 +6,4 @@ import Dodge.Creature.ChainUpdates defaultImpulsive :: [World -> Creature -> Creature] -> Creature -> World -> World -defaultImpulsive = stateUpdate . impulsiveAI' . chainCreatureUpdates +defaultImpulsive = stateUpdate . impulsiveAIBefore . chainCreatureUpdates diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 6867ca865..d5e0ba761 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -1061,7 +1061,95 @@ data Action } deriving (Generic) 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) data Strategy = Flank Int diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index fbd290c95..4b70d1ad9 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -18,6 +18,7 @@ import Sound.Data import Geometry import LensHelp +--import System.Random import Data.List import Data.Maybe --import Data.Function @@ -45,6 +46,7 @@ updateUniverse u = case _menuLayers u of {- | The update step. -} functionalUpdate :: Configuration -> World -> World functionalUpdate cfig w = checkEndGame +-- . updateRandGen . (worldClock +~ 1) . doRewind . updateDistortions @@ -83,6 +85,10 @@ functionalUpdate cfig w = checkEndGame where (x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl +-- hack +--updateRandGen :: World -> World +--updateRandGen = randGen %~ (snd . (uniform :: StdGen -> (Int,StdGen))) + doRewind :: World -> World doRewind w = case _maybeWorld w of Just' w' -> w' & timeFlow .~ RewindingLastFrame