Cleanup
This commit is contained in:
@@ -43,7 +43,7 @@ followImpulse cr w imp = case imp of
|
|||||||
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown w cr)
|
Bark sid -> (soundStart (CrMouth cid) cpos sid Nothing, resetCrVocCoolDown w cr)
|
||||||
Move p -> crup $ crMvBy p cr
|
Move p -> crup $ crMvBy p cr
|
||||||
MoveForward x -> crup $ crMvForward x cr
|
MoveForward x -> crup $ crMvForward x cr
|
||||||
Turn a -> crup $ creatureTurn a cr
|
Turn a -> crup $ cr & crDir +~ a
|
||||||
TurnToward p a -> crup $ creatureTurnToward p a cr
|
TurnToward p a -> crup $ creatureTurnToward p a cr
|
||||||
TurnTo p -> crup $ creatureTurnTo p cr
|
TurnTo p -> crup $ creatureTurnTo p cr
|
||||||
ChangePosture post -> crup $ cr & crStance . posture .~ post
|
ChangePosture post -> crup $ cr & crStance . posture .~ post
|
||||||
@@ -55,7 +55,7 @@ followImpulse cr w imp = case imp of
|
|||||||
( hitCr cid'
|
( hitCr cid'
|
||||||
, crMvAbsolute (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20
|
, crMvAbsolute (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20
|
||||||
)
|
)
|
||||||
RandomTurn a -> (randGen .~ snd (rr a), creatureTurn (fst $ rr a) cr)
|
RandomTurn a -> (randGen .~ snd (rr a), cr & crDir +~ (fst $ rr a))
|
||||||
MakeSound sid -> (soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing, cr)
|
MakeSound sid -> (soundStart (CrSound (_crID cr)) (_crPos cr) sid Nothing, cr)
|
||||||
DropItem -> undefined
|
DropItem -> undefined
|
||||||
ChangeStrategy strat -> crup $ cr & crActionPlan . apStrategy .~ strat
|
ChangeStrategy strat -> crup $ cr & crActionPlan . apStrategy .~ strat
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
module Dodge.Creature.Impulse.Movement where
|
module Dodge.Creature.Impulse.Movement (
|
||||||
|
creatureTurnToward,
|
||||||
|
creatureTurnTowardDir,
|
||||||
|
crMvAbsolute,
|
||||||
|
crMvBy,
|
||||||
|
crMvForward,
|
||||||
|
creatureTurnTo,
|
||||||
|
) where
|
||||||
|
|
||||||
import Dodge.Base
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
|
import Dodge.Base
|
||||||
import Dodge.Creature.Statistics
|
import Dodge.Creature.Statistics
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import Geometry
|
import Geometry
|
||||||
@@ -17,14 +24,10 @@ crMvBy ::
|
|||||||
Creature
|
Creature
|
||||||
crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr
|
crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr
|
||||||
|
|
||||||
crMvAbsolute ::
|
crMvAbsolute :: Point2 -> Creature -> Creature
|
||||||
-- | Movement translation vector
|
|
||||||
Point2 ->
|
|
||||||
Creature ->
|
|
||||||
Creature
|
|
||||||
crMvAbsolute p' cr =
|
crMvAbsolute p' cr =
|
||||||
advanceStepCounter (magV p) cr
|
advanceStepCounter (magV p) cr
|
||||||
& crPos %~ (+.+ p)
|
& crPos +~ p
|
||||||
& crMvDir .~ argV p
|
& crMvDir .~ argV p
|
||||||
where
|
where
|
||||||
p = strengthFactor (getCrMoveSpeed cr) *.* p'
|
p = strengthFactor (getCrMoveSpeed cr) *.* p'
|
||||||
@@ -35,18 +38,10 @@ strengthFactor i
|
|||||||
| i < 1 = 0
|
| i < 1 = 0
|
||||||
| otherwise = 0.02 * fromIntegral i
|
| otherwise = 0.02 * fromIntegral i
|
||||||
|
|
||||||
crMvForward ::
|
crMvForward :: Float -> Creature -> Creature
|
||||||
-- | Speed
|
|
||||||
Float ->
|
|
||||||
Creature ->
|
|
||||||
Creature
|
|
||||||
crMvForward speed = crMvBy (V2 speed 0)
|
crMvForward speed = crMvBy (V2 speed 0)
|
||||||
|
|
||||||
advanceStepCounter ::
|
advanceStepCounter :: Float -> Creature -> Creature
|
||||||
-- | Speed
|
|
||||||
Float ->
|
|
||||||
Creature ->
|
|
||||||
Creature
|
|
||||||
advanceStepCounter speed = crStance . carriage %~ f
|
advanceStepCounter speed = crStance . carriage %~ f
|
||||||
where
|
where
|
||||||
f car = case car of
|
f car = case car of
|
||||||
@@ -54,9 +49,6 @@ advanceStepCounter speed = crStance . carriage %~ f
|
|||||||
Walking i ff -> Walking (i + ceiling speed) ff
|
Walking i ff -> Walking (i + ceiling speed) ff
|
||||||
_ -> car
|
_ -> car
|
||||||
|
|
||||||
creatureTurn :: Float -> Creature -> Creature
|
|
||||||
creatureTurn a = crDir +~ a
|
|
||||||
|
|
||||||
creatureTurnTo :: Point2 -> Creature -> Creature
|
creatureTurnTo :: Point2 -> Creature -> Creature
|
||||||
creatureTurnTo p cr
|
creatureTurnTo p cr
|
||||||
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
|
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
|
||||||
@@ -67,34 +59,25 @@ creatureTurnTo p cr
|
|||||||
|
|
||||||
-- the following is perhaps not ideal because it mixes normalizeAngle with
|
-- the following is perhaps not ideal because it mixes normalizeAngle with
|
||||||
-- angleVV, but it seems to work
|
-- angleVV, but it seems to work
|
||||||
creatureTurnTowardDir ::
|
creatureTurnTowardDir :: Float -> Float -> Creature -> Creature
|
||||||
-- | Angle
|
|
||||||
Float ->
|
|
||||||
-- | Turn speed
|
|
||||||
Float ->
|
|
||||||
Creature ->
|
|
||||||
Creature
|
|
||||||
creatureTurnTowardDir a turnSpeed cr
|
creatureTurnTowardDir a turnSpeed cr
|
||||||
| abs (normalizeAnglePi (a - cdir)) <= turnSpeed = cr & crDir .~ dirToTarget
|
| abs (normalizeAnglePi (a - cdir)) <= turnSpeed = cr & crDir .~ dirToTarget
|
||||||
| otherwise = cr & crDir %~ addOrSub turnSpeed
|
| otherwise = cr & crDir %~ addOrSub turnSpeed
|
||||||
where
|
where
|
||||||
addOrSub | isLeftOfA dirToTarget cdir = (+)
|
addOrSub
|
||||||
|
| isLeftOfA dirToTarget cdir = (+)
|
||||||
| otherwise = subtract
|
| otherwise = subtract
|
||||||
cdir = _crDir cr
|
cdir = _crDir cr
|
||||||
dirToTarget = argV $ rotateV a (V2 1 0)
|
dirToTarget = argV $ rotateV a (V2 1 0)
|
||||||
|
|
||||||
|
|
||||||
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
||||||
creatureTurnToward p turnSpeed cr
|
creatureTurnToward p turnSpeed cr
|
||||||
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
|
| vToTarg == V2 0 0 = cr -- this should deal with the angleVV error
|
||||||
| errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed =
|
-- | errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed =
|
||||||
|
| angleVV vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed =
|
||||||
cr & crDir .~ dirToTarget
|
cr & crDir .~ dirToTarget
|
||||||
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed
|
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed
|
||||||
| otherwise = cr & crDir -~ turnSpeed
|
| otherwise = cr & crDir -~ turnSpeed
|
||||||
where
|
where
|
||||||
vToTarg = p -.- _crPos cr
|
vToTarg = p -.- _crPos cr
|
||||||
dirToTarget = argV vToTarg
|
dirToTarget = argV vToTarg
|
||||||
|
|
||||||
-- | Speed modifier of an item when not aiming.
|
|
||||||
equipSpeed :: Item -> Float
|
|
||||||
equipSpeed _ = 1
|
|
||||||
|
|||||||
Reference in New Issue
Block a user