summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_ppolamp.cpp
blob: 32adaac799fe1ff8695dc7d3d1c727049c4deb92 (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
/**
 * @file d_a_ppolamp.cpp
 * 
*/

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

#include "d/actor/d_a_ppolamp.h"
#include "Z2AudioLib/Z2Instances.h"
#include "d/d_com_inf_game.h"
#include "f_op/f_op_camera_mng.h"

static int daPPolamp_c_createHeap(fopAc_ac_c* i_this) {
    return ((daPPolamp_c*)i_this)->createHeap();
}

static char* l_arcName = "PPolamp";

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

int daPPolamp_c::create() {
    int rv = dComIfG_resLoad(this, l_arcName);
    if (rv == cPhs_COMPLEATE_e) {
        if (fopAcM_entrySolidHeap(this, daPPolamp_c_createHeap, 0x1010) == 0) {
            return cPhs_ERROR_e;
        }
        initParam();
        setModelMtx();
        fopAcM_SetMtx(this, mModel1->getBaseTRMtx());
        Vec local_1c;
        Vec local_28 = {0.0f, -45.0f, 0.0f};
        cMtx_multVec(mModel1->getBaseTRMtx(), &local_28, &local_1c);
        mDoMtx_stack_c::transS(local_1c.x, local_1c.y, local_1c.z);
        mDoMtx_stack_c::YrotM(shape_angle.y);
        mDoMtx_stack_c::XrotM(shape_angle.x);
        mDoMtx_stack_c::ZrotM(shape_angle.z);
        mModel2->setBaseTRMtx(mDoMtx_stack_c::get());
    }
    return rv;
}

int daPPolamp_c::execute() {
    if (mSwingTimer != 0) {
        mSwingTimer--;
    } else {
        moveSwing();
    }
    setModelMtx();
    setPclModelMtx();
    mBck.play();
    return 1;
}

int daPPolamp_c::draw() {
    g_env_light.settingTevStruct(0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mModel1, &tevStr);
    mDoExt_modelUpdateDL(mModel1);
    g_env_light.setLightTevColorType_MAJI(mModel2, &tevStr);
    static J3DGXColorS10 TEV_COLOR_1 = (GXColorS10){0x48, 0x85, 0xff, 0xff};
    static J3DGXColorS10 TEV_COLOR_2 = (GXColorS10){0, 0, 0xff, 0xff};
    J3DModelData* modelData = mModel2->getModelData();
    for (u16 i = 0; i < modelData->getMaterialNum(); i++)
    {
        J3DMaterial* material = modelData->getMaterialNodePointer(i);
        if (material != NULL) {
            material->setTevColor(1, &TEV_COLOR_1);
            material->setTevColor(2, &TEV_COLOR_2);
        }
    }
    mBck.entry(modelData);
    mDoExt_modelUpdateDL(mModel2);
    return 1;
}

int daPPolamp_c::Delete() {
    this->~daPPolamp_c();
    return 1;
}

void daPPolamp_c::setModelMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mDoMtx_stack_c::XrotM(shape_angle.x);
    mDoMtx_stack_c::ZrotM(shape_angle.z);
    mModel1->setBaseTRMtx(mDoMtx_stack_c::get());
}

void daPPolamp_c::setPclModelMtx() {
    Vec local_20;
    Vec local_2c = {0.0f, -45.0f, 0.0f};
    cMtx_multVec(mModel1->getBaseTRMtx(), &local_2c, &local_20);
    mDoMtx_stack_c::transS(local_20.x, local_20.y, local_20.z);
    camera_process_class* camera = dComIfGp_getCamera(0);
    if (camera != NULL) {
        cXyz cStack_38 = camera->view.lookat.eye - current.pos;
        mDoMtx_stack_c::YrotM(cStack_38.atan2sX_Z());
        mDoMtx_stack_c::XrotM(cStack_38.atan2sY_XZ());
    }
    mModel2->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daPPolamp_c::createHeap() {
    J3DModelData* a_model_data_p = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 8);
    JUT_ASSERT(347, a_model_data_p != NULL);
    mModel1 = mDoExt_J3DModel__create(a_model_data_p, 0x80000, 0x11000084);
    if (mModel1 == NULL) {
        return 0;
    }

    a_model_data_p = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 7);
    JUT_ASSERT(360, a_model_data_p != NULL);
    mModel2 = mDoExt_J3DModel__create(a_model_data_p, 0x80000, 0x11000084);
    if (mModel2 == NULL) {
        return 0;
    }

    J3DAnmTransform* a_bck_p = (J3DAnmTransform*)dComIfG_getObjectRes(l_arcName, 4);
    JUT_ASSERT(372, a_bck_p != NULL);
    if (mBck.init(a_bck_p, 1, 2, 1.0f, 0, -1, false) == 0) {
        return 0;
    }

    return 1;
}

void daPPolamp_c::moveSwing() {
    s16 sVar1 = field_0x598 * 65 - 500;
    ANGLE_ADD(shape_angle.z, field_0x5a4 * (field_0x59c * sVar1));
    ANGLE_ADD(shape_angle.y, field_0x59e * field_0x5a4);
    if (sVar1 > 500) {
        field_0x598 = 0;
        field_0x59c *= -1;
        field_0x59e = cM_rndFX(450.0f);
        if (cLib_chaseF(&field_0x5a4, field_0x5a8, cM_rndF(0.1f)) != 0) {
            field_0x5a8 = cM_rndF(1.1f);
            if (field_0x5a4 < 0.12f) {
                mSwingTimer = cM_rndF(80.0f);
            }
        }
    }
    field_0x598++;
}

void daPPolamp_c::initParam() {
    field_0x598 = 0;
    field_0x59c = 1;
    field_0x59e = 0;
    mSwingTimer = 0;
    field_0x5a4 = 0.2f;
    field_0x5a8 = 1.0f;
}

static int daPPolamp_create(daPPolamp_c* i_this) {
    fopAcM_ct(i_this, daPPolamp_c);
    return i_this->create();
}

static int daPPolamp_Delete(daPPolamp_c* i_this) {
    return i_this->Delete();
}

static int daPPolamp_execute(daPPolamp_c* i_this) {
    return i_this->execute();
}

static int daPPolamp_draw(daPPolamp_c* i_this) {
    return i_this->draw();
}

static actor_method_class daPPolamp_METHODS = {
    (process_method_func)daPPolamp_create,
    (process_method_func)daPPolamp_Delete,
    (process_method_func)daPPolamp_execute,
    NULL,
    (process_method_func)daPPolamp_draw,
};

actor_process_profile_definition g_profile_PPolamp = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_PPolamp_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daPPolamp_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_PPolamp_e,
    /* Actor SubMtd */ &daPPolamp_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e | fopAcStts_NOEXEC_e,
    /* Group        */ fopAc_ENV_e,
    /* Cull Type    */ fopAc_CULLBOX_12_e,
};

AUDIO_INSTANCES;