about summary refs log tree commit diff
path: root/src/Xanthous/AI/Gormlak.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-10-16T02·54-0400
committerGriffin Smith <root@gws.fyi>2019-10-16T02·54-0400
commit4882350f5d7e54a6ae5c8760f2510273dae19c60 (patch)
treeb8b61ec39abf51d2599be2dead82504f67f6fbe0 /src/Xanthous/AI/Gormlak.hs
parent8a4220df830adb6f1616ca02dd06902474fd25df (diff)
Don't walk gormlaks into walls
Because of the way lines are drawn, a specific configuration of
positioning for gormlaks would have them decide they desperately wanted
to walk *inside* a wall, which they would then both fail to do but also
always collide with whenever they tried to go anywhere else.
Diffstat (limited to 'src/Xanthous/AI/Gormlak.hs')
-rw-r--r--src/Xanthous/AI/Gormlak.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Xanthous/AI/Gormlak.hs b/src/Xanthous/AI/Gormlak.hs
index e13eb8ffe71a..268e33ad6caa 100644
--- a/src/Xanthous/AI/Gormlak.hs
+++ b/src/Xanthous/AI/Gormlak.hs
@@ -27,7 +27,9 @@ import qualified Xanthous.Entities.RawTypes as Raw
 import           Xanthous.Entities (Entity(..), Brain(..), brainVia)
 import           Xanthous.Game.State (entities, GameState, entityIs)
 import           Xanthous.Game.Lenses
-                 ( Collision(..), collisionAt, character, characterPosition )
+                 ( Collision(..), entityCollision, collisionAt
+                 , character, characterPosition
+                 )
 import           Xanthous.Data.EntityMap.Graphics (linesOfSight, canSee)
 import           Xanthous.Random
 import           Xanthous.Monad (say)
@@ -72,9 +74,13 @@ stepGormlak ticks pe@(Positioned pos creature) = do
             then attackCharacter $> pos'
             else pure $ pos' `stepTowards` charPos
       else do
-        lines <- uses entities $ linesOfSight pos' (Creature.visionRadius creature')
+        lines <- map (takeWhile (isNothing . entityCollision . map snd . snd)
+                    -- the first item on these lines is always the creature itself
+                    . fromMaybe mempty . tailMay)
+                . linesOfSight pos' (Creature.visionRadius creature')
+                <$> use entities
         line <- choose $ weightedBy length lines
-        pure $ fromMaybe pos' $ fmap fst . headMay =<< tailMay =<< line
+        pure $ fromMaybe pos' $ fmap fst . headMay =<< line
 
     vision = Creature.visionRadius creature
     attackCharacter = do