From 77e69228f7f0bb6ced8e6daa35b9bf1723f8c6c3 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 2 Jan 2024 03:48:07 -0800 Subject: [PATCH] Metal SA2 Crate crushes players if it falls onto them --- src/objects/crate.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/objects/crate.cpp b/src/objects/crate.cpp index 3f208b311..01499b8cc 100644 --- a/src/objects/crate.cpp +++ b/src/objects/crate.cpp @@ -332,11 +332,46 @@ struct Crate : Box if (metal() && !inflictor->boosting()) { + crush(inflictor); + return false; } return Box::damage(inflictor); } + +private: + bool clip2d(const Toucher* inflictor) const + { + LineSegment a = aabb(); + LineSegment b = inflictor->aabb(); + + return a.a.x < b.b.x && b.a.x < a.b.x && a.a.y < b.b.y && b.a.y < a.b.y; + } + + void crush(Toucher* inflictor) + { + if (!momz) + { + return; + } + + if ((momz < 0 ? mobj_t::z - inflictor->floorz : inflictor->ceilingz - top()) > inflictor->height) + { + return; + } + + if (!clip2d(inflictor)) + { + // Bumping the side of a falling crate should not + // kill you. + // Note: this check is imperfect. That's why + // everything is guarded by momz anyway. + return; + } + + P_DamageMobj(inflictor, this, nullptr, 1, DMG_CRUSHED); + } }; struct Ice : Box