From 95fe4864cccb7b4fdd0ab4beb8b28bc51885244a Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 27 Oct 2024 21:22:45 +0100 Subject: [PATCH 1/3] a bit of d_a_insect --- config/SOUE01/splits.txt | 5 + config/SOUE01/symbols.txt | 51 ++++----- configure.py | 1 + include/d/a/d_a_insect.h | 76 +++++++++++++ include/d/a/d_a_player.h | 2 +- src/d/a/d_a_insect.cpp | 223 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 332 insertions(+), 26 deletions(-) create mode 100644 include/d/a/d_a_insect.h create mode 100644 src/d/a/d_a_insect.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 4970d2cb..ddc6649c 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -547,6 +547,11 @@ d/lyt/d_screen_fader.cpp: .data start:0x80528D68 end:0x80528D90 .sdata2 start:0x8057ABE0 end:0x8057AC08 +d/a/d_a_insect.cpp: + .text start:0x8018F190 end:0x80190710 + .data start:0x8052ABD8 end:0x8052ACC0 + .sdata2 start:0x8057ADD8 end:0x8057AE30 + d/d_cs_base.cpp: .text start:0x801BC6C0 end:0x801BD250 .data start:0x8052E860 end:0x8052E968 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index be65cf08..3fec0081 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -10222,38 +10222,38 @@ fn_8018EBE0 = .text:0x8018EBE0; // type:function size:0x38 fn_8018EC20 = .text:0x8018EC20; // type:function size:0x2C fn_8018EC50 = .text:0x8018EC50; // type:function size:0x538 fn_8018F190 = .text:0x8018F190; // type:function size:0x60 -fn_8018F1F0 = .text:0x8018F1F0; // type:function size:0xAC +checkForLinkScare__12dAcOInsect_cFv = .text:0x8018F1F0; // type:function size:0xAC fn_8018F2A0 = .text:0x8018F2A0; // type:function size:0xA0 -fn_8018F340 = .text:0x8018F340; // type:function size:0x4C -fn_8018F390 = .text:0x8018F390; // type:function size:0x50 -fn_8018F3E0 = .text:0x8018F3E0; // type:function size:0x40 -fn_8018F420 = .text:0x8018F420; // type:function size:0x38 -fn_8018F460 = .text:0x8018F460; // type:function size:0xD8 -fn_8018F540 = .text:0x8018F540; // type:function size:0x8 -fn_8018F550 = .text:0x8018F550; // type:function size:0xD4 -fn_8018F630 = .text:0x8018F630; // type:function size:0xB8 -fn_8018F6F0 = .text:0x8018F6F0; // type:function size:0x4 -fn_8018F700 = .text:0x8018F700; // type:function size:0x8 -fn_8018F710 = .text:0x8018F710; // type:function size:0x30 -fn_8018F740 = .text:0x8018F740; // type:function size:0x84 -fn_8018F7D0 = .text:0x8018F7D0; // type:function size:0x8 -fn_8018F7E0 = .text:0x8018F7E0; // type:function size:0x8 -fn_8018F7F0 = .text:0x8018F7F0; // type:function size:0xA8 -fn_8018F8A0 = .text:0x8018F8A0; // type:function size:0x8 +isLinkUsingBugNet__12dAcOInsect_cFv = .text:0x8018F340; // type:function size:0x4C +getLinkSpeedLevel__12dAcOInsect_cFv = .text:0x8018F390; // type:function size:0x50 +isLinkNearby__12dAcOInsect_cFf = .text:0x8018F3E0; // type:function size:0x40 +isLinkNearbyZ__12dAcOInsect_cFf = .text:0x8018F420; // type:function size:0x38 +someBaseFunction__12dAcOInsect_cFv = .text:0x8018F460; // type:function size:0xD8 +dAcOInsect_0x8C__12dAcOInsect_cFv = .text:0x8018F540; // type:function size:0x8 +someBaseFunction0__12dAcOInsect_cFv = .text:0x8018F550; // type:function size:0xD4 +addAttentionTarget__12dAcOInsect_cFv = .text:0x8018F630; // type:function size:0xB8 +shouldAddAttentionTarget__12dAcOInsect_cFv = .text:0x8018F6F0; // type:function size:0x4 +getAttentionField__12dAcOInsect_cFv = .text:0x8018F700; // type:function size:0x8 +preAttention__12dAcOInsect_cFv = .text:0x8018F710; // type:function size:0x30 +dAcOInsect_0x80__12dAcOInsect_cFv = .text:0x8018F740; // type:function size:0x84 +dAcOInsect_0x84__12dAcOInsect_cFv = .text:0x8018F7D0; // type:function size:0x8 +dAcOInsect_0x88__12dAcOInsect_cFv = .text:0x8018F7E0; // type:function size:0x8 +isLinkCloseAndFlag__12dAcOInsect_cFv = .text:0x8018F7F0; // type:function size:0xA8 +dAcOInsect_0x94__12dAcOInsect_cFv = .text:0x8018F8A0; // type:function size:0x8 fn_8018F8B0 = .text:0x8018F8B0; // type:function size:0x14C fn_8018FA00 = .text:0x8018FA00; // type:function size:0x7C -fn_8018FA80 = .text:0x8018FA80; // type:function size:0x18 -fn_8018FAA0 = .text:0x8018FAA0; // type:function size:0x28 +resetScale__12dAcOInsect_cFv = .text:0x8018FA80; // type:function size:0x18 +fn_8018FAA0__12dAcOInsect_cFv = .text:0x8018FAA0; // type:function size:0x28 fn_8018FAD0 = .text:0x8018FAD0; // type:function size:0x314 fn_8018FDF0 = .text:0x8018FDF0; // type:function size:0x2C0 fn_801900B0 = .text:0x801900B0; // type:function size:0xD0 -fn_80190180 = .text:0x80190180; // type:function size:0x2C0 +fn_80190180__12dAcOInsect_cFR4mAng = .text:0x80190180; // type:function size:0x2C0 fn_80190440 = .text:0x80190440; // type:function size:0x1D0 fn_80190610 = .text:0x80190610; // type:function size:0x2C -fn_80190640 = .text:0x80190640; // type:function size:0x4 -fn_80190650 = .text:0x80190650; // type:function size:0x4 -fn_80190660 = .text:0x80190660; // type:function size:0x8 -fn_80190670 = .text:0x80190670; // type:function size:0xA0 +dAcOInsect_0xAC__12dAcOInsect_cFv = .text:0x80190640; // type:function size:0x4 +dAcOInsect_0xA8__12dAcOInsect_cFv = .text:0x80190650; // type:function size:0x4 +dAcOInsect_0xA4__12dAcOInsect_cFv = .text:0x80190660; // type:function size:0x8 +__dt__12dAcOInsect_cFv = .text:0x80190670; // type:function size:0xA0 fn_80190710 = .text:0x80190710; // type:function size:0x14 fn_80190730 = .text:0x80190730; // type:function size:0x48 fn_80190780 = .text:0x80190780; // type:function size:0x40 @@ -33803,7 +33803,8 @@ lbl_8052A890 = .data:0x8052A890; // type:object size:0xC8 lbl_8052A958 = .data:0x8052A958; // type:object size:0x68 lbl_8052A9C0 = .data:0x8052A9C0; // type:object size:0x1AC lbl_8052AB6C = .data:0x8052AB6C; // type:object size:0x6C -lbl_8052ABD8 = .data:0x8052ABD8; // type:object size:0xE8 +@LOCAL@addAttentionTarget__12dAcOInsect_cFv@tmpTarget = .data:0x8052ABD8; // type:object size:0x30 scope:local +__vt__12dAcOInsect_c = .data:0x8052AC08; // type:object size:0xB4 lbl_8052ACC0 = .data:0x8052ACC0; // type:object size:0x10 lbl_8052ACD0 = .data:0x8052ACD0; // type:object size:0x340 lbl_8052B010 = .data:0x8052B010; // type:object size:0x34 diff --git a/configure.py b/configure.py index 474e5cd1..83b1612a 100644 --- a/configure.py +++ b/configure.py @@ -413,6 +413,7 @@ config.libs = [ Object(NonMatching, "d/lyt/d_lyt_pause_disp_00.cpp"), Object(Matching, "d/lyt/d_lyt_fader.cpp"), Object(Matching, "d/lyt/d_screen_fader.cpp"), + Object(NonMatching, "d/a/d_a_insect.cpp"), Object(NonMatching, "d/d_cs_base.cpp"), Object(NonMatching, "d/d_cs_game.cpp"), Object(Matching, "d/lyt/d_lyt_common_arrow.cpp"), diff --git a/include/d/a/d_a_insect.h b/include/d/a/d_a_insect.h new file mode 100644 index 00000000..e0497c76 --- /dev/null +++ b/include/d/a/d_a_insect.h @@ -0,0 +1,76 @@ +#include "d/a/d_a_base.h" +#include "d/a/obj/d_a_obj_base.h" +#include "m/m_mtx.h" +#include "m/m_vec.h" + +class dAcOInsect_c : public dAcObjBase_c { +public: + dAcOInsect_c() {} + virtual ~dAcOInsect_c() {} + + /* 0x80 */ virtual f32 dAcOInsect_0x80(); + /* 0x84 */ virtual f32 dAcOInsect_0x84() { + return 0.0f; + } + /* 0x88 */ virtual f32 dAcOInsect_0x88() { + return 0.0f; + } + /* 0x8C */ virtual f32 dAcOInsect_0x8C() { + return 0.0f; + } + /* 0x90 */ virtual f32 getAttentionField() { + return 0.0f; + } + /* 0x94 */ virtual f32 dAcOInsect_0x94() { + return 0.0f; + } + /* 0x98 */ virtual bool shouldAddAttentionTarget() { + return isLinkUsingBugNet(); + } + /* 0x9C */ virtual void addAttentionTarget(); + /* 0xA0 */ virtual void preAttention(); + /* 0xA4 */ virtual s32 dAcOInsect_0xA4() { + return 0; + } + /* 0xA8 */ virtual bool dAcOInsect_0xA8() { + return checkForLinkScare(); + } + /* 0xAC */ virtual void dAcOInsect_0xAC() {} + /* 0xB0 */ virtual void dAcOInsect_0xB0(); + +protected: + void goPoof(); + bool isLinkNearby(f32 radius); + bool isLinkNearbyZ(f32 distance); + void someBaseFunction(); + bool someBaseFunction0(); + bool checkForLinkScare(); + bool isLinkCloseAndFlag(); + s32 getLinkSpeedLevel(); + static bool isLinkUsingBugNet(); + bool resetScale(); + bool fn_8018FAA0(); + bool fn_80190180(mAng &outAng); + +private: + /* 0x330 */ s32 field_0x330; + /* 0x334 */ u8 field_0x334; + /* 0x335 */ u8 field_0x335; + /* 0x338 */ u32 field_0x338; + /* 0x33C */ mVec3_c field_0x33C; + /* 0x348 */ u8 field_0x348[0x35C - 0x348]; + /* 0x35C */ f32 field_0x35C; + /* 0x360 */ u8 field_0x360[0x3BE - 0x360]; + /* 0x3BE */ u8 field_0x3BE; + /* 0x3BF */ u8 field_0x3BF; + /* 0x3C0 */ mMtx_c field_0x3C0; + /* 0x3F0 */ u8 field_0x3F0[0x3F8 - 0x3F0]; + /* 0x3F8 */ u32 mLinkNearby; + /* 0x3FC */ dAcRef_c field_0x3FC; + /* 0x408 */ u8 field_0x408[0x40D - 0x408]; + /* 0x40D */ u8 field_0x40D; + /* 0x410 */ mVec3_c field_0x410[3]; + /* 0x434 */ mVec3_c field_0x434[3]; + /* 0x458 */ u8 field_0x458[0x45C - 0x458]; + /* 0x45C */ mVec3_c field_0x45C; +}; diff --git a/include/d/a/d_a_player.h b/include/d/a/d_a_player.h index a5969ffd..9e0a1698 100644 --- a/include/d/a/d_a_player.h +++ b/include/d/a/d_a_player.h @@ -178,7 +178,7 @@ public: /* vt 0x280 */ virtual void vt_0x280(); /* vt 0x284 */ virtual bool isUsingBugnet() const; /* vt 0x288 */ virtual const mVec3_c &getBugNetPos() const; - /* vt 0x28C */ virtual void isUsingBugnet1(); + /* vt 0x28C */ virtual bool isUsingBugnet1(); /* vt 0x290 */ virtual void bugNetCollectTreasure(); /* vt 0x294 */ virtual void somethingSwitchDials(); /* vt 0x298 */ virtual void vt_0x298(); diff --git a/src/d/a/d_a_insect.cpp b/src/d/a/d_a_insect.cpp new file mode 100644 index 00000000..9ae59c4a --- /dev/null +++ b/src/d/a/d_a_insect.cpp @@ -0,0 +1,223 @@ +#include "d/a/d_a_insect.h" + +#include "common.h" +#include "d/a/d_a_player.h" +#include "egg/math/eggMath.h" +#include "m/m_vec.h" +#include "rvl/MTX/mtxvec.h" +#include "toBeSorted/attention.h" + +void AcOInsectFloats() { + 50.0f; + 1.0f; + 30.0f; + 5000.0f; + 0.1f; + 10.0f; + 500.0f; + 0.0f; + 400.0f; + -200.0f; + 200.0f; + 20.0f; + EGG::Math::epsilon(); + 5.0f; + -5.0f; + 0.99f; + int x = 0; + (f32) x; +} + +void AcOInsectFloats2() { + -1.0f; + 0.5f; + 2250000.0f; +} + +bool dAcOInsect_c::checkForLinkScare() { + if (dAcPy_c::LINK != nullptr) { + // TODO + } + + return false; +} + +bool dAcOInsect_c::isLinkUsingBugNet() { + if (dAcPy_c::LINK != nullptr && !dAcPy_c::LINK->isUsingBugnet()) { + return false; + } + return true; +} + +s32 dAcOInsect_c::getLinkSpeedLevel() { + if (dAcPy_c::LINK != nullptr) { + f32 speed = fabsf(dAcPy_c::LINK->forwardSpeed); + if (speed < 0.1f) { + return 0; + } else if (speed < 10.0f) { + return 1; + } else { + return 2; + } + } + + return 3; +} + +bool dAcOInsect_c::isLinkNearby(f32 rad) { + if (dAcPy_c::LINK != nullptr && isWithinPlayerRadius(rad)) { + return true; + } + return false; +} + +bool dAcOInsect_c::isLinkNearbyZ(f32 dist) { + if (dAcPy_c::LINK != nullptr && fabsf(dAcPy_c::LINK->position.y - position.y) > dist) { + return false; + } + return true; +} + +void dAcOInsect_c::someBaseFunction() { + dAcPy_c *link = dAcPy_c::LINK; + if (link != nullptr) { + if (isLinkNearbyZ(500.0f) && isLinkNearby(dAcOInsect_0x8C())) { + field_0x335 = field_0x334; + field_0x334 = link->isUsingBugnet1(); + if (link->isUsingBugnet1()) { + field_0x330++; + return; + } + field_0x330 = 0; + return; + } else { + field_0x334 = 0; + field_0x335 = 0; + field_0x330 = 0; + } + } +} + +bool dAcOInsect_c::someBaseFunction0() { + f32 rad = dAcOInsect_0x80(); + if (isLinkNearbyZ(500.0f) && isLinkNearby(rad)) { + field_0x338 = 1; + return true; + } + bool b = (field_0x335 != 0 && field_0x334 == 0) || field_0x330 > 3; + if (b) { + field_0x338 = 2; + return true; + } else { + field_0x338 = 0; + return false; + } +} + +void dAcOInsect_c::addAttentionTarget() { + preAttention(); + static InteractionTargetDef tmpTarget = {1, 0, 0, UNK_18, 0x2, 150.0f, 0.0f, 0.0f, -300.0f, 100.0f, 50.0f, 1.0f}; + if (shouldAddAttentionTarget()) { + AttentionManager *attn = AttentionManager::sInstance; + if (attn != nullptr) { + attn->addCatchTarget(*this, 0x1, 400.0f, -200.0f, 200.0f); + tmpTarget.field_0x14 = getAttentionField(); + attn->addTarget(*this, tmpTarget, 0, nullptr); + } + } +} + +void dAcOInsect_c::preAttention() { + // It's always the simplest vector functions that cause problems + poscopy2 = position; + f32 y = position.y; + y += 20.0f; + poscopy2.y = y; + poscopy3 = poscopy2; +} + +f32 dAcOInsect_c::dAcOInsect_0x80() { + switch (getLinkSpeedLevel()) { + case 1: return dAcOInsect_0x84(); + case 2: return dAcOInsect_0x88(); + default: return dAcOInsect_0x84(); + } +} + +bool dAcOInsect_c::isLinkCloseAndFlag() { + dAcPy_c *link = dAcPy_c::LINK; + if (link != nullptr && link->checkFlags0x350(0x2000)) { + f32 d = dAcOInsect_0x94(); + return getSquareDistanceTo(link->position) < d; + } + return false; +} + +bool dAcOInsect_c::resetScale() { + mScale.set(1.0f, 1.0f, 1.0f); + return true; +} + +bool dAcOInsect_c::fn_8018FAA0() { + if (field_0x3FC.get() != 0 && field_0x40D == 0) { + return true; + } + + return false; +} + +// Looks like it decides on a direction and angle based on a target point? +bool dAcOInsect_c::fn_80190180(mAng &outAng) { + // Stack and reg problems + mVec3_c vecs[4]; + vecs[0].set(1.0f, 0.0f, 1.0f); + vecs[1].set(1.0f, 0.0f, -1.0f); + vecs[2].set(-1.0f, 0.0f, -1.0f); + vecs[3].set(-1.0f, 0.0f, 1.0f); + + int i3 = -1; + + s16 angs[4]; + angs[0] = 0x2000; + angs[1] = 0x6000; + angs[2] = 0xA000; + angs[3] = 0xE000; + + if (field_0x3BF != 0) { + f32 len = fabsf(field_0x33C.y + field_0x35C * 0.5f - position.y); + for (int i = 0; i < 4; i++) { + mVec3_c tmp = vecs[i] * 20.0f; + // ??? + mVec3_c tmp2 = tmp; + PSMTXMultVec(field_0x3C0, tmp2, tmp2); + f32 len2 = fabsf(field_0x33C.y + field_0x35C * 0.5f - tmp2.y); + if (len > len2) { + len = len2; + i3 = i; + } + } + } else if (field_0x3BE != 0) { + mVec3_c dir = field_0x33C - position; + f32 len = dir.x * dir.x + dir.z * dir.z; + for (int i = 0; i < 4; i++) { + mVec3_c tmp = vecs[i] * 20.0f; + // ??? + mVec3_c tmp2 = tmp; + PSMTXMultVec(field_0x3C0, tmp2, tmp2); + mVec3_c dir2 = field_0x33C - tmp2; + f32 len2 = dir2.x * dir2.x + dir2.z * dir2.z; + if (len > len2) { + len = len2; + i3 = i; + } + } + } + + if (i3 >= 0) { + outAng = angs[i3]; + field_0x45C = vecs[i3]; + return true; + } + + return false; +} From d0c8173466c022516208b43dc4f9e8b18571dc4f Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 8 Nov 2024 23:07:31 -0500 Subject: [PATCH 2/3] update d_a_insect --- config/SOUE01/symbols.txt | 22 +-- include/d/a/d_a_base.h | 5 +- include/d/a/d_a_insect.h | 36 ++++- include/d/a/d_a_player.h | 5 + include/d/a/obj/d_a_obj_base.h | 4 + include/d/col/bg/d_bg_s_spl_grp_chk.h | 4 + include/m/m_angle.h | 5 + include/m/m_mtx.h | 6 + include/m/m_vec.h | 7 + src/d/a/d_a_insect.cpp | 205 ++++++++++++++++++++------ 10 files changed, 236 insertions(+), 63 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 7c2ec179..cbfbb8ff 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -10221,13 +10221,13 @@ fn_8018EB80 = .text:0x8018EB80; // type:function size:0x5C fn_8018EBE0 = .text:0x8018EBE0; // type:function size:0x38 fn_8018EC20 = .text:0x8018EC20; // type:function size:0x2C fn_8018EC50 = .text:0x8018EC50; // type:function size:0x538 -fn_8018F190 = .text:0x8018F190; // type:function size:0x60 +kill__12dAcOInsect_cFv = .text:0x8018F190; // type:function size:0x60 checkForLinkScare__12dAcOInsect_cFv = .text:0x8018F1F0; // type:function size:0xAC -fn_8018F2A0 = .text:0x8018F2A0; // type:function size:0xA0 +checkDeath__12dAcOInsect_cFR9dBgS_Acch = .text:0x8018F2A0; // type:function size:0xA0 isLinkUsingBugNet__12dAcOInsect_cFv = .text:0x8018F340; // type:function size:0x4C getLinkSpeedLevel__12dAcOInsect_cFv = .text:0x8018F390; // type:function size:0x50 -isLinkNearby__12dAcOInsect_cFf = .text:0x8018F3E0; // type:function size:0x40 -isLinkNearbyZ__12dAcOInsect_cFf = .text:0x8018F420; // type:function size:0x38 +checkPlayerRadius__12dAcOInsect_cFf = .text:0x8018F3E0; // type:function size:0x40 +checkPlayerElevationDiff__12dAcOInsect_cFf = .text:0x8018F420; // type:function size:0x38 someBaseFunction__12dAcOInsect_cFv = .text:0x8018F460; // type:function size:0xD8 dAcOInsect_0x8C__12dAcOInsect_cFv = .text:0x8018F540; // type:function size:0x8 someBaseFunction0__12dAcOInsect_cFv = .text:0x8018F550; // type:function size:0xD4 @@ -10240,16 +10240,16 @@ dAcOInsect_0x84__12dAcOInsect_cFv = .text:0x8018F7D0; // type:function size:0x8 dAcOInsect_0x88__12dAcOInsect_cFv = .text:0x8018F7E0; // type:function size:0x8 isLinkCloseAndFlag__12dAcOInsect_cFv = .text:0x8018F7F0; // type:function size:0xA8 dAcOInsect_0x94__12dAcOInsect_cFv = .text:0x8018F8A0; // type:function size:0x8 -fn_8018F8B0 = .text:0x8018F8B0; // type:function size:0x14C -fn_8018FA00 = .text:0x8018FA00; // type:function size:0x7C +checkDeath__12dAcOInsect_cFR8cCcD_Obj = .text:0x8018F8B0; // type:function size:0x14C +checkCaught__12dAcOInsect_cFR8cCcD_Obj = .text:0x8018FA00; // type:function size:0x7C resetScale__12dAcOInsect_cFv = .text:0x8018FA80; // type:function size:0x18 fn_8018FAA0__12dAcOInsect_cFv = .text:0x8018FAA0; // type:function size:0x28 -fn_8018FAD0 = .text:0x8018FAD0; // type:function size:0x314 -fn_8018FDF0 = .text:0x8018FDF0; // type:function size:0x2C0 -fn_801900B0 = .text:0x801900B0; // type:function size:0xD0 +fn_8018FAD0__12dAcOInsect_cFv = .text:0x8018FAD0; // type:function size:0x314 +fn_8018FDF0__12dAcOInsect_cFRC7mVec3_c = .text:0x8018FDF0; // type:function size:0x2C0 +fn_801900B0__12dAcOInsect_cFRC7mVec3_cRC7mVec3_c = .text:0x801900B0; // type:function size:0xD0 fn_80190180__12dAcOInsect_cFR4mAng = .text:0x80190180; // type:function size:0x2C0 -fn_80190440 = .text:0x80190440; // type:function size:0x1D0 -fn_80190610 = .text:0x80190610; // type:function size:0x2C +fn_80190440__12dAcOInsect_cFv = .text:0x80190440; // type:function size:0x1D0 +fn_80190160__12dAcOInsect_cFv = .text:0x80190610; // type:function size:0x2C dAcOInsect_0xAC__12dAcOInsect_cFv = .text:0x80190640; // type:function size:0x4 dAcOInsect_0xA8__12dAcOInsect_cFv = .text:0x80190650; // type:function size:0x4 dAcOInsect_0xA4__12dAcOInsect_cFv = .text:0x80190660; // type:function size:0x8 diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index 2be88e75..5e085107 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -9,7 +9,6 @@ #include "stddef.h" #include "toBeSorted/tlist.h" - class dAcBase_c; struct SoundSource { @@ -147,6 +146,10 @@ public: return diff.x * diff.x + diff.z * diff.z; } + f32 getDistanceTo(const mVec3_c &to) const { + return position.distance(to); + } + bool IsOutOfRange(const mVec3_c &point, f32 radius) { return getSquareDistanceTo(point) > radius; } diff --git a/include/d/a/d_a_insect.h b/include/d/a/d_a_insect.h index e0497c76..54bdb548 100644 --- a/include/d/a/d_a_insect.h +++ b/include/d/a/d_a_insect.h @@ -1,5 +1,8 @@ #include "d/a/d_a_base.h" #include "d/a/obj/d_a_obj_base.h" +#include "d/col/bg/d_bg_w_base.h" +#include "d/col/c/c_cc_d.h" +#include "d/col/c/c_m3d_g_pla.h" #include "m/m_mtx.h" #include "m/m_vec.h" @@ -36,12 +39,14 @@ public: return checkForLinkScare(); } /* 0xAC */ virtual void dAcOInsect_0xAC() {} - /* 0xB0 */ virtual void dAcOInsect_0xB0(); + /* 0xB0 */ virtual bool checkCaught(cCcD_Obj &col); protected: - void goPoof(); - bool isLinkNearby(f32 radius); - bool isLinkNearbyZ(f32 distance); + void kill(); + void checkDeath(dBgS_Acch &acch); + bool checkDeath(cCcD_Obj &col); + bool checkPlayerRadius(f32 radius); + bool checkPlayerElevationDiff(f32 distance); void someBaseFunction(); bool someBaseFunction0(); bool checkForLinkScare(); @@ -50,6 +55,11 @@ protected: static bool isLinkUsingBugNet(); bool resetScale(); bool fn_8018FAA0(); + bool fn_8018FAD0(); + void fn_8018FDF0(const mVec3_c &); + int fn_801900B0(const mVec3_c &, const mVec3_c &); + void fn_80190440(); + void fn_80190160(); bool fn_80190180(mAng &outAng); private: @@ -58,16 +68,26 @@ private: /* 0x335 */ u8 field_0x335; /* 0x338 */ u32 field_0x338; /* 0x33C */ mVec3_c field_0x33C; - /* 0x348 */ u8 field_0x348[0x35C - 0x348]; + /* 0x348 */ mVec3_c field_0x348; + /* 0x354 */ f32 field_0x354; + /* 0x358 */ f32 field_0x358; /* 0x35C */ f32 field_0x35C; - /* 0x360 */ u8 field_0x360[0x3BE - 0x360]; + /* 0x360 */ mVec3_c field_0x360; + /* 0x36C */ mVec3_c field_0x36C; + /* 0x378 */ u8 field_0x378[0x3A8 - 0x378]; + /* 0x3A8 */ cM3dGPla mPlane_0x3A8; + /* 0x3B8 */ int mMaterial; + /* 0x3BC */ u8 field_0x3BC; + /* 0x3BD */ u8 field_0x3BD; /* 0x3BE */ u8 field_0x3BE; /* 0x3BF */ u8 field_0x3BF; /* 0x3C0 */ mMtx_c field_0x3C0; - /* 0x3F0 */ u8 field_0x3F0[0x3F8 - 0x3F0]; + /* 0x3F0 */ u8 field_0x3F0[0x3F4 - 0x3F0]; + /* 0x3F4 */ u8 field_0x3F4; /* 0x3F8 */ u32 mLinkNearby; /* 0x3FC */ dAcRef_c field_0x3FC; - /* 0x408 */ u8 field_0x408[0x40D - 0x408]; + /* 0x408 */ u8 field_0x408[0x40C - 0x408]; + /* 0x40C */ u8 field_0x40C; /* 0x40D */ u8 field_0x40D; /* 0x410 */ mVec3_c field_0x410[3]; /* 0x434 */ mVec3_c field_0x434[3]; diff --git a/include/d/a/d_a_player.h b/include/d/a/d_a_player.h index 5d644a1d..97115c85 100644 --- a/include/d/a/d_a_player.h +++ b/include/d/a/d_a_player.h @@ -224,6 +224,7 @@ public: /* 0x360 */ UNKWORD field_0x360; /* 0x364 */ u32 mActionFlags; /* 0x368 */ u32 mActionFlagsCont; + /* 0x36C */ int mCurrentAction; // TODO (Document Enum) inline bool checkFlags0x340(u32 mask) const { return (someFlags_0x340 & mask) != 0; @@ -237,5 +238,9 @@ public: return mActionFlags & FLG0_FLY; } + int getCurrentAction() const { + return mCurrentAction; + } + static dAcPy_c *LINK; }; diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index c492dfdb..0f9db422 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -97,6 +97,10 @@ public: return getVelocityMag() <= EGG::Math::epsilon(); } + bool isSlowerThan(f32 speed) const { + return fabsf(forwardSpeed) <= speed; + } + // could be their own thing? /* 8002de40 */ static void *getOarcFile(const char *oarcName, const char *fileName); /* 8002de60 */ static void *getOarcSubEntry(const char *oarcName, const char *fileName); diff --git a/include/d/col/bg/d_bg_s_spl_grp_chk.h b/include/d/col/bg/d_bg_s_spl_grp_chk.h index d4d47f25..8d80a520 100644 --- a/include/d/col/bg/d_bg_s_spl_grp_chk.h +++ b/include/d/col/bg/d_bg_s_spl_grp_chk.h @@ -67,6 +67,10 @@ public: void CopyGnd() { mGroundCopy = mGnd; } + + f32 GetGroundH() const { + return mGroundH; + } }; #endif diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 5500de1c..387ee6be 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -68,6 +68,11 @@ struct mAng { f32 radian() const { return ((2.f * M_PI) / 65536.0f) * mVal; } + + f32 radian2() const { + return mVal * sAngToRad; + } + static s16 fromRad(f32 rad) { return rad * sRadToAng; } diff --git a/include/m/m_mtx.h b/include/m/m_mtx.h index e3dabf65..12fb49bf 100644 --- a/include/m/m_mtx.h +++ b/include/m/m_mtx.h @@ -9,6 +9,7 @@ #include "m/m_vec.h" #include "nw4r/types_nw4r.h" #include "rvl/MTX/mtx.h" +#include "rvl/MTX/mtxvec.h" class mMtx_c : public EGG::Matrix34f { typedef f32 (*MtxRef)[4]; @@ -70,6 +71,11 @@ public: void trans(f32 x, f32 y, f32 z) { PSMTXTrans(*this, x, y, z); } + mVec3_c multVec(const mVec3_c &v) const { + mVec3_c ret = v; + PSMTXMultVec(*this, ret, ret); + return ret; + } mMtx_c &operator+=(const mMtx_c &rhs) { PSMTXConcat(*this, rhs, *this); diff --git a/include/m/m_vec.h b/include/m/m_vec.h index 4e21dafc..b2564cfa 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -217,6 +217,13 @@ public: return PSVECMag(*this); } + f32 distance(const mVec3_c &to) const { + return EGG::Math::sqrt(PSVECSquareDistance(*this, to)); + } + + f32 squareMagXZ() const { + return x * x + z * z; + } void rotY(const mAng &angle); void CopyTo(nw4r::math::VEC3 *p) { diff --git a/src/d/a/d_a_insect.cpp b/src/d/a/d_a_insect.cpp index 9ae59c4a..af296b3c 100644 --- a/src/d/a/d_a_insect.cpp +++ b/src/d/a/d_a_insect.cpp @@ -1,47 +1,96 @@ #include "d/a/d_a_insect.h" +#include "c/c_math.h" #include "common.h" #include "d/a/d_a_player.h" +#include "d/col/bg/d_bg_pc.h" +#include "d/col/bg/d_bg_s.h" +#include "d/col/bg/d_bg_s_acch.h" +#include "d/col/bg/d_bg_s_lin_chk.h" +#include "d/col/bg/d_bg_w_base.h" +#include "d/col/c/c_cc_d.h" +#include "d/col/c/c_m3d_g_pla.h" #include "egg/math/eggMath.h" +#include "m/m_angle.h" +#include "m/m_mtx.h" #include "m/m_vec.h" #include "rvl/MTX/mtxvec.h" #include "toBeSorted/attention.h" -void AcOInsectFloats() { - 50.0f; - 1.0f; - 30.0f; - 5000.0f; - 0.1f; - 10.0f; - 500.0f; - 0.0f; - 400.0f; - -200.0f; - 200.0f; - 20.0f; - EGG::Math::epsilon(); - 5.0f; - -5.0f; - 0.99f; - int x = 0; - (f32) x; +#include + +// Very Hack ?? +static inline bool IsZero(f32 in) { + return in <= EGG::Math::epsilon(); } -void AcOInsectFloats2() { - -1.0f; - 0.5f; - 2250000.0f; +// void AcOInsectFloats() { +// 50.0f; +// 1.0f; +// 30.0f; +// 5000.0f; +// 0.1f; +// 10.0f; +// 500.0f; +// 0.0f; +// 400.0f; +// -200.0f; +// 200.0f; +// 20.0f; +// EGG::Math::epsilon(); +// 5.0f; +// -5.0f; +// 0.99f; +// int x = 0; +// (f32) x; +// } + +// void AcOInsectFloats2() { +// -1.0f; +// 0.5f; +// 2250000.0f; +// } + +extern "C" void fn_800298B0(u16, mVec3_c *, mVec3_c *, u32, u32, u32, u32, u32); +extern "C" u16 PARTICLE_RESOURCE_ID_MAPPING_394_; + +void dAcOInsect_c::kill() { + // Small Ordering issue between loading particle id and position + fn_800298B0(PARTICLE_RESOURCE_ID_MAPPING_394_, &position, nullptr, 0, 0, 0, 0, 0); + playSound(0x1236); // TODO (Sound ID) + deleteRequest(); } bool dAcOInsect_c::checkForLinkScare() { if (dAcPy_c::LINK != nullptr) { - // TODO + if (dAcPy_c::LINK->getCurrentAction() == 12 /* Rolling */) { // TODO (Player Action Enum) + if (dAcPy_c::LINK->getDistanceTo(position) < 50.f) { + mLinkNearby = 1; + return true; + } + } else if (dAcPy_c::LINK->forwardSpeed > 1.f) { + if (dAcPy_c::LINK->getDistanceTo(position) < 30.f) { + mLinkNearby = 1; + return true; + } + } } return false; } +void dAcOInsect_c::checkDeath(dBgS_Acch &acch) { + if (acch.ChkWaterHit() && acch.mWtr.GetGroundH() >= position.y) { + kill(); + } + if (acch.ChkGroundLanding() && dBgS::GetInstance()->GetSpecialCode(acch.mGnd) == POLY_ATTR_LAVA) { + kill(); + } + if (position.y < pos_copy.y - 5000.f) { + deleteRequest(); + } +} + bool dAcOInsect_c::isLinkUsingBugNet() { if (dAcPy_c::LINK != nullptr && !dAcPy_c::LINK->isUsingBugnet()) { return false; @@ -64,14 +113,14 @@ s32 dAcOInsect_c::getLinkSpeedLevel() { return 3; } -bool dAcOInsect_c::isLinkNearby(f32 rad) { +bool dAcOInsect_c::checkPlayerRadius(f32 rad) { if (dAcPy_c::LINK != nullptr && isWithinPlayerRadius(rad)) { return true; } return false; } -bool dAcOInsect_c::isLinkNearbyZ(f32 dist) { +bool dAcOInsect_c::checkPlayerElevationDiff(f32 dist) { if (dAcPy_c::LINK != nullptr && fabsf(dAcPy_c::LINK->position.y - position.y) > dist) { return false; } @@ -81,7 +130,7 @@ bool dAcOInsect_c::isLinkNearbyZ(f32 dist) { void dAcOInsect_c::someBaseFunction() { dAcPy_c *link = dAcPy_c::LINK; if (link != nullptr) { - if (isLinkNearbyZ(500.0f) && isLinkNearby(dAcOInsect_0x8C())) { + if (checkPlayerElevationDiff(500.0f) && checkPlayerRadius(dAcOInsect_0x8C())) { field_0x335 = field_0x334; field_0x334 = link->isUsingBugnet1(); if (link->isUsingBugnet1()) { @@ -100,7 +149,7 @@ void dAcOInsect_c::someBaseFunction() { bool dAcOInsect_c::someBaseFunction0() { f32 rad = dAcOInsect_0x80(); - if (isLinkNearbyZ(500.0f) && isLinkNearby(rad)) { + if (checkPlayerElevationDiff(500.0f) && checkPlayerRadius(rad)) { field_0x338 = 1; return true; } @@ -130,9 +179,7 @@ void dAcOInsect_c::addAttentionTarget() { void dAcOInsect_c::preAttention() { // It's always the simplest vector functions that cause problems poscopy2 = position; - f32 y = position.y; - y += 20.0f; - poscopy2.y = y; + poscopy2.y += 20.f; poscopy3 = poscopy2; } @@ -153,6 +200,31 @@ bool dAcOInsect_c::isLinkCloseAndFlag() { return false; } +bool dAcOInsect_c::checkDeath(cCcD_Obj &col) { + if (field_0x3F4 != 0) { + field_0x3F4--; + return false; + } + + if (col.ChkTgHit() && + (col.ChkTgAtHitType(AT_TYPE_0x2) || col.ChkTgAtHitType(AT_TYPE_0x8) || col.ChkTgAtHitType(AT_TYPE_0x20) || + col.ChkTgAtHitType(AT_TYPE_0x40) || col.ChkTgAtHitType(AT_TYPE_0x80) || col.ChkTgAtHitType(AT_TYPE_0x2000) || + col.ChkTgAtHitType(AT_TYPE_0x4000) || col.ChkTgAtHitType(AT_TYPE_0x800000) || + col.ChkTgAtHitType(AT_TYPE_0x800))) { + mLinkNearby = 0; + return true; + } + + return false; +} + +bool dAcOInsect_c::checkCaught(cCcD_Obj &col) { + if (col.ChkTgHit() && col.ChkTgAtHitType(AT_TYPE_BUGNET)) { + return true; + } + return false; +} + bool dAcOInsect_c::resetScale() { mScale.set(1.0f, 1.0f, 1.0f); return true; @@ -166,6 +238,50 @@ bool dAcOInsect_c::fn_8018FAA0() { return false; } +bool dAcOInsect_c::fn_8018FAD0() { + f32 speed = fabsf(forwardSpeed); + if (IsZero(speed)) { + fn_8018FDF0(mPlane_0x3A8.GetN()); + return true; + } else { + f32 clampSpeed = speed < 5.0f ? forwardSpeed > 0.f ? forwardSpeed : -5.f : 5.f; + + mVec3_c pos0 = position + field_0x360; + mVec3_c pos1 = pos0 + field_0x36C * forwardSpeed; + int linType = fn_801900B0(pos0, pos1); + field_0x410[0] = pos0; + field_0x434[0] = pos1; + // TODO + } +} + +void dAcOInsect_c::fn_8018FDF0(const mVec3_c &point) { + mMtx_c mtx; + field_0x360 = point; + mtx.setAxisRotation(field_0x360, rotation.y.radian2()); + // TODO + f32 a_comparision = 0.99f; +} + +int dAcOInsect_c::fn_801900B0(const mVec3_c &point0, const mVec3_c &point1) { + cM3dGPla pla; + if (!dBgS_ObjLinChk::LineCross(&point0, &point1, this)) { + return 1; + } + if (!dBgS_ObjLinChk::GetTriPla(&pla)) { + return 1; + } + if (mMaterial != dBgS_ObjLinChk::GetMaterial()) { + return 2; + } + + position = dBgS_ObjLinChk::GetInstance().GetLinEnd(); + mPlane_0x3A8 = pla; + field_0x3BC = 1; + fn_8018FDF0(pla.GetN()); + return 0; +} + // Looks like it decides on a direction and angle based on a target point? bool dAcOInsect_c::fn_80190180(mAng &outAng) { // Stack and reg problems @@ -186,11 +302,8 @@ bool dAcOInsect_c::fn_80190180(mAng &outAng) { if (field_0x3BF != 0) { f32 len = fabsf(field_0x33C.y + field_0x35C * 0.5f - position.y); for (int i = 0; i < 4; i++) { - mVec3_c tmp = vecs[i] * 20.0f; - // ??? - mVec3_c tmp2 = tmp; - PSMTXMultVec(field_0x3C0, tmp2, tmp2); - f32 len2 = fabsf(field_0x33C.y + field_0x35C * 0.5f - tmp2.y); + // mVec3_c tmp2 = field_0x3C0.multVec(vecs[i] * 20.0f); + f32 len2 = fabsf(field_0x33C.y + field_0x35C * 0.5f - field_0x3C0.multVec(vecs[i] * 20.0f).y); if (len > len2) { len = len2; i3 = i; @@ -198,14 +311,10 @@ bool dAcOInsect_c::fn_80190180(mAng &outAng) { } } else if (field_0x3BE != 0) { mVec3_c dir = field_0x33C - position; - f32 len = dir.x * dir.x + dir.z * dir.z; + f32 len = dir.squareMagXZ(); for (int i = 0; i < 4; i++) { - mVec3_c tmp = vecs[i] * 20.0f; - // ??? - mVec3_c tmp2 = tmp; - PSMTXMultVec(field_0x3C0, tmp2, tmp2); - mVec3_c dir2 = field_0x33C - tmp2; - f32 len2 = dir2.x * dir2.x + dir2.z * dir2.z; + // mVec3_c tmp2 = field_0x3C0.multVec(vecs[i] * 20.0f); + f32 len2 = (field_0x33C - field_0x3C0.multVec(vecs[i] * 20.0f)).squareMagXZ(); if (len > len2) { len = len2; i3 = i; @@ -221,3 +330,13 @@ bool dAcOInsect_c::fn_80190180(mAng &outAng) { return false; } + +void dAcOInsect_c::fn_80190440() { + f32 a = 2250000.f; // float order +} + +void dAcOInsect_c::fn_80190160() { + field_0x33C = field_0x348; + field_0x354 = field_0x358; + field_0x40C = 0; +} From d7e874b23eff0e87a2bbeec5d5ee379a54d5e112 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 8 Nov 2024 23:09:16 -0500 Subject: [PATCH 3/3] cleanup comments --- src/d/a/d_a_insect.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/d/a/d_a_insect.cpp b/src/d/a/d_a_insect.cpp index af296b3c..1cebf79e 100644 --- a/src/d/a/d_a_insect.cpp +++ b/src/d/a/d_a_insect.cpp @@ -24,33 +24,6 @@ static inline bool IsZero(f32 in) { return in <= EGG::Math::epsilon(); } -// void AcOInsectFloats() { -// 50.0f; -// 1.0f; -// 30.0f; -// 5000.0f; -// 0.1f; -// 10.0f; -// 500.0f; -// 0.0f; -// 400.0f; -// -200.0f; -// 200.0f; -// 20.0f; -// EGG::Math::epsilon(); -// 5.0f; -// -5.0f; -// 0.99f; -// int x = 0; -// (f32) x; -// } - -// void AcOInsectFloats2() { -// -1.0f; -// 0.5f; -// 2250000.0f; -// } - extern "C" void fn_800298B0(u16, mVec3_c *, mVec3_c *, u32, u32, u32, u32, u32); extern "C" u16 PARTICLE_RESOURCE_ID_MAPPING_394_; @@ -177,7 +150,6 @@ void dAcOInsect_c::addAttentionTarget() { } void dAcOInsect_c::preAttention() { - // It's always the simplest vector functions that cause problems poscopy2 = position; poscopy2.y += 20.f; poscopy3 = poscopy2;