{-# LANGUAGE DeriveGeneric, TupleSections #-}
module Game.LambdaHack.Common.Actor
(
Actor(..), ResDelta(..), ActorMaxSkills, Watchfulness(..)
, deltasSerious, deltasSeriousThisTurn
, deltasHears, deltaBenign, deltaWasBenign
, actorCanMelee, actorCanMeleeToHarm, actorWorthChasing, actorWorthKilling
, gearSpeed, actorTemplate, actorWaits, actorWaitsOrSleeps, actorDying
, hpTooLow, calmEnough, calmFull, hpFull, canSleep, prefersSleep
, checkAdjacent, eqpOverfull, eqpFreeN
, getCarriedIidsAndTrunk, getCarriedIidCStore
, ActorDict, monsterGenChance, smellTimeout
) where
import Prelude ()
import Game.LambdaHack.Core.Prelude
import Data.Binary
import qualified Data.EnumMap.Strict as EM
import Data.Int (Int64)
import Data.Ratio
import GHC.Generics (Generic)
import Game.LambdaHack.Common.Item
import Game.LambdaHack.Common.Misc
import Game.LambdaHack.Common.Point
import Game.LambdaHack.Common.Time
import Game.LambdaHack.Common.Types
import Game.LambdaHack.Common.Vector
import qualified Game.LambdaHack.Core.Dice as Dice
import Game.LambdaHack.Core.Random
import qualified Game.LambdaHack.Definition.Ability as Ability
import Game.LambdaHack.Definition.Defs
data Actor = Actor
{
Actor -> ItemId
btrunk :: ItemId
, Actor -> Maybe Int
bnumber :: Maybe Int
, Actor -> Int64
bhp :: Int64
, Actor -> ResDelta
bhpDelta :: ResDelta
, Actor -> Int64
bcalm :: Int64
, Actor -> ResDelta
bcalmDelta :: ResDelta
, Actor -> Point
bpos :: Point
, Actor -> Maybe Point
boldpos :: Maybe Point
, Actor -> LevelId
blid :: LevelId
, Actor -> FactionId
bfid :: FactionId
, Actor -> Maybe ([Vector], Speed)
btrajectory :: Maybe ([Vector], Speed)
, Actor -> ItemBag
borgan :: ItemBag
, Actor -> ItemBag
beqp :: ItemBag
, Actor -> Int
bweapon :: Int
, Actor -> Int
bweapBenign :: Int
, Actor -> Watchfulness
bwatch :: Watchfulness
, Actor -> Bool
bproj :: Bool
}
deriving (Int -> Actor -> ShowS
[Actor] -> ShowS
Actor -> String
(Int -> Actor -> ShowS)
-> (Actor -> String) -> ([Actor] -> ShowS) -> Show Actor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Actor] -> ShowS
$cshowList :: [Actor] -> ShowS
show :: Actor -> String
$cshow :: Actor -> String
showsPrec :: Int -> Actor -> ShowS
$cshowsPrec :: Int -> Actor -> ShowS
Show, Actor -> Actor -> Bool
(Actor -> Actor -> Bool) -> (Actor -> Actor -> Bool) -> Eq Actor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Actor -> Actor -> Bool
$c/= :: Actor -> Actor -> Bool
== :: Actor -> Actor -> Bool
$c== :: Actor -> Actor -> Bool
Eq, (forall x. Actor -> Rep Actor x)
-> (forall x. Rep Actor x -> Actor) -> Generic Actor
forall x. Rep Actor x -> Actor
forall x. Actor -> Rep Actor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Actor x -> Actor
$cfrom :: forall x. Actor -> Rep Actor x
Generic)
instance Binary Actor
data ResDelta = ResDelta
{ ResDelta -> (Int64, Int64)
resCurrentTurn :: (Int64, Int64)
, ResDelta -> (Int64, Int64)
resPreviousTurn :: (Int64, Int64)
}
deriving (Int -> ResDelta -> ShowS
[ResDelta] -> ShowS
ResDelta -> String
(Int -> ResDelta -> ShowS)
-> (ResDelta -> String) -> ([ResDelta] -> ShowS) -> Show ResDelta
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResDelta] -> ShowS
$cshowList :: [ResDelta] -> ShowS
show :: ResDelta -> String
$cshow :: ResDelta -> String
showsPrec :: Int -> ResDelta -> ShowS
$cshowsPrec :: Int -> ResDelta -> ShowS
Show, ResDelta -> ResDelta -> Bool
(ResDelta -> ResDelta -> Bool)
-> (ResDelta -> ResDelta -> Bool) -> Eq ResDelta
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResDelta -> ResDelta -> Bool
$c/= :: ResDelta -> ResDelta -> Bool
== :: ResDelta -> ResDelta -> Bool
$c== :: ResDelta -> ResDelta -> Bool
Eq, (forall x. ResDelta -> Rep ResDelta x)
-> (forall x. Rep ResDelta x -> ResDelta) -> Generic ResDelta
forall x. Rep ResDelta x -> ResDelta
forall x. ResDelta -> Rep ResDelta x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResDelta x -> ResDelta
$cfrom :: forall x. ResDelta -> Rep ResDelta x
Generic)
instance Binary ResDelta
type ActorMaxSkills = EM.EnumMap ActorId Ability.Skills
type ActorDict = EM.EnumMap ActorId Actor
data Watchfulness = WWatch | WWait Int | WSleep | WWake
deriving (Int -> Watchfulness -> ShowS
[Watchfulness] -> ShowS
Watchfulness -> String
(Int -> Watchfulness -> ShowS)
-> (Watchfulness -> String)
-> ([Watchfulness] -> ShowS)
-> Show Watchfulness
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Watchfulness] -> ShowS
$cshowList :: [Watchfulness] -> ShowS
show :: Watchfulness -> String
$cshow :: Watchfulness -> String
showsPrec :: Int -> Watchfulness -> ShowS
$cshowsPrec :: Int -> Watchfulness -> ShowS
Show, Watchfulness -> Watchfulness -> Bool
(Watchfulness -> Watchfulness -> Bool)
-> (Watchfulness -> Watchfulness -> Bool) -> Eq Watchfulness
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Watchfulness -> Watchfulness -> Bool
$c/= :: Watchfulness -> Watchfulness -> Bool
== :: Watchfulness -> Watchfulness -> Bool
$c== :: Watchfulness -> Watchfulness -> Bool
Eq, (forall x. Watchfulness -> Rep Watchfulness x)
-> (forall x. Rep Watchfulness x -> Watchfulness)
-> Generic Watchfulness
forall x. Rep Watchfulness x -> Watchfulness
forall x. Watchfulness -> Rep Watchfulness x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Watchfulness x -> Watchfulness
$cfrom :: forall x. Watchfulness -> Rep Watchfulness x
Generic)
instance Binary Watchfulness
deltasSerious :: ResDelta -> Bool
deltasSerious :: ResDelta -> Bool
deltasSerious ResDelta{..} = (Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resCurrentTurn Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
minusM2
Bool -> Bool -> Bool
|| (Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resPreviousTurn Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
minusM2
deltasSeriousThisTurn :: ResDelta -> Bool
deltasSeriousThisTurn :: ResDelta -> Bool
deltasSeriousThisTurn ResDelta{..} = (Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resCurrentTurn Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
minusM2
deltasHears :: ResDelta -> Bool
deltasHears :: ResDelta -> Bool
deltasHears ResDelta{..} = (Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resCurrentTurn Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
minusM1
Bool -> Bool -> Bool
|| (Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resPreviousTurn Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
minusM1
deltaBenign :: ResDelta -> Bool
deltaBenign :: ResDelta -> Bool
deltaBenign ResDelta{(Int64, Int64)
resCurrentTurn :: (Int64, Int64)
resCurrentTurn :: ResDelta -> (Int64, Int64)
resCurrentTurn} =
(Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resCurrentTurn Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0
deltaWasBenign :: ResDelta -> Bool
deltaWasBenign :: ResDelta -> Bool
deltaWasBenign ResDelta{(Int64, Int64)
resPreviousTurn :: (Int64, Int64)
resPreviousTurn :: ResDelta -> (Int64, Int64)
resPreviousTurn} =
(Int64, Int64) -> Int64
forall a b. (a, b) -> a
fst (Int64, Int64)
resPreviousTurn Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0
actorCanMelee :: ActorMaxSkills -> ActorId -> Actor -> Bool
{-# INLINE actorCanMelee #-}
actorCanMelee :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorCanMelee actorMaxSkills :: ActorMaxSkills
actorMaxSkills aid :: ActorId
aid b :: Actor
b =
let actorMaxSk :: Skills
actorMaxSk = ActorMaxSkills
actorMaxSkills ActorMaxSkills -> ActorId -> Skills
forall k a. Enum k => EnumMap k a -> k -> a
EM.! ActorId
aid
condUsableWeapon :: Bool
condUsableWeapon = Actor -> Int
bweapon Actor
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
canMelee :: Bool
canMelee = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMelee Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
in Bool
condUsableWeapon Bool -> Bool -> Bool
&& Bool
canMelee
actorCanMeleeToHarm :: ActorMaxSkills -> ActorId -> Actor -> Bool
{-# INLINE actorCanMeleeToHarm #-}
actorCanMeleeToHarm :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorCanMeleeToHarm actorMaxSkills :: ActorMaxSkills
actorMaxSkills aid :: ActorId
aid b :: Actor
b =
let actorMaxSk :: Skills
actorMaxSk = ActorMaxSkills
actorMaxSkills ActorMaxSkills -> ActorId -> Skills
forall k a. Enum k => EnumMap k a -> k -> a
EM.! ActorId
aid
condUsableWeapon :: Bool
condUsableWeapon = Actor -> Int
bweapon Actor
b Int -> Int -> Int
forall a. Num a => a -> a -> a
- Actor -> Int
bweapBenign Actor
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
canMelee :: Bool
canMelee = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMelee Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
in Bool
condUsableWeapon Bool -> Bool -> Bool
&& Bool
canMelee
actorWorthChasing :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthChasing :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthChasing actorMaxSkills :: ActorMaxSkills
actorMaxSkills aid :: ActorId
aid b :: Actor
b =
let hasLoot :: Bool
hasLoot = Bool -> Bool
not (ItemBag -> Bool
forall k a. EnumMap k a -> Bool
EM.null (ItemBag -> Bool) -> ItemBag -> Bool
forall a b. (a -> b) -> a -> b
$ Actor -> ItemBag
beqp Actor
b)
actorMaxSk :: Skills
actorMaxSk = ActorMaxSkills
actorMaxSkills ActorMaxSkills -> ActorId -> Skills
forall k a. Enum k => EnumMap k a -> k -> a
EM.! ActorId
aid
in Actor -> Bool
bproj Actor
b
Bool -> Bool -> Bool
|| (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMove Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
Bool -> Bool -> Bool
|| Actor -> Watchfulness
bwatch Actor
b Watchfulness -> Watchfulness -> Bool
forall a. Eq a => a -> a -> Bool
== Watchfulness
WWake
Bool -> Bool -> Bool
|| Bool
hasLoot
Bool -> Bool -> Bool
|| Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkProject Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
Bool -> Bool -> Bool
|| Actor -> Watchfulness
bwatch Actor
b Watchfulness -> Watchfulness -> Bool
forall a. Eq a => a -> a -> Bool
== Watchfulness
WSleep
Bool -> Bool -> Bool
&& Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxHP Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 30)
Bool -> Bool -> Bool
&& Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 0
actorWorthKilling :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthKilling :: ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthKilling actorMaxSkills :: ActorMaxSkills
actorMaxSkills aid :: ActorId
aid b :: Actor
b =
ActorMaxSkills -> ActorId -> Actor -> Bool
actorWorthChasing ActorMaxSkills
actorMaxSkills ActorId
aid Actor
b
Bool -> Bool -> Bool
|| ActorMaxSkills -> ActorId -> Actor -> Bool
actorCanMeleeToHarm ActorMaxSkills
actorMaxSkills ActorId
aid Actor
b Bool -> Bool -> Bool
&& Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 0
gearSpeed :: Ability.Skills -> Speed
gearSpeed :: Skills -> Speed
gearSpeed actorMaxSk :: Skills
actorMaxSk = Int -> Speed
toSpeed (Int -> Speed) -> Int -> Speed
forall a b. (a -> b) -> a -> b
$
Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
minSpeed (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSpeed Skills
actorMaxSk)
actorTemplate :: ItemId -> Maybe Int -> Int64 -> Int64 -> Point -> LevelId
-> FactionId -> Bool
-> Actor
actorTemplate :: ItemId
-> Maybe Int
-> Int64
-> Int64
-> Point
-> LevelId
-> FactionId
-> Bool
-> Actor
actorTemplate btrunk :: ItemId
btrunk bnumber :: Maybe Int
bnumber bhp :: Int64
bhp bcalm :: Int64
bcalm bpos :: Point
bpos blid :: LevelId
blid bfid :: FactionId
bfid bproj :: Bool
bproj =
let btrajectory :: Maybe a
btrajectory = Maybe a
forall a. Maybe a
Nothing
boldpos :: Maybe a
boldpos = Maybe a
forall a. Maybe a
Nothing
borgan :: EnumMap k a
borgan = EnumMap k a
forall k a. EnumMap k a
EM.empty
beqp :: EnumMap k a
beqp = EnumMap k a
forall k a. EnumMap k a
EM.empty
bweapon :: Int
bweapon = 0
bweapBenign :: Int
bweapBenign = 0
bwatch :: Watchfulness
bwatch = Watchfulness
WWatch
bhpDelta :: ResDelta
bhpDelta = (Int64, Int64) -> (Int64, Int64) -> ResDelta
ResDelta (0, 0) (0, 0)
bcalmDelta :: ResDelta
bcalmDelta = (Int64, Int64) -> (Int64, Int64) -> ResDelta
ResDelta (0, 0) (0, 0)
in $WActor :: ItemId
-> Maybe Int
-> Int64
-> ResDelta
-> Int64
-> ResDelta
-> Point
-> Maybe Point
-> LevelId
-> FactionId
-> Maybe ([Vector], Speed)
-> ItemBag
-> ItemBag
-> Int
-> Int
-> Watchfulness
-> Bool
-> Actor
Actor{..}
actorWaits :: Actor -> Bool
{-# INLINE actorWaits #-}
actorWaits :: Actor -> Bool
actorWaits b :: Actor
b = case Actor -> Watchfulness
bwatch Actor
b of
WWait{} -> Bool
True
_ -> Bool
False
actorWaitsOrSleeps :: Actor -> Bool
{-# INLINE actorWaitsOrSleeps #-}
actorWaitsOrSleeps :: Actor -> Bool
actorWaitsOrSleeps b :: Actor
b = case Actor -> Watchfulness
bwatch Actor
b of
WWait{} -> Bool
True
WSleep -> Bool
True
_ -> Bool
False
actorDying :: Actor -> Bool
actorDying :: Actor -> Bool
actorDying b :: Actor
b = Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0
Bool -> Bool -> Bool
|| Actor -> Bool
bproj Actor
b Bool -> Bool -> Bool
&& (Bool
-> (([Vector], Speed) -> Bool) -> Maybe ([Vector], Speed) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True ([Vector] -> Bool
forall a. [a] -> Bool
null ([Vector] -> Bool)
-> (([Vector], Speed) -> [Vector]) -> ([Vector], Speed) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Vector], Speed) -> [Vector]
forall a b. (a, b) -> a
fst) (Actor -> Maybe ([Vector], Speed)
btrajectory Actor
b)
Bool -> Bool -> Bool
|| ItemBag -> Bool
forall k a. EnumMap k a -> Bool
EM.null (Actor -> ItemBag
beqp Actor
b))
hpTooLow :: Actor -> Ability.Skills -> Bool
hpTooLow :: Actor -> Skills -> Bool
hpTooLow b :: Actor
b actorMaxSk :: Skills
actorMaxSk =
5 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
* Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< Int -> Int64
xM (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxHP Skills
actorMaxSk) Bool -> Bool -> Bool
&& Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Int64
xM 40
Bool -> Bool -> Bool
|| Actor -> Int64
bhp Actor
b Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
oneM
calmEnough :: Actor -> Ability.Skills -> Bool
calmEnough :: Actor -> Skills -> Bool
calmEnough b :: Actor
b actorMaxSk :: Skills
actorMaxSk =
let calmMax :: Int
calmMax = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxCalm Skills
actorMaxSk
in 2 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
* Int -> Int64
xM Int
calmMax Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 3 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
* Actor -> Int64
bcalm Actor
b
calmFull :: Actor -> Ability.Skills -> Bool
calmFull :: Actor -> Skills -> Bool
calmFull b :: Actor
b actorMaxSk :: Skills
actorMaxSk =
let calmMax :: Int
calmMax = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxCalm Skills
actorMaxSk
in Int -> Int64
xM Int
calmMax Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Actor -> Int64
bcalm Actor
b
hpFull :: Actor -> Ability.Skills -> Bool
hpFull :: Actor -> Skills -> Bool
hpFull b :: Actor
b actorMaxSk :: Skills
actorMaxSk = Int -> Int64
xM (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxHP Skills
actorMaxSk) Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Actor -> Int64
bhp Actor
b
canSleep :: Ability.Skills -> Bool
canSleep :: Skills -> Bool
canSleep actorMaxSk :: Skills
actorMaxSk = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkWait Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 3
Bool -> Bool -> Bool
&& (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSight Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
Bool -> Bool -> Bool
|| Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkHearing Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0)
prefersSleep :: Ability.Skills -> Bool
actorMaxSk :: Skills
actorMaxSk = Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMoveItem Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0
Bool -> Bool -> Bool
&& Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkAggression Skills
actorMaxSk Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 2
checkAdjacent :: Actor -> Actor -> Bool
checkAdjacent :: Actor -> Actor -> Bool
checkAdjacent sb :: Actor
sb tb :: Actor
tb = Actor -> LevelId
blid Actor
sb LevelId -> LevelId -> Bool
forall a. Eq a => a -> a -> Bool
== Actor -> LevelId
blid Actor
tb Bool -> Bool -> Bool
&& Point -> Point -> Bool
adjacent (Actor -> Point
bpos Actor
sb) (Actor -> Point
bpos Actor
tb)
eqpOverfull :: Actor -> Int -> Bool
eqpOverfull :: Actor -> Int -> Bool
eqpOverfull b :: Actor
b n :: Int
n = let size :: Int
size = [Int] -> Int
forall a. Num a => [a] -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ ((Int, ItemTimers) -> Int) -> [(Int, ItemTimers)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, ItemTimers) -> Int
forall a b. (a, b) -> a
fst ([(Int, ItemTimers)] -> [Int]) -> [(Int, ItemTimers)] -> [Int]
forall a b. (a -> b) -> a -> b
$ ItemBag -> [(Int, ItemTimers)]
forall k a. EnumMap k a -> [a]
EM.elems (ItemBag -> [(Int, ItemTimers)]) -> ItemBag -> [(Int, ItemTimers)]
forall a b. (a -> b) -> a -> b
$ Actor -> ItemBag
beqp Actor
b
in Bool -> Bool -> Bool
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
size Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 10 Bool -> (Actor, Int, Int) -> Bool
forall a. Show a => Bool -> a -> Bool
`blame` (Actor
b, Int
n, Int
size))
(Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Int
size Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 10
eqpFreeN :: Actor -> Int
eqpFreeN :: Actor -> Int
eqpFreeN b :: Actor
b = let size :: Int
size = [Int] -> Int
forall a. Num a => [a] -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ ((Int, ItemTimers) -> Int) -> [(Int, ItemTimers)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, ItemTimers) -> Int
forall a b. (a, b) -> a
fst ([(Int, ItemTimers)] -> [Int]) -> [(Int, ItemTimers)] -> [Int]
forall a b. (a -> b) -> a -> b
$ ItemBag -> [(Int, ItemTimers)]
forall k a. EnumMap k a -> [a]
EM.elems (ItemBag -> [(Int, ItemTimers)]) -> ItemBag -> [(Int, ItemTimers)]
forall a b. (a -> b) -> a -> b
$ Actor -> ItemBag
beqp Actor
b
in Bool -> Int -> Int
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
size Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 10 Bool -> (Actor, Int) -> Bool
forall a. Show a => Bool -> a -> Bool
`blame` (Actor
b, Int
size))
(Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ 10 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
size
getCarriedIidsAndTrunk :: Actor -> [ItemId]
getCarriedIidsAndTrunk :: Actor -> [ItemId]
getCarriedIidsAndTrunk b :: Actor
b =
let trunk :: ItemBag
trunk = ItemId -> (Int, ItemTimers) -> ItemBag
forall k a. Enum k => k -> a -> EnumMap k a
EM.singleton (Actor -> ItemId
btrunk Actor
b) (Int, ItemTimers)
quantSingle
in ItemBag -> [ItemId]
forall k a. Enum k => EnumMap k a -> [k]
EM.keys (ItemBag -> [ItemId]) -> ItemBag -> [ItemId]
forall a b. (a -> b) -> a -> b
$ ((Int, ItemTimers) -> (Int, ItemTimers) -> (Int, ItemTimers))
-> [ItemBag] -> ItemBag
forall a k. (a -> a -> a) -> [EnumMap k a] -> EnumMap k a
EM.unionsWith (Int, ItemTimers) -> (Int, ItemTimers) -> (Int, ItemTimers)
forall a b. a -> b -> a
const [Actor -> ItemBag
beqp Actor
b, Actor -> ItemBag
borgan Actor
b, ItemBag
trunk]
getCarriedIidCStore :: Actor -> [(ItemId, CStore)]
getCarriedIidCStore :: Actor -> [(ItemId, CStore)]
getCarriedIidCStore b :: Actor
b =
let bagCarried :: (t, EnumMap t a) -> [(t, t)]
bagCarried (cstore :: t
cstore, bag :: EnumMap t a
bag) = (t -> (t, t)) -> [t] -> [(t, t)]
forall a b. (a -> b) -> [a] -> [b]
map (,t
cstore) ([t] -> [(t, t)]) -> [t] -> [(t, t)]
forall a b. (a -> b) -> a -> b
$ EnumMap t a -> [t]
forall k a. Enum k => EnumMap k a -> [k]
EM.keys EnumMap t a
bag
in ((CStore, ItemBag) -> [(ItemId, CStore)])
-> [(CStore, ItemBag)] -> [(ItemId, CStore)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CStore, ItemBag) -> [(ItemId, CStore)]
forall t t a. Enum t => (t, EnumMap t a) -> [(t, t)]
bagCarried [(CStore
CEqp, Actor -> ItemBag
beqp Actor
b), (CStore
COrgan, Actor -> ItemBag
borgan Actor
b)]
monsterGenChance :: Dice.AbsDepth -> Dice.AbsDepth -> Int -> Int -> Rnd Bool
monsterGenChance :: AbsDepth -> AbsDepth -> Int -> Int -> Rnd Bool
monsterGenChance (Dice.AbsDepth ldepth :: Int
ldepth) (Dice.AbsDepth totalDepth :: Int
totalDepth)
lvlSpawned :: Int
lvlSpawned actorCoeff :: Int
actorCoeff =
Bool -> Rnd Bool -> Rnd Bool
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
totalDepth Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 Bool -> Bool -> Bool
&& Int
ldepth Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0) (Rnd Bool -> Rnd Bool) -> Rnd Bool -> Rnd Bool
forall a b. (a -> b) -> a -> b
$
let scaledDepth :: Int
scaledDepth = Int
ldepth Int -> Int -> Int
forall a. Num a => a -> a -> a
* 10 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
totalDepth
maxCoeff :: Int
maxCoeff = 100 Int -> Int -> Int
forall a. Num a => a -> a -> a
* 30
coeff :: Int
coeff = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
maxCoeff (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
actorCoeff Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
lvlSpawned Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
scaledDepth Int -> Int -> Int
forall a. Num a => a -> a -> a
- 2)
in Chance -> Rnd Bool
chance (Chance -> Rnd Bool) -> Chance -> Rnd Bool
forall a b. (a -> b) -> a -> b
$ 3 Integer -> Integer -> Chance
forall a. Integral a => a -> a -> Ratio a
% Int -> Integer
forall a b.
(Integral a, Integral b, IsIntSubType a b ~ 'True) =>
a -> b
intCast (Int
coeff Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` 1)
smellTimeout :: Delta Time
smellTimeout :: Delta Time
smellTimeout = Delta Time -> Int -> Delta Time
timeDeltaScale (Time -> Delta Time
forall a. a -> Delta a
Delta Time
timeTurn) 200