Creature springs checks for heights

This commit is contained in:
2026-04-04 08:33:09 +01:00
parent 615295ca3e
commit def204d211
8 changed files with 96 additions and 66 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ updateExpBarrel ps cr w = case cr ^. crHP of
HP _ -> HP _ ->
w w
& makeExplosionAt ((cr ^. crPos) & _z +~ 20) 0 & makeExplosionAt ((cr ^. crPos) & _z +~ 20) 0
& cWorld . lWorld . creatures . ix (_crID cr) . crHP .~ CrIsGibs & cWorld . lWorld . creatures . ix (_crID cr) . crHP .~ CrDestroyed Gibbed
_ -> w _ -> w
where where
f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos . _xy) (argV p) w' f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos . _xy) (argV p) w'
@@ -44,7 +44,7 @@ updateExpBarrel ps cr w = case cr ^. crHP of
updateBarrel :: Creature -> World -> World updateBarrel :: Creature -> World -> World
updateBarrel cr = case cr ^. crHP of updateBarrel cr = case cr ^. crHP of
HP x | x > 0 -> doDamage (cr ^. crID) HP x | x > 0 -> doDamage (cr ^. crID)
HP _ -> cWorld . lWorld . creatures . ix (_crID cr) . crHP .~ CrIsGibs HP _ -> cWorld . lWorld . creatures . ix (_crID cr) . crHP .~ CrDestroyed Gibbed
_ -> id _ -> id
damsToExpBarrel :: [Damage] -> Creature -> Creature damsToExpBarrel :: [Damage] -> Creature -> Creature
+7 -3
View File
@@ -32,6 +32,7 @@ module Dodge.Base.Collide (
anythingHitCirc, anythingHitCirc,
collide3WallsFloor, collide3WallsFloor,
collide3, collide3,
crHeight,
) where ) where
import Data.Foldable import Data.Foldable
@@ -174,10 +175,13 @@ collide3Creature sp cr (ep, m) = fromMaybe (ep, m) $ do
crHeight :: Creature -> Maybe Float crHeight :: Creature -> Maybe Float
crHeight cr = case cr ^. crHP of crHeight cr = case cr ^. crHP of
HP{} -> Just 25 HP{} -> Just $ case cr ^. crType of
HoverCrit {} -> 10
ChaseCrit {} -> 25
Avatar {} -> 25
_ -> error "Need to define crHeight for this crType"
CrIsCorpse{} -> Just 5 CrIsCorpse{} -> Just 5
CrIsGibs -> Nothing CrDestroyed{} -> Nothing
CrIsPitted -> Nothing
wallToSurface :: Wall -> (Point3, Point3, [(Point3, Point3)]) wallToSurface :: Wall -> (Point3, Point3, [(Point3, Point3)])
wallToSurface wl = (g x, g $ vNormal (x - y), [(g x, g (y - x)), (g y, g (x - y))]) wallToSurface wl = (g x, g $ vNormal (x - y), [(g x, g (y - x)), (g y, g (x - y))])
+1 -2
View File
@@ -139,6 +139,5 @@ hasAutoDoorBody :: Creature -> Bool
hasAutoDoorBody cr = case cr ^. crHP of hasAutoDoorBody cr = case cr ^. crHP of
HP {} -> True HP {} -> True
CrIsCorpse {} -> True CrIsCorpse {} -> True
CrIsGibs -> False CrDestroyed {} -> False
CrIsPitted -> False
+2 -2
View File
@@ -39,7 +39,7 @@ import ShapePicture.Data
-- allow for knockbacks etc to be determined as well as intended movements -- allow for knockbacks etc to be determined as well as intended movements
updateCreature :: Creature -> World -> World updateCreature :: Creature -> World -> World
updateCreature cr updateCreature cr
| cr ^. crPos . _z < negate 300 = (tocr . crHP .~ CrIsPitted) . destroyAllInvItems cr | cr ^. crPos . _z < negate 300 = (tocr . crHP .~ CrDestroyed Pitted) . destroyAllInvItems cr
| CrIsCorpse _ <- cr ^. crHP = updateCarriage (_crID cr) . chasmTestCorpse cr | CrIsCorpse _ <- cr ^. crHP = updateCarriage (_crID cr) . chasmTestCorpse cr
| null (cr ^? crHP . _HP) = id | null (cr ^? crHP . _HP) = id
| otherwise = updateLivingCreature cr | otherwise = updateLivingCreature cr
@@ -143,7 +143,7 @@ corpseOrGib cr = case cr ^? crDamage . to maxDamageType . _Just . _1 of
Just PhysicalDamage Just PhysicalDamage
| _crPain cr > 200 -> | _crPain cr > 200 ->
makeCrGibs cr makeCrGibs cr
. sethp CrIsGibs . sethp (CrDestroyed Gibbed)
. dodeathsound GibsDeath . dodeathsound GibsDeath
_ -> _ ->
sethp (CrIsCorpse thecorpse) sethp (CrIsCorpse thecorpse)
+5 -2
View File
@@ -59,11 +59,13 @@ data Creature = Creature
, _crWallTouch :: IM.IntMap Point2 , _crWallTouch :: IM.IntMap Point2
} }
-- Prisms, not lenses
data CrHP data CrHP
= HP Int = HP Int
| CrIsCorpse SPic | CrIsCorpse SPic
| CrIsGibs | CrDestroyed CrDestructionType
| CrIsPitted
data CrDestructionType = Gibbed | Pitted
data DeathType = CookDeath | PoisonDeath | PlainDeath | GibsDeath data DeathType = CookDeath | PoisonDeath | PlainDeath | GibsDeath
@@ -93,4 +95,5 @@ concat
[ ''Creature [ ''Creature
, ''Intention , ''Intention
, ''CrHP , ''CrHP
, ''CrDestructionType
] ]
+2 -1
View File
@@ -23,7 +23,8 @@ data Vocalization
data CrMvType data CrMvType
= NoMvType = NoMvType
| MvWalking {_mvSpeed :: Float} | MvWalking {_mvSpeed :: Float} -- note this may interact with a friction element
-- so currently 26.04.03 the actual max speed when walking is twice this
| CrMvType | CrMvType
{ _mvSpeed :: Float { _mvSpeed :: Float
, _mvTurnRad :: FloatFloat , _mvTurnRad :: FloatFloat
+68 -52
View File
@@ -1,50 +1,58 @@
{-# OPTIONS_GHC -Wno-unused-imports #-} {-# OPTIONS_GHC -Wno-unused-imports #-}
module Dodge.TestString where module Dodge.TestString where
import Dodge.Creature.Picture
import Dodge.WallCreatureCollisions
import Data.List ((\\))
import ShortShow
import Geometry
import qualified SDL
import Linear
import Dodge.ListDisplayParams
import Dodge.SelectionSections
import qualified Control.Foldl as L
import Dodge.DoubleTree
import Dodge.Data.DoubleTree
import Dodge.Item.Grammar
import Dodge.Item.Display
import AesonHelp import AesonHelp
import Dodge.SmoothScroll import qualified Control.Foldl as L
import HelpNum
import Dodge.Base.Coordinate
import Geometry.Vector
import Data.Maybe
import Dodge.Render.Lights
import Data.Aeson (ToJSON)
import Data.ByteString.Lazy.Char8 (unpack)
import qualified Data.Aeson.Encode.Pretty as AEP
import Control.Lens import Control.Lens
import Dodge.Data.Universe import Data.Aeson (ToJSON)
import qualified IntMapHelp as IM import qualified Data.Aeson.Encode.Pretty as AEP
import qualified Data.Map.Strict as M import Data.ByteString.Lazy.Char8 (unpack)
import NewInt
import Data.Foldable import Data.Foldable
import Data.List ((\\))
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid import Data.Monoid
import Dodge.Base.Coordinate
import Dodge.Creature.Picture
import Dodge.Data.DoubleTree
import Dodge.Data.Universe
import Dodge.DoubleTree
import Dodge.Item.Display
import Dodge.Item.Grammar
import Dodge.ListDisplayParams
import Dodge.Render.Lights
import Dodge.SelectionSections
import Dodge.SmoothScroll
import Dodge.WallCreatureCollisions
import Geometry
import Geometry.Vector
import HelpNum
import qualified IntMapHelp as IM
import Linear
import NewInt
import RandomHelp import RandomHelp
import qualified SDL
import ShortShow
tocrs ::
( IM.IntMap Creature ->
Const (Endo [String]) (IM.IntMap Creature)
) ->
Universe ->
Const (Endo [String]) Universe
tocrs = uvWorld . cWorld . lWorld . creatures
testStringInit :: Universe -> [String] testStringInit :: Universe -> [String]
testStringInit u = [show p, show op', show oop, show (op' - oop), show . norm $ op' - oop, show d] testStringInit u = u ^.. tocrs . each . crStance . carriage . to show
<> u ^.. tocr . crStance . carriage . to show
<> u ^.. tocr . crMvDir . to show -- where
where -- tocr = uvWorld . cWorld . lWorld . creatures . ix 0
tocr = uvWorld . cWorld . lWorld . creatures . ix 0 -- f = fromMaybe 0
f = fromMaybe 0 -- p = f $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crPos
p = f $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crPos -- op' = f $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crOldPos
op' = f $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crOldPos -- oop = fromMaybe 0 $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crOldOldPos
oop = fromMaybe 0 $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crOldOldPos -- d = fromMaybe 0 $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crDir
d = fromMaybe 0 $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crDir
-- u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crActionPlan . apStrategy . to show -- u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crActionPlan . apStrategy . to show
-- <> u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crActionPlan . apAction . to show -- <> u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crActionPlan . apAction . to show
-- <> u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crPerception . cpAttention . to show -- <> u ^.. uvWorld . cWorld . lWorld . creatures . ix 1 . crPerception . cpAttention . to show
@@ -58,7 +66,7 @@ testStringInit u = [show p, show op', show oop, show (op' - oop), show . norm $
-- a <> fromMaybe [] (do -- a <> fromMaybe [] (do
-- a w1 <- u ^? uvWorld . cWorld . lWorld . walls . ix 18 -- a w1 <- u ^? uvWorld . cWorld . lWorld . walls . ix 18
-- a w2 <- u ^? uvWorld . cWorld . lWorld . walls . ix 61 -- a w2 <- u ^? uvWorld . cWorld . lWorld . walls . ix 61
-- a let -- a let
-- a f = uncurry (-) . (^. wlLine) -- a f = uncurry (-) . (^. wlLine)
-- a g = argV . f -- a g = argV . f
-- a h = normalizeV . uncurry (-) . (^. wlLine) -- a h = normalizeV . uncurry (-) . (^. wlLine)
@@ -72,29 +80,37 @@ testStringInit u = [show p, show op', show oop, show (op' - oop), show . norm $
-- a ] -- a ]
-- a ) -- a )
-- <> (fmap show $ u ^.. uvWorld . cWorld . lWorld . machines . each . mcMaterial) -- <> (fmap show $ u ^.. uvWorld . cWorld . lWorld . machines . each . mcMaterial)
--testStringInit u = map show (u ^.. uvWorld . cWorld . lWorld . machines . traverse . mcDir) -- testStringInit u = map show (u ^.. uvWorld . cWorld . lWorld . machines . traverse . mcDir)
--testStringInit u = map show -- testStringInit u = map show
-- (u ^.. uvWorld . cWorld . lWorld . machines . traverse .mcType . _McDistributer) -- (u ^.. uvWorld . cWorld . lWorld . machines . traverse .mcType . _McDistributer)
-- <> -- <>
-- map f (u ^.. uvWorld . cWorld . lWorld . machines . traverse) -- map f (u ^.. uvWorld . cWorld . lWorld . machines . traverse)
-- where -- where
-- f mc = show (mc ^. mcID) <> shortShow (mc ^. mcType) -- f mc = show (mc ^. mcID) <> shortShow (mc ^. mcType)
-- [show $ foldMap (foldMap (Sum . length . (^. seObstacles))) -- [show $ foldMap (foldMap (Sum . length . (^. seObstacles)))
-- $ u ^. uvWorld . cWorld . incGraph] -- $ u ^. uvWorld . cWorld . incGraph]
-- foldMap prettyShort $ u ^? uvWorld . cWorld . lWorld . machines . ix 0 . mcType . _McProxSensor -- foldMap prettyShort $ u ^? uvWorld . cWorld . lWorld . machines . ix 0 . mcType . _McProxSensor
--testStringInit u = foldMap prettyShort $ u ^.. uvWorld . cWorld . lWorld . machines -- testStringInit u = foldMap prettyShort $ u ^.. uvWorld . cWorld . lWorld . machines
-- showh _ = "" -- showh _ = ""
-- shortShow -- shortShow
topTestPart :: Universe -> [String] topTestPart :: Universe -> [String]
topTestPart u = [maybe "" showManObj $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . manObject topTestPart u =
[ maybe "" showManObj $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . manObject
] ]
showManObj :: ManipulatedObject -> String showManObj :: ManipulatedObject -> String
showManObj SortInventory = "SortInventory" showManObj SortInventory = "SortInventory"
showManObj (SelectedItem x y as z) = "SelItem: "++ show x++ " Root: "++show y++" Attached: "++show z showManObj (SelectedItem x y as z) =
++ " AimStance: " ++ show as "SelItem: "
++ show x
++ " Root: "
++ show y
++ " Attached: "
++ show z
++ " AimStance: "
++ show as
showManObj SelNothing = "SelNothing" showManObj SelNothing = "SelNothing"
showManObj SortCloseItem = "SortCloseItem" showManObj SortCloseItem = "SortCloseItem"
showManObj (SelCloseItem x) = "CloseItem " ++ show x showManObj (SelCloseItem x) = "CloseItem " ++ show x
@@ -103,10 +119,10 @@ showManObj (SelCloseButton x) = "CloseButton " ++ show x
showTimeFlow :: TimeFlowStatus -> String showTimeFlow :: TimeFlowStatus -> String
showTimeFlow tfs = case tfs of showTimeFlow tfs = case tfs of
RespawnDelay i -> "Respawndelay"++show i RespawnDelay i -> "Respawndelay" ++ show i
NormalTimeFlow -> "NormalTimeFlow" NormalTimeFlow -> "NormalTimeFlow"
ItemScrollTimeFlow {_reverseAmount = ra } -> "ItemScrollTimeFlow" ++ show ra ItemScrollTimeFlow{_reverseAmount = ra} -> "ItemScrollTimeFlow" ++ show ra
CameraScrollTimeFlow {_reverseAmount = ra } -> "CameraScrollTimeFlow" ++ show ra CameraScrollTimeFlow{_reverseAmount = ra} -> "CameraScrollTimeFlow" ++ show ra
RewindLeftClick {_reverseAmount = ra } -> "RewindLeftClick" ++ show ra RewindLeftClick{_reverseAmount = ra} -> "RewindLeftClick" ++ show ra
PausedTimeFlow {_timeFlowCharge = ra } -> "PausedTimeFlow" ++ show ra PausedTimeFlow{_timeFlowCharge = ra} -> "PausedTimeFlow" ++ show ra
PauseTimeMessage {} -> "PausedTimeMessage" PauseTimeMessage{} -> "PausedTimeMessage"
+9 -2
View File
@@ -975,16 +975,23 @@ canSpring cr =
cr ^. crPos . _z >= 0 && case cr ^. crHP of cr ^. crPos . _z >= 0 && case cr ^. crHP of
HP{} -> True HP{} -> True
CrIsCorpse{} -> True CrIsCorpse{} -> True
CrIsGibs -> False CrDestroyed{} -> False
CrIsPitted -> False
-- should possibly limit how big this can get
crCrSpring :: Creature -> Creature -> World -> World crCrSpring :: Creature -> Creature -> World -> World
crCrSpring c1 c2 crCrSpring c1 c2
| id1 == id2 = id | id1 == id2 = id
| vec == V2 0 0 = id | vec == V2 0 0 = id
| diff >= comRad = id | diff >= comRad = id
| diffheight = id
| otherwise = cWorld . lWorld . creatures %~ ( olap c1 c2 . olap' c2 c1) | otherwise = cWorld . lWorld . creatures %~ ( olap c1 c2 . olap' c2 c1)
where where
z c = c ^. crPos . _z
h c = fmap (+ z c) (crHeight c)
diffheight = fromMaybe True $ do
h1 <- h c1
h2 <- h c2
return $ (z c1 > h2 || z c2 > h1)
olap a b = ix (a ^. crID) . crPos . _xy +~ overlap b olap a b = ix (a ^. crID) . crPos . _xy +~ overlap b
olap' a b = ix (a ^. crID) . crPos . _xy -~ overlap b olap' a b = ix (a ^. crID) . crPos . _xy -~ overlap b
id1 = _crID c1 id1 = _crID c1