summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_acorn_leaf.cpp
blob: 6c5a3845ac18f89ab7563b177e05a77f58706466 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
// Generated by dtk
// Translation Unit: d_a_acorn_leaf.cpp
//

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_acorn_leaf.h"
#include "d/d_cc_d.h"
#include "d/d_com_inf_game.h"
#include "f_op/f_op_actor_mng.h"
#include "JSystem/J3DGraphAnimator/J3DModel.h"
#include "d/actor/d_a_tsubo.h"
#include "d/actor/d_a_player.h"
#include "res/Object/VigaH.h"

static cXyz acorn_offset(0.0f, 15.0f, 0.0f);

static dCcD_SrcCyl l_cyl_src = {
    // dCcD_SrcGObjInf
    {
        /* Flags             */ 0,
        /* SrcObjAt  Type    */ 0,
        /* SrcObjAt  Atp     */ 0,
        /* SrcObjAt  SPrm    */ 0,
        /* SrcObjTg  Type    */ AT_TYPE_ALL,
        /* SrcObjTg  SPrm    */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsOther_e,
        /* SrcObjCo  SPrm    */ cCcD_CoSPrm_Set_e | cCcD_CoSPrm_IsOther_e | cCcD_CoSPrm_VsGrpAll_e,
        /* SrcGObjAt Se      */ 0,
        /* SrcGObjAt HitMark */ dCcG_AtHitMark_None_e,
        /* SrcGObjAt Spl     */ dCcG_At_Spl_UNK0,
        /* SrcGObjAt Mtrl    */ 0,
        /* SrcGObjAt SPrm    */ 0,
        /* SrcGObjTg Se      */ 0,
        /* SrcGObjTg HitMark */ 0,
        /* SrcGObjTg Spl     */ dCcG_Tg_Spl_UNK0,
        /* SrcGObjTg Mtrl    */ 0,
        /* SrcGObjTg SPrm    */ dCcG_TgSPrm_NoHitMark_e,
        /* SrcGObjCo SPrm    */ 0,
    },
    // cM3dGCylS
    {{
        /* Center */ {0.0f, 0.0f, 0.0f},
        /* Radius */ 0.0f,
        /* Height */ 0.0f,
    }},
};

const char daAleaf_c::m_arcname[] = "VigaH";

namespace daAleaf_prm {
    inline u32 getItemBitNo(daAleaf_c* actor) {
        return (fopAcM_GetParam(actor) >> 6) & 0x7F;
    }

    inline u32 getItemNo(daAleaf_c* actor) {
        return fopAcM_GetParam(actor) & 0x3F;
    }
};

/* 000000EC-0000010C       .text CheckCreateHeap__FP10fopAc_ac_c */
static BOOL CheckCreateHeap(fopAc_ac_c* i_actor) {
    return ((daAleaf_c*)i_actor)->CreateHeap();
}

/* 0000010C-00000258       .text CreateHeap__9daAleaf_cFv */
BOOL daAleaf_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(daAleaf_c::m_arcname, dRes_INDEX_VIGAH_BDL_VIGAH_e);
    JUT_ASSERT(DEMO_SELECT(258, 262), modelData != NULL);

    unk_298 = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000022);
    if (unk_298 == NULL) {
        return FALSE;
    }

    J3DAnmTransform* pbck = (J3DAnmTransform*)dComIfG_getObjectRes(daAleaf_c::m_arcname, dRes_INDEX_VIGAH_BCK_VIGAH_e);
    JUT_ASSERT(DEMO_SELECT(273, 277), pbck != NULL);

    if (!unk_408.init(modelData, pbck, true, J3DFrameCtrl::EMode_RESET)) {
        return FALSE;
    }

    return TRUE;
}

/* 00000258-00000314       .text CreateInit__9daAleaf_cFv */
void daAleaf_c::CreateInit() {
    fopAcM_SetMtx(this, unk_298->getBaseTRMtx());
    fopAcM_setCullSizeBox(this, -50.0f, 0.0f, -50.0f, 50.0f, 100.0f, 50.0f);
    unk_29C.Init(255, 255, this);
    unk_2D8.Set(l_cyl_src);
    unk_2D8.SetStts(&unk_29C);
    current.angle = home.angle;
    unk_428 = fpcM_ERROR_PROCESS_ID_e;
    unk_424 = fpcM_ERROR_PROCESS_ID_e;
    set_mtx();
    create_acorn_sub(false);
}

/* 00000314-00000384       .text create_acorn__9daAleaf_cFv */
void daAleaf_c::create_acorn(void) {
    fopAc_ac_c* sp8;

    if ((unk_420 == 0) && !fopAcM_SearchByID(unk_424, &sp8)) {
        create_acorn_sub(true);
        unk_420 = 60;
    }

    if (unk_420 > 0) {
        unk_420--;
    }
}

