summaryrefslogtreecommitdiff
path: root/src/REL/d/a/obj/d_a_obj_cloud_dive.cpp
blob: 7e87cbd5c5d566a8d0e112d68c401bd4e89255eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "d/a/obj/d_a_obj_cloud_dive.h"

#include "d/a/d_a_item.h"
#include "d/a/d_a_player.h"
#include "d/a/obj/d_a_obj_base.h"
#include "d/col/cc/d_cc_s.h"
#include "egg/math/eggMath.h"
#include "f/f_base.h"
#include "m/m_vec.h"

SPECIAL_ACTOR_PROFILE(OBJ_CLOUD_DIVE, dAcOcloudDive_c, fProfile::OBJ_CLOUD_DIVE, 0x1C2, 0, 0);

const f32 dAcOcloudDive_c::mRadius1 = 100.0f;
const f32 dAcOcloudDive_c::mRadius2 = 200.0f;
const f32 dAcOcloudDive_c::height = 40.0f;

dCcD_SrcCyl dAcOcloudDive_c::sCylSrc = {
    /* mObjInf */
    {/* mObjAt */ {0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0},
     /* mObjTg */
     {AT_TYPE_BOMB, 0x111, {0, 0, 0x407}, 0, 0},
     /* mObjCo */ {0}},
    /* mCylInf */
    {100.f, 10.f}
};

STATE_DEFINE(dAcOcloudDive_c, Wait);
STATE_DEFINE(dAcOcloudDive_c, Dead);

bool dAcOcloudDive_c::createHeap() {
    return true;
}

int dAcOcloudDive_c::create() {
    CREATE_ALLOCATOR(dAcOcloudDive_c);
    mStts.mRank = 0xD;
    mCollider.Set(sCylSrc);
    mCollider.mStts = &mStts;
    field_0x4DC = getFromParams(0, 3);
    mItemID = getFromParams(2, 0xFF);
    if ((u16)getFromParams(2, 0xFF) == 0xFF) {
        mItemID = 0;
    }
    if (field_0x4DC == 1) {
        mRadius = mRadius2;
    } else {
        mRadius = mRadius1;
    }
    updateMatrix();
    mStateMgr.changeState(StateID_Wait);
    mBoundingBox.Set(mVec3_c(-0.0f, -0.0f, -0.0f), mVec3_c(0.0f, 0.0f, 0.0f));
    return SUCCEEDED;
}

int dAcOcloudDive_c::doDelete() {
    return SUCCEEDED;
}

int dAcOcloudDive_c::actorExecute() {
    mStateMgr.executeState();
    mCollider.SetR(mRadius);
    mCollider.SetH(height);
    mCollider.SetC(mPosition - mVec3_c(0.0f, height / 2, 0.0f));
    dCcS::GetInstance()->Set(&mCollider);
    return SUCCEEDED;
}

int dAcOcloudDive_c::draw() {
    return SUCCEEDED;
}

void dAcOcloudDive_c::initializeState_Wait() {}

void dAcOcloudDive_c::executeState_Wait() {
    if (fn_350_6F0()) {
        mStateMgr.changeState(StateID_Dead);
    }
    if (fn_350_760()) {
        dAcItem_c::giveItem22((ITEM_ID)mItemID, 0, -1);
        mStateMgr.changeState(StateID_Dead);
    }
}

void dAcOcloudDive_c::finalizeState_Wait() {}

void dAcOcloudDive_c::initializeState_Dead() {
    deleteRequest();
}

void dAcOcloudDive_c::executeState_Dead() {}
void dAcOcloudDive_c::finalizeState_Dead() {}

bool dAcOcloudDive_c::fn_350_6F0() {
    return mCollider.mTg.mRPrm & 1 && mCollider.mTg.GetActor() != nullptr && mCollider.ChkTgAtHitType(0x20);
}

bool dAcOcloudDive_c::fn_350_760() {
    bool ret = false;
    bool temp = false;

    mVec3_c deltaPosition = dAcPy_c::GetLink()->mPosition - mPosition;
    f32 distance = EGG::Math<f32>::sqrt(deltaPosition.squareMagXZ());

    if (distance <= mRadius) {
        if (deltaPosition.y <= height / 2) {
            temp = true;
        }
    }
    if (temp) {
        if (deltaPosition.y >= -height / 2) {
            ret = true;
        }
    }
    return ret;
}