summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_hys.cpp
blob: 851ed74cd0f31bfb3261787c8f42164baa858914 (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
/**
 * d_a_hys.cpp
 * Object - Eye switch
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_hys.h"
#include "res/Object/Hys.h"
#include "d/d_com_inf_game.h"
#include "m_Do/m_Do_mtx.h"

const char* daHys_c::m_arcname[2] = {"Hys", "Hys"};

/* Model file indexes. */
const s16 daHys_c::m_bdlidx[2] = {dRes_INDEX_HYS_BDL_HYS_e, dRes_INDEX_HYS_BDL_HYS_e};
/* Texture animation file indexes. */
const s16 daHys_c::m_btpidx[2] = {dRes_INDEX_HYS_BTP_HYS_e, dRes_INDEX_HYS_BTP_HYS_e};
/* Collision mesh file indexes. */
const s16 daHys_c::m_dzbidx[2] = {dRes_INDEX_HYS_DZB_HYS_e, dRes_INDEX_HYS_DZB_HYS_e};
const u32 daHys_c::m_heapsize[2] = {0xA00, 0xA00};
const f32 daHys_c::m_tg_r[2] = {35.0f, 70.0f};

static dCcD_SrcSph l_sph_src = {
    // dCcD_SrcGObjInf
    {
        /* Flags             */ 0,
        /* SrcObjAt  Type    */ 0,
        /* SrcObjAt  Atp     */ 0,
        /* SrcObjAt  SPrm    */ 0,
        /* SrcObjTg  Type    */ AT_TYPE_NORMAL_ARROW | AT_TYPE_FIRE_ARROW | AT_TYPE_ICE_ARROW | AT_TYPE_LIGHT_ARROW,
        /* SrcObjTg  SPrm    */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsOther_e,
        /* SrcObjCo  SPrm    */ 0,
        /* 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    */ dCcG_TgSPrm_NoHitMark_e,
        /* SrcGObjCo SPrm    */ 0,
    },
    // cM3dGSphS
    {{
        /* Center */ {0.0f, 0.0f, 0.0f},
        /* Radius */ 30.0f,
    }},
};

/* 00000078-000000B8       .text Delete__7daHys_cFv */
BOOL daHys_c::Delete() {
    dComIfG_resDeleteDemo(&mPhs, m_arcname[mType]);
    return TRUE;
}

/* 000000B8-00000250       .text CreateHeap__7daHys_cFv */
BOOL daHys_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData *)dComIfG_getObjectRes(m_arcname[mType], m_bdlidx[mType]);
    JUT_ASSERT(DEMO_SELECT(258, 262), modelData != NULL);

    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11020022);
    if (mpModel == NULL) {
        return FALSE;
    }

    J3DAnmTexPattern* pbtp = (J3DAnmTexPattern *)dComIfG_getObjectRes(m_arcname[mType], m_btpidx[mType]);
    JUT_ASSERT(DEMO_SELECT(272, 276), pbtp != NULL);

    if (!mBtpAnm.init(modelData, pbtp, FALSE, J3DFrameCtrl::EMode_NONE)) {
        return FALSE;
    }
    field_0x458 = 0;
    return TRUE;
}

cPhs_State daHys_c::_create() {
    fopAcM_ct(this, daHys_c);

    mType = fopAcM_GetParam(this) >> 8;
    cPhs_State res = dComIfG_resLoad(&mPhs, m_arcname[mType]);
    if (res == cPhs_COMPLEATE_e) {
        res = MoveBGCreate(m_arcname[mType], m_dzbidx[mType], dBgS_MoveBGProc_TypicalRotY, m_heapsize[mType]);
        if (res == cPhs_ERROR_e) {
            return cPhs_ERROR_e;
        }
    }

    return res;
}

/* 00000250-00000368       .text Create__7daHys_cFv */
BOOL daHys_c::Create() {
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    fopAcM_setCullSizeBox(this, -240.0f, -240.0f, -90.0f, 240.0f, 240.0f, 90.0f);

    mStts.Init(255, 255, this);
    mSph.Set(l_sph_src);
    mSph.SetStts(&mStts);
    mSph.SetR(m_tg_r[mType]);

    set_mtx();
    mSwitchNo = fopAcM_GetParam(this) & 0xFF;

    if (fopAcM_isSwitch(this, mSwitchNo)) {
        field_0x450 = 1;
        field_0x458 = 3;
    } else {
        field_0x450 = 0;
        field_0x458 = 0;
    }

    if (mType == 1) {
        scale.setall(2.0f);
    }

    return TRUE;
}

