Fix space leak when assigning targeted creature
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module Dodge.Creature.Impulse
|
||||
( impulsiveAIR
|
||||
-- , impulsiveAI
|
||||
, impulsiveAI
|
||||
, impulsiveAI'
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Vocalization
|
||||
@@ -15,6 +15,7 @@ import System.Random
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader
|
||||
import Data.Bifunctor
|
||||
--import Data.Maybe
|
||||
|
||||
impulsiveAIR
|
||||
:: (Creature -> Reader World Creature)
|
||||
@@ -23,17 +24,17 @@ impulsiveAIR
|
||||
-> (World -> World , Maybe Creature)
|
||||
impulsiveAIR impf cr w = second Just $ followImpulses w . ($ w) . runReader $ impf cr
|
||||
|
||||
--impulsiveAI :: (World -> Creature -> Creature)
|
||||
-- -> Creature
|
||||
-- -> World
|
||||
-- -> (World -> World , Maybe Creature)
|
||||
--impulsiveAI impf cr w = second Just $ followImpulses w $ impf w cr
|
||||
|
||||
impulsiveAI :: (World -> Creature -> Creature)
|
||||
-> Creature
|
||||
-> World
|
||||
-> (World -> World , Maybe Creature)
|
||||
impulsiveAI impf cr w = second Just $ followImpulses w $ impf w cr
|
||||
|
||||
impulsiveAI' :: (World -> Creature -> Creature)
|
||||
-> Creature
|
||||
-> World
|
||||
-> (World -> World , Creature)
|
||||
impulsiveAI' impf cr w = followImpulses w $ impf w cr
|
||||
impulsiveAI impf cr w = followImpulses w $ impf w cr
|
||||
|
||||
followImpulses :: World -> Creature -> (World -> World, Creature)
|
||||
followImpulses w cr = foldr
|
||||
@@ -70,6 +71,10 @@ followImpulse cr w imp = case imp of
|
||||
ImpulseUseTarget f -> case cr ^? crIntention . targetCr . _Just of
|
||||
Just tcr -> followImpulse cr w (f tcr)
|
||||
_ -> (id,cr)
|
||||
-- ImpulseUseTarget f -> fromMaybe (id,cr) $ do
|
||||
-- cid <- cr ^? crIntention . targetCr . _Just
|
||||
-- tcr <- w ^? creatures . ix cid
|
||||
-- return $ followImpulse cr w (f tcr)
|
||||
ImpulseUseAheadPos f -> followImpulse cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||
MvForward -> (id, crMvForward speed cr)
|
||||
MvTurnToward p -> (id, creatureTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir)) cr)
|
||||
@@ -86,4 +91,3 @@ followImpulse cr w imp = case imp of
|
||||
hitCr i = over (creatures . ix i . crState . crDamage) (addDam i)
|
||||
. soundStart (CrSound cid) cpos hitS Nothing
|
||||
addDam i dams = Blunt 100 cpos (posFromID i) (posFromID i) : dams
|
||||
|
||||
|
||||
Reference in New Issue
Block a user