/* 00000384-00000460       .text create_acorn_sub__9daAleaf_cFb */
fpc_ProcID daAleaf_c::create_acorn_sub(bool arg1) {
    u32 params = daTsubo::Act_c::prm_make_acorn(arg1, daAleaf_prm::getItemNo(this), daAleaf_prm::getItemBitNo(this));

    mDoMtx_stack_c::XrotS(home.angle.x);
    cXyz sp10;
    mDoMtx_stack_c::multVec(&acorn_offset, &sp10);

    unk_424 = fopAcM_createChildFromOffset(fpcNm_TSUBO_e, fpcM_GetID(this), params, &sp10, fopAcM_GetRoomNo(this), NULL, NULL, -1, NULL);
    unk_41B = false;
    unk_41C = false;

    return unk_424;
}

/* 0000049C-000005EC       .text _create__9daAleaf_cFv */
cPhs_State daAleaf_c::_create() {
    fopAcM_ct(this, daAleaf_c);

    cPhs_State ret = dComIfG_resLoad(&unk_290, daAleaf_c::m_arcname);
    if (ret == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, CheckCreateHeap, 0x620)) {
            return cPhs_ERROR_e;
        }
        CreateInit();
    }
    return ret;
}

/* 00000848-000008D0       .text set_mtx__9daAleaf_cFv */
void daAleaf_c::set_mtx() {
    unk_298->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::ZXYrotM(current.angle.x, current.angle.y, current.angle.z);
    unk_298->setBaseTRMtx(mDoMtx_stack_c::get());
}

/* 000008D0-00000C44       .text _execute__9daAleaf_cFv */
bool daAleaf_c::_execute() {
    daPy_py_c* player = (daPy_py_c*)dComIfGp_getPlayer(0);
    fopAc_ac_c* actor = fopAcM_SearchByID(unk_424);
    
    bool var_r29 = false;

    if (actor != NULL) {
        var_r29 = ((daTsubo::Act_c*)actor)->prm_get_stick();
    }

    create_acorn();

    if (actor != NULL) {
        if (unk_41C < 69) {
            unk_41C++;
        }

        if (unk_41C == 69) {
            unk_418 = true;
            unk_408.setPlaySpeed(1.0f);
            unk_408.setFrame(0.0f);
            unk_41C = 70;
        }
    }

    if (!var_r29 && unk_419) {
        unk_418 = true;
        unk_408.setPlaySpeed(1.0f);
    }

    f32 var_f31 = (player->current.pos - current.pos).absXZ();

    if (var_f31 < 50.0f && (unk_42C - var_f31) > 3.0f && std::fabsf(player->current.pos.y - current.pos.y) < 5.0f) {
        unk_418 = true;
        unk_408.setPlaySpeed(1.0f);
    }

    if (var_f31 < 200.0f && unk_428 != player->getGrabActorID() && player->getGrabActorID() == fpcM_ERROR_PROCESS_ID_e) {
        fopAc_ac_c* actor = fopAcM_SearchByID(unk_428);

        if (actor != NULL) {
            f32 var_f1 = (actor->current.pos - current.pos).absXZ();
            
            if (var_f1 < 70.0f) {
                unk_418 = true;
                unk_408.setPlaySpeed(1.0f);
            }
        }
    }

    if (unk_418 && unk_408.play()) {
        unk_418 = false;
    }

    set_mtx();

    unk_419 = var_r29;
    unk_428 = player->getGrabActorID();
    unk_42C = var_f31;

    return true;
}

/* 00000C44-00000CD4       .text _draw__9daAleaf_cFv */
bool daAleaf_c::_draw() {
    g_env_light.settingTevStruct(TEV_TYPE_ACTOR, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(unk_298, &tevStr);

    unk_408.entry(unk_298->getModelData());
    mDoExt_modelUpdateDL(unk_298);
    unk_408.remove(unk_298->getModelData());

    return true;
}

bool daAleaf_c::_delete() {
    dComIfG_resDeleteDemo(&unk_290, daAleaf_c::m_arcname);
    return true;
}

/* 00000CD4-00000CF4       .text daAleaf_Create__FPv */
static cPhs_State daAleaf_Create(void* i_this) {
    return ((daAleaf_c*)i_this)->_create();
}

/* 00000CF4-00000D24       .text daAleaf_Delete__FPv */
static BOOL daAleaf_Delete(void* i_this) {
    return ((daAleaf_c*)i_this)->_delete();
}

/* 00000D24-00000D48       .text daAleaf_Draw__FPv */
static BOOL daAleaf_Draw(void* i_this) {
    return ((daAleaf_c*)i_this)->_draw();
}

/* 00000D48-00000D6C       .text daAleaf_Execute__FPv */
static BOOL daAleaf_Execute(void* i_this) {
    return ((daAleaf_c*)i_this)->_execute();
}

/* 00000D6C-00000D74       .text daAleaf_IsDelete__FPv */
static BOOL daAleaf_IsDelete(void*) {
    return TRUE;
}

static actor_method_class daAleafMethodTable = {
    (process_method_func)daAleaf_Create,
    (process_method_func)daAleaf_Delete,
    (process_method_func)daAleaf_Execute,
    (process_method_func)daAleaf_IsDelete,
    (process_method_func)daAleaf_Draw,
};

actor_process_profile_definition g_profile_ACORN_LEAF = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0007,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_ACORN_LEAF_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daAleaf_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_ACORN_LEAF_e,
    /* Actor SubMtd */ &daAleafMethodTable,
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};