From 05086d6f4af015870d00d8c38af636998b0630a6 Mon Sep 17 00:00:00 2001 From: jgk Date: Wed, 5 May 2021 17:36:10 +0200 Subject: [PATCH] Refector --- src/Dodge/AIs.hs | 858 ++++++++++++-------------- src/Dodge/AIs.hs.orig | 374 +++++------ src/Dodge/Creature.hs | 3 + src/Dodge/Creature.hs.orig | 18 +- src/Dodge/Creature/AI.hs | 11 + src/Dodge/Creature/AI/Data.hs | 12 + src/Dodge/Creature/Action.hs | 14 +- src/Dodge/Creature/Impulse/Data.hs | 58 ++ src/Dodge/Creature/Inanimate.hs | 3 + src/Dodge/Creature/Picture.hs | 1 + src/Dodge/Creature/Stance/Data.hs | 25 + src/Dodge/Creature/State.hs | 3 + src/Dodge/Creature/State/Data.hs | 75 +-- src/Dodge/Creature/YourControl.hs | 2 + src/Dodge/Data.hs | 37 +- src/Dodge/Data.hs.orig | 10 +- src/Dodge/Default.hs | 2 + src/Dodge/Floor.hs | 1 + src/Dodge/Item/Weapon/Bullet.hs | 1 + src/Dodge/Item/Weapon/Laser.hs | 1 + src/Dodge/LevelGen/AutoDoor.hs | 1 + src/Dodge/Path.hs | 8 +- src/Dodge/Room/Boss.hs | 1 + src/Dodge/Room/NoNeedWeapon.hs | 1 + src/Dodge/WallCreatureCollisions.hs | 1 + src/Dodge/WorldEvent.hs | 2 +- src/Dodge/WorldEvent/HitEffect.hs | 1 + src/Dodge/WorldEvent/Shockwave.hs | 1 + src/Dodge/WorldEvent/SpawnParticle.hs | 1 + 29 files changed, 760 insertions(+), 766 deletions(-) create mode 100644 src/Dodge/Creature/AI.hs create mode 100644 src/Dodge/Creature/AI/Data.hs create mode 100644 src/Dodge/Creature/Impulse/Data.hs create mode 100644 src/Dodge/Creature/Stance/Data.hs diff --git a/src/Dodge/AIs.hs b/src/Dodge/AIs.hs index 7b9fa631b..325c74666 100644 --- a/src/Dodge/AIs.hs +++ b/src/Dodge/AIs.hs @@ -1,4 +1,17 @@ -module Dodge.AIs where +module Dodge.AIs + ( chaseAI + , basicShooterAI + , twitchMissAI + , launcherAI + , chargeAI + , sniperAI + , dodgeAI + , miniAI + , spawnerAI + ) where +import Dodge.Creature.Stance.Data +import Dodge.Creature.State.Data +import Dodge.Creature.Impulse.Data import Dodge.Data import Dodge.Base import Dodge.Path @@ -37,149 +50,82 @@ expandToAI ai w (f,g) cr = let (sideE, g', cr') = ai w g cr in ((sideE . f, g'), Just cr') -chaseAI :: - World -> (World -> World,StdGen) -> Creature -> ((World -> World , StdGen), Maybe Creature) -chaseAI w (f,g') cr = +replaceGoal :: [[Impulse]] -> Creature -> Creature +replaceGoal newImpulses = over (crState . goals) ((newImpulses ++) . tail) + +addGoal :: [[Impulse]] -> Creature -> Creature +addGoal newImpulses = over (crState . goals) (newImpulses ++) + +replaceImpulse :: [Impulse] -> Creature -> Creature +replaceImpulse newActions = over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) + +addImpulse :: [Impulse] -> Creature -> Creature +addImpulse newActions = over (crState . goals) (\(as:ass) -> (newActions++as):ass) + +chaseAI = expandToAI chaseAI' + +chaseAI' :: World -> StdGen -> Creature -> (World -> World, StdGen, Creature) +chaseAI' w g' cr = let cid = _crID cr cpos = _crPos cr - damageYou = over (creatures . ix 0 . crState . crDamage) addDam - . soundOnce (fromIntegral hitSound) + hitCr i = over (creatures . ix i . crState . crDamage) addDam + . soundOnce (fromIntegral hitSound) addDam dams = (( Blunt 100 cpos ypos ypos ) : dams ) ypos = _crPos $ you w combinedRad = _crRad cr + _crRad (you w) (a,g) = randomR (-0.2,0.2) g' (wtime,g1) = randomR (15,25) g' randomTurn = over crDir (+a) - randomTurn2 = over crDir (+(signum a)) isCrowded = (length $ IM.elems $ IM.filter isCloseFaction (_creatures w)) > 2 isCloseFaction cr' = _faction (_crState cr') == _faction (_crState cr) && dist cpos (_crPos cr') < 25 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions - = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions - = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) - in --if _crHP cr <= 0 then killCr w f cr else - case head $ _goals $ _crState cr of - [] -> ((f, g') , replaceGoal [] cr) - (Wait:_) | dist cpos ypos < 900 && hasLOS cpos ypos w - -> ((f ,g') - ,addGoal [[WaitFor wtime,MoveTo ypos]] cr) - | dist cpos ypos < 900 && hasLOSIndirect cpos ypos w - -> ((f , g') - ,addGoal [[WaitFor wtime,PathTo ypos]] cr) - | otherwise -> ( (f , g') - ,Just cr) - (WaitFor x:gls)| x == 0 -> ( (f , g') - ,replaceAction [] cr --- $ drawCircleAtForCol cpos 10 (withAlpha 0.5 cyan) - ) - | hasLOS cpos ypos w - -> ( (f, g') - ,replaceAction [WaitFor (x-1)] $ crTurnTowardSpeed 0.05 ypos cr - ) - | otherwise -> ( (f, g') - , replaceAction [WaitFor (x-1)] cr ) + in case head $ _goals $ _crState cr of + [] -> (id, g', replaceGoal [] cr) + (Wait:_) + | dist cpos ypos < 900 && hasLOS cpos ypos w + -> (id, g', addGoal [[WaitFor wtime,MoveTo ypos]] cr) + | dist cpos ypos < 900 && hasLOSIndirect cpos ypos w + -> (id, g', addGoal [[WaitFor wtime,PathTo ypos]] cr) + | otherwise -> (id, g', cr) + (WaitFor x:gls) + | x == 0 -> (id, g', replaceImpulse [] cr) + | hasLOS cpos ypos w + -> (id, g', replaceImpulse [WaitFor (x-1)] $ crTurnTowardSpeed 0.05 ypos cr) + | otherwise -> (id, g', replaceImpulse [WaitFor (x-1)] cr ) (MoveTo p:gls) - | dist ypos cpos < combinedRad + 5 - && abs ((_crDir cr) - argV (ypos -.- cpos)) < pi/4 -- same error as above - -> ( (damageYou . f , g') - , replaceAction [MeleeAttack 5] $ - over crPos - (+.+ (12 *.* errorNormalizeVAI (ypos -.- cpos))) cr - ) - | hasLOS cpos ypos w -> ( (f , g) - , replaceAction [MoveTo ypos] - $ crMvForward 2.5 $ randomTurn - $ crTurnTowardSpeed 0.05 p cr - ) - | dist p cpos < 10 -> ( (f, g') - , replaceAction [] cr) - | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 - -> ( (f ,g' ) - , Just $ crTurnTowardSpeed 0.05 p cr) - | otherwise -> ( (f, g' ) - , Just $ crMvForward 2.5 $ crTurnTowardSpeed 0.05 p cr) + | dist ypos cpos < combinedRad + 5 && abs ((_crDir cr) - argV (ypos -.- cpos)) < pi/4 + -> ( hitCr 0 , g' + , replaceImpulse [MeleeAttack 5] + $ over crPos (+.+ (12 *.* errorNormalizeVAI (ypos -.- cpos))) cr + ) + | hasLOS cpos ypos w -> + ( id , g , replaceImpulse [MoveTo ypos] + $ crMvForward 2.5 $ randomTurn $ crTurnTowardSpeed 0.05 p cr) + | dist p cpos < 10 -> ( id, g' , replaceImpulse [] cr) + | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 + -> ( id ,g' , crTurnTowardSpeed 0.05 p cr) + | otherwise -> ( id, g' , crMvForward 2.5 $ crTurnTowardSpeed 0.05 p cr) (MoveToFor p x:gls) - | hasLOS cpos ypos w -> - ( (f , g ) - , replaceAction [MoveTo ypos] - $ crMvForward 2.5 $ randomTurn $ crTurnTowardSpeed 0.05 p cr - ) - | dist p cpos < 10 -> ( (f , g) - , replaceAction [] cr) - | x == 0 -> ( (f , g) - , replaceAction [] cr) - | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 - -> ( (f , g) - , replaceAction [MoveToFor p (max 0 (x-1))] - $ crTurnTowardSpeed 0.05 p cr) - | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (max 0 (x-1))] - $ crMvForward 2.5 $ crTurnTowardSpeed 0.05 p cr) - (PathTo p:_) - | dist p cpos < 10 -> ( (f , g) - , replaceAction [] cr --- $ drawCircleAtForCol p 10 (withAlpha 0.5 blue) - ) - | hasLOS cpos p w -> ( (f , g) - , addAction [MoveToFor p 10] cr --- $ drawCircleAtForCol p 10 (withAlpha 0.5 green) - ) + | hasLOS cpos ypos w -> + ( id , g , replaceImpulse [MoveTo ypos] + $ crMvForward 2.5 $ randomTurn $ crTurnTowardSpeed 0.05 p cr + ) + | dist p cpos < 10 -> ( id , g , replaceImpulse [] cr) + | x == 0 -> ( id , g , replaceImpulse [] cr) + | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> + ( id , g , replaceImpulse [MoveToFor p (max 0 (x-1))] $ crTurnTowardSpeed 0.05 p cr) | otherwise -> - --((f, g) , replaceAction [] cr) --- case makePathBetweenPs cpos p w of --- Just (q:_) -> ( (f , g) --- --- , addAction [MoveToFor q 10] cr --- ) --- _ -> ((f , g) --- --- , replaceAction [] cr --- ) - case pointTowardsGoal cpos p w of - Just q -> ( (f , g) - - , addAction [MoveToFor q 10] cr - ) - _ -> ((f , g) - - , replaceAction [] cr - ) - --- case pointTowardsGoal' cpos p w of - -- Right q -> addAction [MoveToFor q 10] ------ let ns = map fst $ concatMap doublePair $ _pathGraph' w ------ a' = listToMaybe $ sortBy (compare `on` dist cpos) $ ns ------ b' = listToMaybe $ sortBy (compare `on` dist p) $ ns ------ g :: World -> World ------ g = fromMaybe id $ fmap (\p -> drawCircleAtForCol p 10 yellow) a' ------ h = fromMaybe id $ fmap (\p -> drawCircleAtForCol p 10 blue) b' ------ incf = incidenceToFunction $ pairsToIncidence ------ $ concatMap doublePair $ _pathGraph' w ------ as :: [Point] ------ as = concat $ maybeToList $ fmap incf a' ------ g' w = foldr (\p -> drawCircleAtForCol p 5 orange) w as ------ h' qs w = foldr (\p -> drawCircleAtForCol p 5 orange) w qs ------ in case makePath' <$> return incf <*> b' <*> a' of ------ Just (q:qs) -> ( f . h' qs ------ . drawCircleAtForCol q 10 magenta ------ , addAction [MoveToFor q 10] cr ------ -- $ drawLineForCol ((cpos : (concat $ maybeToList $ makePathBetweenPs ------ -- cpos p w)) ++ [p]) 50 red ------ ) -------- Left s -> error s -------- - -> (f,cr) ------ _ -> ( f ------ . g . h . g' ------ , replaceAction [] cr ------ ) + ( id , g , replaceImpulse [MoveToFor p (max 0 (x-1))] + $ crMvForward 2.5 $ crTurnTowardSpeed 0.05 p cr) + (PathTo p:_) + | dist p cpos < 10 -> ( id , g , replaceImpulse [] cr) + | hasLOS cpos p w -> ( id , g , addImpulse [MoveToFor p 10] cr) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( id , g , addImpulse [MoveToFor q 10] cr) + _ -> ( id , g , replaceImpulse [] cr) (MeleeAttack x:_) - | x == 0 -> ( (f , g) - , replaceAction [WaitFor wtime] cr ) - | otherwise -> ( (f , g) - , replaceAction [MeleeAttack (x-1)] cr ) + | x == 0 -> ( id , g , replaceImpulse [WaitFor wtime] cr ) + | otherwise -> ( id , g , replaceImpulse [MeleeAttack (x-1)] cr ) factionIs :: Faction -> Creature -> Bool @@ -227,13 +173,13 @@ spreadOut ypos crs cpos = p ---- $ _creatures w ---- tp = f ypos flockers cpos ---- combinedRad = _crRad cr + _crRad (you w) ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) ----- replaceAction newActions = over (creatures . ix cid . crState . goals) +---- replaceGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) +---- replaceImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ----- addAction newActions = over (creatures . ix cid . crState . goals) +---- addImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\(as:ass) -> (newActions++as):ass) ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of @@ -248,29 +194,29 @@ spreadOut ypos crs cpos = p ---- && x == 0 ---- -> over (creatures . ix cid . crPos) ---- (+.+ (12 *.* errorNormalizeVAI (ypos -.- cpos))) ----- $ replaceAction [MeleeAttack 5] +---- $ replaceImpulse [MeleeAttack 5] ---- $ damageYou ---- w ---- | canSee cid (_yourID w) w && dist cpos ypos < 50 ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 ypos cid ----- $ replaceAction [MoveToFor ypos (max 0 (x-1))] w +---- $ replaceImpulse [MoveToFor ypos (max 0 (x-1))] w ---- | x == 0 && canSee cid (_yourID w) w ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid ----- $ replaceAction [MoveToFor tp 0] w ----- | x == 0 -> replaceAction [MoveToFor p 10] w +---- $ replaceImpulse [MoveToFor tp 0] w +---- | x == 0 -> replaceImpulse [MoveToFor p 10] w ---- | canSee cid (_yourID w) w ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid ----- $ replaceAction [MoveToFor p (x-1)] w +---- $ replaceImpulse [MoveToFor p (x-1)] w ---- | dist cpos p < 20 -> w ---- | otherwise -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid w ---- (MeleeAttack x:_) ----- | x == 0 -> replaceAction [WaitFor 5] w ----- | otherwise -> replaceAction [MeleeAttack (x-1)] w ----- (WaitFor x:gls)| x == 0 -> replaceAction [] w +---- | x == 0 -> replaceImpulse [WaitFor 5] w +---- | otherwise -> replaceImpulse [MeleeAttack (x-1)] w +---- (WaitFor x:gls)| x == 0 -> replaceImpulse [] w ---- | canSee cid (_yourID w) w ---- -> turnTowardSpeed 0.05 ypos cid ----- $ replaceAction [WaitFor (x-1)] w ----- | otherwise -> replaceAction [WaitFor (x-1)] w +---- $ replaceImpulse [WaitFor (x-1)] w +---- | otherwise -> replaceImpulse [WaitFor (x-1)] w ---- ---- encircleAI' :: Int -> World -> World ---- encircleAI' cid w = @@ -290,13 +236,13 @@ spreadOut ypos crs cpos = p ---- foldr1 (+.+) ---- (map _crPos $ IM.elems flockers) ---- combinedRad = _crRad cr + _crRad (you w) ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) ----- replaceAction newActions = over (creatures . ix cid . crState . goals) +---- replaceGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) +---- replaceImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ----- addAction newActions = over (creatures . ix cid . crState . goals) +---- addImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\(as:ass) -> (newActions++as):ass) ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of @@ -309,29 +255,29 @@ spreadOut ypos crs cpos = p ---- && x == 0 ---- -> over (creatures . ix cid . crPos) ---- (+.+ (12 *.* errorNormalizeVAI (ypos -.- cpos))) ----- $ replaceAction [MeleeAttack 5] +---- $ replaceImpulse [MeleeAttack 5] ---- $ damageYou ---- w ---- | canSee cid (_yourID w) w && dist cpos ypos < 50 ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 ypos cid ----- $ replaceAction [MoveToFor ypos (max 0 (x-1))] w +---- $ replaceImpulse [MoveToFor ypos (max 0 (x-1))] w ---- | x == 0 && canSee cid (_yourID w) w ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid ----- $ replaceAction [MoveToFor tp 0] w ----- | x == 0 -> replaceAction [MoveToFor p 10] w +---- $ replaceImpulse [MoveToFor tp 0] w +---- | x == 0 -> replaceImpulse [MoveToFor p 10] w ---- | canSee cid (_yourID w) w ---- -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid ----- $ replaceAction [MoveToFor p (x-1)] w +---- $ replaceImpulse [MoveToFor p (x-1)] w ---- | dist cpos p < 20 -> w ---- | otherwise -> mvForward 2 cid $ turnTowardSpeed 0.5 p cid w ---- (MeleeAttack x:_) ----- | x == 0 -> replaceAction [WaitFor 5] w ----- | otherwise -> replaceAction [MeleeAttack (x-1)] w ----- (WaitFor x:gls)| x == 0 -> replaceAction [] w +---- | x == 0 -> replaceImpulse [WaitFor 5] w +---- | otherwise -> replaceImpulse [MeleeAttack (x-1)] w +---- (WaitFor x:gls)| x == 0 -> replaceImpulse [] w ---- | canSee cid (_yourID w) w ---- -> turnTowardSpeed 0.02 ypos cid ----- $ replaceAction [WaitFor (x-1)] w ----- | otherwise -> replaceAction [WaitFor (x-1)] w +---- $ replaceImpulse [WaitFor (x-1)] w +---- | otherwise -> replaceImpulse [WaitFor (x-1)] w spawnerAI :: Creature -> World -> (World -> World,StdGen) -> Creature -> ((World -> World, StdGen), Maybe Creature) @@ -340,11 +286,11 @@ spawnerAI spawn w (f,g) cr = cid = _crID cr cpos = _crPos cr ypos = _crPos $ you w - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) needChild = length (filter (\cr' -> (cr' ^? crState . faction) == Just (SpawnedBy cid)) @@ -355,14 +301,14 @@ spawnerAI spawn w (f,g) cr = case head $ _goals $ _crState cr of (WaitFor x:_) | x == 0 && needChild -> ( (spawnChild . f , g) - ,replaceAction [WaitFor 200] $ over crDir (+ 1) cr + ,replaceImpulse [WaitFor 200] $ over crDir (+ 1) cr ) | canSee cid (_yourID w) w -> ( (f , g) - ,replaceAction [WaitFor (max 0 (x-1))] + ,replaceImpulse [WaitFor (max 0 (x-1))] $ set (crDir) (argV (ypos -.- cpos)) cr ) | otherwise -> ( (f , g) - ,replaceAction [WaitFor (max 0 (x-1))] cr) + ,replaceImpulse [WaitFor (max 0 (x-1))] cr) placeCrFaction :: Creature -> Faction -> Point2 -> Point2 -> Float -> World -> World placeCrFaction cr fact p op rot w = over creatures addCr w @@ -387,13 +333,13 @@ placeCrFaction cr fact p op rot w = over creatures addCr w ---- isCrowded = (length $ IM.elems $ IM.filter isCloseFaction (_creatures w)) > 2 ---- isCloseFaction cr' = _faction (_crState cr') == ChaseCritters ---- && dist cpos (_crPos cr') < 25 ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) ----- replaceAction newActions = over (creatures . ix cid . crState . goals) +---- replaceGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addGoal newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) +---- replaceImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ----- addAction newActions = over (creatures . ix cid . crState . goals) +---- addImpulse newActions = over (creatures . ix cid . crState . goals) ---- (\(as:ass) -> (newActions++as):ass) ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of @@ -402,46 +348,46 @@ placeCrFaction cr fact p op rot w = over creatures addCr w ---- | canSeeIndirect cid (_yourID w) w ---- -> addGoal [[PathTo ypos]] w ---- | otherwise -> replaceGoal [] w ----- (WaitFor x:gls)| x == 0 -> replaceAction [] w +---- (WaitFor x:gls)| x == 0 -> replaceImpulse [] w ---- | canSee cid (_yourID w) w ---- -> turnTowardSpeed 0.05 ypos cid ----- $ replaceAction [WaitFor (x-1)] w ----- | otherwise -> replaceAction [WaitFor (x-1)] w +---- $ replaceImpulse [WaitFor (x-1)] w +---- | otherwise -> replaceImpulse [WaitFor (x-1)] w ---- (MoveToFor p x:gls) ---- | dist ypos cpos < combinedRad + 5 ---- && abs ((_crDir cr) - argV (ypos -.- cpos)) < pi/4 -- same error as above ---- -- && x == 0 ---- -> over (creatures . ix cid . crPos) ---- (+.+ (12 *.* errorNormalizeVAI (ypos -.- cpos))) ----- $ replaceAction [MeleeAttack 5] +---- $ replaceImpulse [MeleeAttack 5] ---- $ damageYou ---- w ----- | x == 0 && isCrowded -> replaceAction [] $ randomTurn2 w +---- | x == 0 && isCrowded -> replaceImpulse [] $ randomTurn2 w ---- | canSee cid (_yourID w) w -> replaceGoal [[MoveToFor ypos (max 0 (x-1))]] ---- $ mvForward 2.5 cid $ randomTurn $ turnTowardSpeed 0.05 p cid w ----- | dist p cpos < 10 -> replaceAction [] w ----- | x == 0 -> replaceAction [] w ----- -- | not (canSeePoint cid p w) -> replaceAction [PathTo p] w ----- -- | not (canSeePoint cid p w) -> replaceAction [] w +---- | dist p cpos < 10 -> replaceImpulse [] w +---- | x == 0 -> replaceImpulse [] w +---- -- | not (canSeePoint cid p w) -> replaceImpulse [PathTo p] w +---- -- | not (canSeePoint cid p w) -> replaceImpulse [] w ---- | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 ----- -> replaceAction [MoveToFor p (max 0 (x-1))] $ turnTowardSpeed 0.05 p cid w ----- | otherwise -> replaceAction [MoveToFor p (max 0 (x-1))] +---- -> replaceImpulse [MoveToFor p (max 0 (x-1))] $ turnTowardSpeed 0.05 p cid w +---- | otherwise -> replaceImpulse [MoveToFor p (max 0 (x-1))] ---- $ mvForward 2.5 cid $ turnTowardSpeed 0.05 p cid w ---- (PathTo p:_) ----- | dist p cpos < 10 -> replaceAction [] w ----- | canSeePoint cid p w -> addAction [MoveToFor p 10] w +---- | dist p cpos < 10 -> replaceImpulse [] w +---- | canSeePoint cid p w -> addImpulse [MoveToFor p 10] w ---- | otherwise -> ----- case pointTowardsGoal' cpos p w of ----- Right q -> addAction [MoveToFor q 10] +---- case pointTowardsImpulse' cpos p w of +---- Right q -> addImpulse [MoveToFor q 10] ---- -- $ drawCircleAtForCol q 10 magenta ---- -- $ drawLineForCol ((cpos : (concat $ maybeToList $ makePathBetweenPs ---- -- cpos p w)) ++ [p]) 50 red ---- w ---- --Left s -> error s ----- _ -> replaceAction [] w +---- _ -> replaceImpulse [] w ---- (MeleeAttack x:_) ----- | x == 0 -> replaceAction [WaitFor wtime] w ----- | otherwise -> replaceAction [MeleeAttack (x-1)] w +---- | x == 0 -> replaceImpulse [WaitFor wtime] w +---- | otherwise -> replaceImpulse [MeleeAttack (x-1)] w ---- (TrackYou:_) -> addGoal [[WaitFor wtime,PathTo ypos]] $ set randGen g1 w ---- (InitTrackYou:_)| canSeeIndirect cid (_yourID w) w -> replaceGoal [[TrackYou]] w ---- | otherwise -> w @@ -468,11 +414,11 @@ miniAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] @@ -487,27 +433,27 @@ miniAI w (f,g) cr = (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -527,17 +473,17 @@ miniAI w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ turnCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -554,11 +500,11 @@ miniAI w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ turnCloseSlow p cr) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ turnCloseSlow p cr) strafeOrChargeAI :: Float -> Float -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) strafeOrChargeAI inRange outRange w (f,g) cr = @@ -587,11 +533,11 @@ strafeOrChargeAI inRange outRange w (f,g) cr = = crTurnTowardSpeed 0.05 p' . crStrafeLeft 3 where v = vNormal $ p -.- cpos p' = p +.+ 0.5 *.* (v -.- 20 *.* (normalizeV v)) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] @@ -607,27 +553,27 @@ strafeOrChargeAI inRange outRange w (f,g) cr = , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -647,17 +593,17 @@ strafeOrChargeAI inRange outRange w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ strafeCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -674,13 +620,13 @@ strafeOrChargeAI inRange outRange w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ strafeCloseSlow p + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ strafeCloseSlow p cr ) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ strafeCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ strafeCloseSlow p cr) chargeAI :: World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) chargeAI w (f,g) cr = @@ -699,47 +645,47 @@ chargeAI w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of (MoveTo p:_) - | dist cpos ypos < 40 -> ((f,g) , replaceAction [Fire] cr) + | dist cpos ypos < 40 -> ((f,g) , replaceImpulse [Fire] cr) | canSeeFire cpos ypos w -> ((f,g), Just . crMvBy (3,0) . fTurn ypos $ cr) | otherwise -> ((f,g), Just . crMvBy (3,0) . fTurn p $ cr) (Fire:_) | dist cpos ypos < 60 && canSeeFire cpos ypos w -> ((tryUseItem cid . f,g), Just $ fTurn ypos cr) - | otherwise -> ((f,g), replaceAction [] cr) + | otherwise -> ((f,g), replaceImpulse [] cr) [] | canSeeFireVisionAny cid (_yourID w) w - -> ( ( f , g' ) , addAction [MoveTo ypos] cr) + -> ( ( f , g' ) , addImpulse [MoveTo ypos] cr) | otherwise -> ( ( f , g' ) , Just cr) - (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] cr ) + (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g' ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g') - , replaceAction [MoveTo ypos] cr + , replaceImpulse [MoveTo ypos] cr ) | x == 0 -> ( (f , g') - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g') , replaceAction [] cr ) - (Init:_) -> ((f,g), replaceAction [] cr) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g') , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g') , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g') , replaceImpulse [] cr ) + (Init:_) -> ((f,g), replaceImpulse [] cr) launcherAI :: Float -> Float -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) launcherAI inRange outRange w (f,g) cr = @@ -755,11 +701,11 @@ launcherAI inRange outRange w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) ts = take 3 $ randomRs (20,25) g retreatActions = SetPosture Aiming @@ -847,28 +793,28 @@ launcherAI inRange outRange w (f,g) cr = ) in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of - (TurnTo p:_) -> ( (f,g') , replaceAction [] . crTurnTo p $ cr) - (TurnByFor a 0:_) -> ( (f,g') , replaceAction [] . over crDir (+a) $ cr) - (TurnByFor a i:_) -> ( (f,g') , replaceAction [TurnByFor a (i-1)] . over crDir (+a) $ cr) - (SetPosture pture:_) -> ((f,g), replaceAction [] $ set (crState . stance . posture) pture cr) - (MoveByFor p 0:_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (MoveByFor p i:_) -> ((f,g'), replaceAction [MoveByFor p (i-1)] . crMvBy p $ cr) + (TurnTo p:_) -> ( (f,g') , replaceImpulse [] . crTurnTo p $ cr) + (TurnByFor a 0:_) -> ( (f,g') , replaceImpulse [] . over crDir (+a) $ cr) + (TurnByFor a i:_) -> ( (f,g') , replaceImpulse [TurnByFor a (i-1)] . over crDir (+a) $ cr) + (SetPosture pture:_) -> ((f,g), replaceImpulse [] $ set (crState . stance . posture) pture cr) + (MoveByFor p 0:_) -> ((f,g'), replaceImpulse [] . crMvBy p $ cr) + (MoveByFor p i:_) -> ((f,g'), replaceImpulse [MoveByFor p (i-1)] . crMvBy p $ cr) (Fire:_) | pointHitsWalls cpos (cpos +.+ 40 *.* unitVectorAtAngle (_crDir cr)) (wallsAlongLine cpos (cpos +.+ 40 *.* unitVectorAtAngle (_crDir cr)) w) - -> ((f,g),replaceAction [] cr) - | otherwise -> ((tryUseItem cid . f,g'), replaceAction [] cr) - (GoalID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (GoalID i (MoveByFor p x):_) + -> ((f,g),replaceImpulse [] cr) + | otherwise -> ((tryUseItem cid . f,g'), replaceImpulse [] cr) + (ImpulseID i (MoveByFor p 0):_) -> ((f,g'), replaceImpulse [] . crMvBy p $ cr) + (ImpulseID i (MoveByFor p x):_) | canSeeFire cpos (aCrPos i w) w -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceImpulse [ImpulseID i (MoveByFor p (x-1))] . crMvBy p . crTurnTowardSpeed 0.01 (aCrPos i w) $ cr ) | otherwise -> ( (f,g') - , replaceAction [GoalID i (MoveForwardFor (x-1))] + , replaceImpulse [ImpulseID i (MoveForwardFor (x-1))] . crMvBy p $ cr ) @@ -885,49 +831,49 @@ launcherAI inRange outRange w (f,g) cr = ) | otherwise -> ( (f,g') - , replaceAction [] + , replaceImpulse [] . crTurnTo p $ cr ) [] | noAmmo -> ( (tryUseItem cid . f, g') - , addAction [Reload] cr + , addImpulse [Reload] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g' ) - -- , addAction (WaitFor 9:fireActions) - , addAction (WaitFor 9:fireActions) + -- , addImpulse (WaitFor 9:fireActions) + , addImpulse (WaitFor 9:fireActions) $ updateSearch cr ) | otherwise -> ( ( f , g' ) , replaceGoal [] cr ) - (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] cr ) + (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g' ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g') , replaceGoal [[],[PathTo ypos]] cr ) | x == 0 -> ( (f , g') - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g') , replaceAction [] cr ) - (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceAction [WaitFor recupTime] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g') , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g') , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g') , replaceImpulse [] cr ) + (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceImpulse [WaitFor recupTime] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g') , Just $ cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g') , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') @@ -956,11 +902,11 @@ dodgeAI inRange outRange w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) retreatOffset = let a | dist cpos ypos < 50 = 0 | isLeftOfA (_crDir cr) (argV $ ypos -.- cpos) @@ -973,11 +919,11 @@ dodgeAI inRange outRange w (f,g) cr = (ypos +.+ vNormal (cpos -.- ypos)) ts = take 5 $ randomRs (7,10) g chargeActions = TurnToward ypos - : (GoalID 0 (MoveByFor (3,0) 15)) - : (concatMap (\t -> [GoalID 0 (MoveByFor (3,0) t),Fire]) ts) + : (ImpulseID 0 (MoveByFor (3,0) 15)) + : (concatMap (\t -> [ImpulseID 0 (MoveByFor (3,0) t),Fire]) ts) retreatActions = TurnToward retreatOffset - :(GoalID 0 (MoveByFor (-3,0) 9)) - : (concatMap (\t -> [GoalID 0 (MoveByFor (-3,0) t),Fire]) ts) + :(ImpulseID 0 (MoveByFor (-3,0) 9)) + : (concatMap (\t -> [ImpulseID 0 (MoveByFor (-3,0) t),Fire]) ts) strafeLeftActions = TurnToward (yposr 150) : MoveByFor (0,3) 4 : (concatMap (\t -> [MoveByFor (0,3) t,Fire]) ts) strafeRightActions = TurnToward (yposl 150) : MoveByFor (0,-3) 4 @@ -1002,21 +948,21 @@ dodgeAI inRange outRange w (f,g) cr = ) in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of - (MoveByFor p 0:_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (MoveByFor p i:_) -> ((f,g'), replaceAction [MoveByFor p (i-1)] . crMvBy p $ cr) - (Fire:_) -> ((tryUseItem cid . f,g'), replaceAction [] cr) - (GoalID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (GoalID i (MoveByFor p x):_) + (MoveByFor p 0:_) -> ((f,g'), replaceImpulse [] . crMvBy p $ cr) + (MoveByFor p i:_) -> ((f,g'), replaceImpulse [MoveByFor p (i-1)] . crMvBy p $ cr) + (Fire:_) -> ((tryUseItem cid . f,g'), replaceImpulse [] cr) + (ImpulseID i (MoveByFor p 0):_) -> ((f,g'), replaceImpulse [] . crMvBy p $ cr) + (ImpulseID i (MoveByFor p x):_) | canSeeFire cpos (aCrPos i w) w -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceImpulse [ImpulseID i (MoveByFor p (x-1))] . crMvBy p . crTurnTowardSpeed 0.01 (aCrPos i w) $ cr ) | otherwise -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceImpulse [ImpulseID i (MoveByFor p (x-1))] . crMvBy p $ cr ) (TurnToward p:_) @@ -1032,36 +978,36 @@ dodgeAI inRange outRange w (f,g) cr = ) | otherwise -> ( (f,g') - , replaceAction [] + , replaceImpulse [] $ cr ) - [] | noAmmo -> ( (tryUseItem cid . f, g') , addAction [Reload] cr) + [] | noAmmo -> ( (tryUseItem cid . f, g') , addImpulse [Reload] cr) | canSeeFireVisionAny cid (_yourID w) w - -> ( ( f , g' ) , addAction (WaitFor 9:fireActions) $ updateSearch cr) + -> ( ( f , g' ) , addImpulse (WaitFor 9:fireActions) $ updateSearch cr) | otherwise -> ( ( f , g' ) , replaceGoal [] cr) - (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] + (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g' ), replaceImpulse [WaitFor (x-1)] $ crTurnTowardSpeed 0.05 ypos cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g') , replaceGoal [[],[PathTo ypos]] cr ) | x == 0 -> ( (f , g') - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g') , replaceAction [] cr ) - (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceAction [WaitFor recupTime] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g') , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g') , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g') , replaceImpulse [] cr ) + (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceImpulse [WaitFor recupTime] cr ) | otherwise -> ( (f , g') , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') @@ -1102,11 +1048,11 @@ circleClockwiseAI inRange outRange w (f,g) cr = = crTurnTowardSpeed 0.05 p' . crStrafeLeft 3 where v = vNormal $ p -.- cpos p' = p +.+ 0.5 *.* (v -.- 20 *.* (normalizeV v)) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] @@ -1122,27 +1068,27 @@ circleClockwiseAI inRange outRange w (f,g) cr = , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -1162,17 +1108,17 @@ circleClockwiseAI inRange outRange w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ strafeCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -1189,13 +1135,13 @@ circleClockwiseAI inRange outRange w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ strafeCloseSlow p + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ strafeCloseSlow p cr ) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ strafeCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ strafeCloseSlow p cr) twitchMissAI :: Float -> Float -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) twitchMissAI inRange outRange w (f,g) cr = @@ -1219,11 +1165,11 @@ twitchMissAI inRange outRange w (f,g) cr = closeDist | dist p cpos < inRange = -1 | dist p cpos < outRange = 0 | otherwise = 1 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) (t,g') = randomR (fireRate+10,fireRate+15) g retreatPs = sortBy (compare `on` dist cpos) $ map f $ nRaysRad 8 400 @@ -1235,47 +1181,47 @@ twitchMissAI inRange outRange w (f,g) cr = $ wallsAlongLine ypos retreatP' w retreatP = head $ sortBy (compare `on` (\p -> dist p ypos < 300)) $ retreatP'' : retreatPs fireActions = [TurnToward yposoff, Fire, TurnTo ypos, WaitFor t - ,Fire,Fire,Reload,GoalID 0 (WaitFor 20),MakeJudgement] + ,Fire,Fire,Reload,ImpulseID 0 (WaitFor 20),MakeJudgement] fleeActions = [MoveToFor retreatP 50,MakeJudgement] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] -> ((f,g), replaceGoal [] cr) (MakeJudgement:_) - | not (canSeeFire cpos ypos w) -> ((f,g),replaceAction [] cr) - | dist cpos ypos > 400 -> ((f,g), replaceAction [MoveToFor ypos 20] cr) - | dist cpos ypos < 150 -> ((f,g'),replaceAction fleeActions $ crMvBy (3,0) cr) - | otherwise -> ((f,g'),replaceAction fireActions cr) - (GoalID i (WaitFor x):gls) - | x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [GoalID i (WaitFor (x-1))] + | not (canSeeFire cpos ypos w) -> ((f,g),replaceImpulse [] cr) + | dist cpos ypos > 400 -> ((f,g), replaceImpulse [MoveToFor ypos 20] cr) + | dist cpos ypos < 150 -> ((f,g'),replaceImpulse fleeActions $ crMvBy (3,0) cr) + | otherwise -> ((f,g'),replaceImpulse fireActions cr) + (ImpulseID i (WaitFor x):gls) + | x == 0 -> ( (f ,g' ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g' ), replaceImpulse [ImpulseID i (WaitFor (x-1))] $ strafeCloseSlow ypos cr ) - (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] cr ) + (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g' ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) - | x == 0 -> ( (f, g') , replaceAction [] cr) - | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr) + | x == 0 -> ( (f, g') , replaceImpulse [] cr) + | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.5 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.5 p cr ) | otherwise -> ( (f , g') - , replaceAction [MoveToFor p (x-1)] $ crMvForward 3 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 3 $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | canSeeFire cpos ypos w -> ((f,g),replaceGoal [[MakeJudgement]] cr) - | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 50] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g') , addAction [MoveToFor q 50] cr ) - _ -> ( (f , g') , replaceAction [] cr ) + | dist p cpos < 10 -> ( (f , g') , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g') , addImpulse [MoveToFor p 50] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g') , addImpulse [MoveToFor q 50] cr ) + _ -> ( (f , g') , replaceImpulse [] cr ) (Fire:gls) -> ( (tryUseItem cid . f , g' ) - , replaceAction [] cr + , replaceImpulse [] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g') , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g') , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g') , Just $ strafeCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') @@ -1296,8 +1242,8 @@ twitchMissAI inRange outRange w (f,g) cr = | errorAngleVV 99 (p -.- cpos) (unitVectorAtAngle $ _crDir cr) > 0.2 -> ( (f,g') , Just . crTurnTowardSpeed 0.1 p $ cr) | otherwise - -> ( (f,g') , replaceAction [] . crTurnTo p $ cr) - (TurnTo p:_) -> ( (f,g') , replaceAction [] . crTurnTo p $ cr) + -> ( (f,g') , replaceImpulse [] . crTurnTo p $ cr) + (TurnTo p:_) -> ( (f,g') , replaceImpulse [] . crTurnTo p $ cr) closeToRangeAI :: Float -> Float -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) closeToRangeAI inRange outRange w (f,g) cr = @@ -1319,11 +1265,11 @@ closeToRangeAI inRange outRange w (f,g) cr = closeDist | dist p cpos < inRange = -1.5 | dist p cpos < outRange = 0 | otherwise = 1.5 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of @@ -1337,27 +1283,27 @@ closeToRangeAI inRange outRange w (f,g) cr = , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 3 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 3 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -1378,17 +1324,17 @@ closeToRangeAI inRange outRange w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ strafeCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -1405,13 +1351,13 @@ closeToRangeAI inRange outRange w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ strafeCloseSlow p + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ strafeCloseSlow p cr ) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ strafeCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ strafeCloseSlow p cr) suppressShooterAI :: World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) suppressShooterAI w (f,g) cr = @@ -1425,11 +1371,11 @@ suppressShooterAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] @@ -1444,27 +1390,27 @@ suppressShooterAI w (f,g) cr = (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -1484,17 +1430,17 @@ suppressShooterAI w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ turnCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- $ replaceAction [] w + -- $ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -1511,11 +1457,11 @@ suppressShooterAI w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ turnCloseSlow p cr) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ turnCloseSlow p cr) basicShooterAI :: World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) basicShooterAI w (f,g) cr = @@ -1529,11 +1475,11 @@ basicShooterAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] @@ -1548,27 +1494,27 @@ basicShooterAI w (f,g) cr = (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) , replaceGoal [[AimAt ypos aimtime]] cr ) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) - , replaceAction [] cr + , replaceImpulse [] cr ) - | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr) + | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) - (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,PathTo p @@ -1588,17 +1534,17 @@ basicShooterAI w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[PathTo p,WaitFor 50 ]] cr ) - (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ turnCloseSlow ypos cr ) -- no longer chase if see you when reloading - -- -$ replaceAction [] w + -- -$ replaceImpulse [] w | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -1615,11 +1561,11 @@ basicShooterAI w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ turnCloseSlow p cr) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ turnCloseSlow p cr) sniperAI :: World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) sniperAI w (f,g) cr = @@ -1633,34 +1579,34 @@ sniperAI w (f,g) cr = | errorAngleVV 22 (p -.- cpos) (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) - replaceAction newActions + replaceGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addGoal newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) + replaceImpulse newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) - addAction newActions + addImpulse newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) in case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) , replaceGoal [[AimAt ypos aimtime]] cr) | otherwise -> ( ( f , g ) , replaceGoal [] cr) (WaitFor x:gls) | canSeeFire cpos ypos w -> ( ( f , g1 ) , replaceGoal [[AimAt ypos aimtime]] cr) - | x == 0 -> ( (f ,g ), replaceAction [] cr ) - | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) + | x == 0 -> ( (f ,g ), replaceImpulse [] cr ) + | otherwise -> ( (f ,g ), replaceImpulse [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) , replaceGoal [[AimAt ypos aimtime]] cr) - | x == 0 -> ( (f , g) , replaceAction [] cr) - | dist p cpos < 1 -> ( (f , g) , replaceAction [] cr) + | x == 0 -> ( (f , g) , replaceImpulse [] cr) + | dist p cpos < 1 -> ( (f , g) , replaceImpulse [] cr) | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -> - ( (f , g) , replaceAction [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) + ( (f , g) , replaceImpulse [MoveToFor p (x-1)] $ crTurnTowardSpeed 0.05 p cr ) | otherwise -> ( (f , g) - , replaceAction [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) + , replaceImpulse [MoveToFor p (x-1)] $ crMvForward 2 $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) - | dist p cpos < 1 -> ( (f , g) , replaceAction [] cr ) - | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of - Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) - _ -> ( (f , g) , replaceAction [] cr ) + | dist p cpos < 1 -> ( (f , g) , replaceImpulse [] cr ) + | hasLOS cpos p w -> ( (f , g) , addImpulse [MoveToFor p 100] cr ) + | otherwise -> case pointTowardsImpulse cpos p w of + Just q -> ( (f , g) , addImpulse [MoveToFor q 100] cr ) + _ -> ( (f , g) , replaceImpulse [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) , replaceGoal [[Reload ,WaitFor 50 ]] cr) | canSeeFireVisionAll cid (_yourID w) w -> @@ -1670,14 +1616,14 @@ sniperAI w (f,g) cr = | otherwise -> ( (f , g) , replaceGoal [[WaitFor 50 ]] cr) (Reload:gls) - | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) + | _wpReloadState wp == 0 -> ( (f , g) , replaceImpulse [] cr ) | canSeeFireVisionAny cid (_yourID w) w -> ( (f , g) , Just $ turnCloseSlow ypos cr) | otherwise -> ( (f , g) , Just cr) - (Search i:gls) | i == 0 -> ( (f , g) , replaceAction [] cr) + (Search i:gls) | i == 0 -> ( (f , g) , replaceImpulse [] cr) | otherwise -> ( ( f , g1) - , replaceAction [ PathTo (randomPointXStepsFrom 3 cpos w) + , replaceImpulse [ PathTo (randomPointXStepsFrom 3 cpos w) , Search (i-1) ] cr ) @@ -1694,11 +1640,11 @@ sniperAI w (f,g) cr = (InitGuard :_) -> ( (f,g) ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) - (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) + (AimAt p i:_) | i == 0 -> ( (f,g) , replaceImpulse [FireAt p] cr ) | canSeeFireVision cid (_yourID w) w - -> ( (f,g) , replaceAction [AimAt ypos (i-1)] $ crTurnTowardSpeed 0.2 p cr) + -> ( (f,g) , replaceImpulse [AimAt ypos (i-1)] $ crTurnTowardSpeed 0.2 p cr) | otherwise - -> ( (f,g) , replaceAction [AimAt p (i-1)] $ turnCloseSlow p cr) + -> ( (f,g) , replaceImpulse [AimAt p (i-1)] $ turnCloseSlow p cr) errorNormalizeVAI :: Point2 -> Point2 errorNormalizeVAI (0,0) = error "problem with function: errorNormalizeVAI in DodgeAIs" diff --git a/src/Dodge/AIs.hs.orig b/src/Dodge/AIs.hs.orig index 6b1d91f11..a2e4d1215 100644 --- a/src/Dodge/AIs.hs.orig +++ b/src/Dodge/AIs.hs.orig @@ -78,10 +78,10 @@ spreadOut ypos crs cpos = p ---- $ _creatures w ---- tp = f ypos flockers cpos ---- combinedRad = _crRad cr + _crRad (you w) ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) +---- replaceImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) ---- replaceAction newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ---- addAction newActions = over (creatures . ix cid . crState . goals) @@ -89,7 +89,7 @@ spreadOut ypos crs cpos = p ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of ---- [] | canSee cid (_yourID w) w ----- -> replaceGoal [[MoveToFor tp 10]] w +---- -> replaceImpulse [[MoveToFor tp 10]] w ---- | otherwise -> w ---- (MoveToFor p x:_) ---- | dist ypos cpos < combinedRad + 5 @@ -141,10 +141,10 @@ spreadOut ypos crs cpos = p ---- foldr1 (+.+) ---- (map _crPos $ IM.elems flockers) ---- combinedRad = _crRad cr + _crRad (you w) ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) +---- replaceImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) ---- replaceAction newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ---- addAction newActions = over (creatures . ix cid . crState . goals) @@ -152,7 +152,7 @@ spreadOut ypos crs cpos = p ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of ---- [] | canSee cid (_yourID w) w ----- -> replaceGoal [[MoveToFor tp 10]] w +---- -> replaceImpulse [[MoveToFor tp 10]] w ---- | otherwise -> w ---- (MoveToFor p x:_) ---- | dist ypos cpos < combinedRad + 5 @@ -191,8 +191,8 @@ spawnerAI spawn w (f,g) cr = cid = _crID cr cpos = _crPos cr ypos = _crPos $ you w - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -241,21 +241,21 @@ chaseAI w (f,g') cr = isCrowded = (length $ IM.elems $ IM.filter isCloseFaction (_creatures w)) > 2 isCloseFaction cr' = _faction (_crState cr') == _faction (_crState cr) && dist cpos (_crPos cr') < 25 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of - [] -> ((f, g') , replaceGoal [] cr) + [] -> ((f, g') , replaceImpulse [] cr) (Wait:_) | dist cpos ypos < 900 && hasLOS cpos ypos w -> ((f ,g') - ,addGoal [[WaitFor wtime,MoveTo ypos]] cr) + ,addImpulse [[WaitFor wtime,MoveTo ypos]] cr) | dist cpos ypos < 900 && hasLOSIndirect cpos ypos w -> ((f , g') - ,addGoal [[WaitFor wtime,PathTo ypos]] cr) + ,addImpulse [[WaitFor wtime,PathTo ypos]] cr) | otherwise -> ( (f , g') ,Just cr) (WaitFor x:gls)| x == 0 -> ( (f , g') @@ -325,7 +325,7 @@ chaseAI w (f,g') cr = -- -- , replaceAction [] cr -- ) - case pointTowardsGoal cpos p w of + case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 10] cr @@ -335,7 +335,7 @@ chaseAI w (f,g') cr = , replaceAction [] cr ) --- case pointTowardsGoal' cpos p w of +-- case pointTowardsImpulse' cpos p w of -- Right q -> addAction [MoveToFor q 10] ----- let ns = map fst $ concatMap doublePair $ _pathGraph' w ----- a' = listToMaybe $ sortBy (compare `on` dist cpos) $ ns @@ -381,10 +381,10 @@ chaseAI w (f,g') cr = ---- isCrowded = (length $ IM.elems $ IM.filter isCloseFaction (_creatures w)) > 2 ---- isCloseFaction cr' = _faction (_crState cr') == ChaseCritters ---- && dist cpos (_crPos cr') < 25 ----- replaceGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ tail gs) ----- addGoal newGoals = over (creatures . ix cid . crState . goals) ----- (\gs -> newGoals ++ gs) +---- replaceImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ tail gs) +---- addImpulse newImpulses = over (creatures . ix cid . crState . goals) +---- (\gs -> newImpulses ++ gs) ---- replaceAction newActions = over (creatures . ix cid . crState . goals) ---- (\((_:as):ass) -> (newActions ++ as):ass) ---- addAction newActions = over (creatures . ix cid . crState . goals) @@ -392,10 +392,10 @@ chaseAI w (f,g') cr = ---- in if _crHP cr <= 0 then killCr cid w else ---- case head $ _goals $ _crState cr of ---- [] | canSee cid (_yourID w) w ----- -> replaceGoal [[MoveToFor ypos 10]] w +---- -> replaceImpulse [[MoveToFor ypos 10]] w ---- | canSeeIndirect cid (_yourID w) w ----- -> addGoal [[PathTo ypos]] w ----- | otherwise -> replaceGoal [] w +---- -> addImpulse [[PathTo ypos]] w +---- | otherwise -> replaceImpulse [] w ---- (WaitFor x:gls)| x == 0 -> replaceAction [] w ---- | canSee cid (_yourID w) w ---- -> turnTowardSpeed 0.05 ypos cid @@ -411,7 +411,7 @@ chaseAI w (f,g') cr = ---- $ damageYou ---- w ---- | x == 0 && isCrowded -> replaceAction [] $ randomTurn2 w ----- | canSee cid (_yourID w) w -> replaceGoal [[MoveToFor ypos (max 0 (x-1))]] +---- | canSee cid (_yourID w) w -> replaceImpulse [[MoveToFor ypos (max 0 (x-1))]] ---- $ mvForward 2.5 cid $ randomTurn $ turnTowardSpeed 0.05 p cid w ---- | dist p cpos < 10 -> replaceAction [] w ---- | x == 0 -> replaceAction [] w @@ -425,7 +425,7 @@ chaseAI w (f,g') cr = ---- | dist p cpos < 10 -> replaceAction [] w ---- | canSeePoint cid p w -> addAction [MoveToFor p 10] w ---- | otherwise -> ----- case pointTowardsGoal' cpos p w of +---- case pointTowardsImpulse' cpos p w of ---- Right q -> addAction [MoveToFor q 10] ---- -- $ drawCircleAtForCol q 10 magenta ---- -- $ drawLineForCol ((cpos : (concat $ maybeToList $ makePathBetweenPs @@ -436,17 +436,17 @@ chaseAI w (f,g') cr = ---- (MeleeAttack x:_) ---- | x == 0 -> replaceAction [WaitFor wtime] w ---- | otherwise -> replaceAction [MeleeAttack (x-1)] w ----- (TrackYou:_) -> addGoal [[WaitFor wtime,PathTo ypos]] $ set randGen g1 w ----- (InitTrackYou:_)| canSeeIndirect cid (_yourID w) w -> replaceGoal [[TrackYou]] w +---- (TrackYou:_) -> addImpulse [[WaitFor wtime,PathTo ypos]] $ set randGen g1 w +---- (InitTrackYou:_)| canSeeIndirect cid (_yourID w) w -> replaceImpulse [[TrackYou]] w ---- | otherwise -> w ---- (Guard p p':_) | canSeeIndirect cid (_yourID w) w ----- -> addGoal [[WaitFor wtime,PathTo ypos]] $ set randGen g1 w +---- -> addImpulse [[WaitFor wtime,PathTo ypos]] $ set randGen g1 w ---- | dist cpos p > 10 ----- -> addGoal [[PathTo p]] w +---- -> addImpulse [[PathTo p]] w ---- | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 ---- -> turnTowardSpeed 0.05 p' cid w ---- | otherwise -> w ----- (InitGuard :_) -> replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] w +---- (InitGuard :_) -> replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] w -- be aware that the crit can be removed -- don't just refer to its id in the -- world->world part @@ -462,30 +462,30 @@ miniAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -499,11 +499,11 @@ miniAI w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -512,14 +512,14 @@ miniAI w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ turnCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ turnCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ turnCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -537,16 +537,16 @@ miniAI w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (0)]] cr + , addImpulse [[AimAt ypos (0)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -581,31 +581,31 @@ strafeOrChargeAI inRange outRange w (f,g) cr = = crTurnTowardSpeed 0.05 p' . crStrafeLeft 3 where v = vNormal $ p -.- cpos p' = p +.+ 0.5 *.* (v -.- 20 *.* (normalizeV v)) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -619,11 +619,11 @@ strafeOrChargeAI inRange outRange w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -632,14 +632,14 @@ strafeOrChargeAI inRange outRange w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ strafeCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ strafeCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ strafeCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -657,16 +657,16 @@ strafeOrChargeAI inRange outRange w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -693,8 +693,8 @@ chargeAI w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -730,7 +730,7 @@ chargeAI w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) _ -> ( (f , g') , replaceAction [] cr ) (Init:_) -> ((f,g), replaceAction [] cr) @@ -749,8 +749,8 @@ launcherAI inRange outRange w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -851,18 +851,18 @@ launcherAI inRange outRange w (f,g) cr = (wallsAlongLine cpos (cpos +.+ 40 *.* unitVectorAtAngle (_crDir cr)) w) -> ((f,g),replaceAction [] cr) | otherwise -> ((tryUseItem cid . f,g'), replaceAction [] cr) - (GoalID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (GoalID i (MoveByFor p x):_) + (ImpulseID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) + (ImpulseID i (MoveByFor p x):_) | canSeeFire cpos (aCrPos i w) w -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceAction [ImpulseID i (MoveByFor p (x-1))] . crMvBy p . crTurnTowardSpeed 0.01 (aCrPos i w) $ cr ) | otherwise -> ( (f,g') - , replaceAction [GoalID i (MoveForwardFor (x-1))] + , replaceAction [ImpulseID i (MoveForwardFor (x-1))] . crMvBy p $ cr ) @@ -893,13 +893,13 @@ launcherAI inRange outRange w (f,g) cr = $ updateSearch cr ) | otherwise -> ( ( f , g' ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g') - , replaceGoal [[],[PathTo ypos]] cr + , replaceImpulse [[],[PathTo ypos]] cr ) | x == 0 -> ( (f , g') , replaceAction [] cr @@ -913,7 +913,7 @@ launcherAI inRange outRange w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) _ -> ( (f , g') , replaceAction [] cr ) (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceAction [WaitFor recupTime] cr ) @@ -925,16 +925,16 @@ launcherAI inRange outRange w (f,g) cr = | otherwise -> ( (f , g') , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') - , addGoal [[WaitFor aimtime],[PathTo ypos]] cr + , addImpulse [[WaitFor aimtime],[PathTo ypos]] cr ) | dist cpos p > 10 - -> ( (f,g') , addGoal [[PathTo p]] cr) + -> ( (f,g') , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g') ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g') ,Just cr) (Init :_) -> ( (f,g') - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) dodgeAI :: Float -> Float -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) dodgeAI inRange outRange w (f,g) cr = @@ -950,8 +950,8 @@ dodgeAI inRange outRange w (f,g) cr = updateSearch = over (crState . goals) f where f (g:_:h:gs) = (g:[PathTo ypos]:h:gs) f (g:gs) = (g:[PathTo ypos]:gs) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -967,11 +967,11 @@ dodgeAI inRange outRange w (f,g) cr = (ypos +.+ vNormal (cpos -.- ypos)) ts = take 5 $ randomRs (7,10) g chargeActions = TurnToward ypos - : (GoalID 0 (MoveByFor (3,0) 15)) - : (concatMap (\t -> [GoalID 0 (MoveByFor (3,0) t),Fire]) ts) + : (ImpulseID 0 (MoveByFor (3,0) 15)) + : (concatMap (\t -> [ImpulseID 0 (MoveByFor (3,0) t),Fire]) ts) retreatActions = TurnToward retreatOffset - :(GoalID 0 (MoveByFor (-3,0) 9)) - : (concatMap (\t -> [GoalID 0 (MoveByFor (-3,0) t),Fire]) ts) + :(ImpulseID 0 (MoveByFor (-3,0) 9)) + : (concatMap (\t -> [ImpulseID 0 (MoveByFor (-3,0) t),Fire]) ts) strafeLeftActions = TurnToward (yposr 150) : MoveByFor (0,3) 4 : (concatMap (\t -> [MoveByFor (0,3) t,Fire]) ts) strafeRightActions = TurnToward (yposl 150) : MoveByFor (0,-3) 4 @@ -999,18 +999,18 @@ dodgeAI inRange outRange w (f,g) cr = (MoveByFor p 0:_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) (MoveByFor p i:_) -> ((f,g'), replaceAction [MoveByFor p (i-1)] . crMvBy p $ cr) (Fire:_) -> ((tryUseItem cid . f,g'), replaceAction [] cr) - (GoalID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) - (GoalID i (MoveByFor p x):_) + (ImpulseID i (MoveByFor p 0):_) -> ((f,g'), replaceAction [] . crMvBy p $ cr) + (ImpulseID i (MoveByFor p x):_) | canSeeFire cpos (aCrPos i w) w -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceAction [ImpulseID i (MoveByFor p (x-1))] . crMvBy p . crTurnTowardSpeed 0.01 (aCrPos i w) $ cr ) | otherwise -> ( (f,g') - , replaceAction [GoalID i (MoveByFor p (x-1))] + , replaceAction [ImpulseID i (MoveByFor p (x-1))] . crMvBy p $ cr ) (TurnToward p:_) @@ -1032,13 +1032,13 @@ dodgeAI inRange outRange w (f,g) cr = [] | noAmmo -> ( (tryUseItem cid . f, g') , addAction [Reload] cr) | canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g' ) , addAction (WaitFor 9:fireActions) $ updateSearch cr) - | otherwise -> ( ( f , g' ) , replaceGoal [] cr) + | otherwise -> ( ( f , g' ) , replaceImpulse [] cr) (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] $ crTurnTowardSpeed 0.05 ypos cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g') - , replaceGoal [[],[PathTo ypos]] cr + , replaceImpulse [[],[PathTo ypos]] cr ) | x == 0 -> ( (f , g') , replaceAction [] cr @@ -1052,24 +1052,24 @@ dodgeAI inRange outRange w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g') , addAction [MoveToFor q 100] cr ) _ -> ( (f , g') , replaceAction [] cr ) (Reload:_) | _wpReloadState wp == 0 -> ( (f , g') , replaceAction [WaitFor recupTime] cr ) | otherwise -> ( (f , g') , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') - , addGoal [[WaitFor aimtime],[PathTo ypos]] cr + , addImpulse [[WaitFor aimtime],[PathTo ypos]] cr ) | dist cpos p > 10 - -> ( (f,g') , addGoal [[PathTo p]] cr) + -> ( (f,g') , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g') ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g') ,Just cr) (InitGuard :_) -> ( ( f,g') -- (InitGuard :_) -> ( (over lightSources (IM.insert cid (crLight cid)) . f,g') - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (x:_) -> error $ "missing the following pattern in case expression:" ++ show x @@ -1096,31 +1096,31 @@ circleClockwiseAI inRange outRange w (f,g) cr = = crTurnTowardSpeed 0.05 p' . crStrafeLeft 3 where v = vNormal $ p -.- cpos p' = p +.+ 0.5 *.* (v -.- 20 *.* (normalizeV v)) - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -1134,11 +1134,11 @@ circleClockwiseAI inRange outRange w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -1147,14 +1147,14 @@ circleClockwiseAI inRange outRange w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ strafeCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ strafeCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ strafeCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -1172,16 +1172,16 @@ circleClockwiseAI inRange outRange w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -1213,8 +1213,8 @@ twitchMissAI inRange outRange w (f,g) cr = closeDist | dist p cpos < inRange = -1 | dist p cpos < outRange = 0 | otherwise = 1 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -1229,19 +1229,19 @@ twitchMissAI inRange outRange w (f,g) cr = $ wallsAlongLine ypos retreatP' w retreatP = head $ sortBy (compare `on` (\p -> dist p ypos < 300)) $ retreatP'' : retreatPs fireActions = [TurnToward yposoff, Fire, TurnTo ypos, WaitFor t - ,Fire,Fire,Reload,GoalID 0 (WaitFor 20),MakeJudgement] + ,Fire,Fire,Reload,ImpulseID 0 (WaitFor 20),MakeJudgement] fleeActions = [MoveToFor retreatP 50,MakeJudgement] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of - [] -> ((f,g), replaceGoal [] cr) + [] -> ((f,g), replaceImpulse [] cr) (MakeJudgement:_) | not (canSeeFire cpos ypos w) -> ((f,g),replaceAction [] cr) | dist cpos ypos > 400 -> ((f,g), replaceAction [MoveToFor ypos 20] cr) | dist cpos ypos < 150 -> ((f,g'),replaceAction fleeActions $ crMvBy (3,0) cr) | otherwise -> ((f,g'),replaceAction fireActions cr) - (GoalID i (WaitFor x):gls) + (ImpulseID i (WaitFor x):gls) | x == 0 -> ( (f ,g' ), replaceAction [] cr ) - | otherwise -> ( (f ,g' ), replaceAction [GoalID i (WaitFor (x-1))] + | otherwise -> ( (f ,g' ), replaceAction [ImpulseID i (WaitFor (x-1))] $ strafeCloseSlow ypos cr ) (WaitFor x:gls)| x == 0 -> ( (f ,g' ), replaceAction [] cr ) | otherwise -> ( (f ,g' ), replaceAction [WaitFor (x-1)] cr ) @@ -1255,10 +1255,10 @@ twitchMissAI inRange outRange w (f,g) cr = , replaceAction [MoveToFor p (x-1)] $ crMvForward 3 $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) - | canSeeFire cpos ypos w -> ((f,g),replaceGoal [[MakeJudgement]] cr) + | canSeeFire cpos ypos w -> ((f,g),replaceImpulse [[MakeJudgement]] cr) | dist p cpos < 10 -> ( (f , g') , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g') , addAction [MoveToFor p 50] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g') , addAction [MoveToFor q 50] cr ) _ -> ( (f , g') , replaceAction [] cr ) (Fire:gls) -> ( (tryUseItem cid . f , g' ) @@ -1273,16 +1273,16 @@ twitchMissAI inRange outRange w (f,g) cr = | otherwise -> ( (f , g) , Just cr) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g') - , addGoal [[MakeJudgement]] cr + , addImpulse [[MakeJudgement]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (TurnToward p:_) | errorAngleVV 99 (p -.- cpos) (unitVectorAtAngle $ _crDir cr) > 2 @@ -1313,8 +1313,8 @@ closeToRangeAI inRange outRange w (f,g) cr = closeDist | dist p cpos < inRange = -1.5 | dist p cpos < outRange = 0 | otherwise = 1.5 - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions @@ -1322,20 +1322,20 @@ closeToRangeAI inRange outRange w (f,g) cr = in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -1349,11 +1349,11 @@ closeToRangeAI inRange outRange w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -1362,7 +1362,7 @@ closeToRangeAI inRange outRange w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[AimAt ypos (fireRate+ aimtime - 80)]] + , replaceImpulse [[AimAt ypos (fireRate+ aimtime - 80)]] $ strafeCloseSlow p cr ) | pathToPointFireable cid p w @@ -1370,7 +1370,7 @@ closeToRangeAI inRange outRange w (f,g) cr = , Just $ strafeCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -1388,16 +1388,16 @@ closeToRangeAI inRange outRange w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -1419,30 +1419,30 @@ suppressShooterAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -1456,11 +1456,11 @@ suppressShooterAI w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -1469,14 +1469,14 @@ suppressShooterAI w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ turnCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ turnCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ turnCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -1494,16 +1494,16 @@ suppressShooterAI w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -1523,30 +1523,30 @@ basicShooterAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -1560,11 +1560,11 @@ basicShooterAI w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 10 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,PathTo p ,WaitFor 50 --,Search 1 ,WaitFor 100 @@ -1573,14 +1573,14 @@ basicShooterAI w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ turnCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ turnCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ turnCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[PathTo p,WaitFor 50 ]] cr + , replaceImpulse [[PathTo p,WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -1598,16 +1598,16 @@ basicShooterAI w (f,g) cr = ) (Guard p p':_) | dist ypos cpos < 900 && canSeeFireVisionAny cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 10 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVisionAll cid (_yourID w) w @@ -1626,30 +1626,30 @@ sniperAI w (f,g) cr = (unitVectorAtAngle (_crDir cr)) < 0.4 = crTurnTowardSpeed 0.01 p | otherwise = crTurnTowardSpeed 0.05 p - replaceGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ tail gs) - addGoal newGoals = Just . over (crState . goals) (\gs -> newGoals ++ gs) + replaceImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ tail gs) + addImpulse newImpulses = Just . over (crState . goals) (\gs -> newImpulses ++ gs) replaceAction newActions = Just . over (crState . goals) (\((_:as):ass) -> (newActions ++ as):ass) addAction newActions = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = Just --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] in --if _crHP cr <= 0 then killCr w f cr else case head $ _goals $ _crState cr of [] | canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | otherwise -> ( ( f , g ) - , replaceGoal [] cr + , replaceImpulse [] cr ) (WaitFor x:gls)| canSeeFire cpos ypos w -> ( ( f , g1 ) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f ,g ), replaceAction [] cr ) | otherwise -> ( (f ,g ), replaceAction [WaitFor (x-1)] cr ) (MoveToFor p x:gls) | canSeeFire cpos ypos w -> ( (f , g1) - , replaceGoal [[AimAt ypos aimtime]] cr + , replaceImpulse [[AimAt ypos aimtime]] cr ) | x == 0 -> ( (f , g) , replaceAction [] cr @@ -1663,11 +1663,11 @@ sniperAI w (f,g) cr = $ crTurnTowardSpeed 0.05 p cr ) (PathTo p:_) | dist p cpos < 1 -> ( (f , g) , replaceAction [] cr ) | hasLOS cpos p w -> ( (f , g) , addAction [MoveToFor p 100] cr ) - | otherwise -> case pointTowardsGoal cpos p w of + | otherwise -> case pointTowardsImpulse cpos p w of Just q -> ( (f , g) , addAction [MoveToFor q 100] cr ) _ -> ( (f , g) , replaceAction [] cr ) (FireAt p:gls) | noAmmo -> ( (tryUseItem cid . f , g ) - , replaceGoal [[Reload + , replaceImpulse [[Reload ,WaitFor 50 --,Search 1 ,WaitFor 100 ]] @@ -1675,14 +1675,14 @@ sniperAI w (f,g) cr = ) | canSeeFireVisionAll cid (_yourID w) w -> ( (tryUseItem cid . f , g) - , replaceGoal [[FireAt ypos]] $ turnCloseSlow p cr + , replaceImpulse [[FireAt ypos]] $ turnCloseSlow p cr ) | pathToPointFireable cid p w -> ( (tryUseItem cid . f , g) , Just $ turnCloseSlow p cr ) | otherwise -> ( (f , g) - , replaceGoal [[WaitFor 50 ]] cr + , replaceImpulse [[WaitFor 50 ]] cr ) (Reload:gls) | _wpReloadState wp == 0 -> ( (f , g) , replaceAction [] cr ) | canSeeFireVisionAny cid (_yourID w) w @@ -1700,16 +1700,16 @@ sniperAI w (f,g) cr = ) (Guard p p':_) | canSeeFireVision cid (_yourID w) w -> ( ( f , g1) - , addGoal [[AimAt ypos (2*aimtime)]] cr + , addImpulse [[AimAt ypos (2*aimtime)]] cr ) | dist cpos p > 1 - -> ( (f,g) , addGoal [[PathTo p]] cr) + -> ( (f,g) , addImpulse [[PathTo p]] cr) | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -> ( (f,g) ,Just $ crTurnTowardSpeed 0.05 p' cr) | otherwise -> ( (f,g) ,Just cr) (InitGuard :_) -> ( (f,g) - ,replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr + ,replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] cr ) (AimAt p i:_) | i == 0 -> ( (f,g) , replaceAction [FireAt p] cr ) | canSeeFireVision cid (_yourID w) w @@ -1726,27 +1726,27 @@ sniperAI w (f,g) cr = -- (unitVectorAtAngle (_crDir cr)) < 0.4 -- = turnTowardSpeed 0.01 p cid -- | otherwise = turnTowardSpeed 0.05 p cid --- replaceGoal newGoals = over (creatures . ix cid . crState . goals) --- (\gs -> newGoals ++ tail gs) --- addGoal newGoals = over (creatures . ix cid . crState . goals) --- (\gs -> newGoals ++ gs) +-- replaceImpulse newImpulses = over (creatures . ix cid . crState . goals) +-- (\gs -> newImpulses ++ tail gs) +-- addImpulse newImpulses = over (creatures . ix cid . crState . goals) +-- (\gs -> newImpulses ++ gs) -- replaceAction newActions = over (creatures . ix cid . crState . goals) -- (\((_:as):ass) -> (newActions ++ as):ass) -- addAction newActions = over (creatures . ix cid . crState . goals) -- (\(as:ass) -> (newActions++as):ass) -- autoFireTweak p | _wpIsAuto wp = id --- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]] +-- | otherwise = replaceImpulse [[AimAt p (_itUseRate wp * 2)]] -- in if _crHP cr <= 0 then killCr cid w else -- case head $ _goals $ _crState cr of -- [] | canSeeAny cid (_yourID w) w --- -> replaceGoal [[AimAt ypos 50]] w --- | otherwise -> replaceGoal [] w +-- -> replaceImpulse [[AimAt ypos 50]] w +-- | otherwise -> replaceImpulse [] w -- (WaitFor x:gls)| canSeeAny cid (_yourID w) w --- -> replaceGoal [[AimAt ypos 50]] w +-- -> replaceImpulse [[AimAt ypos 50]] w -- | x == 0 -> replaceAction [] w -- | otherwise -> replaceAction [WaitFor (x-1)] w -- (MoveToFor p x:gls) --- | canSeeAny cid (_yourID w) w -> replaceGoal [[AimAt ypos 50]] w +-- | canSeeAny cid (_yourID w) w -> replaceImpulse [[AimAt ypos 50]] w -- | x == 0 || not (canSeePoint cid p w) -> replaceAction [] w -- | dist p cpos < 10 -> replaceAction [] w -- | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 @@ -1755,11 +1755,11 @@ sniperAI w (f,g) cr = -- $ mvForward speed cid $ turnTowardSpeed 0.05 p cid w -- (PathTo p:_) | dist p cpos < 10 -> replaceAction [] w -- | canSeePoint cid p w -> addAction [MoveToFor p 100] w --- | otherwise -> case pointTowardsGoal cpos p w of +-- | otherwise -> case pointTowardsImpulse cpos p w of -- Just q -> addAction [MoveToFor q 100] w -- _ -> replaceAction [] w -- (MoveFire mp tp:gls) --- | noAmmo -> replaceGoal [[Reload +-- | noAmmo -> replaceImpulse [[Reload -- ,MoveFire mp tp -- ]] -- $ tryUseItem cid w @@ -1775,13 +1775,13 @@ sniperAI w (f,g) cr = -- $ replaceAction [] w -- | otherwise -> w -- (Guard p p':_)| canSeeAny cid (_yourID w) w --- -> addGoal [[AimAt ypos 50]] w +-- -> addImpulse [[AimAt ypos 50]] w -- | dist cpos p > 10 --- -> addGoal [[PathTo p]] w +-- -> addImpulse [[PathTo p]] w -- | errorAngleVV 21 (unitVectorAtAngle (_crDir cr)) (p' -.- p) > pi/8 -- -> turnTowardSpeed 0.05 p' cid w -- | otherwise -> w --- (InitGuard :_) -> replaceGoal [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] w +-- (InitGuard :_) -> replaceImpulse [[Guard cpos (cpos +.+ 50 *.* unitVectorAtAngle (_crDir cr))]] w -- (AimAt p i:_) | i == 0 -> replaceAction [MoveFire p p] w -- | angleVV (unitVectorAtAngle (_crDir cr)) (p -.- cpos) > pi/4 -- -> replaceAction [AimAt p (i-1)] $ turnTowardSpeed 0.05 p cid w @@ -1789,7 +1789,7 @@ sniperAI w (f,g) cr = -- -> replaceAction [AimAt ypos (i-1)] $ turnCloseSlow p -- $ strafeTo speed p cid w -- | otherwise --- -> replaceGoal [[AimAt p (i-1),Search 1]] $ turnCloseSlow p +-- -> replaceImpulse [[AimAt p (i-1),Search 1]] $ turnCloseSlow p -- $ strafeTo speed p cid w -- (Search i:gls) | i == 0 -> replaceAction [] w -- | otherwise -> replaceAction [PathTo (randomPointXStepsFrom 3 cpos w) diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index cbe15c202..37985ebb2 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -3,6 +3,9 @@ module Dodge.Creature , module Dodge.Creature.Inanimate ) where +import Dodge.Creature.Stance.Data +import Dodge.Creature.State.Data +import Dodge.Creature.Impulse.Data import Dodge.Data import Dodge.AIs import Dodge.Default diff --git a/src/Dodge/Creature.hs.orig b/src/Dodge/Creature.hs.orig index 38941056c..0ca65ad42 100644 --- a/src/Dodge/Creature.hs.orig +++ b/src/Dodge/Creature.hs.orig @@ -227,15 +227,15 @@ goalPict cr = let r = _crRad cr in case _crState cr of -- | crDam > _crHP cr -> color white $ circleSolid r | otherwise -> case head gls of [] -> sizeColEnemy r white - (MoveToFor p i:_) -> dGoals $ sizeColEnemy r green - (WaitFor x:_) -> dGoals $ sizeColEnemy r yellow - (FireAt p:_) -> dGoals $ sizeColEnemy r red - (Reload:_) -> dGoals $ sizeColEnemy r orange - (PathTo p:_) -> dGoals $ sizeColEnemy r cyan - (SubPathTo p i _:_) -> dGoals $ sizeColEnemy r blue - (Search i:_) -> dGoals $ sizeColEnemy r black - _ -> dGoals $ sizeColEnemy r magenta - where dGoals p = pictures [p, rotate (0 - _crDir cr) $ scale 0.1 0.1 $ color white $ text $ show gls] + (MoveToFor p i:_) -> dImpulses $ sizeColEnemy r green + (WaitFor x:_) -> dImpulses $ sizeColEnemy r yellow + (FireAt p:_) -> dImpulses $ sizeColEnemy r red + (Reload:_) -> dImpulses $ sizeColEnemy r orange + (PathTo p:_) -> dImpulses $ sizeColEnemy r cyan + (SubPathTo p i _:_) -> dImpulses $ sizeColEnemy r blue + (Search i:_) -> dImpulses $ sizeColEnemy r black + _ -> dImpulses $ sizeColEnemy r magenta + where dImpulses p = pictures [p, rotate (0 - _crDir cr) $ scale 0.1 0.1 $ color white $ text $ show gls] _ -> sizeColEnemy r (light $ dim green) startCr :: Creature diff --git a/src/Dodge/Creature/AI.hs b/src/Dodge/Creature/AI.hs new file mode 100644 index 000000000..093cb0e60 --- /dev/null +++ b/src/Dodge/Creature/AI.hs @@ -0,0 +1,11 @@ +module Dodge.Creature.AI + where +import Dodge.Data + +import Control.Lens +import System.Random + +insectAI + :: ( World -> StdGen -> Creature -> (World -> World, StdGen, Creature) ) + -> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature) +insectAI = undefined diff --git a/src/Dodge/Creature/AI/Data.hs b/src/Dodge/Creature/AI/Data.hs new file mode 100644 index 000000000..759d548db --- /dev/null +++ b/src/Dodge/Creature/AI/Data.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE StrictData #-} +module Dodge.Creature.AI.Data + where +import Dodge.Creature.State.Data +import Dodge.Creature.Impulse.Data + +import Control.Lens +data Intelligence + = Zombie { _crImpulse :: Impulse } + | Inanimate + diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index 238b3f09a..7711636fa 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -9,8 +9,10 @@ module Dodge.Creature.Action where import Dodge.Creature.Action.UseItem import Dodge.Creature.Action.Movement +import Dodge.Creature.Stance.Data +import Dodge.Creature.State.Data import Dodge.WorldEvent.Shockwave -import Dodge.Data +import Dodge.Data hiding (carriage) import Dodge.Base import Dodge.SoundLogic import Dodge.WorldEvent @@ -176,6 +178,16 @@ crTurnTo crTurnTo p cr = set crDir dirToTarget cr where dirToTarget = argV (p -.- _crPos cr) +crRandomTurn + :: RandomGen g + => Float -- ^ Max possible angle, supposed to be positive + -> Creature + -> g + -> (Creature, g) +crRandomTurn a cr g = + let (r, g') = randomR (negate a, a) g + in (cr & crDir +~ r, g') + crTurnTowardSpeed :: Float -- ^ Turn speed -> Point2 -- ^ Target position diff --git a/src/Dodge/Creature/Impulse/Data.hs b/src/Dodge/Creature/Impulse/Data.hs new file mode 100644 index 000000000..00ef51258 --- /dev/null +++ b/src/Dodge/Creature/Impulse/Data.hs @@ -0,0 +1,58 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE StrictData #-} +module Dodge.Creature.Impulse.Data + where +import Dodge.Creature.Stance.Data +import Geometry.Data + +import Control.Lens +data Impulse + = MoveTo Point2 + | MoveToFor Point2 Int + | MoveFire Point2 Point2 + | PathTo Point2 + | PathAlong [Point2] + | SubPathTo Point2 Int Point2 + | Wait + | WaitFor Int + | WaitForID Int Int + | FireAt Point2 + | FireAtID Int Point2 + | Fire + | Reload + | IncreaseAlert Int + | Guard Point2 Point2 + | Search Int + | SearchNear Point2 + | AimAt Point2 Int + | InitGuard + | Init + | MeleeAttack Int + | InitTrackYou + | TrackYou + | Track Int + | TrackFor Int Int + | TurnByFor Float Int + | TurnTo Point2 + | TurnToward Point2 + | TurnTowardAngle Float + | StrafeLeftAround Int Point2 + | StrafeRightAround Int Point2 + | StrafeLeftFor Int + | StrafeRightFor Int + | StrafeLeftForSpeed Int Float + | StrafeRightForSpeed Int Float + | StrafeLeftFire + | StrafeRightFire + | MoveForwardFor Int + | MoveForwardFire + | MoveBackwardFor Int + | MoveByFor Point2 Int + | MoveBackwardFire + | ImpulseID Int Impulse + | AtRange Float + | AtRanges Float Float + | RepeatAction Int Impulse + | MakeJudgement + | SetPosture Posture + deriving (Eq,Show) diff --git a/src/Dodge/Creature/Inanimate.hs b/src/Dodge/Creature/Inanimate.hs index 9f61e1a4f..fcd297461 100644 --- a/src/Dodge/Creature/Inanimate.hs +++ b/src/Dodge/Creature/Inanimate.hs @@ -4,6 +4,9 @@ Inanimate objects such as lamps, barrels, etc module Dodge.Creature.Inanimate where import Dodge.Data +import Dodge.Creature.Stance.Data +import Dodge.Creature.State.Data +import Dodge.Creature.Impulse.Data import Dodge.Base import Dodge.Picture.Layer import Dodge.Default diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 65213b793..2b41854a7 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -6,6 +6,7 @@ module Dodge.Creature.Picture , circLine ) where import Dodge.Data +import Dodge.Creature.State.Data import Dodge.Picture.Layer import Picture import Geometry diff --git a/src/Dodge/Creature/Stance/Data.hs b/src/Dodge/Creature/Stance/Data.hs new file mode 100644 index 000000000..c90b55a17 --- /dev/null +++ b/src/Dodge/Creature/Stance/Data.hs @@ -0,0 +1,25 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE StrictData #-} +module Dodge.Creature.Stance.Data + where +import Geometry.Data + +import Control.Lens +data Stance = Stance + {_carriage :: Carriage + ,_posture :: Posture + } + deriving (Eq,Show) +data Carriage + = Walking { _stepCycle :: Int, _stepToAdd :: Int } + | Standing + | Floating + | Flying + | Boosting Point2 + deriving (Eq,Show) +data Posture = Aiming | AtEase + deriving (Eq,Show) + +makeLenses ''Stance +makeLenses ''Carriage +makeLenses ''Posture diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 5c39e2edb..8f4d375f6 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -1,5 +1,8 @@ module Dodge.Creature.State where import Dodge.Data +import Dodge.Creature.State.Data +import Dodge.Creature.Stance.Data +import Dodge.Data import Dodge.Base import Dodge.SoundLogic import Dodge.RandomHelp diff --git a/src/Dodge/Creature/State/Data.hs b/src/Dodge/Creature/State/Data.hs index 04dcf3f0b..c58192bd5 100644 --- a/src/Dodge/Creature/State/Data.hs +++ b/src/Dodge/Creature/State/Data.hs @@ -4,11 +4,13 @@ module Dodge.Creature.State.Data where import Geometry import Dodge.Data.DamageType +import Dodge.Creature.Impulse.Data +import Dodge.Creature.Stance.Data import Control.Lens data CreatureState = CrSt - { _goals :: [[Goal]] + { _goals :: [[Impulse]] , _stance :: Stance , _faction :: Faction , _crDamage :: [DamageType] @@ -27,72 +29,7 @@ data CrSpState = Barrel { _piercedPoints :: [Point2]} | GenCr deriving (Eq,Show,Ord) -data Goal - = MoveTo Point2 - | MoveToFor Point2 Int - | MoveFire Point2 Point2 - | PathTo Point2 - | PathAlong [Point2] - | SubPathTo Point2 Int Point2 - | Wait - | WaitFor Int - | WaitForID Int Int - | FireAt Point2 - | FireAtID Int Point2 - | Fire - | Reload - | IncreaseAlert Int - | Guard Point2 Point2 - | Search Int - | SearchNear Point2 - | AimAt Point2 Int - | InitGuard - | Init - | MeleeAttack Int - | InitTrackYou - | TrackYou - | Track Int - | TrackFor Int Int - | TurnByFor Float Int - | TurnTo Point2 - | TurnToward Point2 - | TurnTowardAngle Float - | StrafeLeftAround Int Point2 - | StrafeRightAround Int Point2 - | StrafeLeftFor Int - | StrafeRightFor Int - | StrafeLeftForSpeed Int Float - | StrafeRightForSpeed Int Float - | StrafeLeftFire - | StrafeRightFire - | MoveForwardFor Int - | MoveForwardFire - | MoveBackwardFor Int - | MoveByFor Point2 Int - | MoveBackwardFire - | GoalID Int Goal - | AtRange Float - | AtRanges Float Float - | RepeatAction Int Goal - | MakeJudgement - | SetPosture Posture - deriving (Eq,Show) -data Stance = Stance - {_carriage :: Carriage - ,_posture :: Posture - } - deriving (Eq,Show) -data Carriage - = Walking { _stepCycle :: Int, _stepToAdd :: Int } - | Standing - | Floating - | Flying - | Boosting Point2 - deriving (Eq,Show) -data Posture = Aiming | AtEase - deriving (Eq,Show) -data Mind = ZombieMind | HumanMind - deriving (Eq,Show) + data Faction = GenericFaction Int | ZombieFaction @@ -104,6 +41,4 @@ data Faction makeLenses ''CreatureState makeLenses ''CrSpState -makeLenses ''Goal -makeLenses ''Carriage -makeLenses ''Posture +makeLenses ''Impulse diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index c5c8901c2..2f541c204 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -4,6 +4,8 @@ import Dodge.Data import Dodge.Base import Dodge.Creature.Action import Dodge.Creature.State +import Dodge.Creature.State.Data +import Dodge.Creature.Stance.Data import Dodge.Update.UsingInput import Dodge.Config.KeyConfig import Dodge.Item.Attachment.Data diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 20b1b106f..bde28e140 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -10,16 +10,14 @@ module Dodge.Data ( module Dodge.Data , module Dodge.Data.DamageType , module Dodge.Data.SoundOrigin - , module Dodge.Creature.Data - , module Dodge.Creature.State.Data , Point2 (..) , Sound (..) , soundTime - ) - where + ) where import Dodge.Picture.Layer.Data import Dodge.Creature.Data import Dodge.Creature.State.Data +import Dodge.Creature.Stance.Data import Dodge.Data.Menu import Dodge.Data.SoundOrigin import Dodge.Data.DamageType @@ -46,7 +44,6 @@ import SDL (Scancode, MouseButton) import qualified SDL.Mixer as Mix import Graphics.Rendering.OpenGL (PrimitiveMode (..),GLfloat,Program,VertexArrayObject,BufferObject) import Codec.Picture (Image,PixelRGBA8) - data World = World { _keys :: !(S.Set Scancode) , _mouseButtons :: !(S.Set MouseButton) @@ -103,14 +100,11 @@ data World = World , _sideEffects :: [PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)] , _doneSideEffects :: [PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)] } - data Corpse = Corpse { _cpPos :: Point2 , _cpPict :: Picture , _cpRes :: Creature } - - data Cloud = Cloud { _clID :: Int , _clPos :: Point2 @@ -120,7 +114,6 @@ data Cloud = Cloud , _clTimer :: Int , _clEffect :: Cloud -> World -> World } - data LightSource = LS { _lsID :: !Int , _lsPos :: !Point2 @@ -128,14 +121,12 @@ data LightSource = LS , _lsRad :: !Float , _lsIntensity :: !Float } - data TempLightSource = TLS { _tlsPos :: !Point2 , _tlsRad :: !Float , _tlsIntensity :: !Float , _tlsUpdate :: World -> TempLightSource -> (World, Maybe TempLightSource) } - data Creature = Creature { _crPos :: Point2 , _crOldPos :: Point2 @@ -158,12 +149,10 @@ data Creature = Creature , _crCorpse :: Picture , _crApplyDamage :: [DamageType] -> Creature -> (World -> World,Creature) } - data WorldState = DoorNumOpen Int | CrNumAlive Int deriving (Eq,Ord) - data Button = Button { _btPict :: Picture , _btPos :: Point2 @@ -173,10 +162,8 @@ data Button = Button , _btText :: String , _btState :: ButtonState } - data ButtonState = BtOn | BtOff | BtNoLabel deriving (Eq, Show) - data PressPlate = PressPlate { _ppPict :: Picture , _ppPos :: Point2 @@ -185,13 +172,10 @@ data PressPlate = PressPlate , _ppID :: Int , _ppText :: String } - data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, _flItID :: Int} - data ItemPos = InInv { _itCrId :: Int , _itInvId :: Int } | OnFloor { _itFlID :: Int } - data Item = Weapon { _itName :: String @@ -287,7 +271,6 @@ data Item , _itScrollDown :: Int -> World -> World } | NoItem - data ItEffect = NoItEffect | ItInvEffect {_itInvEffect :: Creature -> Int -> World -> World @@ -306,15 +289,12 @@ data ItZoom = ItZoom ,_itZoomMin :: Float ,_itZoomFac :: Float } - data IntID a = IntID Int a - data HammerPosition = HammerDown | HammerReleased | HammerUp | NoHammer - data ItemIdentity = Pistol | SpreadGun @@ -346,11 +326,8 @@ data ItemIdentity | LightningGun | PoisonSprayer deriving (Eq,Show,Ord,Enum) - -{- -Objects without ids. -Update themselves, perhaps with side effects. - -} +{- Objects without ids. +Update themselves, perhaps with side effects. -} data Particle = Particle { _ptDraw :: Particle -> Picture @@ -389,10 +366,8 @@ data Particle , _btMaxTime' :: Int , _btTimer' :: Int } - type HitEffect = Particle -> [(Point2, (Either3 Creature Wall ForceField))] -> World -> (World,Maybe Particle) - data Projectile = Projectile { _pjPos :: Point2 @@ -411,9 +386,7 @@ data Projectile , _pjUpdate :: World -> World , _pjPayload :: Point2-> World -> World } - data Either3 a b c = E3x1 a | E3x2 b | E3x3 c - data Wall = Wall { _wlLine :: (Point2,Point2) @@ -454,7 +427,6 @@ data Wall , _blDegrades :: [Int] , _blShadows :: [Int] } - data ForceField = FF { _ffLine :: [Point2] , _ffID :: Int , _ffColor :: Color @@ -468,7 +440,6 @@ makeLenses ''Cloud makeLenses ''Creature makeLenses ''LightSource makeLenses ''TempLightSource -makeLenses ''Stance makeLenses ''Item makeLenses ''ItemPos makeLenses ''ItEffect diff --git a/src/Dodge/Data.hs.orig b/src/Dodge/Data.hs.orig index 49031a2b6..c34ac6e66 100644 --- a/src/Dodge/Data.hs.orig +++ b/src/Dodge/Data.hs.orig @@ -144,7 +144,7 @@ data Creature = Creature } data CreatureState = CrSt - { _goals :: [[Goal]] + { _goals :: [[Impulse]] , _stance :: Stance , _faction :: Faction , _crDamage :: [DamageType] @@ -157,7 +157,7 @@ data CrSpState = Barrel { _piercedPoints :: [Point2]} | GenCr deriving (Eq,Show,Ord) -data Goal +data Impulse = MoveTo Point2 | MoveToFor Point2 Int | MoveFire Point2 Point2 @@ -200,10 +200,10 @@ data Goal | MoveBackwardFor Int | MoveByFor Point2 Int | MoveBackwardFire - | GoalID Int Goal + | ImpulseID Int Impulse | AtRange Float | AtRanges Float Float - | RepeatAction Int Goal + | RepeatAction Int Impulse | MakeJudgement | SetPosture Posture deriving (Eq,Show) @@ -652,7 +652,7 @@ makeLenses ''Cloud makeLenses ''Creature makeLenses ''CreatureState makeLenses ''CrSpState -makeLenses ''Goal +makeLenses ''Impulse makeLenses ''LightSource makeLenses ''TempLightSource makeLenses ''Stance diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 5084079d4..35cfc5d00 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -8,6 +8,8 @@ This module contains prototypical data structures. module Dodge.Default where import Dodge.Item.Weapon.ExtraEffect import Dodge.Data +import Dodge.Creature.Stance.Data +import Dodge.Creature.State.Data import Dodge.Data.Menu import Dodge.SoundLogic import Dodge.Base diff --git a/src/Dodge/Floor.hs b/src/Dodge/Floor.hs index da81e15a7..61db73c2d 100644 --- a/src/Dodge/Floor.hs +++ b/src/Dodge/Floor.hs @@ -7,6 +7,7 @@ import Geometry import Picture import Dodge.Data import Dodge.Room +import Dodge.Creature.State.Data import Dodge.Room.Procedural import Dodge.Room.RoadBlock import Dodge.Room.Data diff --git a/src/Dodge/Item/Weapon/Bullet.hs b/src/Dodge/Item/Weapon/Bullet.hs index c391189ea..285614321 100644 --- a/src/Dodge/Item/Weapon/Bullet.hs +++ b/src/Dodge/Item/Weapon/Bullet.hs @@ -9,6 +9,7 @@ import Dodge.WorldEvent import Dodge.SoundLogic import Dodge.RandomHelp import Dodge.WorldEvent.Shockwave +import Dodge.Creature.State.Data import Dodge.Creature.Property import Geometry import Picture diff --git a/src/Dodge/Item/Weapon/Laser.hs b/src/Dodge/Item/Weapon/Laser.hs index 7daea7d53..2af54a7fb 100644 --- a/src/Dodge/Item/Weapon/Laser.hs +++ b/src/Dodge/Item/Weapon/Laser.hs @@ -11,6 +11,7 @@ import Dodge.WorldEvent.SpawnParticle import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.HelperParticle import Dodge.WorldEvent.Flash +import Dodge.Creature.State.Data import Geometry import Picture diff --git a/src/Dodge/LevelGen/AutoDoor.hs b/src/Dodge/LevelGen/AutoDoor.hs index cfcfdd64b..5faa56448 100644 --- a/src/Dodge/LevelGen/AutoDoor.hs +++ b/src/Dodge/LevelGen/AutoDoor.hs @@ -5,6 +5,7 @@ Creation of doors that open when creatures approach them. module Dodge.LevelGen.AutoDoor where import Dodge.Data +import Dodge.Creature.State.Data import Dodge.Base import Dodge.SoundLogic import Dodge.Creature.Property diff --git a/src/Dodge/Path.hs b/src/Dodge/Path.hs index a8b718f92..6fdce52cd 100644 --- a/src/Dodge/Path.hs +++ b/src/Dodge/Path.hs @@ -147,14 +147,14 @@ makePathBetweenPs' a b w = fmap (mapMaybe (lab g)) $ makePathBetween' a b w where g = _pathGraph w -pointTowardsGoal :: Point2 -> Point2 -> World -> Maybe Point2 -pointTowardsGoal a b w = join $ fmap (listToMaybe . filter (flip (isWalkable a) w)) +pointTowardsImpulse :: Point2 -> Point2 -> World -> Maybe Point2 +pointTowardsImpulse a b w = join $ fmap (listToMaybe . filter (flip (isWalkable a) w)) -- $ pathBetween a b w $ makePathBetweenPs a b w -- -pointTowardsGoal' :: Point2 -> Point2 -> World -> Either String Point2 -pointTowardsGoal' a b w = join $ fmap (maybeToEither "NOSEEPATH" . listToMaybe . filter (flip (isWalkable a) w)) +pointTowardsImpulse' :: Point2 -> Point2 -> World -> Either String Point2 +pointTowardsImpulse' a b w = join $ fmap (maybeToEither "NOSEEPATH" . listToMaybe . filter (flip (isWalkable a) w)) $ makePathBetweenPs' b a w maybeToEither :: a -> Maybe b -> Either a b diff --git a/src/Dodge/Room/Boss.hs b/src/Dodge/Room/Boss.hs index a5f4340c1..2dbcb4f0e 100644 --- a/src/Dodge/Room/Boss.hs +++ b/src/Dodge/Room/Boss.hs @@ -11,6 +11,7 @@ import Dodge.Room.Link import Dodge.Room.Corridor import Dodge.LevelGen.Data import Dodge.Creature +import Dodge.Creature.State.Data import Dodge.RandomHelp import Dodge.Layout.Tree.Polymorphic import Geometry diff --git a/src/Dodge/Room/NoNeedWeapon.hs b/src/Dodge/Room/NoNeedWeapon.hs index a2a2a47c4..fcdbc4e70 100644 --- a/src/Dodge/Room/NoNeedWeapon.hs +++ b/src/Dodge/Room/NoNeedWeapon.hs @@ -4,6 +4,7 @@ module Dodge.Room.NoNeedWeapon ) where import Dodge.Data import Dodge.Creature +import Dodge.Creature.State.Data import Dodge.Creature.Inanimate import Dodge.Room.Data import Dodge.Room.Procedural diff --git a/src/Dodge/WallCreatureCollisions.hs b/src/Dodge/WallCreatureCollisions.hs index 416937df2..356b26183 100644 --- a/src/Dodge/WallCreatureCollisions.hs +++ b/src/Dodge/WallCreatureCollisions.hs @@ -1,6 +1,7 @@ module Dodge.WallCreatureCollisions where -- imports {{{ import Dodge.Data +import Dodge.Creature.State.Data import Dodge.Base import Geometry diff --git a/src/Dodge/WorldEvent.hs b/src/Dodge/WorldEvent.hs index c73d37c92..fed86be63 100644 --- a/src/Dodge/WorldEvent.hs +++ b/src/Dodge/WorldEvent.hs @@ -21,7 +21,7 @@ import Dodge.WorldEvent.Explosion import Dodge.WorldEvent.SpawnParticle import Dodge.WorldEvent.Shockwave import Dodge.LightSources - +import Dodge.Creature.State.Data import Dodge.Data import Dodge.Base import Dodge.SoundLogic diff --git a/src/Dodge/WorldEvent/HitEffect.hs b/src/Dodge/WorldEvent/HitEffect.hs index 1e1536221..4183fa2c4 100644 --- a/src/Dodge/WorldEvent/HitEffect.hs +++ b/src/Dodge/WorldEvent/HitEffect.hs @@ -1,6 +1,7 @@ module Dodge.WorldEvent.HitEffect where import Dodge.Data +import Dodge.Creature.State.Data import Geometry diff --git a/src/Dodge/WorldEvent/Shockwave.hs b/src/Dodge/WorldEvent/Shockwave.hs index ba59a7d98..b0779a694 100644 --- a/src/Dodge/WorldEvent/Shockwave.hs +++ b/src/Dodge/WorldEvent/Shockwave.hs @@ -4,6 +4,7 @@ module Dodge.WorldEvent.Shockwave ) where import Dodge.Data +import Dodge.Creature.State.Data import Dodge.Base import Dodge.Picture.Layer import Geometry diff --git a/src/Dodge/WorldEvent/SpawnParticle.hs b/src/Dodge/WorldEvent/SpawnParticle.hs index ac83b58e7..1f0907130 100644 --- a/src/Dodge/WorldEvent/SpawnParticle.hs +++ b/src/Dodge/WorldEvent/SpawnParticle.hs @@ -4,6 +4,7 @@ Creation of particles in the world. module Dodge.WorldEvent.SpawnParticle where import Dodge.Data +import Dodge.Creature.State.Data import Dodge.Base import Dodge.Picture import Dodge.Picture.Layer