Cleanup creatures somewhat, fix LOS to LOSIndirect

This commit is contained in:
2022-07-03 15:07:55 +01:00
parent b43ec42a2e
commit ffdfaa41c0
24 changed files with 81 additions and 116 deletions
+15 -15
View File
@@ -37,7 +37,7 @@ tryMeleeAttack cr tcr
| _crMeleeCooldown cr == 0
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi/4
= cr & crActionPlan . crImpulse .~ [Melee $ _crID tcr]
= cr & crActionPlan . apImpulse .~ [Melee $ _crID tcr]
| otherwise = cr
where
cpos = _crPos cr
@@ -48,7 +48,7 @@ setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
int = _crIntention cr
mtpos = do
tpos <- _crPos <$> _targetCr int
if hasLOS (_crPos cr) tpos w
if hasLOSIndirect (_crPos cr) tpos w
then Just tpos
else Nothing
mpos = mtpos
@@ -89,26 +89,26 @@ flockACC w cr = case cr ^? crIntention . targetCr . _Just of
in cr & crIntention . mvToPoint ?~ tpos +.+ horShift
chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _crStrategy (_crActionPlan cr) of
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
StrategyActions _ _ -> cr
WarningCry -> cr
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p -> cr & crActionPlan . crAction .~ [PathTo p]
Just p -> cr & crActionPlan . apAction .~ [PathTo p]
_ -> viewTarget w cr
goToTarget :: World -> Creature -> Creature
goToTarget w cr =
case cr ^? crIntention . mvToPoint . _Just of
Just p -> cr & crActionPlan . crAction .~ [PathTo p]
Just p -> cr & crActionPlan . apAction .~ [PathTo p]
_ -> viewTarget w cr
viewTarget :: World -> Creature -> Creature
viewTarget w cr = do
case cr ^? crIntention . viewPoint . _Just of
Just p | hasLOSIndirect p (_crPos cr) w -> cr'
& crActionPlan . crAction %~ replaceNullWith (TurnToA p)
& crActionPlan . apAction %~ replaceNullWith (TurnToA p)
& crIntention . viewPoint .~ Nothing
| otherwise -> cr' & crActionPlan . crAction %~ replaceNullWith (PathTo p)
| otherwise -> cr' & crActionPlan . apAction %~ replaceNullWith (PathTo p)
Nothing -> cr-- & crPerception . crAwakeLevel .~ Lethargic
where
cr' = cr & crPerception . cpVigilance .~ Vigilant
@@ -118,16 +118,16 @@ replaceNullWith x [] = [x]
replaceNullWith _ xs = xs
doStrategyActions :: Creature -> Creature
doStrategyActions cr = case cr ^? crActionPlan . crStrategy of
Just (StrategyActions strat acs) -> cr & crActionPlan . crAction .~ acs
& crActionPlan . crStrategy .~ strat
doStrategyActions cr = case cr ^? crActionPlan . apStrategy of
Just (StrategyActions strat acs) -> cr & crActionPlan . apAction .~ acs
& crActionPlan . apStrategy .~ strat
_ -> cr
reloadOverride :: Creature -> Creature
reloadOverride cr
| cr ^? crInv . ix (crSel cr) . itConsumption . laLoaded == Just 0
&& cr ^. crStance . posture == Aiming
= cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
= cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
| otherwise = cr
where
reloadActions =
@@ -147,9 +147,9 @@ watchUpdateStrat
-> World
-> Creature
-> Creature
watchUpdateStrat fs w cr = case cr ^? crActionPlan . crStrategy of
watchUpdateStrat fs w cr = case cr ^? crActionPlan . apStrategy of
Just WatchAndWait -> cr
& crActionPlan . crStrategy .~ listGuard (map (first uncurry) fs, \_ _ -> WatchAndWait) (w, cr) w cr
& crActionPlan . apStrategy .~ listGuard (map (first uncurry) fs, \_ _ -> WatchAndWait) (w, cr) w cr
_ -> cr
listGuard :: ([(a -> Bool, b)] , b) -> a -> b
@@ -167,8 +167,8 @@ targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
turnIfDamaged :: Creature -> Creature
turnIfDamaged cr
| _crPastDamage cr > 0 = case _crStrategy (_crActionPlan cr) of
| _crPastDamage cr > 0 = case _apStrategy (_crActionPlan cr) of
WatchAndWait -> cr & crPerception . cpVigilance .~ Vigilant
& crActionPlan . crStrategy .~ StrategyActions LookAround [TurnToA (_crPos cr -.- unitVectorAtAngle (_crDir cr))]
& crActionPlan . apStrategy .~ StrategyActions LookAround [TurnToA (_crPos cr -.- unitVectorAtAngle (_crDir cr))]
_ -> cr
| otherwise = cr