diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-28T17·20-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-28T19·03-0400 |
commit | 1a0f618a829ec356e29176c77ea90a8a5a0157b4 (patch) | |
tree | 90d255974b482f6d59dd26a503d28e7adb090188 /src/Xanthous/AI/Gormlak.hs | |
parent | 915264acae35e71f79c6193d022baa2455d880d3 (diff) |
Implement the start of creature AI
Add a Brain class, which determines for an entity the set of moves it makes every step of the game, and begin to implement that for gormlaks. The idea here is that every step of the game, a gormlak will move towards the furthest-away wall it can see.
Diffstat (limited to 'src/Xanthous/AI/Gormlak.hs')
-rw-r--r-- | src/Xanthous/AI/Gormlak.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Xanthous/AI/Gormlak.hs b/src/Xanthous/AI/Gormlak.hs new file mode 100644 index 000000000000..1cdb977619f3 --- /dev/null +++ b/src/Xanthous/AI/Gormlak.hs @@ -0,0 +1,39 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} +-------------------------------------------------------------------------------- +module Xanthous.AI.Gormlak () where +-------------------------------------------------------------------------------- +import Xanthous.Prelude hiding (lines) +-------------------------------------------------------------------------------- +import Data.Coerce +import Control.Monad.State +-------------------------------------------------------------------------------- +import Xanthous.Data (Positioned(..)) +import qualified Xanthous.Entities.Creature as Creature +import Xanthous.Entities.Creature (Creature) +import qualified Xanthous.Entities.RawTypes as Raw +import Xanthous.Entities (Entity(..), Brain(..), brainVia) +import Xanthous.Game.State (entities, GameState) +import Xanthous.Data.EntityMap.Graphics (linesOfSight) +-------------------------------------------------------------------------------- + +stepGormlak :: MonadState GameState m => Positioned Creature -> m (Positioned Creature) +stepGormlak (Positioned pos creature) = do + lines <- uses entities $ linesOfSight pos (Creature.visionRadius creature) + let newPos = fromMaybe pos + $ fmap fst + . headMay <=< tailMay <=< headMay + . sortOn (Down . length) + $ lines + pure $ Positioned newPos creature + +newtype GormlakBrain = GormlakBrain Creature + +instance Brain GormlakBrain where + step = fmap coerce . stepGormlak . coerce +-------------------------------------------------------------------------------- + +instance Brain Creature where step = brainVia GormlakBrain + +instance Entity Creature where + blocksVision _ = False + description = view $ Creature.creatureType . Raw.description |