module Game.LambdaHack.Tile
(SecretTime, SmellTime
, kindHasFeature, kindHas, hasFeature
, isClear, isLit, isExplorable, similar, canBeHidden, speedup
) where
import qualified Data.List as L
import qualified Data.Array.Unboxed as A
import Game.LambdaHack.Content.TileKind
import qualified Game.LambdaHack.Feature as F
import qualified Game.LambdaHack.Kind as Kind
import Game.LambdaHack.Time
type SecretTime = Time
type SmellTime = Time
kindHasFeature :: F.Feature -> TileKind -> Bool
kindHasFeature f t = f `elem` tfeature t
kindHas :: [F.Feature] -> [F.Feature] -> TileKind -> Bool
kindHas yes no t = L.all (`kindHasFeature` t) yes
&& not (L.any (`kindHasFeature` t) no)
hasFeature :: Kind.Ops TileKind -> F.Feature -> Kind.Id TileKind -> Bool
hasFeature Kind.Ops{okind} f t =
kindHasFeature f (okind t)
isClear :: Kind.Ops TileKind -> Kind.Id TileKind -> Bool
isClear Kind.Ops{ospeedup = Kind.TileSpeedup{isClearTab}} = isClearTab
isLit :: Kind.Ops TileKind -> Kind.Id TileKind -> Bool
isLit Kind.Ops{ospeedup = Kind.TileSpeedup{isLitTab}} = isLitTab
isExplorable :: Kind.Ops TileKind -> Kind.Id TileKind -> Bool
isExplorable cops tk =
not (hasFeature cops F.Closable tk)
&& (isClear cops tk
|| hasFeature cops F.Walkable tk)
similar :: TileKind -> TileKind -> Bool
similar t u =
tsymbol t == tsymbol u &&
tname t == tname u &&
tcolor t == tcolor u &&
tcolor2 t == tcolor2 u
canBeHidden :: Kind.Ops TileKind -> TileKind -> Bool
canBeHidden Kind.Ops{ofoldrWithKey} t =
let sim _ s acc = acc || kindHasFeature F.Hidden s && similar t s
in ofoldrWithKey sim False
speedup :: Kind.Ops TileKind -> Kind.Speedup TileKind
speedup Kind.Ops{ofoldrWithKey, obounds} =
let createTab :: (TileKind -> Bool) -> A.UArray (Kind.Id TileKind) Bool
createTab p =
let f _ k acc = p k : acc
clearAssocs = ofoldrWithKey f []
in A.listArray obounds clearAssocs
tabulate :: (TileKind -> Bool) -> Kind.Id TileKind -> Bool
tabulate p = (createTab p A.!)
isClearTab = tabulate $ kindHasFeature F.Clear
isLitTab = tabulate $ kindHasFeature F.Lit
in Kind.TileSpeedup {isClearTab, isLitTab}