Make _targetCr an Int id rather than a full creature
This commit is contained in:
@@ -32,8 +32,10 @@ import LensHelp
|
||||
import Linear
|
||||
import RandomHelp
|
||||
|
||||
overrideMeleeCloseTarget :: Creature -> Creature
|
||||
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
||||
overrideMeleeCloseTarget :: World -> Creature -> Creature
|
||||
overrideMeleeCloseTarget w cr = maybe cr (tryMeleeAttack cr) $ do
|
||||
i <- _targetCr $ _crIntention cr
|
||||
w ^? cWorld . lWorld . creatures . ix i
|
||||
|
||||
tryMeleeAttack :: Creature -> Creature -> Creature
|
||||
tryMeleeAttack cr tcr
|
||||
@@ -58,7 +60,8 @@ setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
|
||||
where
|
||||
int = _crIntention cr
|
||||
mtpos = do
|
||||
tpos <- (^. crPos . _xy) <$> _targetCr int
|
||||
i <- int ^. targetCr
|
||||
tpos <- w ^? cWorld . lWorld . creatures . ix i . crPos . _xy
|
||||
guard $ hasLOSIndirect (cr ^. crPos . _xy) tpos w
|
||||
return tpos
|
||||
mpos = mtpos <|> _mvToPoint int
|
||||
@@ -90,29 +93,29 @@ setTargetMv targFunc w cr =
|
||||
|
||||
-- ugly
|
||||
flockACC :: World -> Creature -> Creature
|
||||
flockACC w cr = case cr ^? crIntention . targetCr . _Just of
|
||||
Nothing -> cr
|
||||
Just tcr ->
|
||||
let tpos = tcr ^. crPos . _xy
|
||||
cpos = cr ^. crPos . _xy
|
||||
isFarACC cr' =
|
||||
_crGroup cr' == _crGroup cr
|
||||
&& _crID cr' /= _crID cr
|
||||
&& dist (cr' ^. crPos . _xy) tpos > dist cpos tpos
|
||||
macr =
|
||||
safeMinimumOn (dist cpos . (^. crPos . _xy))
|
||||
. filter isFarACC
|
||||
$ crsNearCirc cpos 50 w
|
||||
in case macr of
|
||||
Nothing -> cr
|
||||
Just acr ->
|
||||
let r = crRad (acr ^. crType) + crRad (cr ^. crType) + 10
|
||||
horDir = normalizeV (vNormal (cpos -.- tpos))
|
||||
horShift =
|
||||
if isLHS tpos cpos (acr ^. crPos . _xy)
|
||||
then r *.* horDir
|
||||
else negate r *.* horDir
|
||||
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||
flockACC w cr = fromMaybe cr $ do
|
||||
i <- cr ^. crIntention . targetCr
|
||||
tcr <- w ^? cWorld . lWorld . creatures . ix i
|
||||
let tpos = tcr ^. crPos . _xy
|
||||
cpos = cr ^. crPos . _xy
|
||||
isFarACC cr' =
|
||||
_crGroup cr' == _crGroup cr
|
||||
&& _crID cr' /= _crID cr
|
||||
&& dist (cr' ^. crPos . _xy) tpos > dist cpos tpos
|
||||
macr =
|
||||
safeMinimumOn (dist cpos . (^. crPos . _xy))
|
||||
. filter isFarACC
|
||||
$ crsNearCirc cpos 50 w
|
||||
return $ case macr of
|
||||
Nothing -> cr
|
||||
Just acr ->
|
||||
let r = crRad (acr ^. crType) + crRad (cr ^. crType) + 10
|
||||
horDir = normalizeV (vNormal (cpos -.- tpos))
|
||||
horShift =
|
||||
if isLHS tpos cpos (acr ^. crPos . _xy)
|
||||
then r *.* horDir
|
||||
else negate r *.* horDir
|
||||
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
|
||||
|
||||
chaseCritMv :: World -> Creature -> Creature
|
||||
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
|
||||
@@ -203,7 +206,7 @@ targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
||||
Just (Cognizant _) ->
|
||||
(w ^?! cWorld . lWorld . creatures . ix 0)
|
||||
`seq` cr
|
||||
& crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
|
||||
& crIntention . targetCr ?~ 0
|
||||
& crPerception . cpVigilance .~ Vigilant
|
||||
_ -> cr & crIntention . targetCr .~ Nothing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user