Implement basic attention and awareness

This commit is contained in:
2021-05-08 17:34:25 +02:00
parent 1aa59cc205
commit 86faf9fd01
12 changed files with 243 additions and 135 deletions
+10 -3
View File
@@ -14,6 +14,13 @@ import qualified Data.IntMap.Strict as IM
import System.Random
import Control.Lens
composeInternalAIs
:: [World -> Creature -> Creature]
-> World
-> Creature
-> Creature
composeInternalAIs fs w c = foldr ($ w) c fs
impulsiveAI
:: (World -> Creature -> Creature) -- ^ Internal AI update, should determine impulses
-> World
@@ -46,7 +53,7 @@ followImpulse imp w cr = case imp of
MoveForward x -> (id, crMvForward x cr)
Turn a -> (id, creatureTurn a cr)
TurnToward p a -> (id, creatureTurnToward p a cr)
UseItem -> (crUseItem cr, cr)
-- UseItem -> (crUseItem cr, cr)
SwitchToItem i -> (id, cr & crInvSel .~ i)
Melee crID ->
(hitCr crID
@@ -88,11 +95,11 @@ performAction cr w ac = case ac of
Just x | x > 0 -> ( [UseItem] , Just ShootTillEmpty )
_ -> ( [] , Nothing )
AimAtCloseSlow tcid p speed slowSpeed a
| canSee (_crID cr) tcid w && abs (normalizeAngle $ cdir - argV (tpos -.- cpos)) < a
| canSee (_crID cr) tcid w && safeAngleVV (unitVectorAtAngle cdir) (tpos -.- cpos) < a
-> ([TurnToward tpos slowSpeed] , Just $ AimAtCloseSlow tcid tpos speed slowSpeed a)
| canSee (_crID cr) tcid w
-> ([TurnToward tpos speed] , Just $ AimAtCloseSlow tcid tpos speed slowSpeed a)
| abs (normalizeAngle (cdir - (argV (p -.- cpos)))) < a
| safeAngleVV (unitVectorAtAngle cdir) (tpos -.- cpos) < a
-> ([TurnToward p slowSpeed] , Just $ AimAtCloseSlow tcid p speed slowSpeed a)
| otherwise -> ([TurnToward p speed] , Just $ AimAtCloseSlow tcid p speed slowSpeed a)
where