summaryrefslogtreecommitdiff
path: root/src/d/d_ky_thunder.cpp
blob: f96cb38938ce1785b97bbdf8cd1255ad62db92d7 (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
//
// Generated by dtk
// Translation Unit: d_ky_thunder.cpp
//

#include "d/dolzel.h" // IWYU pragma: keep
#include "d/d_ky_thunder.h"
#include "f_op/f_op_kankyo.h"
#include "f_op/f_op_kankyo_mng.h"
#include "f_op/f_op_camera.h"
#include "d/d_com_inf_game.h"
#include "d/d_kankyo_rain.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
#include "JSystem/J3DGraphAnimator/J3DModel.h"
#include "SSystem/SComponent/c_phase.h"
#include "m_Do/m_Do_audio.h"
#include "m_Do/m_Do_ext.h"
#include "m_Do/m_Do_mtx.h"

dThunder_c::~dThunder_c() {
    mDoExt_destroySolidHeap(solid_heap);
}

BOOL dThunder_c::execute() {
    mModelInfo.mBrk.setPlaySpeed(1.0f);
    if (mModelInfo.mBrk.play()) {
        mDoAud_seStart(JA_SE_OBJ_THUNDER_FAR, &mPos);
        fopKyM_Delete(this);
    }
    return TRUE;
}

BOOL dThunder_c::draw() {
    static cXyz l_offsetPos(0.0f, 40.0f, -250.0f);
    mDoMtx_stack_c::transS(mPos);
    mDoMtx_stack_c::ZrotM(mRot);
    mDoMtx_stack_c::XrotM(mRot);

    Mtx m;
    MTXCopy(mDoMtx_stack_c::get(), m);
    mModelInfo.mpModel->setBaseScale(mScale);
    mModelInfo.mpModel->setBaseTRMtx(m);

    mModelInfo.mBtk.entry(mModelInfo.mpModel->getModelData(), mBtkTime);
    mModelInfo.mBrk.entry(mModelInfo.mpModel->getModelData());

    dComIfGd_setList();
    mDoExt_modelUpdateDL(mModelInfo.mpModel);
    mModelInfo.mInvisModel.entryMaskOff();
    mModelInfo.mBtk.remove(mModelInfo.mpModel->getModelData());
    mModelInfo.mBrk.remove(mModelInfo.mpModel->getModelData());
    return TRUE;
}

/* 80198810-8019886C       .text createHeap__10dThunder_cFv */
BOOL dThunder_c::createHeap() {
    if (solid_heap == NULL) {
        solid_heap = mDoExt_createSolidHeapFromGameToCurrent(0x4a0, 0x20);
        if (solid_heap == NULL)
            return FALSE;
    }

    return TRUE;
}

/* 8019886C-801988B8       .text adjustHeap__10dThunder_cFv */
void dThunder_c::adjustHeap() {
    mDoExt_restoreCurrentHeap();
    if (mDoExt_adjustSolidHeap(solid_heap) >= 0)
        DCStoreRangeNoSync(solid_heap->getStartAddr(), solid_heap->getHeapSize());
}

/* 801988B8-80198A38       .text dThunder_Draw__FP10dThunder_c */
static BOOL dThunder_Draw(dThunder_c* i_this) {
    return i_this->draw();
}

/* 80198A38-80198AB4       .text dThunder_Execute__FP10dThunder_c */
static BOOL dThunder_Execute(dThunder_c* i_this) {
    return i_this->execute();
}

/* 80198AB4-80198ABC       .text dThunder_IsDelete__FP10dThunder_c */
static BOOL dThunder_IsDelete(dThunder_c* i_this) {
    return TRUE;
}

/* 80198ABC-80198B68       .text dThunder_Delete__FP10dThunder_c */
static BOOL dThunder_Delete(dThunder_c* i_this) {
#if VERSION > VERSION_DEMO
    mDoAud_seDeleteObject(&i_this->mPos);
    mDoAud_seDeleteObject(&i_this->mPosNeg);
#endif
    i_this->~dThunder_c();
    return TRUE;
}

/* 80198B68-80198BC4       .text dThunder_Create__FP12kankyo_class */
static cPhs_State dThunder_Create(kankyo_class* i_ky) {
    dThunder_c * i_this = (dThunder_c *)i_ky;
    if (!i_this->createHeap())
        return cPhs_ERROR_e;

    cPhs_State ret = i_this->create();
    i_this->adjustHeap();
    return ret;
}

/* 80198BC4-801990CC       .text create__10dThunder_cFv */
cPhs_State dThunder_c::create() {
    dScnKy_env_light_c& envLight = dKy_getEnvlight();
    camera_class *pCamera = (camera_class*)dComIfGp_getCamera(0);

    new (this) dThunder_c();
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("Always", dRes_INDEX_ALWAYS_BDL_YTHDR00_e);
    JUT_ASSERT(DEMO_SELECT(111, 110), modelData != NULL);

    mModelInfo.mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x01000200);
    if (mModelInfo.mpModel == NULL)
        return cPhs_ERROR_e;

    if (!mModelInfo.mInvisModel.create(mModelInfo.mpModel))
        return cPhs_ERROR_e;

    J3DAnmTextureSRTKey * anm = (J3DAnmTextureSRTKey *)dComIfG_getObjectRes("Always", dRes_INDEX_ALWAYS_BTK_YTHDR00_e);
    JUT_ASSERT(DEMO_SELECT(126, 125), anm != NULL);
    if (!mModelInfo.mBtk.init(modelData, anm, false, J3DFrameCtrl::EMode_LOOP))
        return cPhs_ERROR_e;

    J3DAnmTevRegKey * canm = (J3DAnmTevRegKey *)dComIfG_getObjectRes("Always", dRes_INDEX_ALWAYS_BRK_YTHDR00_e);
    JUT_ASSERT(DEMO_SELECT(141, 140), canm != NULL);
    if (!mModelInfo.mBrk.init(modelData, canm, true, J3DFrameCtrl::EMode_NONE))
        return cPhs_ERROR_e;

    mBtkTime = cM_rndF(1.0f);

    f32 f31;
    f32 f30;
    f32 f29;
    f32 size = envLight.mThunderEff.mState < 10 ? 1.0f : 0.5f;
    cXyz fwd;
    f31 = 5.0f;
    f30 = 20.0f;
    f29 = 80.0f;
    cXyz offs(120000.0f, 2000.0f, 0.0f);

    mRot = 4000.0f;
    mRot = size * cM_rndFX(mRot);
    f32 f1 = cM_rndF(f30 - f31);
    mScale.x = size * (f31 + f1);
    if (cM_rndFX(1.0f) >= 0.5)
        mScale.x *= -1.0f;
    f1 = cM_rndF(f29 - f30);
    mScale.y = size * (f30 + f1);
    mScale.z = 1.0f;

    dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &pCamera->mLookat.mCenter, &fwd);
    f32 distXZ = std::sqrtf(fwd.x * fwd.x + fwd.z * fwd.z);

    s16 rotX = cM_atan2s(fwd.x, fwd.z);
    s16 rotY = cM_atan2s(fwd.y, distXZ);

    if (cM_rndFX(1.0f) >= 0.0f) {
        rotX += 0x4000;
    } else {
        rotX -= 0x4000;
    }

    cXyz rot;
    rot.x = cM_scos(rotY) * cM_ssin(rotX);
    rot.z = cM_scos(rotY) * cM_scos(rotX);

    f32 baseXZ = cM_rndF(offs.x);
    mPos.x = pCamera->mLookat.mEye.x + fwd.x * 100000.0f + rot.x * baseXZ;
    mPos.y = pCamera->mLookat.mEye.y + cM_rndFX(offs.y);
    mPos.z = pCamera->mLookat.mEye.z + fwd.z * 100000.0f + rot.z * baseXZ;

    if (cM_rndF(1.0f) < 0.3f) {
#if VERSION == VERSION_DEMO
        cXyz sp14;
        sp14.x = -mPos.x;
        sp14.y = -mPos.y;
        sp14.z = -mPos.z;
        mDoAud_seStart(JA_SE_OBJ_THUNDER_FAR, &sp14);
#else
        mPosNeg.x = -mPos.x;
        mPosNeg.y = -mPos.y;
        mPosNeg.z = -mPos.z;
        mDoAud_seStart(JA_SE_OBJ_THUNDER_FAR, &mPosNeg);
#endif
    }

    return cPhs_COMPLEATE_e;
}

static kankyo_method_class l_dThunder_Method = {
    (process_method_func)dThunder_Create,
    (process_method_func)dThunder_Delete,
    (process_method_func)dThunder_Execute,
    (process_method_func)dThunder_IsDelete,
    (process_method_func)dThunder_Draw,
};

kankyo_process_profile_definition g_profile_KY_THUNDER = {
    /* Layer ID      */ fpcLy_CURRENT_e,
    /* List ID       */ 0x0007,
    /* List Prio     */ fpcPi_CURRENT_e,
    /* Proc Name     */ fpcNm_KY_THUNDER_e,
    /* Proc SubMtd   */ &g_fpcLf_Method.base,
    /* Size          */ sizeof(dThunder_c),
    /* Size Other    */ 0,
    /* Parameters    */ 0,
    /* Leaf SubMtd   */ &g_fopKy_Method,
    /* Draw Prio     */ fpcDwPi_KY_THUNDER_e,
    /* Kankyo SubMtd */ &l_dThunder_Method,
};