Cleanup creature properties

This commit is contained in:
2022-05-24 23:26:21 +01:00
parent 64a01849d4
commit 546c279fae
8 changed files with 51 additions and 65 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
module Dodge.Creature.Damage where module Dodge.Creature.Damage where
import Dodge.Data import Dodge.Data
import Dodge.Creature.Property import Dodge.Creature.Test
import Dodge.Particle.Spark import Dodge.Particle.Spark
import Dodge.Particle.Bullet.Spawn import Dodge.Particle.Bullet.Spawn
import Color import Color
+1 -1
View File
@@ -1,6 +1,6 @@
module Dodge.Creature.HandPos where module Dodge.Creature.HandPos where
import Dodge.Data import Dodge.Data
import Dodge.Creature.Stance import Dodge.Creature.Test
--import Shape --import Shape
import ShapePicture import ShapePicture
import Geometry import Geometry
+1 -1
View File
@@ -18,7 +18,7 @@ import Dodge.Data
--import Dodge.Picture.Layer --import Dodge.Picture.Layer
import Dodge.Clock import Dodge.Clock
import Dodge.Creature.HandPos (translateToRightHand,translateToLeftHand) import Dodge.Creature.HandPos (translateToRightHand,translateToLeftHand)
import Dodge.Creature.Stance import Dodge.Creature.Test
--import Dodge.Debug.Picture --import Dodge.Debug.Picture
import Picture import Picture
import Geometry import Geometry
-40
View File
@@ -1,40 +0,0 @@
module Dodge.Creature.Property
( crIsArmouredFrom
, crNearSeg
, crNearPoint
) where
import Dodge.Data
import Dodge.Creature.Stance
import Geometry
import Data.Maybe
import Control.Lens
-- the use of crOldPos is because the damage position is calculated on the
-- previous frame
-- Not sure if it is a good idea
crIsArmouredFrom :: Point2 -> Creature -> Bool
crIsArmouredFrom = hasFrontArmour
hasFrontArmour :: Point2 -> Creature -> Bool
hasFrontArmour p cr = fromMaybe False $ do
invid <- cr ^? crEquipment . ix OnChest
ittype <- cr ^? crInv . ix invid . itType
return $ FRONTARMOUR == ittype
&& p /= _crOldPos cr
&& angleVV (unitVectorAtAngle (_crDir cr + frontarmdirection)) (p -.- _crOldPos cr) < pi/2
-- even though angleVV can generate NaN, the comparison seems to deal with it
where
frontarmdirection
| crInAimStance OneHand cr = 0.5
| crInAimStance TwoHandTwist cr = negate 1
| otherwise = 0
--crOnSeg :: Point2 -> Point2 -> Creature -> Bool
--crOnSeg p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr)
crNearSeg :: Float -> Point2 -> Point2 -> Creature -> Bool
crNearSeg d p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr + d)
crNearPoint :: Float -> Point2 -> Creature -> Bool
crNearPoint d p cr = dist (_crPos cr) p < d + _crRad cr
-17
View File
@@ -1,17 +0,0 @@
module Dodge.Creature.Stance where
import Dodge.Data
import Dodge.Creature.Test
import LensHelp
crInAimStance :: AimStance -> Creature -> Bool
crInAimStance as cr = crIsAiming cr -- || (_posture (_crStance cr) == Reloading && hasAmmo cr)
&& cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimStance == Just as
oneH :: Creature -> Bool
oneH = crInAimStance OneHand
twoFlat :: Creature -> Bool
twoFlat = crInAimStance TwoHandFlat
twists :: Creature -> Bool
twists = crInAimStance TwoHandTwist
+46 -3
View File
@@ -1,8 +1,9 @@
{- | {- |
Module testing for properties of creatures, whether they are reloading, etc. Module testing for properties of creatures, whether they are reloading, etc.
Each function takes the world and a creature and returns a bool. Each function takes a creature, and possibly other parameters, and returns a bool.
Note that the creature NEED NOT be the same as the creature with that id in the world, Note that if there is a world parameter,
in fact in some cases a creature with that id may not even exist. the creature NEED NOT be the same as the creature with that id in the world,
in fact a creature with that id need not exist.
-} -}
module Dodge.Creature.Test module Dodge.Creature.Test
where where
@@ -65,3 +66,45 @@ crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumpti
crCanShoot :: Creature -> Bool crCanShoot :: Creature -> Bool
crCanShoot p = crIsAiming p && crHasAmmo p crCanShoot p = crIsAiming p && crHasAmmo p
crInAimStance :: AimStance -> Creature -> Bool
crInAimStance as cr = crIsAiming cr -- || (_posture (_crStance cr) == Reloading && hasAmmo cr)
&& cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimStance == Just as
oneH :: Creature -> Bool
oneH = crInAimStance OneHand
twoFlat :: Creature -> Bool
twoFlat = crInAimStance TwoHandFlat
twists :: Creature -> Bool
twists = crInAimStance TwoHandTwist
-- the use of crOldPos is because the damage position is calculated on the
-- previous frame
-- Not sure if it is a good idea
crIsArmouredFrom :: Point2 -> Creature -> Bool
crIsArmouredFrom = hasFrontArmour
hasFrontArmour :: Point2 -> Creature -> Bool
hasFrontArmour p cr = fromMaybe False $ do
invid <- cr ^? crEquipment . ix OnChest
ittype <- cr ^? crInv . ix invid . itType
return $ FRONTARMOUR == ittype
&& p /= _crOldPos cr
&& angleVV (unitVectorAtAngle (_crDir cr + frontarmdirection)) (p -.- _crOldPos cr) < pi/2
-- even though angleVV can generate NaN, the comparison seems to deal with it
where
frontarmdirection
| crInAimStance OneHand cr = 0.5
| crInAimStance TwoHandTwist cr = negate 1
| otherwise = 0
--crOnSeg :: Point2 -> Point2 -> Creature -> Bool
--crOnSeg p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr)
crNearSeg :: Float -> Point2 -> Point2 -> Creature -> Bool
crNearSeg d p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr + d)
crNearPoint :: Float -> Point2 -> Creature -> Bool
crNearPoint d p cr = dist (_crPos cr) p < d + _crRad cr
+1 -1
View File
@@ -66,7 +66,7 @@ import Dodge.WorldEvent
import Dodge.RandomHelp import Dodge.RandomHelp
import Dodge.Inventory.Lock import Dodge.Inventory.Lock
import Dodge.Creature.HandPos import Dodge.Creature.HandPos
import Dodge.Creature.Stance import Dodge.Creature.Test
--import Dodge.Default --import Dodge.Default
import Dodge.Base import Dodge.Base
import Sound.Data import Sound.Data
+1 -1
View File
@@ -9,7 +9,7 @@ import Dodge.Base
import Color import Color
import Geometry import Geometry
import Dodge.LevelGen.Data import Dodge.LevelGen.Data
import Dodge.Creature.Property import Dodge.Creature.Test
import Dodge.LevelGen.Switch import Dodge.LevelGen.Switch
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM