summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_snow_soup.cpp
blob: 027d0bd8c8e5c7aa63999bf4817f807b70a3ea98 (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
/**
 * @file d_a_obj_snow_soup.cpp
 * 
*/

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

#include "d/actor/d_a_obj_snow_soup.h"
#include "d/d_com_inf_game.h"
#include "f_op/f_op_actor_mng.h"
#include "f_pc/f_pc_name.h"
#include <cstring>

static int daObjSnowSoup_c_createHeap(fopAc_ac_c* i_this) {
    return static_cast<daObjSnowSoup_c*>(i_this)->createHeap();
}

static char* l_arcName = "SnowSoup";

static Vec const SOUP_MODEL_OFFSET = {3317.86f, 214.73f, 323.3f};

daObjSnowSoup_c::daObjSnowSoup_c() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            mpSmkEmtChange[i][j] = NULL;
        }
    }
    memset(mpSmkEmtCommon, 0, 0x10);
    memset(mpModel, 0, 0xc);
}

daObjSnowSoup_c::~daObjSnowSoup_c() {
    dComIfG_resDelete(this, l_arcName);
}

int daObjSnowSoup_c::createHeap() {
    static u32 const BMD_IDX[3] = {3, 4, 5};
    for (int i = 0; i < 3; i++) {
        J3DModelData* model_data = (J3DModelData*)dComIfG_getObjectRes(l_arcName, BMD_IDX[i]);
        mpModel[i] = mDoExt_J3DModel__create(model_data, 0x80000, 0x11000084);
        if (mpModel[i] == NULL) {
            return false;
        }
    }
    return true;
}

cPhs_Step daObjSnowSoup_c::create() {
    fopAcM_ct(this, daObjSnowSoup_c);
    cPhs_Step step = dComIfG_resLoad(this, l_arcName);
    if (step == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daObjSnowSoup_c_createHeap, 0x6500)) {
            return cPhs_ERROR_e;
        }
        init();
        setModelMtx();
        fopAcM_SetMtx(this, mpModel[mState]->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel[mState]->getModelData());
        createSmkEmtCommon();
        createSmkEmtChange(mState);
        mBubblePos.set(SOUP_MODEL_OFFSET.x, SOUP_MODEL_OFFSET.y, SOUP_MODEL_OFFSET.z);
        mFirewoodPos.set(SOUP_MODEL_OFFSET.x, 0.0f, SOUP_MODEL_OFFSET.z);
    }
    return step;
}

int daObjSnowSoup_c::Delete() {
    deleteSmkEmtCommon();
    deleteSmkEmtChange(mState);
    this->~daObjSnowSoup_c();
    return 1;
}

int daObjSnowSoup_c::draw() {
    g_env_light.settingTevStruct(0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel[mState], &tevStr);
    mDoExt_modelUpdate(mpModel[mState]);
    return 1;
}

int daObjSnowSoup_c::execute() {
    mDoAud_seStartLevel(Z2SE_OBJ_NABE_BUBBLE, &mBubblePos, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    mDoAud_seStartLevel(Z2SE_OBJ_FIREWOOD_BURNING, &mFirewoodPos, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    switch (mState) {
    case 0:
            /* dSv_event_flag_c::F_0003 - Snowpeak Ruins - Handed over tomato puree and left room */
        if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[7])) {
            deleteSmkEmtChange(mState);
            mState = 1;
            createSmkEmtChange(mState);
            setModelMtx();
            fopAcM_SetMtx(this, mpModel[mState]->getBaseTRMtx());
            return 1;
        }
        break;
    case 1:
            /* dSv_event_flag_c::F_0004 - Snowpeak Ruins - Handed over secret ingredient and left room */
        if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[8])) {
            deleteSmkEmtChange(mState);
            mState = 2;
            createSmkEmtChange(mState);
            setModelMtx();
            fopAcM_SetMtx(this, mpModel[mState]->getBaseTRMtx());
            return 1;
        }
        break;
    case 2:
        break;
    }
    setModelMtx();
    return 1;
}

void daObjSnowSoup_c::init() {
    mState = 0;
        /* dSv_event_flag_c::F_0004 - Snowpeak Ruins - Handed over secret ingredient and left room */
    if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[8])) {
        mState = 2;
               /* dSv_event_flag_c::F_0003 - Snowpeak Ruins - Handed over tomato puree and left room */
    } else if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[7])) {
        mState = 1;
    }
}

void daObjSnowSoup_c::setModelMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mpModel[mState]->setBaseTRMtx(mDoMtx_stack_c::get());
}

void daObjSnowSoup_c::createSmkEmtCommon() {
    static u16 const PARTICLE_NAME[4] = {0x87E1, 0x87E2, 0x87E3, 0x87E6};
    cXyz vec1(0.0f, 0.0f, 0.0f);
    csXyz vec2(0, 0, 0);
    cXyz vec3(1.0f, 1.0f, 1.0f);
    for (int i = 0; i < 4; i++) {
        mpSmkEmtCommon[i] = dComIfGp_particle_set(PARTICLE_NAME[i], &vec1, &vec2, &vec3);
    }
}

void daObjSnowSoup_c::deleteSmkEmtCommon() {
    for (int i = 0; i < 4; i++) {
        if (mpSmkEmtCommon[i] != NULL) {
            mpSmkEmtCommon[i]->becomeInvalidEmitter();
            mpSmkEmtCommon[i] = NULL;
        }
    }
}

void daObjSnowSoup_c::createSmkEmtChange(int i_state) {
    static u16 const PARTICLE_NAME[3][2] = {{0x8984, 0x8985}, {0x8A8B, 0x8A8D}, {0x8A8C, 0x8A8E}};
    cXyz vec1(0.0f, 0.0f, 0.0f);
    csXyz vec2(0, 0, 0);
    cXyz vec3(1.0f, 1.0f, 1.0f);
    for (int i = 0; i < 2; i++) {
        mpSmkEmtChange[i_state][i] =
            dComIfGp_particle_set(PARTICLE_NAME[i_state][i], &vec1, &vec2, &vec3);
    }
}

void daObjSnowSoup_c::deleteSmkEmtChange(int i_state) {
    for (int i = 0; i < 2; i++) {
        if (mpSmkEmtChange[i_state][i] != NULL) {
            mpSmkEmtChange[i_state][i]->becomeInvalidEmitter();
            mpSmkEmtChange[i_state][i] = NULL;
        }
    }
}


static cPhs_Step daObjSnowSoup_create(daObjSnowSoup_c* i_this) {
    fopAcM_ct(i_this, daObjSnowSoup_c);
    return i_this->create();
}

static int daObjSnowSoup_Delete(daObjSnowSoup_c* i_this) {
    return i_this->Delete();
}

static int daObjSnowSoup_execute(daObjSnowSoup_c* i_this) {
    return i_this->execute();
}

static int daObjSnowSoup_draw(daObjSnowSoup_c* i_this) {
    return i_this->draw();
}

static actor_method_class daObjSnowSoup_METHODS = {
    (process_method_func)daObjSnowSoup_create,
    (process_method_func)daObjSnowSoup_Delete,
    (process_method_func)daObjSnowSoup_execute,
    (process_method_func)NULL,
    (process_method_func)daObjSnowSoup_draw,
};

actor_process_profile_definition g_profile_Obj_SnowSoup = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_SnowSoup_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjSnowSoup_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_SnowSoup_e,
    /* Actor SubMtd */ &daObjSnowSoup_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ENV_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};