summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_leaflift.cpp
blob: 993b9455b12636a788617b5daa1d056169ac6160 (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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
 * d_a_leaflift.cpp
 * Object - Forest Haven - Lilypad lift
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_leaflift.h"
#include "d/d_bg_s_func.h"
#include "d/d_bg_s_movebg_actor.h"
#include "d/d_com_inf_game.h"
#include "d/d_lib.h"
#include "res/Object/Olift.h"
#include "m_Do/m_Do_ext.h"

static dCcD_SrcCyl l_cyl_src = {
    // dCcD_SrcGObjInf
    {
        /* Flags             */ 0,
        /* SrcObjAt  Type    */ 0,
        /* SrcObjAt  Atp     */ 0,
        /* SrcObjAt  SPrm    */ 0,
        /* SrcObjTg  Type    */ 0,
        /* SrcObjTg  SPrm    */ 0,
        /* SrcObjCo  SPrm    */ cCcD_CoSPrm_Set_e | cCcD_CoSPrm_IsOther_e | cCcD_CoSPrm_VsGrpAll_e,
        /* SrcGObjAt Se      */ 0,
        /* SrcGObjAt HitMark */ 0,
        /* SrcGObjAt Spl     */ 0,
        /* SrcGObjAt Mtrl    */ 0,
        /* SrcGObjAt SPrm    */ 0,
        /* SrcGObjTg Se      */ 0,
        /* SrcGObjTg HitMark */ 0,
        /* SrcGObjTg Spl     */ 0,
        /* SrcGObjTg Mtrl    */ 0,
        /* SrcGObjTg SPrm    */ cCcD_TgSPrm_IsPlayer_e,
        /* SrcGObjCo SPrm    */ 0,
    },
    // cM3dGCylS
    {{
        /* Center */ {0.0f, 0.0f, 0.0f},
        /* Radius */ 280.0f,
        /* Height */ 510.0f,
    }},
};

static cXyz up_vec(0.0f, 1.0f, 0.0f);

const char daLlift_c::m_arcname[6] = "Olift";

/* 000000EC-000001C0       .text _delete__9daLlift_cFv */
bool daLlift_c::_delete() {
    if (mEmitter1) {
        mEmitter1->becomeInvalidEmitter();
        mEmitter1 = NULL;
    }
    if (mEmitter2) {
        mEmitter2->becomeInvalidEmitter();
        mEmitter2 = NULL;
    }
    if (mEmitter3) {
        mEmitter3->becomeInvalidEmitter();
        mEmitter3 = NULL;
    }
#if VERSION > VERSION_DEMO
    if (heap)
#endif
    {
        dComIfG_Bgsp()->Release(mpBgW);
    }
    dComIfG_resDeleteDemo(&mPhs, m_arcname);
    return TRUE;
}

/* 000001C0-000001E0       .text CheckCreateHeap__FP10fopAc_ac_c */
static BOOL CheckCreateHeap(fopAc_ac_c* i_this) {
    return ((daLlift_c*)i_this)->CreateHeap();
}

static void rideCallBack(dBgW* param1, fopAc_ac_c* i_this, fopAc_ac_c* i_other);

/* 000001E0-00000338       .text CreateHeap__9daLlift_cFv */
BOOL daLlift_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData *)dComIfG_getObjectRes(m_arcname, dRes_INDEX_OLIFT_BDL_OLIFT_e);
    JUT_ASSERT(DEMO_SELECT(327, 334), modelData != NULL);

    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000022);
    if (!mpModel) {
        return FALSE;
    }

    mpModel->setUserArea((u32)this);
    mpBgW = new dBgW();
    if (mpBgW) {
        cBgD_t* pData = (cBgD_t *)dComIfG_getObjectRes(m_arcname, dRes_INDEX_OLIFT_DZB_OLIFT_e);
        if (mpBgW->Set(pData, cBgW::MOVE_BG_e, &mMtx) == 1) {
            return FALSE; 
        }
        mpBgW->SetCrrFunc(dBgS_MoveBGProc_TypicalRotY);
        mpBgW->SetRideCallback(rideCallBack);
    }
    else {
        return FALSE;
    }
    return TRUE;
} 

static BOOL nodeCallBack(J3DNode* node, int calcTiming);

