Fix bug on dropping item when reloading
This commit is contained in:
+25
-18
@@ -6,6 +6,23 @@ 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
|
||||
( crIsAiming
|
||||
, crIsReloading
|
||||
, crIsArmouredFrom
|
||||
, oneH
|
||||
, twists
|
||||
, twoFlat
|
||||
, crWeaponReady
|
||||
, crInAimStance
|
||||
, crNearPoint
|
||||
, isAnimate
|
||||
, crCanShoot
|
||||
, crHasTargetLOS
|
||||
, crAwayFromPost
|
||||
, crHasTarget
|
||||
, crStratConMatches
|
||||
, crSafeDistFromTarg
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base.Collide
|
||||
@@ -14,29 +31,22 @@ import SameConstr
|
||||
|
||||
import Data.List (find)
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
andTest :: (a -> Bool) -> (a -> Bool) -> a -> Bool
|
||||
andTest f g a = f a && g a
|
||||
|
||||
onBoth :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c
|
||||
onBoth f g h x = f (g x) (h x)
|
||||
|
||||
crIsReloading :: Creature -> Bool
|
||||
crIsReloading cr = case cr ^? crInvSel . iselAction of
|
||||
Just ReloadAction {} -> True
|
||||
_ -> False
|
||||
|
||||
crWeaponReady :: Creature -> Bool
|
||||
crWeaponReady cr = isNothing $ cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just
|
||||
crWeaponReady cr = fromMaybe False $ do
|
||||
ic <- cr ^? crInv . ix (crSel cr) . itConsumption
|
||||
return (_laLoaded ic > 0 && _laPrimed ic)
|
||||
|
||||
crCanSeeCr :: Creature -> (World, Creature) -> Bool
|
||||
crCanSeeCr tcr (w,cr) = hasLOS (_crPos cr) (_crPos tcr) w
|
||||
|
||||
crCanSeeCID :: Int -> (World, Creature) -> Bool
|
||||
crCanSeeCID cid (w,cr) = hasLOS (_crPos cr) (_crPos $ _creatures w IM.! cid) w
|
||||
|
||||
crIsAiming :: Creature -> Bool
|
||||
crIsAiming cr = _posture (_crStance cr) == Aiming
|
||||
|
||||
@@ -64,14 +74,11 @@ crAwayFromPost cr = case find sentinelGoal . _crGoal $ _crActionPlan cr of
|
||||
sentinelGoal (SentinelAt _ _) = True
|
||||
sentinelGoal _ = False
|
||||
|
||||
crHasAmmo :: Creature -> Bool
|
||||
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (crSel cr) . itConsumption . laLoaded
|
||||
|
||||
crCanShoot :: Creature -> Bool
|
||||
crCanShoot p = crIsAiming p && crHasAmmo p
|
||||
crCanShoot cr = crIsAiming cr && crWeaponReady cr
|
||||
|
||||
crInAimStance :: AimStance -> Creature -> Bool
|
||||
crInAimStance as cr = crIsAiming cr -- || (_posture (_crStance cr) == Reloading && hasAmmo cr)
|
||||
crInAimStance as cr = crIsAiming cr
|
||||
&& cr ^? crInv . ix (crSel cr) . itUse . useAim . aimStance == Just as
|
||||
|
||||
oneH :: Creature -> Bool
|
||||
@@ -106,8 +113,8 @@ hasFrontArmour p cr = fromMaybe False $ do
|
||||
--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)
|
||||
--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
|
||||
|
||||
Reference in New Issue
Block a user