summaryrefslogtreecommitdiff
path: root/src/REL/d/a/obj/d_a_obj_bstone.cpp
blob: f801926750a226c5f605495253addbc4986ce81a (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
#include "d/a/obj/d_a_obj_bstone.h"

#include "common.h"
#include "d/a/obj/d_a_obj_base.h"
#include "d/col/bg/d_bg_s.h"
#include "f/f_base.h"
#include "m/m_vec.h"
#include "nw4r/g3d/res/g3d_resfile.h"
#include "nw4r/g3d/res/g3d_resmdl.h"
#include "nw4r/math/math_arithmetic.h"
#include "toBeSorted/time_area_mgr.h"

#include "rvl/GX.h" // IWYU pragma: export

SPECIAL_ACTOR_PROFILE(OBJ_BSTONE, dAcObstonec, fProfile::OBJ_BSTONE, 0x130, 0, 2);

bool dAcObstonec::createHeap() {
    mRes = nw4r::g3d::ResFile(getOarcResFile("Bstone"));
    nw4r::g3d::ResMdl mdl = mRes.GetResMdl("model0");
    TRY_CREATE(mMdl.create(mdl, &mAllocator, 0xA0));
    if (mVariant == 1) {
        mMdl.setPriorityDraw(0xB, 0);
        mMdl.setBlendModeAll(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR, false);
    }
    void *dzb = getOarcFile("Bstone", "dzb/model0.dzb");
    void *plc = getOarcFile("Bstone", "dat/model0.plc");

    updateMatrix();
    mMdl.setLocalMtx(mWorldMtx);
    mMdl.setScale(mScale);
    mScaleMag = nw4r::math::FSqrt(mScale.squaredLength()) * 350.0f;
    mMdl.calc(false);
    return !mBg.Set((cBgD_t *)dzb, (PLC *)plc, cBgW::MOVE_BG_e, &mWorldMtx, &mScale);
}

int dAcObstonec::create() {
    mVariant = mParams & 0xF;
    CREATE_ALLOCATOR(dAcObstonec);

    if (mVariant == 1) {
        mBg.SetUnkBase(2);
    } else {
        mBg.SetUnkBase(1);
    }

    mAcceleration = -1.0f;
    mMaxSpeed = -40.0f;
    mBoundingBox.Set(mVec3_c(-350.0f, -60.0f, -240.0f), mVec3_c(350.0f, 600.0f, 240.0f));
    return SUCCEEDED;
}

int dAcObstonec::doDelete() {
    return SUCCEEDED;
}

int dAcObstonec::actorExecute() {
    f32 tmp = 1.0f;
    if (mVariant != 0) {
        tmp = dTimeAreaMgr_c::GetInstance()->checkPositionIsInPastState(mRoomID, mPosition, nullptr, mScaleMag);
        if (mVariant != 1) {
            if (tmp > 0.0f) {
                mMdl.setPriorityDraw(0xB, 0);
            } else {
                mMdl.setPriorityDraw(0x7F, 0);
            }
        }
    }
    if (tmp > 0.0f) {
        dBgS::GetInstance()->Regist(&mBg, this);
    } else {
        dBgS::GetInstance()->Release(&mBg);
    }

    return SUCCEEDED;
}

int dAcObstonec::draw() {
    if (mVariant != 1 || mBg.ChkUsed()) {
        drawModelType1(&mMdl);
    }
    return SUCCEEDED;
}