/* 00000338-000005F8       .text CreateInit__9daLlift_cFv */
void daLlift_c::CreateInit() {
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    fopAcM_setCullSizeBox(this, -300.0f, -600.0f, -300.0f, 300.0f, 100.0f, 300.0f);
    fopAcM_setCullSizeFar(this, 1.0f);
    mStts.Init(0xFF,0xFF,this);
    mCyl.Set(l_cyl_src);
    mCyl.SetStts(&mStts);
    cXyz waterCheckPos = current.pos;
    waterCheckPos.y += 200.0f;
    mWaterY = dBgS_ObjGndChk_Wtr_Func(waterCheckPos);
    if (mWaterY != -G_CM3D_F_INF) {
        cXyz particlePos = current.pos;
        particlePos.y = mWaterY + 1.0f; 
        mEmitter3 = dComIfGp_particle_set(dPa_name::ID_IT_SN_DEKLIFT_HAMONA00, &particlePos, &current.angle);
        if (mEmitter3) {
            mEmitter3->stopCreateParticle();
        }
    }
    home.pos.y += 15.0f;
    current.pos.y = home.pos.y;
    JUTNameTab* jointName = mpModel->getModelData()->getJointName();
    for (u16 i = 0; i < mpModel->getModelData()->getJointNum(); i++) {
        if (strcmp("j_happa", jointName->getName(i)) == 0) {
            mpModel->getModelData()->getJointNodePointer(i)->setCallBack(&nodeCallBack);
            break;
        }
    }
    mTargetRotation = ZeroQuat;
    mCurrentRotation = mTargetRotation;
    if ((s32)daLlift_prm::getPos(this) == 1) {
        current.pos.y =  home.pos.y + m_height;
    }
    else {
        if (mEmitter3) {
            mEmitter3->playCreateParticle();
        }
    }
    m43F = 0x1e;
    mpModel->calc();
    setMoveBGMtx();
    dComIfG_Bgsp()->Regist(mpBgW, this);
    set_mtx();
    mpBgW->Move();
}

/* 00000634-00000760       .text _create__9daLlift_cFv */
cPhs_State daLlift_c::_create() {
    int res;
    fopAcM_ct(this, daLlift_c);
    res = dComIfG_resLoad(&mPhs, m_arcname);
    if (res == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, CheckCreateHeap, 0xf40)) {
            return cPhs_ERROR_e;
        }
        else {
            CreateInit();
        }
    }
    return res;
}

/* 00000918-000009C4       .text nodeCallBack__FP7J3DNodei */
static BOOL nodeCallBack(J3DNode* node, int calcTiming) {
    if (calcTiming == J3DNodeCBCalcTiming_In) {
        J3DJoint* joint = (J3DJoint*)node;
        s32 jntNo = joint->getJntNo();
        J3DModel* model = j3dSys.getModel();
        daLlift_c* i_this = (daLlift_c*)model->getUserArea();
        if (i_this) {
            mDoMtx_stack_c::copy(model->getAnmMtx(jntNo));
            mDoMtx_stack_c::quatM(&i_this->mCurrentRotation);
            cMtx_copy(mDoMtx_stack_c::get(), J3DSys::mCurrentMtx);
            model->setAnmMtx(jntNo, mDoMtx_stack_c::get());
            cMtx_copy(mDoMtx_stack_c::get(), i_this->mBGMtx);
        }
    }
    return TRUE;
}

/* 000009C4-00000CAC       .text rideCallBack__FP4dBgWP10fopAc_ac_cP10fopAc_ac_c */
static void rideCallBack(dBgW* param1, fopAc_ac_c* i_act, fopAc_ac_c* i_other) {
    daLlift_c* i_this = (daLlift_c*)i_act;
    f32 tiltFactor;
    f32 offsetMagnitude;

    cXyz posOffset = i_other->current.pos - i_this->current.pos;
    tiltFactor = 2.0f;
    if (fopAcM_GetName(i_other) == fpcNm_PLAYER_e) {
        i_this->m43C = TRUE;
        i_this->m43E = TRUE;
        posOffset = posOffset.outprod(up_vec);
        mDoMtx_stack_c::YrotS(-i_this->current.angle.y);
        mDoMtx_stack_c::multVec(&posOffset, &posOffset);
        if (i_this->m43D) {
            posOffset = i_other->current.pos;
            posOffset.x += 200.0f;
            posOffset = posOffset.outprod(up_vec);
            mDoMtx_stack_c::YrotS(-i_this->current.angle.y);
            mDoMtx_stack_c::multVec(&posOffset, &posOffset);
            s16 angle = (i_this->mActorLifetimeFrameCount % 32U) * (0x10000 / 32);
            tiltFactor = cM_ssin(angle) * tiltFactor * 0.25f * (cM_rndFX(0.2f) + 1.0f);
        }
        offsetMagnitude = posOffset.abs();
        if (!posOffset.normalizeRS() ) {
          return;
        }
        s16 temp = -offsetMagnitude * tiltFactor;
        cLib_addCalcAngleS2(&i_this->mTiltAngle, temp, 8, 0x200);
        tiltFactor = cM_ssin(i_this->mTiltAngle);
        i_this->mTargetRotation.x = posOffset.x * tiltFactor;
        i_this->mTargetRotation.y = posOffset.y * tiltFactor;
        i_this->mTargetRotation.z = posOffset.z * tiltFactor;
        i_this->mTargetRotation.w = cM_scos(i_this->mTiltAngle);
    }
    i_this->m43D = FALSE;
}

