summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_digsnow.cpp
blob: 1d74f34e0529e86d67f55062973c65b185c930a5 (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
//
// d_a_obj_digsnow.cpp
// Object - Dig Snow
//

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

#include "d/actor/d_a_obj_digsnow.h"
#include "d/actor/d_a_player.h"
#include "d/d_com_inf_game.h"
#include <cmath>

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

void daObjDigSnow_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    MTXCopy(mDoMtx_stack_c::get(), mBgMtx);
}

int daObjDigSnow_c::Create() {
    initBaseMtx();
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    fopAcM_setCullSizeBox2(this, mpModel->getModelData());

    attention_info.distances[fopAc_attn_ETC_e] = 31;

    mode_init_wait();

    return TRUE;
}

static char* l_arcName = "Y_horiyuk";

int daObjDigSnow_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 4);
    JUT_ASSERT(0x9F, modelData != NULL);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);

    if (mpModel == NULL) {
        return FALSE;
    }

    return TRUE;
}

int daObjDigSnow_c::create1st() {
    if (dComIfGs_isSwitch(getSwNo(), fopAcM_GetHomeRoomNo(this))) {
        return cPhs_ERROR_e;
    }

    cPhs_Step phase_state = dComIfG_resLoad(&mPhaseReq, l_arcName);
    if (phase_state == cPhs_COMPLEATE_e) {
        phase_state = MoveBGCreate(l_arcName, 7, dBgS_MoveBGProc_TypicalRotY, 0x1000, NULL);
        if (phase_state == cPhs_ERROR_e) {
            return phase_state;
        }
    }

    return phase_state;
}

int daObjDigSnow_c::Execute(Mtx** i_mtx) {
    if (daPy_py_c::checkNowWolf()) {
        attention_info.flags = fopAc_AttnFlag_ETC_e;
    } else {
        attention_info.flags = 0;
    }

    action();

    *i_mtx = &mBgMtx;
    setBaseMtx();

    return TRUE;
}

void daObjDigSnow_c::action() {
    typedef void (daObjDigSnow_c::*action_func)();
    static action_func l_func[] = {
        &daObjDigSnow_c::mode_wait,
        &daObjDigSnow_c::mode_dig,
        &daObjDigSnow_c::mode_end,
    };

    (this->*l_func[mAction])();
}

void daObjDigSnow_c::mode_init_wait() {
    mAction = ACTION_WAIT_e;
}

void daObjDigSnow_c::mode_wait() {
    if (mMode == MODE_DIG_e) {
        mode_init_dig();
    }
}

void daObjDigSnow_c::mode_init_dig() {
    dBgS_ObjGndChk obj_gnd_chk;

    obj_gnd_chk.SetActorPid(base.base.id);
    obj_gnd_chk.SetPos(&current.pos);

    f32 gnd_height = dComIfG_Bgsp().GroundCross(&obj_gnd_chk);
    if (gnd_height != -G_CM3D_F_INF) {
        mGroundHeight = gnd_height;
    } else {
#if DEBUG
        // "No BG under digsnow!"
        OS_REPORT_ERROR("掘る雪の下にBGがありません!");
        fopAcM_delete(this);
#endif
    }

    mAction = 1;
}

void daObjDigSnow_c::mode_dig() {
    f32 step = std::fabs(((current.pos.y - mGroundHeight) + 10.0f) / 35.0f);
    if (step < 1.0f) {
        step = 1.0f;
    }

    if (cLib_chaseF(&current.pos.y, mGroundHeight - 30.0f, step) && mMode == MODE_END_e) {
        mode_init_end();
    }
}

void daObjDigSnow_c::mode_init_end() {
    dComIfGs_onSwitch(getSwNo(), fopAcM_GetHomeRoomNo(this));
    fopAcM_delete(this);
    
    mAction = 2;
}

void daObjDigSnow_c::mode_end() {}

int daObjDigSnow_c::Draw() {
    g_env_light.settingTevStruct(0x10, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);

    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();

    return TRUE;
}

int daObjDigSnow_c::Delete() {
    dComIfG_resDelete(&mPhaseReq, l_arcName);
    return TRUE;
}

static int daObjDigSnow_create1st(daObjDigSnow_c* i_this) {
    fopAcM_ct(i_this, daObjDigSnow_c);
    return i_this->create1st();
}

static int daObjDigSnow_MoveBGDelete(daObjDigSnow_c* i_this) {
    return i_this->MoveBGDelete();
}

static int daObjDigSnow_MoveBGExecute(daObjDigSnow_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daObjDigSnow_MoveBGDraw(daObjDigSnow_c* i_this) {
    return i_this->MoveBGDraw();
}

static actor_method_class daObjDigSnow_METHODS = {
    (process_method_func)daObjDigSnow_create1st,     (process_method_func)daObjDigSnow_MoveBGDelete,
    (process_method_func)daObjDigSnow_MoveBGExecute, NULL,
    (process_method_func)daObjDigSnow_MoveBGDraw,
};

actor_process_profile_definition g_profile_Obj_DigSnow = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_DigSnow_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjDigSnow_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_DigSnow_e,
    /* Actor SubMtd */ &daObjDigSnow_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};