diff --git a/src/Dodge/Creature/Damage.hs b/src/Dodge/Creature/Damage.hs index 3e0f68a5d..3708a7d15 100644 --- a/src/Dodge/Creature/Damage.hs +++ b/src/Dodge/Creature/Damage.hs @@ -1,6 +1,6 @@ module Dodge.Creature.Damage where import Dodge.Data -import Dodge.Creature.Property +import Dodge.Creature.Test import Dodge.Particle.Spark import Dodge.Particle.Bullet.Spawn import Color diff --git a/src/Dodge/Creature/HandPos.hs b/src/Dodge/Creature/HandPos.hs index db5c14335..4da5bfcbb 100644 --- a/src/Dodge/Creature/HandPos.hs +++ b/src/Dodge/Creature/HandPos.hs @@ -1,6 +1,6 @@ module Dodge.Creature.HandPos where import Dodge.Data -import Dodge.Creature.Stance +import Dodge.Creature.Test --import Shape import ShapePicture import Geometry diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 4d0019570..6246a5aca 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -18,7 +18,7 @@ import Dodge.Data --import Dodge.Picture.Layer import Dodge.Clock import Dodge.Creature.HandPos (translateToRightHand,translateToLeftHand) -import Dodge.Creature.Stance +import Dodge.Creature.Test --import Dodge.Debug.Picture import Picture import Geometry diff --git a/src/Dodge/Creature/Property.hs b/src/Dodge/Creature/Property.hs deleted file mode 100644 index c996444bc..000000000 --- a/src/Dodge/Creature/Property.hs +++ /dev/null @@ -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 diff --git a/src/Dodge/Creature/Stance.hs b/src/Dodge/Creature/Stance.hs deleted file mode 100644 index baf6e2bfb..000000000 --- a/src/Dodge/Creature/Stance.hs +++ /dev/null @@ -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 diff --git a/src/Dodge/Creature/Test.hs b/src/Dodge/Creature/Test.hs index 67023c87e..19735ce25 100644 --- a/src/Dodge/Creature/Test.hs +++ b/src/Dodge/Creature/Test.hs @@ -1,8 +1,9 @@ {- | Module testing for properties of creatures, whether they are reloading, etc. -Each function takes the world and a creature and returns a bool. -Note that the creature NEED NOT be the same as the creature with that id in the world, -in fact in some cases a creature with that id may not even exist. +Each function takes a creature, and possibly other parameters, and returns a bool. +Note that if there is a world parameter, +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 where @@ -65,3 +66,45 @@ crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumpti crCanShoot :: Creature -> Bool 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 diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 359a34636..11069641a 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -66,7 +66,7 @@ import Dodge.WorldEvent import Dodge.RandomHelp import Dodge.Inventory.Lock import Dodge.Creature.HandPos -import Dodge.Creature.Stance +import Dodge.Creature.Test --import Dodge.Default import Dodge.Base import Sound.Data diff --git a/src/Dodge/Placement/Instance/Door.hs b/src/Dodge/Placement/Instance/Door.hs index 3dfcdc8a7..c8f86980b 100644 --- a/src/Dodge/Placement/Instance/Door.hs +++ b/src/Dodge/Placement/Instance/Door.hs @@ -9,7 +9,7 @@ import Dodge.Base import Color import Geometry import Dodge.LevelGen.Data -import Dodge.Creature.Property +import Dodge.Creature.Test import Dodge.LevelGen.Switch import qualified Data.IntMap.Strict as IM