| 1 | #include "Player/PlayerJudgeDiveInWater.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 4 | #include "Library/Nature/NatureUtil.h" |
| 5 | |
| 6 | #include "Player/IUsePlayerFallDistanceCheck.h" |
| 7 | #include "Player/IUsePlayerHeightCheck.h" |
| 8 | #include "Player/PlayerConst.h" |
| 9 | |
| 10 | PlayerJudgeDiveInWater::PlayerJudgeDiveInWater(const al::LiveActor* player, |
| 11 | const PlayerConst* playerConst, |
| 12 | const IUsePlayerHeightCheck* heightCheck, |
| 13 | const IUsePlayerFallDistanceCheck* fallDistanceCheck) |
| 14 | : mPlayer(player), mConst(playerConst), mHeightCheck(heightCheck), |
| 15 | mFallDistanceCheck(fallDistanceCheck) {} |
| 16 | |
| 17 | bool PlayerJudgeDiveInWater::judge() const { |
| 18 | if (mFallDistanceCheck->getFallDistance() < 10.0f) |
| 19 | return false; |
| 20 | if (mHeightCheck->isAboveGround() && mHeightCheck->getGroundHeight() < 1500.0f) |
| 21 | return false; |
| 22 | |
| 23 | sead::Vector3f up = -al::getGravity(actor: mPlayer); |
| 24 | f32 findDistance = (mConst->getTall() + 1500.0f) * 0.5f; |
| 25 | sead::Vector3f findStart = al::getTrans(actor: mPlayer) + -up * findDistance; |
| 26 | |
| 27 | sead::Vector3f surfacePos = {0.0f, 0.0f, 0.0f}; |
| 28 | sead::Vector3f surfaceNormal = {0.0f, 0.0f, 0.0f}; |
| 29 | if (!al::calcFindWaterSurfaceFlat(&surfacePos, &surfaceNormal, mPlayer, findStart, up, |
| 30 | findDistance)) |
| 31 | return false; |
| 32 | |
| 33 | f32 surfaceDistance = (al::getTrans(actor: mPlayer) - surfacePos).dot(t: up); |
| 34 | if (surfaceDistance < 1500.0f) |
| 35 | return false; |
| 36 | |
| 37 | if (mHeightCheck->isAboveGround()) { |
| 38 | f32 minHeight = (surfaceDistance + mConst->getTall()); |
| 39 | if (mHeightCheck->getGroundHeight() < minHeight) |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | return true; |
| 44 | } |
| 45 | |