//
// Generated by dtk
// Translation Unit: d_a_obj_Ygush00.cpp
//

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_obj_Ygush00.h"
#include "res/Object/Ygush00.h"
#include "f_op/f_op_actor_mng.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "d/d_com_inf_game.h"
#include "d/d_kankyo.h"
#include "d/actor/d_a_obj_gryw00.h"
#include "m_Do/m_Do_ext.h"
#include "m_Do/m_Do_mtx.h"

namespace {
    static const char l_arcname[] = "Ygush00";
};

#if VERSION == VERSION_DEMO
static daObjYgush00_HIO_c l_HIO;

daObjYgush00_HIO_c::daObjYgush00_HIO_c() {
    mNo = -1;
    m05 = 0;
    m06 = 0;
    m07 = 0;
}
#endif

/* 00000078-0000009C       .text solidHeapCB__14daObjYgush00_cFP10fopAc_ac_c */
BOOL daObjYgush00_c::solidHeapCB(fopAc_ac_c* ac) {
    return ((daObjYgush00_c*)ac)->create_heap();
}

/* 0000009C-00000250       .text create_heap__14daObjYgush00_cFv */
bool daObjYgush00_c::create_heap() {
    static u32 mdl_table[] = { dRes_INDEX_YGUSH00_BDL_YGUSH00_e, dRes_INDEX_YGUSH00_BDL_YGSTP00_e, dRes_INDEX_YGUSH00_BDL_YGSTP00_e, dRes_INDEX_YGUSH00_BDL_YGSTP00_e };
    static u32 btk_table[] = { dRes_INDEX_YGUSH00_BTK_YGUSH00_e, dRes_INDEX_YGUSH00_BTK_YGSTP00_e, dRes_INDEX_YGUSH00_BTK_YGSTP00_e, dRes_INDEX_YGUSH00_BTK_YGSTP00_e };
    static u32 bck_table[] = { dRes_INDEX_YGUSH00_BCK_YGUSH00_e, dRes_INDEX_YGUSH00_BCK_YGSTP00_e, dRes_INDEX_YGUSH00_BCK_YGSTP00_e, dRes_INDEX_YGUSH00_BCK_YGSTP00_e };

    bool ret = true;

    J3DModelData* pModelData = static_cast<J3DModelData*>(dComIfG_getObjectRes(l_arcname, mdl_table[mType]));
    J3DAnmTextureSRTKey * pBtk = static_cast<J3DAnmTextureSRTKey*>(dComIfG_getObjectRes(l_arcname, btk_table[mType]));
    J3DAnmTransform * pBck = static_cast<J3DAnmTransform*>(dComIfG_getObjectRes(l_arcname, bck_table[mType]));

    if (!pModelData || !pBtk || !pBck) {
        JUT_ASSERT(DEMO_SELECT(203, 207), FALSE);
        ret = false;
    } else {
        mpModel = mDoExt_J3DModel__create(pModelData, 0x80000, 0x11000222);
        s32 btkRet = mBtkAnm.init(pModelData, pBtk, 1, J3DFrameCtrl::EMode_LOOP);
        s32 bckRet = mBckAnm.init(pModelData, pBck, 1, J3DFrameCtrl::EMode_LOOP);

        if (!mpModel || !btkRet || !bckRet)
            ret = false;
    }

    return ret;
}

/* 00000250-000003F4       .text _create__14daObjYgush00_cFv */
cPhs_State daObjYgush00_c::_create() {
    fopAcM_ct(this, daObjYgush00_c);

    if (fopAcM_IsFirstCreating(this)) {
        u32 type = param_get_arg();
        mType = type;
        if ((int)mType < 0 || 4 <= (int)mType)
            mType = 0;
    }

    cPhs_State ret = dComIfG_resLoad(&mPhase, l_arcname);

    if (ret == cPhs_COMPLEATE_e) {
        if (fopAcM_entrySolidHeap(this, solidHeapCB, 0x740) == 1) {
            mpModel->setBaseScale(scale);
            mDoMtx_stack_c::transS(current.pos);
            mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
            fopAcM_SetMtx(this, mpModel->getBaseTRMtx());

            fopAcM_setCullSizeBox(this,
                scale.x * -80.0f, 0.0f, scale.z * -80.0f,
                scale.x * 80.0f, scale.y * 125.0f, scale.z * 80.0f);
        } else {
            ret = cPhs_ERROR_e;
        }
    }

#if VERSION == VERSION_DEMO
    if (l_HIO.mNo < 0) {
        l_HIO.mNo = mDoHIO_createChild("湧き水", &l_HIO);
    }
#endif

    return ret;
}

