summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_smw_stone.cpp
blob: e964a957293e2f4546cce801db08e65debc51312 (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
/**
 * @file d_a_obj_smw_stone.cpp
 * Object - Sacred Meadow Howling Stone
*/

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

#include "d/actor/d_a_obj_smw_stone.h"
#include "d/actor/d_a_alink.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"

static char* l_arcName = "WStoneF";

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

daSmWStone_c::daSmWStone_c() {
    mpBgW = NULL;
    mMode = 0;
}

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

static u8 const lit_3776[12] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

cPhs_Step daSmWStone_c::create() {
    fopAcM_ct(this, daSmWStone_c);
    cPhs_Step step = dComIfG_resLoad(this, l_arcName);

    if (step == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daSmWStone_c_createHeap, 0x1000)) {
            return cPhs_ERROR_e;
        }

        if (dComIfG_Bgsp().Regist(mpBgW, this)) {
            return cPhs_ERROR_e;
        }

        init();
        setModelMtx();
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());

        dBgS_AcchCir acch_cir;
        dBgS_ObjAcch acch;
        acch_cir.SetWall(0.0f, 10.0f);
        acch.Set(fopAcM_GetPosition_p(this), fopAcM_GetOldPosition_p(this), this, 1,
                 &acch_cir, fopAcM_GetSpeed_p(this), NULL, NULL);
        acch.CrrPos(dComIfG_Bgsp());
        mGroundH = acch.GetGroundH();
        mPolyInfo = acch.m_gnd;
    }

    return step;
}

int daSmWStone_c::execute() {
    switch (mMode) {
    case 0:
        exeModeHowl();
        // fallthrough
    case 1:
    default:
        setModelMtx();
        break;
    }

    return 1;
}

int daSmWStone_c::draw() {
    g_env_light.settingTevStruct(8, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    cXyz pos(current.pos.x, current.pos.y, current.pos.z);
    mShadowKey = dComIfGd_setShadow(mShadowKey, 1, mpModel, &pos, 500.0f, 0.0f, pos.y,
                                    mGroundH, mPolyInfo, &tevStr, 0, 1.0f,
                                    dDlst_shadowControl_c::getSimpleTex());
    return 1;
}

int daSmWStone_c::Delete() {
    attention_info.flags = 0;
    if (mpBgW != NULL && mpBgW->ChkUsed()) {
        dComIfG_Bgsp().Release(mpBgW);
    }
    this->~daSmWStone_c();
    return 1;
}

void daSmWStone_c::exeModeHowl() {
    u8 swbit;
    if (mDelete || (swbit = getSwBit0(), fopAcM_isSwitch(this, swbit))) {
        attention_info.flags = 0;
        mMode = 1;
    } else {
        if (!dComIfGp_event_runCheck()) {
            daAlink_getAlinkActorClass()->startWindStoneSound(2, &current.pos);
        }
        attention_info.flags = 0;
        if (chkWlfInRange()) {
            attention_info.flags |= fopAc_AttnFlag_ETC_e;
            attention_info.distances[fopAc_attn_ETC_e] = 0x41;
            daAlink_c* link = daAlink_getAlinkActorClass();
            if (link != NULL && link->checkWolfHowlSuccessAnime()) {
                attention_info.flags = 0;
                mMode = 1;
            }
        }
    }
}

void daSmWStone_c::setModelMtx() {
    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());
}

int daSmWStone_c::createHeap() {
    J3DModelData* model_data = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 4);
    mpModel = mDoExt_J3DModel__create(model_data, 0x80000, 0x11000084);
    if (mpModel == NULL) {
        return 0;
    }

    mpBgW = new dBgW();
    if (mpBgW == NULL) {
        return 0;
    }
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    MTXCopy(mDoMtx_stack_c::get(), mBgMtx);
    cBgD_t* dzb = (cBgD_t*)dComIfG_getObjectRes(l_arcName, 7);
    if (mpBgW->Set(dzb, 1, &mBgMtx) == 1) {
        return 0;
    }

    return 1;
}

void daSmWStone_c::init() {
    u8 swbit = getSwBit0();
    if (fopAcM_isSwitch(this, swbit)) {
        mMode = 1;
    } else {
        mMode = 0;
    }
    mDelete = false;
    mShadowKey = 0;
}

bool daSmWStone_c::chkWlfInRange() {
    fopAc_ac_c* player = dComIfGp_getPlayer(0);
    if (player == NULL) {
        return false;
    }
    if (daPy_py_c::checkNowWolf()) {
        cXyz pos = player->current.pos;
        if (pos.abs2(current.pos) < 40000.0f) {
            return true;
        }
    }
    return false;
}

static cPhs_Step daSmWStone_create(daSmWStone_c* i_this) {
    fopAcM_ct(i_this, daSmWStone_c);
    return i_this->create();
}

static int daSmWStone_Delete(daSmWStone_c* i_this) {
    return i_this->Delete();
}

static int daSmWStone_execute(daSmWStone_c* i_this) {
    return i_this->execute();
}

static int daSmWStone_draw(daSmWStone_c* i_this) {
    return i_this->draw();
}

static actor_method_class daSmWStone_METHODS = {
    (process_method_func)daSmWStone_create,
    (process_method_func)daSmWStone_Delete,
    (process_method_func)daSmWStone_execute,
    NULL,
    (process_method_func)daSmWStone_draw,
};

actor_process_profile_definition g_profile_Obj_SmWStone = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_SmWStone_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daSmWStone_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_SmWStone_e,
    /* Actor SubMtd */ &daSmWStone_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ENV_e,
    /* Cull Type    */ fopAc_CULLBOX_0_e,
};