/* 00000CAC-00000D34       .text set_mtx__9daLlift_cFv */
void daLlift_c::set_mtx() {
    mpModel->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(current.angle);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

/* 00000D34-00000D9C       .text setMoveBGMtx__9daLlift_cFv */
void daLlift_c::setMoveBGMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(current.angle.y);
    mDoMtx_stack_c::quatM(&mCurrentRotation);
    MTXCopy(mDoMtx_stack_c::get(), mMtx);
}

/* 00000D9C-00000F24       .text _execute__9daLlift_cFv */
bool daLlift_c::_execute() {
    Quaternion interpolatedRotation;
    cXyz adjustedPosition;
    f32 distXZ = fopAcM_searchActorDistanceXZ(this, dComIfGp_getPlayer(0));
    f32 f2 = 270.0f;
    mActorLifetimeFrameCount++;
    if (m43F > 0) {
        m43F--;
        if (m43F == 0) {
            m43E = TRUE;
        }
    }
    if ((!m43C) && (m43E)) {
        mTargetRotation = ZeroQuat;
        if (distXZ > f2) {
            mbIsDescending = TRUE;
        }
    }
    MoveDownLift();
    set_mtx();
    setMoveBGMtx();
    m43C = FALSE;
    mpModel->calc();
    mDoMtx_quatSlerp(&mCurrentRotation, &mTargetRotation, &interpolatedRotation, 0.25f);
    mCurrentRotation = interpolatedRotation;
    mpBgW->Move();
    adjustedPosition = current.pos;
    adjustedPosition.y -= m_height;
    mCyl.SetC(adjustedPosition);
    dComIfG_Ccsp()->Set(&mCyl);
    emitterCtrl();
    return TRUE;
}

/* 00000F24-00000FE0       .text emitterCtrl__9daLlift_cFv */
void daLlift_c::emitterCtrl() {  
    if (mEmitterTimer == 200) {
        if (mEmitter1) {
            mEmitter1->becomeInvalidEmitter();
            mEmitter1 = NULL;
        }
        if (mEmitter2) {
            mEmitter2->becomeInvalidEmitter();
            mEmitter2 = NULL;
        }
    }
    if (mEmitter1) {
        mEmitter1->setGlobalRTMatrix(mBGMtx);
    }
    if (mEmitter2) {
        mEmitter2 ->setGlobalRTMatrix(mBGMtx);
    }
}

/* 00000FE0-000010E0       .text MoveDownLift__9daLlift_cFv */
BOOL daLlift_c::MoveDownLift() {
    float maxSpeed = m_max_speed;
    float minSpeed = m_min_speed;
    if (!mbIsDescending) {
        return TRUE;
    }
    float downVel = cLib_addCalc(&current.pos.y, home.pos.y, 0.1f, maxSpeed, minSpeed);
    if (downVel == 0.0f) {
        mbIsAscending = FALSE;
        mbIsDescending = FALSE;
        if (mEmitter3) {
            mEmitter3->playCreateParticle();
        }
        return TRUE;
    }
    if (downVel != 0.0f && !mbIsAscending) {
        fopAcM_seStart(this, JA_SE_OBJ_LOTUS_LIFT_DOWN, 0);
        mbIsAscending = TRUE;
    }
    return FALSE;
}

/* 000010E0-00001180       .text _draw__9daLlift_cFv */
bool daLlift_c::_draw() {
    g_env_light.settingTevStruct(TEV_TYPE_BG0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelEntryDL(mpModel);
    dComIfGd_setList();
    return TRUE;
}

/* 00001180-000011A0       .text daLlift_Create__FPv */
static cPhs_State daLlift_Create(void* i_this) {
    return ((daLlift_c*)i_this)->_create();
}

/* 000011A0-000011C4       .text daLlift_Delete__FPv */
static BOOL daLlift_Delete(void* i_this) {
    return ((daLlift_c*)i_this)->_delete();
}

/* 000011C4-000011E8       .text daLlift_Draw__FPv */
static BOOL daLlift_Draw(void* i_this) {
    return ((daLlift_c*)i_this)->_draw();
}

/* 000011E8-0000120C       .text daLlift_Execute__FPv */
static BOOL daLlift_Execute(void* i_this) {
    return ((daLlift_c*)i_this)->_execute();
}

/* 0000120C-00001214       .text daLlift_IsDelete__FPv */
static BOOL daLlift_IsDelete(void* i_this) {
    return TRUE;
}

static actor_method_class daLliftMethodTable = {
    (process_method_func)daLlift_Create,
    (process_method_func)daLlift_Delete,
    (process_method_func)daLlift_Execute,
    (process_method_func)daLlift_IsDelete,
    (process_method_func)daLlift_Draw,
};

actor_process_profile_definition g_profile_LEAF_LIFT = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0003,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_LEAF_LIFT_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daLlift_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_LEAF_LIFT_e,
    /* Actor SubMtd */ &daLliftMethodTable,
    /* Status       */ fopAcStts_NOCULLEXEC_e | fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};