diff --git a/src/Dodge/Base/Collide.hs b/src/Dodge/Base/Collide.hs index e1a6be936..a5390103d 100644 --- a/src/Dodge/Base/Collide.hs +++ b/src/Dodge/Base/Collide.hs @@ -260,7 +260,7 @@ canSee i j w = hasLOS p1 p2 w -- jpos = _crPos (_creatures w IM.! j) canSeeIndirect :: Int -> Int -> World -> Bool -canSeeIndirect i j w = any (isJust . uncurry (intersectSegSeg ipos jpos) . _wlLine) +canSeeIndirect i j w = not $ any (isJust . uncurry (intersectSegSeg ipos jpos) . _wlLine) $ IM.filter wlIsOpaque $ wallsAlongLine ipos jpos w where ipos = _crPos (_creatures w IM.! i) diff --git a/src/Dodge/Creature/ChooseTarget.hs b/src/Dodge/Creature/ChooseTarget.hs index e4d07a28c..24e9129de 100644 --- a/src/Dodge/Creature/ChooseTarget.hs +++ b/src/Dodge/Creature/ChooseTarget.hs @@ -15,7 +15,7 @@ targetYouLOS cr w targetYouCognizant :: Creature -> World -> Maybe Creature targetYouCognizant cr w | hasLOS (_crPos cr) (_crPos $ you w) w - && isCog (cr ^? crPerception . crAwarenessLevel . ix 0) + && isCog (cr ^? crPerception . cpAwareness . ix 0) = Just $ you w | otherwise = Nothing where diff --git a/src/Dodge/Creature/Impulse/Movement.hs b/src/Dodge/Creature/Impulse/Movement.hs index 0524eb91d..1dffe5686 100644 --- a/src/Dodge/Creature/Impulse/Movement.hs +++ b/src/Dodge/Creature/Impulse/Movement.hs @@ -9,10 +9,8 @@ import Control.Lens {- | Creature attempts to moves under its own steam. The idea is that this may or may not work, depending on the status of the creature. For now, though, this cannot fail. -} -crMvBy - :: Point2 -- ^ Movement translation vector, will be made relative to creature direction - -> Creature - -> Creature +crMvBy :: Point2 -- ^ Movement translation vector, will be made relative to creature direction + -> Creature -> Creature crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr crMvAbsolute diff --git a/src/Dodge/Creature/Memory/Data.hs b/src/Dodge/Creature/Memory/Data.hs index 71f255098..a639e5090 100644 --- a/src/Dodge/Creature/Memory/Data.hs +++ b/src/Dodge/Creature/Memory/Data.hs @@ -6,8 +6,8 @@ import Geometry.Data import Control.Lens -newtype MemoryState = MemoryState +newtype Memory = Memory { _soundsToInvestigate :: [Point2] } -makeLenses ''MemoryState +makeLenses ''Memory diff --git a/src/Dodge/Creature/Perception.hs b/src/Dodge/Creature/Perception.hs index 29131363b..9ccd9e70d 100644 --- a/src/Dodge/Creature/Perception.hs +++ b/src/Dodge/Creature/Perception.hs @@ -34,15 +34,15 @@ chaseCritPerceptionUpdate is w = {- | Update a creatures awareness based upon the creatures' current direction of attention -} -- TODO delete? basicAwarenessUpdate :: Creature -> Creature -basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of - Fixated i -> cr & crPerception . crAwarenessLevel +basicAwarenessUpdate cr = case _cpAttention $ _crPerception cr of + Fixated i -> cr & crPerception . cpAwareness %~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness) AttentiveTo is -> cr - & crPerception . crAwarenessLevel + & crPerception . cpAwareness %~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) & maybeBark where - oldAwareness = _crAwarenessLevel $ _crPerception cr + oldAwareness = _cpAwareness $ _crPerception cr newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness thejitter = do @@ -65,15 +65,15 @@ basicAwarenessUpdate cr = case _crAttentionDir $ _crPerception cr of -- TODO fold in randgen update, requires that this is a world to world function chaseCritAwarenessUpdate :: World -> Creature -> Creature -chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of - Fixated i -> cr & crPerception . crAwarenessLevel +chaseCritAwarenessUpdate w cr = case _cpAttention $ _crPerception cr of + Fixated i -> cr & crPerception . cpAwareness %~ (IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness) AttentiveTo is -> cr - & crPerception . crAwarenessLevel + & crPerception . cpAwareness %~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) & maybeBark where - oldAwareness = _crAwarenessLevel $ _crPerception cr + oldAwareness = _cpAwareness $ _crPerception cr newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness --randBool = takeOne [False,True] & evalState $ _randGen w @@ -92,15 +92,15 @@ chaseCritAwarenessUpdate w cr = case _crAttentionDir $ _crPerception cr of ] | otherwise = id -cogRaised :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel +cogRaised :: Awareness -> Awareness -> Awareness cogRaised Suspicious{} Cognizant{} = Cognizant 100 cogRaised _ _ = Suspicious 0 -isCognizant :: AwarenessLevel -> Bool +isCognizant :: Awareness -> Bool isCognizant Cognizant {} = True isCognizant _ = False -combineAwareness :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel +combineAwareness :: Awareness -> Awareness -> Awareness combineAwareness (Suspicious x) (Suspicious y) | x + y < 5000 = Suspicious $ x + y | otherwise = Cognizant 1000 @@ -110,7 +110,7 @@ combineAwareness (Cognizant x) (Cognizant y) = Cognizant $ min 10000 $ x + y {- | Decrease awareness level. Returns 'Maybe' value for use with 'IM.mapMaybe' -} -decreaseAwareness :: AwarenessLevel -> Maybe AwarenessLevel +decreaseAwareness :: Awareness -> Maybe Awareness decreaseAwareness (Suspicious 0) = Nothing decreaseAwareness (Suspicious x) = Just $ Suspicious (x - 50) decreaseAwareness (Cognizant 0) = Just $ Suspicious 1000 @@ -123,26 +123,26 @@ basicAttentionUpdate -> World -> Creature -> Creature -basicAttentionUpdate cids w cr = cr & crPerception . crAttentionDir .~ +basicAttentionUpdate cids w cr = cr & crPerception . cpAttention .~ AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids) newExtraAwareness :: Creature -- ^ source creature -> World -> Int -- ^ target creature id - -> Maybe AwarenessLevel + -> Maybe Awareness newExtraAwareness cr w cid | not $ canSeeIndirect (_crID cr) cid w = Nothing | otherwise = Just . Suspicious $ _viFOV vi ang * _viDist vi d * awakeLevelPerception cr where - vi = _crVision $ _crPerception cr + vi = _cpVision $ _crPerception cr tpos = _crPos $ _creatures w IM.! cid cpos = _crPos cr ang = angleVV (unitVectorAtAngle (_crDir cr)) (tpos - cpos) d = dist tpos cpos awakeLevelPerception :: Creature -> Float -awakeLevelPerception cr = case _crAwakeLevel $ _crPerception cr of +awakeLevelPerception cr = case _cpVigilance $ _crPerception cr of Comatose -> 0 Asleep -> 10 Lethargic -> 200 @@ -162,13 +162,13 @@ rememberSounds w cr = cr & awakeupdate where awakeupdate | null closesounds = id - | otherwise = crPerception . crAwakeLevel .~ Vigilant + | otherwise = crPerception . cpVigilance .~ Vigilant closesounds = map fst (filter (soundIsClose w cr) (newSounds w)) -- TODO work out correct form for sounds passing through walls soundIsClose :: World -> Creature -> (Point2,Float) -> Bool soundIsClose w cr (pos,vol) = dist cpos pos < 2000 - && vol > (_auDist . _crAudition $ _crPerception cr) (dist pos cpos) + && vol > (_auDist . _cpAudition $ _crPerception cr) (dist pos cpos) && hasLOS cpos pos w where cpos = _crPos cr diff --git a/src/Dodge/Creature/Perception/Data.hs b/src/Dodge/Creature/Perception/Data.hs index 2dfdd55ce..ce227fe14 100644 --- a/src/Dodge/Creature/Perception/Data.hs +++ b/src/Dodge/Creature/Perception/Data.hs @@ -1,20 +1,20 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE StrictData #-} module Dodge.Creature.Perception.Data - ( PerceptionState (..) - , AwakeLevel (..) - , AttentionDir (..) - , AwarenessLevel (..) + ( Perception (..) + , Vigilance (..) + , Attention (..) + , Awareness (..) , Vision (..) , Audition (..) -- lenses , getAttentiveTo , getFixated - , crAttentionDir - , crAwakeLevel - , crAwarenessLevel - , crVision - , crAudition + , cpAttention + , cpVigilance + , cpAwareness + , cpVision + , cpAudition , viFOV , viDist , auDist @@ -23,12 +23,12 @@ module Dodge.Creature.Perception.Data import Control.Lens import qualified Data.IntMap as IM -data PerceptionState = PerceptionState - { _crAwakeLevel :: AwakeLevel - , _crAttentionDir :: AttentionDir - , _crAwarenessLevel :: IM.IntMap AwarenessLevel - , _crVision :: Vision - , _crAudition :: Audition +data Perception = Perception + { _cpVigilance :: Vigilance + , _cpAttention :: Attention + , _cpAwareness :: IM.IntMap Awareness + , _cpVision :: Vision + , _cpAudition :: Audition } data Vision = Eyes @@ -39,7 +39,7 @@ newtype Audition = Ears { _auDist :: Float -> Float } -data AwakeLevel +data Vigilance = Comatose | Asleep | Lethargic @@ -47,16 +47,16 @@ data AwakeLevel | Overstrung deriving (Eq,Ord,Show) -data AttentionDir - = AttentiveTo {_getAttentiveTo :: IM.IntMap AwarenessLevel } +data Attention + = AttentiveTo {_getAttentiveTo :: IM.IntMap Awareness } | Fixated {_getFixated :: Int } -data AwarenessLevel +data Awareness = Suspicious Float | Cognizant Float deriving (Eq,Ord) -makeLenses ''AttentionDir -makeLenses ''PerceptionState +makeLenses ''Attention +makeLenses ''Perception makeLenses ''Vision makeLenses ''Audition diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 28094016c..a4e18386c 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -90,8 +90,8 @@ creatureDisplayText cfig w cr . scale theScale theScale . stackText $ clockCycle 25 (V.fromList - [ \cr' -> [crDisplayAwake cr'] - , \cr' -> [crDisplayAlert cr'] + [ \cr' -> [crDisplayVigilance cr'] + , \cr' -> [crDisplayAwareness cr'] ] ) w cr where @@ -101,13 +101,13 @@ creatureDisplayText cfig w cr v = cpos -.- campos (V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v -crDisplayAlert :: Creature -> String -crDisplayAlert cr +crDisplayAwareness :: Creature -> String +crDisplayAwareness cr | isSuspicious = "?" | isCognizant = "!" | otherwise = "." where - imAwarenesses = _crAwarenessLevel (_crPerception cr) + imAwarenesses = _cpAwareness (_crPerception cr) isSuspicious = any f imAwarenesses && not (null imAwarenesses) isCognizant = any g imAwarenesses && not (null imAwarenesses) f (Suspicious _) = True @@ -115,14 +115,8 @@ crDisplayAlert cr g (Cognizant _) = True g _ = False -crDisplayAwake :: Creature -> String -crDisplayAwake = show . _crAwakeLevel . _crPerception ---crDisplayAwake cr = case _crAwakeLevel (_crPerception cr) of --- Comatose -> "-" --- Asleep -> "Z" --- Lethargic -> "L" --- Vigilant -> "V" --- Overstrung -> "O" +crDisplayVigilance :: Creature -> String +crDisplayVigilance = show . _cpVigilance . _crPerception --damageMod :: Creature -> Picture -> Picture --damageMod cr pic = piercingMod $ bluntScale pic diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index b7af6d611..c6289accc 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -110,7 +110,7 @@ viewTarget w cr = do | otherwise -> cr' & crActionPlan . crAction %~ replaceNullWith (PathTo p) Nothing -> cr-- & crPerception . crAwakeLevel .~ Lethargic where - cr' = cr & crPerception . crAwakeLevel .~ Vigilant + cr' = cr & crPerception . cpVigilance .~ Vigilant replaceNullWith :: a -> [a] -> [a] replaceNullWith x [] = [x] @@ -158,7 +158,7 @@ listGuard ( (test,y):ps, z ) x listGuard (_,z) _ = z targetYouWhenCognizant :: World -> Creature -> Creature -targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 of +targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of -- so this caused a space leak: be careful with ?~ -- consider changing targeted creature to be just an index Just (Cognizant _) -> _creatures w IM.! 0 `seq` cr & crIntention . targetCr ?~ _creatures w IM.! 0 @@ -167,7 +167,7 @@ targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 turnIfDamaged :: Creature -> Creature turnIfDamaged cr | _crPastDamage cr > 0 = case _crStrategy (_crActionPlan cr) of - WatchAndWait -> cr & crPerception . crAwakeLevel .~ Vigilant + WatchAndWait -> cr & crPerception . cpVigilance .~ Vigilant & crActionPlan . crStrategy .~ StrategyActions LookAround [TurnToA (_crPos cr -.- unitVectorAtAngle (_crDir cr))] _ -> cr | otherwise = cr diff --git a/src/Dodge/Creature/SetTarget.hs b/src/Dodge/Creature/SetTarget.hs index ce2a5126c..f93141bbd 100644 --- a/src/Dodge/Creature/SetTarget.hs +++ b/src/Dodge/Creature/SetTarget.hs @@ -9,7 +9,7 @@ targetYouWhenCognizant :: World -> Creature -> Creature -targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 of +targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0 _ -> cr & crIntention . targetCr .~ Nothing diff --git a/src/Dodge/Creature/Statistics.hs b/src/Dodge/Creature/Statistics.hs index 7339d4bfd..be789745b 100644 --- a/src/Dodge/Creature/Statistics.hs +++ b/src/Dodge/Creature/Statistics.hs @@ -1,5 +1,6 @@ module Dodge.Creature.Statistics ( getCrStrength + , getCrDexterity ) where import Dodge.Data import qualified IntMapHelp as IM diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index cd9845ea5..9d57f48a5 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -356,8 +356,8 @@ data Creature = Creature , _crStance :: Stance , _crActionPlan :: ActionPlan , _crMeleeCooldown :: Int - , _crPerception :: PerceptionState - , _crMemory :: MemoryState + , _crPerception :: Perception + , _crMemory :: Memory , _crVocalization :: Vocalization , _crFaction :: Faction , _crGroup :: CrGroup diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 8b3bb4965..da14db57b 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -81,21 +81,19 @@ defaultCreatureSkin = CreatureSkin (greyN 0.9) (light4 green) (greyN 0.3) defaultInanimate :: Creature defaultInanimate = defaultCreature & crActionPlan .~ Inanimate -defaultCreatureMemory :: MemoryState -defaultCreatureMemory = MemoryState - { _soundsToInvestigate = [] - } +defaultCreatureMemory :: Memory +defaultCreatureMemory = Memory { _soundsToInvestigate = [] } defaultInvSize :: Int defaultInvSize = 20 -defaultPerceptionState :: PerceptionState -defaultPerceptionState = PerceptionState - { _crAwakeLevel = Lethargic - , _crAttentionDir = AttentiveTo IM.empty - , _crAwarenessLevel = IM.empty - , _crVision = defaultVision - , _crAudition = defaultAudition +defaultPerceptionState :: Perception +defaultPerceptionState = Perception + { _cpVigilance = Lethargic + , _cpAttention = AttentiveTo IM.empty + , _cpAwareness = IM.empty + , _cpVision = defaultVision + , _cpAudition = defaultAudition } defaultVision :: Vision defaultVision = Eyes diff --git a/src/Dodge/Render/ShapePicture.hs b/src/Dodge/Render/ShapePicture.hs index 25440ab56..bf58df797 100644 --- a/src/Dodge/Render/ShapePicture.hs +++ b/src/Dodge/Render/ShapePicture.hs @@ -157,16 +157,16 @@ drawPathing cfig w crDisplayInfo :: Configuration -> World -> Creature -> Maybe (Point2,[String]) crDisplayInfo cfig w cr - | _crID cr == 0 = Nothing +-- | _crID cr == 0 = Nothing | crOnScreen = Just (_crPos cr, catMaybes -- [fmap show $ ap ^? crGoal - [fmap show $ cr ^? crHP - ,fmap show $ ap ^? crStrategy - ,fmap show $ cr ^? crPos - ,fmap show $ cr ^? crPerception . crAwakeLevel --- ,fmap show $ cr ^? crOldPos - ,fmap show $ ap ^? crAction - ,fmap show $ ap ^? crImpulse + [ fmap show $ cr ^? crHP + , fmap show $ ap ^? crStrategy + , fmap show $ cr ^? crPos + , fmap show $ cr ^? crPerception . cpVigilance +-- , fmap show $ cr ^? crOldPos + , fmap show $ ap ^? crAction + , fmap show $ ap ^? crImpulse ] ) | otherwise = Nothing