summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_firepillar.cpp
blob: 986762a1fe213ec50ab860c2fb885013575d7b79 (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
/**
 * @file d_a_obj_firepillar.cpp
 * 
*/

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

#include "d/actor/d_a_obj_firepillar.h"
#include "d/d_cc_d.h"
#include "d/d_com_inf_game.h"
#include "d/d_debug_viewer.h"
#include "f_op/f_op_actor_mng.h"

void daObjFPillar_c::initBaseMtx() {
    setBaseMtx();
}

void daObjFPillar_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);
}

static cull_box l_cull_box = {
    {-30.0f, -10.0f, -30.0f},
    {30.0f, 60.0f, 30.0f},
};

static dCcD_SrcCps l_cps_src = {
    {
        {0x0, {{0x100, 0x1, 0x1d}, {0x0, 0x0}, 0x0}}, // mObj
        {dCcD_SE_NONE, 0x0, 0x0, 0x1, 0x2}, // mGObjAt
        {dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x4}, // mGObjTg
        {0x0}, // mGObjCo
    }, // mObjInf
    {
        {{0.0f, 0.0f, 0.0f}, {0.0f, 100.0f, 0.0f}, 50.0f}, // mCps
    } // mCpsAttr
};

int daObjFPillar_c::Create() {
    initBaseMtx();
    mStts.Init(0, 0xff, this);
    mCps.Set(l_cps_src);
    mCps.SetStts(&mStts);
    f32 maxy = l_cull_box.max.y * scale.y;
    fopAcM_setCullSizeBox(this,
        (l_cull_box.min.x * scale.x),
        (l_cull_box.min.y * scale.y),
        (l_cull_box.min.z * scale.x),
        (l_cull_box.max.x * scale.x),
        maxy,
        maxy);
    return 1;
}

int daObjFPillar_c::create() {
    fopAcM_ct(this, daObjFPillar_c);
    int rv = Create();
    if (rv == 0) {
        return cPhs_ERROR_e;
    }
    return cPhs_COMPLEATE_e;
}

int daObjFPillar_c::execute() {
    action();
    mCylScale.x = scale.x;
    mCylScale.z = scale.z;
    cXyz cStack_1c(0.0f, 1.0f, 0.0f);
    cStack_1c.y *= mCylScale.y * 100.0f;
    mDoMtx_stack_c::ZXYrotS(current.angle.x, current.angle.y, current.angle.z);
    mDoMtx_stack_c::multVec(&cStack_1c, &cStack_1c);
    field_0x954.mStart = current.pos;
    field_0x954.mEnd = cStack_1c + current.pos;
    field_0x954.mRadius = scale.x * 50.0f;
    if (mCylScale.y > scale.y * 0.1f) {
        mCps.cM3dGCps::Set(field_0x954);
        dComIfG_Ccsp()->Set(&mCps);
    }
    return 1;
}

void daObjFPillar_c::action() {
    static daObjFPillar_c::actionFunc l_func[3] = {
        &daObjFPillar_c::actionOff,
        &daObjFPillar_c::actionOnWait,
        &daObjFPillar_c::actionOn,
    };
    (this->*(l_func[mAction]))();
}

void daObjFPillar_c::actionOffInit() {
    u8 bVar1 = daObjFPillar_prm::getArg0(this);
    if (bVar1 == 0xff) {
        bVar1 = 1;
    }
    mActionTimer = bVar1 * 15;
    mAction = ACTION_OFF;
}

void daObjFPillar_c::actionOff() {
    cLib_chaseF(&mCylScale.y, 0.0f, scale.y * 0.1f);
    if (mActionTimer == 0) {
        actionOnWaitInit();
    } else {
        if (daObjFPillar_prm::getSwNo(this) != 0xff) {
            if (fopAcM_isSwitch(this, daObjFPillar_prm::getSwNo(this))) {
                mActionTimer--;
            }
        } else {
            mActionTimer--;
        }
    }
}