/* 000004F4-00000524       .text _delete__14daObjYgush00_cFv */
bool daObjYgush00_c::_delete() {
    dComIfG_resDelete(&mPhase, l_arcname);

#if VERSION == VERSION_DEMO
    if (l_HIO.mNo >= 0) {
        mDoHIO_deleteChild(l_HIO.mNo);
        l_HIO.mNo = -1;
    }
#endif

    return true;
}

/* 00000524-0000066C       .text _execute__14daObjYgush00_cFv */
bool daObjYgush00_c::_execute() {
    if (mType != 3 || dComIfGs_isEventBit(dSv_event_flag_c::COLORS_IN_HYRULE) == 1) {
        mBtkAnm.play();
        mBckAnm.play();
    }

    if (mType == 1) {
        if (mpGryw00 != NULL) {
            if (mpGryw00->get_draw_water_lv(mpGryw00) <= current.pos.y) {
                fopAcM_seStartCurrent(this, JA_SE_OBJ_SPRING, 0);
            }
        } else {
            mpGryw00 = (daObjGryw00_c*)fopAcM_SearchByName(fpcNm_Obj_Gryw00_e);
        }
    } else {
        fopAcM_seStartCurrent(this, JA_SE_OBJ_SPRING, 0);
    }

    return true;
}

/* 0000066C-000006FC       .text _draw__14daObjYgush00_cFv */
bool daObjYgush00_c::_draw() {
    g_env_light.settingTevStruct(TEV_TYPE_BG1, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    mBtkAnm.entry(mpModel->getModelData());
    mBckAnm.entry(mpModel->getModelData());
    mDoExt_modelUpdateDL(mpModel);
    return true;
}

/* 000006FC-0000071C       .text daObjYgush00_Create__FP14daObjYgush00_c */
static cPhs_State daObjYgush00_Create(daObjYgush00_c* i_this) {
    return i_this->_create();
}

/* 0000071C-00000740       .text daObjYgush00_Delete__FP14daObjYgush00_c */
static BOOL daObjYgush00_Delete(daObjYgush00_c* i_this) {
    return i_this->_delete();
}

/* 00000740-00000764       .text daObjYgush00_Execute__FP14daObjYgush00_c */
static BOOL daObjYgush00_Execute(daObjYgush00_c* i_this) {
    return i_this->_execute();
}

/* 00000764-00000788       .text daObjYgush00_Draw__FP14daObjYgush00_c */
static BOOL daObjYgush00_Draw(daObjYgush00_c* i_this) {
    return i_this->_draw();
}

/* 00000788-00000790       .text daObjYgush00_IsDelete__FP14daObjYgush00_c */
static BOOL daObjYgush00_IsDelete(daObjYgush00_c* i_this) {
    UNUSED(i_this);
    return TRUE;
}

static BOOL daObjYgush00_ToFore(daObjYgush00_c* i_this) {
    return TRUE;
}

static BOOL daObjYgush00_ToBack(daObjYgush00_c* i_this) {
    return TRUE;
}

static actor_method_class l_daObjYgush00_Method = {
    (process_method_func)daObjYgush00_Create,
    (process_method_func)daObjYgush00_Delete,
    (process_method_func)daObjYgush00_Execute,
    (process_method_func)daObjYgush00_IsDelete,
    (process_method_func)daObjYgush00_Draw,
};

actor_process_profile_definition g_profile_Obj_Ygush00 = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0003,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_Ygush00_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjYgush00_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_Ygush00_e,
    /* Actor SubMtd */ &l_daObjYgush00_Method,
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};