/* 00000368-000003F8       .text set_mtx__7daHys_cFv */
void daHys_c::set_mtx() {
    mpModel->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(current.angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    mDoMtx_copy(mDoMtx_stack_c::get(), mBgMtx);
}

/* 000003F8-000004A4       .text Execute__7daHys_cFPPA3_A4_f */
BOOL daHys_c::Execute(Mtx** mtx) {
    mode_proc_call();

    mpModel->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(current.angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    cMtx_copy(mDoMtx_stack_c::get(), mBgMtx);

    *mtx = &mBgMtx;
    return TRUE;
}

/* 000004A4-00000560       .text mode_proc_call__7daHys_cFv */
void daHys_c::mode_proc_call() {
    typedef void (daHys_c::*ModeFunc)();
    static const ModeFunc mode_proc[2] = {
        &daHys_c::mode_wait,
        &daHys_c::mode_sw_on,
    };

    (this->*mode_proc[field_0x450])();
    mSph.SetC(current.pos);
    dComIfG_Ccsp()->Set(&mSph);
}

/* 00000560-00000600       .text mode_wait__7daHys_cFv */
void daHys_c::mode_wait() {
    if (mSph.ChkTgHit()) {
        cCcD_Obj* obj = mSph.GetTgHitObj();
        if (obj != NULL && (obj->ChkAtType(AT_TYPE_NORMAL_ARROW) ||
                            obj->ChkAtType(AT_TYPE_FIRE_ARROW) ||
                            obj->ChkAtType(AT_TYPE_ICE_ARROW) ||
                            obj->ChkAtType(AT_TYPE_LIGHT_ARROW))) {
            mSph.ClrTgHit();
            mode_sw_on_init();
            return;
        }
    }

    if (field_0x458 != 0) {
        field_0x458--;
    }
}

/* 00000600-00000690       .text mode_sw_on_init__7daHys_cFv */
void daHys_c::mode_sw_on_init() {
    fopAcM_onSwitch(this, mSwitchNo);
    field_0x450 = 1;
    fopAcM_seStart(this, JA_SE_OBJ_ARROW_SW_ON, 0);
}

/* 00000690-000006F8       .text mode_sw_on__7daHys_cFv */
void daHys_c::mode_sw_on() {
    if (!fopAcM_isSwitch(this, mSwitchNo)) {
        mode_wait_init();
    } else {
        if (field_0x458 < 3) {
            field_0x458++;
        }
    }
}

/* 000006F8-00000704       .text mode_wait_init__7daHys_cFv */
void daHys_c::mode_wait_init() {
    field_0x450 = 0;
}

/* 00000704-00000778       .text Draw__7daHys_cFv */
BOOL daHys_c::Draw() {
    g_env_light.settingTevStruct(TEV_TYPE_ACTOR, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    mBtpAnm.entry(mpModel->getModelData(), field_0x458);
    mDoExt_modelUpdateDL(mpModel);
    return TRUE;
}

/* 00000778-00000904       .text daHys_Create__FPv */
static cPhs_State daHys_Create(void* i_this) {
    return ((daHys_c*)i_this)->_create();
}

/* 00000BBC-00000BDC       .text daHys_Delete__FPv */
static BOOL daHys_Delete(void* i_this) {
    return ((daHys_c*)i_this)->MoveBGDelete();
}

/* 00000BDC-00000C08       .text daHys_Draw__FPv */
static BOOL daHys_Draw(void* i_this) {
    return ((daHys_c*)i_this)->MoveBGDraw();
}

/* 00000C08-00000C28       .text daHys_Execute__FPv */
static BOOL daHys_Execute(void* i_this) {
    return ((daHys_c*)i_this)->MoveBGExecute();
}

/* 00000C28-00000C30       .text daHys_IsDelete__FPv */
static BOOL daHys_IsDelete(void*) {
    return TRUE;
}

static actor_method_class daHysMethodTable = {
    (process_method_func)daHys_Create,
    (process_method_func)daHys_Delete,
    (process_method_func)daHys_Execute,
    (process_method_func)daHys_IsDelete,
    (process_method_func)daHys_Draw,
};

actor_process_profile_definition g_profile_Hys = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0008,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Hys_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daHys_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Hys_e,
    /* Actor SubMtd */ &daHysMethodTable,
    /* Status       */ fopAcStts_NOCULLEXEC_e | fopAcStts_CULL_e | fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};