module Dodge.Creature.Impulse.Flee
    where
import Dodge.Data
import Geometry
import FoldableHelp

retreatPointForFrom
    :: Float -> World -> Creature -> Point2 -> Maybe Point2
retreatPointForFrom d _ cr p 
    = safeMinimumOn (dist cpos) 
    $ divideCircle 10 p d
  where
    cpos = _crPos cr
--    = head $ sortBy (compare `on` (\p -> dist p ypos < 300)) $ retreatP'' : retreatPs
--  where
--    retreatPs = sortBy (compare `on` dist cpos) $ map f $ nRaysRad 8 400
--        where f p = fromMaybe (ypos +.+ p) $ fmap fst
--                        $ reflectPointWalls ypos (ypos +.+ p) (wallsAlongLine ypos (ypos +.+ p) w)
--    retreatP' = cpos +.+ 300 *.* (cpos -.- ypos)
--    retreatP'' = fromMaybe retreatP' $ fmap fst
--                                     $ reflectPointWalls ypos retreatP' 
--                                     $ wallsAlongLine ypos retreatP' w
