Fix space leak when assigning targeted creature

This commit is contained in:
2021-12-10 02:56:14 +00:00
parent e5db9ba5d0
commit 15e1fbc060
7 changed files with 33 additions and 18 deletions
+2 -1
View File
@@ -201,5 +201,6 @@ targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crPerception . crAwarenes
targetYouWhenCognizant :: World -> Creature -> Creature
targetYouWhenCognizant w cr = case cr ^? crPerception . crAwarenessLevel . ix 0 of
Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0
-- so this caused a space leak: be careful with ?~
Just (Cognizant _) -> _creatures w IM.! 0 `seq` cr & crIntention . targetCr ?~ _creatures w IM.! 0
_ -> cr & crIntention . targetCr .~ Nothing