summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_bk_leaf.cpp
blob: e698ae068322a17ac30a22ef278ea9366ab848e1 (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
/**
 * d_a_obj_bk_leaf.cpp
 *
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep

#include "d/actor/d_a_obj_bk_leaf.h"
#include "d/actor/d_a_obj_carry.h"
#include "d/d_com_inf_game.h"

static int CheckCreateHeap(fopAc_ac_c* i_this) {
    return static_cast<daBkLeaf_c*>(i_this)->CreateHeap();
}

void daBkLeaf_c::setBokkuri() {
    u32 sp10 = 0;
    csXyz currentAngle(current.angle);
    daObjCarry_c::make_prm(&sp10, &currentAngle, 6, getItem(), getItemBit(), 1, 2);
    field_0x578 = fopAcM_createChild(fpcNm_Obj_Carry_e, fopAcM_GetID(this), 0, &current.pos,
                                     fopAcM_GetRoomNo(this), &currentAngle, &scale, -1, 0);
}

void daBkLeaf_c::initBaseMtx() {
    mpModel->setBaseScale(scale);
    setBaseMtx();
}

void daBkLeaf_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daBkLeaf_c::Create() {
    initBaseMtx();
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    fopAcM_setCullSizeBox2(this, mpModel->getModelData());
    field_0x578 = -1;
    field_0x57D = 0;
    if (checkSetDeku()) {
        field_0x57C = 0;
        setBokkuri();
    } else {
        field_0x57C = 2;
    }
    return 1;
}

static const char* l_arcName = "Obj_bkl";

static const char* l_bmdName = "hl.bmd";

static const char* l_bckName = "hl_shake1.bck";

int daBkLeaf_c::CreateHeap() {
    int retVal;
    mpModel = mDoExt_J3DModel__create(
        static_cast<J3DModelData*>(dComIfG_getObjectRes(l_arcName, l_bmdName)), 0x80000,
        0x11000084);
    if (mpModel == NULL) {
        retVal = 0;
    } else {
        J3DAnmTransform* transform =
            static_cast<J3DAnmTransform*>(dComIfG_getObjectRes(l_arcName, l_bckName));
        mpBckAnm = new mDoExt_bckAnm;
        if (mpBckAnm == NULL || mpBckAnm->init(transform, 1, 0, 1.0f, 0, -1, false) == 0) {
            retVal = 0;
        } else {
            retVal = 1;
        }
    }
    return retVal;
}

int daBkLeaf_c::create() {
    fopAcM_ct(this, daBkLeaf_c);
    int retVal = dComIfG_resLoad(&mPhase, l_arcName);
    if (retVal == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, CheckCreateHeap, 0x980)) {
            return cPhs_ERROR_e;
        } else {
            if (Create() == 0) {
                return cPhs_ERROR_e;
            }
        }
    }
    return retVal;
}

int daBkLeaf_c::execute() {
    switch (field_0x57C) {
    case 0:
        if (field_0x57D != 0 && fopAcM_SearchByID(field_0x578) == NULL) {
            field_0x57E = 0x3C;
            mpBckAnm->setFrame(0.0f);
            mpBckAnm->setPlaySpeed(1.0f);
            field_0x57C = 1;
        }
        break;
    case 1:
        if (field_0x57E > 0) {
            field_0x57E--;
        }
        if (field_0x57E == 0) {
            setBokkuri();
            if (field_0x57D == 0xFF) {
                field_0x57C = 0;
            } else {
                field_0x57D--;
                if (field_0x57D == 0) {
                    field_0x57C = 2;
                } else {
                    field_0x57C = 0;
                }
            }
        }
        break;
    case 2:
        break;
    }
    setBaseMtx();
    return 1;
}

int daBkLeaf_c::draw() {
    g_env_light.settingTevStruct(0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    mpBckAnm->entry(mpModel->getModelData());
    mDoExt_modelUpdateDL(mpModel);
    mpBckAnm->remove(mpModel->getModelData());
    return 1;
}

int daBkLeaf_c::_delete() {
    dComIfG_resDelete(&mPhase, l_arcName);
    return 1;
}

static int daBkLeaf_Draw(daBkLeaf_c* i_this) {
    return i_this->draw();
}

static int daBkLeaf_Execute(daBkLeaf_c* i_this) {
    return i_this->execute();
}

static int daBkLeaf_Delete(daBkLeaf_c* i_this) {
    return i_this->_delete();
}

static int daBkLeaf_Create(fopAc_ac_c* i_this) {
    return static_cast<daBkLeaf_c*>(i_this)->create();
}

static actor_method_class l_daBkLeaf_Method = {
    (process_method_func)daBkLeaf_Create,  (process_method_func)daBkLeaf_Delete,
    (process_method_func)daBkLeaf_Execute, NULL,
    (process_method_func)daBkLeaf_Draw,
};

actor_process_profile_definition g_profile_Obj_BkLeaf = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_BkLeaf_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daBkLeaf_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_BkLeaf_e,
    /* Actor SubMtd */ &l_daBkLeaf_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};