void daObjFPillar_c::actionOnWaitInit() {
    u8 bVar1 = daObjFPillar_prm::getArg1(this);
    if (bVar1 == 0xff) {
        bVar1 = 1;
    }
    mActionTimer = bVar1 * 15;
    mActionTimer = 30;
    mAction = ACTION_ON_WAIT;
}

void daObjFPillar_c::actionOnWait() {
    cLib_chaseF(&mCylScale.y, scale.y * 0.1f, scale.y * 0.02f);
    if (mActionTimer == 0) {
        actionOnInit();
    } else {
        if (daObjFPillar_prm::getSwNo(this) != 0xff) {
            if (fopAcM_isSwitch(this, daObjFPillar_prm::getSwNo(this))) {
                mActionTimer--;
            } else {
                actionOffInit();
            }
        } else {
            mActionTimer--;
        }
    }
}

void daObjFPillar_c::actionOnInit() {
    u8 bVar1 = daObjFPillar_prm::getArg2(this);
    if (bVar1 == 0xff) {
        bVar1 = 1;
    }
    mActionTimer = bVar1 * 15;
    mActionTimer = 30;
    mAction = ACTION_ON;
}

void daObjFPillar_c::actionOn() {
    f32 target = scale.y;
    if (mActionTimer == 0) {
        target = 0.0;
    } else {
        if (daObjFPillar_prm::getSwNo(this) != 0xff) {
            if (fopAcM_isSwitch(this, daObjFPillar_prm::getSwNo(this))) {
                mActionTimer--;
            } else {
                target = 0.0;
            }
        } else {
            mActionTimer--;
        }
    }
    int reachedTarget = cLib_chaseF(&mCylScale.y, target, scale.y * 0.1f);
    if (reachedTarget && target == 0.0f) {
        actionOffInit();
    }
}

static void drawCylinder(cXyz* pos, cXyz* scale, csXyz* angle) {
    static GXColor const color = {0xFF,00,00,0x60};

    #if DEBUG
    mDoMtx_stack_c::transS(pos->x, pos->y, pos->z);
    mDoMtx_stack_c::ZXYrotM(angle->x, angle->y, angle->z);
    mDoMtx_stack_c::scaleM(scale->x * 50.0f, scale->y * 50.0f, scale->x * 50.0f);
    mDoMtx_stack_c::transM(0.0f, 1.0f, 0.0f);
    mDoMtx_stack_c::XrotM(0x4000);
    Mtx mtx;
    MTXCopy(mDoMtx_stack_c::get(), mtx);
    dDbVw_drawCylinderMXlu(mtx, color, 1);
    #endif
}

int daObjFPillar_c::draw() {
    drawCylinder(&current.pos, &mCylScale, &current.angle);
    return 1;
}

int daObjFPillar_c::_delete() {
    return 1;
}

static int daObjFPillar_Draw(daObjFPillar_c* i_this) {
    return i_this->draw();
}

static int daObjFPillar_Execute(daObjFPillar_c* i_this) {
    return i_this->execute();
}

static int daObjFPillar_Delete(daObjFPillar_c* i_this) {
    fopAcM_GetID(i_this);
    return i_this->_delete();
}

static int daObjFPillar_Create(fopAc_ac_c* i_this) {
    fopAcM_GetID(i_this);
    return static_cast<daObjFPillar_c*>(i_this)->create();
}

static actor_method_class l_daObjFPillar_Method = {
    (process_method_func)daObjFPillar_Create,
    (process_method_func)daObjFPillar_Delete,
    (process_method_func)daObjFPillar_Execute,
    NULL,
    (process_method_func)daObjFPillar_Draw,
};

actor_process_profile_definition g_profile_Obj_FirePillar = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_FirePillar_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjFPillar_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_FirePillar_e,
    /* Actor SubMtd */ &l_daObjFPillar_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};