Make _targetCr an Int id rather than a full creature

This commit is contained in:
2025-10-15 20:09:17 +01:00
parent 57ca53638a
commit 5e6ed1d793
13 changed files with 122 additions and 123 deletions
+26 -22
View File
@@ -1,5 +1,6 @@
module Dodge.Creature.Boid where
import Data.Maybe
import Linear
import Dodge.Creature.Radius
import Control.Lens
@@ -176,9 +177,10 @@ swarmUsingCenter ::
World ->
Creature ->
Creature
swarmUsingCenter updT upd w cr = case _targetCr $ _crIntention cr of
Nothing -> upd cenp cr
Just tcr -> updT tcr cenp cr
swarmUsingCenter updT upd w cr = fromMaybe (upd cenp cr) $ do
i <- _targetCr $ _crIntention cr
tcr <- w ^? cWorld . lWorld . creatures . ix i
return $ updT tcr cenp cr
where
cid = _crID cr
cenp = _crGroupCenter $ _creatureGroups (_lWorld (_cWorld w)) IM.! _crGroupID (_crGroup $ _creatures (_lWorld (_cWorld w)) IM.! cid)
@@ -191,9 +193,10 @@ flockChaseTarget ::
World ->
Creature ->
Creature
flockChaseTarget updT upd w cr = case _targetCr $ _crIntention cr of
Nothing -> upd crs cr
Just tcr -> updT tcr crs cr
flockChaseTarget updT upd w cr = fromMaybe (upd crs cr) $ do
i <- _targetCr $ _crIntention cr
tcr <- w ^? cWorld . lWorld . creatures . ix i
return $ updT tcr crs cr
where
is = _swarm $ _crGroup cr
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
@@ -213,18 +216,18 @@ flockPointTarget f targFunc w cr = case targFunc cr w of
crs = IM.restrictKeys (w ^. cWorld . lWorld . creatures) is
p = f crTarg crs cr
flockToPointUsing ::
(Creature -> Point2 -> Creature -> Point2) ->
(Point2 -> Creature -> Creature -> [Impulse]) ->
Creature ->
Reader World Creature
flockToPointUsing pf mvf cr = reader $ \w -> case _targetCr $ _crIntention cr of
Nothing -> cr
Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
where
cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
-- crGroupCenter $ _creatureGroups (_cWorld w) IM.! _crGroupID (_crGroup cr)
ptarg = pf tcr cenp cr
--flockToPointUsing ::
-- (Creature -> Point2 -> Creature -> Point2) ->
-- (Point2 -> Creature -> Creature -> [Impulse]) ->
-- Creature ->
-- Reader World Creature
--flockToPointUsing pf mvf cr = reader $ \w -> case _targetCr $ _crIntention cr of
-- Nothing -> cr
-- Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
-- where
-- cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
-- -- crGroupCenter $ _creatureGroups (_cWorld w) IM.! _crGroupID (_crGroup cr)
-- ptarg = pf tcr cenp cr
flockToPointUsing' ::
(Creature -> Point2 -> Creature -> Point2) ->
@@ -232,12 +235,13 @@ flockToPointUsing' ::
World ->
Creature ->
Creature
flockToPointUsing' pf mvf w cr = case _targetCr $ _crIntention cr of
Nothing -> cr
Just tcr -> cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
flockToPointUsing' pf mvf w cr = fromMaybe cr $ do
i <- _targetCr $ _crIntention cr
tcr <- w ^? cWorld . lWorld . creatures . ix i
let ptarg = pf tcr cenp cr
return $ cr & crActionPlan . apImpulse .~ mvf ptarg cr tcr
where
cenp = w ^?! cWorld . lWorld . creatureGroups . ix (cr ^?! crGroup . crGroupID) . crGroupCenter
ptarg = pf tcr cenp cr
flockFunc ::
(Creature -> Point2 -> Creature -> Point2) ->