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-09-28T19·02-0400
committerGriffin Smith <root@gws.fyi>2019-09-28T19·03-0400
commitec39dc0a5bed58e0b0b48eeac98e0fd0ceaa65db (patch)
tree65a53bd79b15020572524db0a6e65ec549b5ab24 /src/Xanthous/AI/Gormlak.hs
parentabea2dcfac0e094bf4ce0d378763af7816b04501 (diff)
Tweak gormlak movement slightly
- Don't let gormlaks run into things like walls or each other
- Add a small element of randomness to gormlaks' motion
- Increase gormlaks' vision by a large amount
Diffstat (limited to 'src/Xanthous/AI/Gormlak.hs')
-rw-r--r--src/Xanthous/AI/Gormlak.hs34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/Xanthous/AI/Gormlak.hs b/src/Xanthous/AI/Gormlak.hs
index 1cdb977619f3..6ea9254ba200 100644
--- a/src/Xanthous/AI/Gormlak.hs
+++ b/src/Xanthous/AI/Gormlak.hs
@@ -6,25 +6,43 @@ import           Xanthous.Prelude hiding (lines)
 --------------------------------------------------------------------------------
 import           Data.Coerce
 import           Control.Monad.State
+import           Control.Monad.Random
 --------------------------------------------------------------------------------
-import           Xanthous.Data (Positioned(..))
+import           Xanthous.Data (Positioned(..), positioned)
+import           Xanthous.Data.EntityMap
 import qualified Xanthous.Entities.Creature as Creature
 import           Xanthous.Entities.Creature (Creature)
+import           Xanthous.Entities.Character (Character)
 import qualified Xanthous.Entities.RawTypes as Raw
 import           Xanthous.Entities (Entity(..), Brain(..), brainVia)
-import           Xanthous.Game.State (entities, GameState)
+import           Xanthous.Game.State (entities, GameState, entityIs)
+import           Xanthous.Game.Lenses (Collision(..), collisionAt)
 import           Xanthous.Data.EntityMap.Graphics (linesOfSight)
+import           Xanthous.Random
 --------------------------------------------------------------------------------
 
-stepGormlak :: MonadState GameState m => Positioned Creature -> m (Positioned Creature)
-stepGormlak (Positioned pos creature) = do
+stepGormlak
+  :: (MonadState GameState m, MonadRandom m)
+  => Positioned Creature
+  -> m (Positioned Creature)
+stepGormlak pe@(Positioned pos creature) = do
   lines <- uses entities $ linesOfSight pos (Creature.visionRadius creature)
+  line <- choose $ weightedBy length lines
+  -- traceShowM ("current position", pos)
+  -- traceShowM ("lines", (headMay <=< tailMay) <$> lines)
   let newPos = fromMaybe pos
                $ fmap fst
-               . headMay <=< tailMay <=< headMay
-               . sortOn (Down . length)
-               $ lines
-  pure $ Positioned newPos creature
+               . headMay
+               =<< tailMay
+               =<< line
+  collisionAt newPos >>= \case
+    Nothing -> pure $ Positioned newPos creature
+    Just Stop -> pure pe
+    Just Combat -> do
+      ents <- use $ entities . atPosition newPos
+      if | any (entityIs @Creature) ents -> pure pe
+         | any (entityIs @Character) ents -> undefined
+         | otherwise -> pure pe
 
 newtype GormlakBrain = GormlakBrain Creature