diff --git a/src/Dodge/Creature/Update.hs b/src/Dodge/Creature/Update.hs index fbb1c4015..f61f80102 100644 --- a/src/Dodge/Creature/Update.hs +++ b/src/Dodge/Creature/Update.hs @@ -25,12 +25,12 @@ updateCreature cr = chasmTest cr . case _crType cr of chasmTest :: Creature -> World -> World chasmTest cr w - | _crZVel cr < 0 = w & cWorld . lWorld . creatures . ix (_crID cr) . crZVel -~ 1 + | _crZVel cr < 0 = w & cWorld . lWorld . creatures . ix (_crID cr) . crZVel -~ 0.5 & cWorld . lWorld . creatures . ix (_crID cr) . crZ +~ _crZVel cr | Just (x,y) <- List.find g (foldMap loopPairs $ w ^. cWorld . chasms) = w & soundContinue (CrChasm (_crID cr)) (_crPos cr) debrisS (Just 100) & cWorld . lWorld . creatures . ix (_crID cr) . crPos -~ normalizeV (vNormal (x-y)) - | any f (w ^. cWorld . chasms) = w & cWorld . lWorld . creatures . ix (_crID cr) . crZVel -~ 1 + | any f (w ^. cWorld . chasms) = w & cWorld . lWorld . creatures . ix (_crID cr) . crZVel -~ 0.5 | otherwise = w where g = uncurry $ circOnSeg (_crPos cr) (crRad $ cr ^. crType) diff --git a/src/Dodge/Data/Projectile.hs b/src/Dodge/Data/Projectile.hs index 770d08ed3..c4b2c033c 100644 --- a/src/Dodge/Data/Projectile.hs +++ b/src/Dodge/Data/Projectile.hs @@ -16,13 +16,13 @@ import Dodge.Data.Payload data Projectile = Shell { _pjPos :: Point2 + , _pjZ :: Float , _pjVel :: Point2 , _pjDir :: Float , _pjSpin :: Float , _pjID :: Int , _pjPayload :: Payload , _pjTimer :: Int - , _pjZ :: Float , _pjZVel :: Float , _pjBarrelSpin :: Maybe (Int, Float) , _pjType :: ProjectileType @@ -49,7 +49,7 @@ data RocketHoming data GrenadeHitEffect = GBounce {_bounceTolerance :: Float} | GStick - | GStuckCreature {_stuckCrID :: Int, _stuckCrOffset :: Point2, _stuckCrRot :: Float} + | GStuckCreature {_stuckCrID :: Int, _stuckCrOffset :: Point3, _stuckCrRot :: Float} | GStuckWall {_stuckWlID :: WallStructure} deriving (Show, Eq, Ord, Read) --Generic, Flat) diff --git a/src/Dodge/Projectile/Update.hs b/src/Dodge/Projectile/Update.hs index dbde2c8e6..1d5942534 100644 --- a/src/Dodge/Projectile/Update.hs +++ b/src/Dodge/Projectile/Update.hs @@ -22,12 +22,15 @@ import qualified IntMapHelp as IM import LensHelp import NewInt import RandomHelp +import Linear.Metric updateProjectile :: Projectile -> World -> World updateProjectile pj w = (cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer -~ 1) . shellExplosionCheck pj . moveProjectile pj + . tryThrust pj + . trySpin pj $ doGravityPU pj w doGravityPU :: Projectile -> World -> World @@ -38,16 +41,18 @@ doGravityPU pj applyGravityPU :: Projectile -> World -> World applyGravityPU pj w - | newz <= 0 && abs (pj ^. pjZVel) < 1 = - w - & topj . pjVel %~ decvel - & topj . pjSpin %~ decspin - | newz < 0 = - w & topj . pjZ .~ 0 - & topj . pjZVel %~ bouncez - & topj . pjVel %~ decvel - & topj . pjSpin %~ decspin - & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing +-- | newz <= 0 && abs (pj ^. pjZVel) < 1 = +-- w +-- & topj . pjVel %~ decvel +-- & topj . pjSpin %~ decspin +-- | newz < 0 = +-- w & topj . pjZ .~ 0 +-- & topj . pjZVel %~ bouncez +-- & topj . pjVel %~ decvel +-- & topj . pjSpin %~ decspin +-- & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing + | _pjZ pj < 1 && abs (norm $ _pjVel pj `v2z` _pjZVel pj) < 1 = w + & topj . pjVel .~ 0 | otherwise = w & topj . pjZ .~ newz & topj . pjZVel -~ 0.5 @@ -76,40 +81,54 @@ shellExplosionCheck pj w where time = _pjTimer pj +shellHitWall :: Point3 -> Point3 -> Wall -> Projectile -> World -> World +shellHitWall p' n wl pj w + | Just GStick <- pj ^? pjType . gnHitEffect = + w + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjType + .~ Grenade (GStuckWall (wl ^. wlStructure)) + & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos) + | Just x <- pj ^? pjType . gnHitEffect . bounceTolerance + , abs (dotV (pj ^. pjVel) (vNormal hitline)) < x = + w + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjVel + %~ reflectIn hitline + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos + .~ p - normalizeV (pj ^. pjVel) + & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing + | otherwise = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos .~ p + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0 + where + p = xyV3 p' + hitline = normalizeV $ uncurry (-) $ _wlLine wl + +shellHitFloor :: Point3 -> Point3 -> Projectile -> World -> World +shellHitFloor p' n pj w + | z < 1 && abs (norm $ _pjVel pj `v2z` zvel) < 1 = w + | otherwise = + w & topj . pjZ .~ 0.1 + & topj . pjZVel %~ bouncez + & topj . pjVel %~ decvel + & topj . pjSpin %~ decspin + & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing + where + bouncez x + | x < -1 = -0.5 * x + | otherwise = 0 + topj = cWorld . lWorld . projectiles . ix (pj ^. pjID) + zvel = pj ^. pjZVel + z = pj ^. pjZ + zvel + decvel v + | magV v > 1 = rotateV (5 * pj ^. pjSpin) $ 0.8 * v + | otherwise = 0 + decspin x + | abs x < 0.01 = 0 + | otherwise = x * 0.9 + ---- note this doesn't take into account moving walls, which may break the ---- bouncing in some way ---tryShellBounce :: (Point2, Either Creature Wall) -> Projectile -> World -> World ---tryShellBounce (p, Right wl) pj w --- | Just GStick <- pj ^? pjType . gnHitEffect = --- w --- & cWorld . lWorld . projectiles . ix (_pjID pj) . pjType --- .~ Grenade (GStuckWall (wl ^. wlStructure)) --- & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos) --- | Just x <- pj ^? pjType . gnHitEffect . bounceTolerance --- , abs (dotV (pj ^. pjVel) (vNormal hitline)) < x = --- w --- & cWorld . lWorld . projectiles . ix (_pjID pj) . pjVel --- %~ reflectIn hitline --- & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos --- .~ p - normalizeV (pj ^. pjVel) --- & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing --- where --- hitline = normalizeV $ uncurry (-) $ _wlLine wl ---tryShellBounce (p, Left cr) pj w --- | Just GStick <- pj ^? pjType . gnHitEffect = --- w --- & cWorld . lWorld . projectiles . ix (_pjID pj) . pjType --- .~ Grenade --- ( GStuckCreature --- (cr ^. crID) --- (rotateV (- cr ^. crDir) (p - cr ^. crPos)) --- (pj ^. pjDir - cr ^. crDir) --- ) --- & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos) ---tryShellBounce _ pj w = explodeShell pj w - -tryShellBounce' :: Point3 -> (Point3, Object ) -> Projectile -> World -> World -tryShellBounce' p' (n, OWall wl) pj w +tryShellBounce :: Point3 -> (Point3, Object ) -> Projectile -> World -> World +tryShellBounce p' (n, OWall wl) pj w | Just GStick <- pj ^? pjType . gnHitEffect = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjType @@ -126,21 +145,21 @@ tryShellBounce' p' (n, OWall wl) pj w where p = xyV3 p' hitline = normalizeV $ uncurry (-) $ _wlLine wl -tryShellBounce' p' (n,OCreature cr) pj w +tryShellBounce p' (n,OCreature cr) pj w | Just GStick <- pj ^? pjType . gnHitEffect = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjType .~ Grenade ( GStuckCreature (cr ^. crID) - (rotateV (- cr ^. crDir) (p - cr ^. crPos)) + (rotate3z (- cr ^. crDir) (p' - ((cr ^. crPos)`v2z`0))) (pj ^. pjDir - cr ^. crDir) ) & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos) where p = xyV3 p' -tryShellBounce' _ _ pj w = w -tryShellBounce' _ _ pj w = explodeShell pj w +tryShellBounce _ _ pj w = w +tryShellBounce _ _ pj w = explodeShell pj w destroyProjectile :: Maybe (NewInt ItmInt) -> Int -> World -> World destroyProjectile mitid pjid w = @@ -230,6 +249,9 @@ pjRemoteSetDirection ph pj w = case ph of where lw = w ^. cWorld . lWorld +moveStuckGrenade :: Creature -> Point3 -> Float -> Projectile -> World -> World +moveStuckGrenade cr p d pj w = w + moveProjectile :: Projectile -> World -> World moveProjectile pj w | Just GStuckWall{} <- pj ^? pjType . gnHitEffect = w @@ -240,21 +262,22 @@ moveProjectile pj w vel = cpos - cr ^. crOldPos in w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos - .~ cpos + rotateV cdir poff + .~ xyV3 ((cpos `v2z` 0) + rotate3z cdir poff) & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir .~ d + cdir & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjVel .~ vel | Just GStuckCreature{} <- pj ^? pjType . gnHitEffect = w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjType .~ Grenade GStick --- | Just thit <- thingHit p (p + _pjVel pj) w = tryShellBounce thit pj w + | (p,Just (n,OWall wl)) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w + = shellHitWall p n wl pj w + | (p,Just (n,OFloor)) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w + = shellHitFloor p n pj w | (p,Just po) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w - = tryShellBounce' p po pj w + = tryShellBounce p po pj w | otherwise = w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99 & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~ _pjSpin pj - & tryThrust pj - & trySpin pj where p = _pjPos pj diff --git a/src/Dodge/Prop/Moving.hs b/src/Dodge/Prop/Moving.hs index 0d499677f..b3d8fc0d1 100644 --- a/src/Dodge/Prop/Moving.hs +++ b/src/Dodge/Prop/Moving.hs @@ -24,10 +24,10 @@ updateDebrisChunk w db = (w, mdb) np = sp + sv cdb = case collide3WallsFloor sp np w of (p,Nothing) -> db & dbPos .~ p - & dbVel -~ V3 0 0 1 + & dbVel -~ V3 0 0 0.5 & dbRot %~ dospin (p,Just (n,_)) -> db & dbPos .~ p + (0.0001 * normalize n) - & dbVel .~ (0.7 * reflectInNormal n sv) - V3 0 0 1 + & dbVel .~ (0.7 * reflectInNormal n sv) - V3 0 0 0.5 dospin = (_dbSpin db *) mdb = do guard (np ^. _z > -1000) diff --git a/src/Dodge/TestString.hs b/src/Dodge/TestString.hs index 667d528ac..0bbe5b23d 100644 --- a/src/Dodge/TestString.hs +++ b/src/Dodge/TestString.hs @@ -28,9 +28,8 @@ import qualified IntMapHelp as IM import qualified Data.Map.Strict as M testStringInit :: Universe -> [String] -testStringInit u = [show $ u ^. uvWorld . testFloat - , show . length $ u ^. uvWorld . cWorld . lWorld . debris - ] +testStringInit u = + map show (u ^.. uvWorld . cWorld . lWorld . projectiles . each . pjZVel) -- map shortShow (u ^.. uvWorld . cWorld . lWorld . debris . each . to g) -- where -- g db = (pz,z,norm v) diff --git a/tags b/tags index 60000360a..52fb3b812 100644 --- a/tags +++ b/tags @@ -2163,16 +2163,16 @@ _pictureShaders src/Data/Preload/Render.hs 28;" f _piercedPoints src/Dodge/Data/Creature/Misc.hs 89;" f _pjBarrelSpin src/Dodge/Data/Projectile.hs 27;" f _pjDetonatorID src/Dodge/Data/Projectile.hs 29;" f -_pjDir src/Dodge/Data/Projectile.hs 20;" f -_pjID src/Dodge/Data/Projectile.hs 22;" f -_pjPayload src/Dodge/Data/Projectile.hs 23;" f +_pjDir src/Dodge/Data/Projectile.hs 21;" f +_pjID src/Dodge/Data/Projectile.hs 23;" f +_pjPayload src/Dodge/Data/Projectile.hs 24;" f _pjPos src/Dodge/Data/Projectile.hs 18;" f _pjScreenID src/Dodge/Data/Projectile.hs 30;" f -_pjSpin src/Dodge/Data/Projectile.hs 21;" f -_pjTimer src/Dodge/Data/Projectile.hs 24;" f +_pjSpin src/Dodge/Data/Projectile.hs 22;" f +_pjTimer src/Dodge/Data/Projectile.hs 25;" f _pjType src/Dodge/Data/Projectile.hs 28;" f -_pjVel src/Dodge/Data/Projectile.hs 19;" f -_pjZ src/Dodge/Data/Projectile.hs 25;" f +_pjVel src/Dodge/Data/Projectile.hs 20;" f +_pjZ src/Dodge/Data/Projectile.hs 19;" f _pjZVel src/Dodge/Data/Projectile.hs 26;" f _plIDCont src/Dodge/Data/GenWorld.hs 82;" f _plMID src/Dodge/Data/GenWorld.hs 81;" f @@ -2681,7 +2681,7 @@ anythingHitCirc src/Dodge/Base/Collide.hs 298;" f applyCME src/Dodge/HeldUse.hs 378;" f applyCreatureDamage src/Dodge/Creature/Damage.hs 13;" f applyEventIO src/Loop.hs 89;" f -applyGravityPU src/Dodge/Projectile/Update.hs 39;" f +applyGravityPU src/Dodge/Projectile/Update.hs 41;" f applyIndividualDamage src/Dodge/Creature/Damage.hs 16;" f applyInvLock src/Dodge/HeldUse.hs 444;" f applyMagnetsToBul src/Dodge/Bullet.hs 30;" f @@ -3257,7 +3257,7 @@ destroyMatS src/Dodge/Material/Sound.hs 7;" f destroyMcType src/Dodge/Machine/Destroy.hs 21;" f destroyMount src/Dodge/Block.hs 100;" f destroyMounts src/Dodge/Block.hs 97;" f -destroyProjectile src/Dodge/Projectile/Update.hs 144;" f +destroyProjectile src/Dodge/Projectile/Update.hs 141;" f detV src/Geometry/Vector.hs 93;" f detector src/Dodge/Item/Held/Utility.hs 27;" f detectorColor src/Dodge/Item/Draw/SPic.hs 465;" f @@ -3295,7 +3295,7 @@ doAfterPlacements src/Dodge/Layout.hs 83;" f doAimTwist src/Dodge/Creature/YourControl.hs 140;" f doAnyEquipmentEffect src/Dodge/Creature/State.hs 223;" f doBackspace src/Dodge/Update/Input/Text.hs 31;" f -doBarrelSpin src/Dodge/Projectile/Update.hs 194;" f +doBarrelSpin src/Dodge/Projectile/Update.hs 191;" f doBlBl src/Dodge/BlBl.hs 5;" f doBlSh src/Dodge/Block/Draw.hs 14;" f doBounce src/Dodge/Base/Collide.hs 66;" f @@ -3326,7 +3326,7 @@ doDrawing src/Dodge/Render.hs 35;" f doDrawing' src/Dodge/Render.hs 46;" f doFloatFloat src/Dodge/FloatFunction.hs 5;" f doGenFloat src/Dodge/HeldUse.hs 1212;" f -doGravityPU src/Dodge/Projectile/Update.hs 33;" f +doGravityPU src/Dodge/Projectile/Update.hs 35;" f doHeldUseEffect src/Dodge/HeldUse.hs 354;" f doInPlacements src/Dodge/Layout.hs 92;" f doIndividualPlacements src/Dodge/Layout.hs 117;" f @@ -3362,7 +3362,7 @@ doTerminalCommandEffect src/Dodge/Terminal.hs 135;" f doTestDrawing src/Dodge/Render.hs 42;" f doTextInputOver src/Dodge/Update/Input/Text.hs 15;" f doTextInputOverUniverse src/Dodge/Update/Input/Text.hs 12;" f -doThrust src/Dodge/Projectile/Update.hs 166;" f +doThrust src/Dodge/Projectile/Update.hs 163;" f doTimeScroll src/Dodge/Update.hs 208;" f doTmTm src/Dodge/TmTm.hs 6;" f doTmWdWd src/Dodge/WorldEffect.hs 99;" f @@ -3592,7 +3592,7 @@ expandPolyByFixed src/Dodge/LevelGen/StaticWalls.hs 97;" f expandPolyCorners src/Dodge/LevelGen/StaticWalls.hs 103;" f expandToSquare src/Dodge/LevelGen/StaticWalls/Deprecated.hs 83;" f expireAndDamage src/Dodge/Bullet.hs 186;" f -explodeShell src/Dodge/Projectile/Update.hs 260;" f +explodeShell src/Dodge/Projectile/Update.hs 261;" f explosionS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 556;" f explosiveBarrel src/Dodge/Creature/Inanimate.hs 25;" f extTrigLitPos src/Dodge/Placement/Instance/Button.hs 84;" f @@ -4344,6 +4344,7 @@ movePenBullet src/Dodge/Bullet.hs 201;" f moveProjectile src/Dodge/Projectile/Update.hs 232;" f moveRoomBy src/Dodge/Room/Link.hs 53;" f moveShockwave src/Dodge/Shockwave/Update.hs 15;" f +moveStuckGrenade src/Dodge/Projectile/Update.hs 229;" f moveToSideFirstOutLink src/Dodge/Room/Warning.hs 55;" f moveWall src/Dodge/Wall/Move.hs 29;" f moveWallID src/Dodge/Wall/Move.hs 24;" f @@ -4507,7 +4508,7 @@ pipe src/Dodge/Item/Craftable.hs 32;" f pistol src/Dodge/Item/Held/Stick.hs 40;" f pistolCrit src/Dodge/Creature/PistolCrit.hs 12;" f pistolerRoom src/Dodge/Room/Room.hs 321;" f -pjRemoteSetDirection src/Dodge/Projectile/Update.hs 211;" f +pjRemoteSetDirection src/Dodge/Projectile/Update.hs 208;" f plBlock src/Dodge/Placement/PlaceSpot/Block.hs 18;" f plDoor src/Dodge/Placement/PlaceSpot/TriggerDoor.hs 22;" f plLineBlock src/Dodge/Placement/PlaceSpot/Block.hs 50;" f @@ -5038,7 +5039,9 @@ shapeVerxSize src/Shape/Parameters.hs 10;" f shatterGun src/Dodge/Item/Held/Weapons.hs 8;" f shatterGunSPic src/Dodge/Item/Draw/SPic.hs 324;" f shatterWall src/Dodge/Item/Weapon/Shatter.hs 26;" f -shellExplosionCheck src/Dodge/Projectile/Update.hs 68;" f +shellExplosionCheck src/Dodge/Projectile/Update.hs 70;" f +shellHitFloor src/Dodge/Projectile/Update.hs 102;" f +shellHitWall src/Dodge/Projectile/Update.hs 81;" f shellMag src/Dodge/Item/Ammo.hs 49;" f shellModule src/Dodge/Item/Scope.hs 123;" f shellShape src/Dodge/Projectile/Draw.hs 34;" f @@ -5436,11 +5439,10 @@ tryPutFloorItemIDInInv src/Dodge/Inventory/Add.hs 26;" f tryPutItemInInv src/Dodge/Inventory/Add.hs 42;" f tryPutItemInInvAt src/Dodge/Inventory/Add.hs 32;" f trySeedFromClipboard src/Dodge/Menu.hs 91;" f -tryShellBounce src/Dodge/Projectile/Update.hs 81;" f -tryShellBounce' src/Dodge/Projectile/Update.hs 111;" f -trySpin src/Dodge/Projectile/Update.hs 154;" f +tryShellBounce src/Dodge/Projectile/Update.hs 107;" f +trySpin src/Dodge/Projectile/Update.hs 151;" f trySynthBullet src/Dodge/Creature/State.hs 249;" f -tryThrust src/Dodge/Projectile/Update.hs 160;" f +tryThrust src/Dodge/Projectile/Update.hs 157;" f tryUseParent src/Dodge/Creature/State.hs 227;" f turnTo src/Dodge/Movement/Turn.hs 8;" f turret src/Dodge/Placement/Instance/Turret.hs 35;" f