diff --git a/include/d/actor/d_a_sail.h b/include/d/actor/d_a_sail.h index 85f6137e..ecbfc59c 100644 --- a/include/d/actor/d_a_sail.h +++ b/include/d/actor/d_a_sail.h @@ -15,23 +15,27 @@ class daSail_packet_c : public J3DPacket { m1C36 = 0; m1C3B = 1; } - - void getMtx() {} - void getNrm() {} - void getPos() {} - void getPosSpd() {} - void getStickMtx() {} - void getTexMtx() {} - void setTevStr(dKy_tevstr_c*) {} + + Mtx* getMtx() { return &mMtx; } + cXyz* getNrm() { return m0C74 + (0x54 * m1C3A); } + cXyz* getPos() { return m00A4 + (0x54 * m1C3A); } + cXyz* getPosSpd() { return m0884; } + Mtx* getStickMtx() { return &mStickMtx; } + Mtx* getTexMtx() { return &mTexMtx; } + void setTevStr(dKy_tevstr_c* tevStr) { mTevStr = tevStr; } void setCorrectNrmAngle(s16, f32); void setNrmMtx(); void setBackNrm(); void setNrmVtx(cXyz*, int, int); virtual void draw(); + virtual ~daSail_packet_c() {} public: - /* 0x0010 */ u8 m0010[0x00A4 - 0x0010]; + /* 0x0010 */ Mtx mMtx; + /* 0x0040 */ Mtx mTexMtx; + /* 0x0070 */ Mtx mStickMtx; + /* 0x00A0 */ dKy_tevstr_c* mTevStr; /* 0x00A4 */ cXyz m00A4[0x54 * 2]; /* 0x0884 */ cXyz m0884[0x54]; /* 0x0C74 */ cXyz m0C74[0x54 * 2]; @@ -41,18 +45,23 @@ class daSail_packet_c : public J3DPacket { /* 0x1C38 */ s16 m1C38; /* 0x1C3A */ u8 m1C3A; /* 0x1C3B */ u8 m1C3B; - /* 0x1C3C */ J3DModel* m1C3C; - /* 0x1C40 */ u8 m1C40[0x1C44 - 0x1C40]; + /* 0x1C3C */ J3DModel* mStickModel; + /* 0x1C40 */ s32 m1C40; /* 0x1C44 */ f32 m1C44; /* 0x1C48 */ f32 m1C48; + /* 0x1C4C */ f32 m1C4C; + /* 0x1C50 */ s16 m1C50; + /* 0x1C52 */ s16 m1C52; }; class sail_class : public fopAc_ac_c { +public: + sail_class() {} + public: /* 0x0290 */ request_of_phase_process_class mClothPhase; /* 0x0298 */ request_of_phase_process_class mKaizokusenPhase; /* 0x02A0 */ daSail_packet_c mSailPacket; - /* 0x1EEC */ u8 m1EEC[0x1EF4 - 0x1EEC]; }; class daSail_HIO_c : public JORReflexible { @@ -73,7 +82,9 @@ class daSail_HIO_c : public JORReflexible { /* 0x05 */ u8 m05; /* 0x06 */ u8 m06; /* 0x07 */ u8 m07; - /* 0x08 */ u8 m08[0x10 - 0x08]; + /* 0x08 */ u8 m08; + /* 0x09 */ u8 m09[0x0C - 0x09]; + /* 0x0C */ f32 m0C; /* 0x10 */ f32 m10; }; diff --git a/include/d/d_kankyo.h b/include/d/d_kankyo.h index 414ddddf..c8d4acbe 100644 --- a/include/d/d_kankyo.h +++ b/include/d/d_kankyo.h @@ -396,6 +396,7 @@ void dKy_instant_rainchg(); SND_INFLUENCE * dKy_Sound_get(); void dKy_Sound_set(cXyz i_pos, int param_1, fpc_ProcID i_actorID, int param_3); void dKy_SordFlush_set(cXyz hitPos, int lightType); +cXyz dKy_FirstlightVec_get(cXyz* param_0); void dKy_itudemo_se(); void dKy_actor_addcol_set(s16, s16, s16, f32); void dKy_actor_addcol_amb_set(s16, s16, s16, f32); diff --git a/src/d/actor/d_a_sail.cpp b/src/d/actor/d_a_sail.cpp index 90ed1fe0..30ef953a 100644 --- a/src/d/actor/d_a_sail.cpp +++ b/src/d/actor/d_a_sail.cpp @@ -8,12 +8,30 @@ #include "d/res/res_cloth.h" #include "d/d_procname.h" #include "d/d_com_inf_game.h" +#include "d/d_kankyo_wether.h" #include "d/actor/d_a_obj_pirateship.h" #include "f_op/f_op_actor_mng.h" #include "m_Do/m_Do_mtx.h" #include "SSystem/SComponent/c_lib.h" -static u8 dummy_bss[0x4C]; +static Vec bss_3569; +// Not sure what these are, but they have size 1, and alignment 1 in the debug maps, but alignment 4 in the non-debug maps. +static u8 bss_1036 ALIGN_DECL(4); +static u8 bss_1034 ALIGN_DECL(4); +static u8 bss_1032 ALIGN_DECL(4); +static u8 bss_1031 ALIGN_DECL(4); +static u8 bss_1026 ALIGN_DECL(4); +static u8 bss_1024 ALIGN_DECL(4); +static u8 bss_1022 ALIGN_DECL(4); +static u8 bss_1021 ALIGN_DECL(4); +static u8 bss_984 ALIGN_DECL(4); +static u8 bss_982 ALIGN_DECL(4); +static u8 bss_980 ALIGN_DECL(4); +static u8 bss_979 ALIGN_DECL(4); +static u8 bss_941 ALIGN_DECL(4); +static u8 bss_939 ALIGN_DECL(4); +static u8 bss_937 ALIGN_DECL(4); +static u8 bss_936 ALIGN_DECL(4); // Needed for the .data section to match. static f32 dummy1[3] = {1.0f, 1.0f, 1.0f}; @@ -438,8 +456,28 @@ u8 l_AmastDL[] ALIGN_DECL(32) = { }; /* 000000EC-00000364 .text setCorrectNrmAngle__15daSail_packet_cFsf */ -void daSail_packet_c::setCorrectNrmAngle(short, float) { - /* Nonmatching */ +void daSail_packet_c::setCorrectNrmAngle(s16 param_0, f32 param_1) { + m1C38 += (s16)(900 + (s32)cM_rndF(200.0f)); + + m1C34 = 300.0f * cM_ssin(m1C38); + + s16 r28 = param_0 + 0x8000; + s32 r27 = param_0; + + s16 r26 = l_HIO.m10 * (1.0f - 0.5f * param_1); + s32 r0 = abs(r28); + s16 r30 = cAngle::d2s(1.25f * r26); + + if (r0 < r30) { + s16 targetAngle = r28 > 0 ? (s16)cAngle::d2s(-r26) : (s16)cAngle::d2s(r26); + cLib_addCalcAngleS2(&m1C36, targetAngle, 5, 192); + } else if (abs(r27) < r30) { + s16 targetAngle = (s16)r27 > 0 ? (s16)cAngle::d2s(-r26) : (s16)cAngle::d2s(r26); + cLib_addCalcAngleS2(&m1C36, targetAngle, 5, 192); + } else { + cLib_addCalcAngleS2(&m1C36, 0, 5, 192); + } + m1C34 += m1C36; } /* 00000364-00000398 .text setNrmMtx__15daSail_packet_cFv */ @@ -449,39 +487,444 @@ void daSail_packet_c::setNrmMtx() { /* 00000398-00000424 .text setBackNrm__15daSail_packet_cFv */ void daSail_packet_c::setBackNrm() { - /* Nonmatching */ + cXyz* vtxNrm1 = m0C74 + (0x54 * m1C3A); + cXyz* vtxNrm2 = m1454 + (0x54 * m1C3A); + for (int i = 0; i < 0x54; i++) { + vtxNrm2->setall(0.0f); + *vtxNrm2 -= *vtxNrm1; + vtxNrm1++; + vtxNrm2++; + } } /* 00000424-00000834 .text setNrmVtx__15daSail_packet_cFP4cXyzii */ -void daSail_packet_c::setNrmVtx(cXyz*, int, int) { - /* Nonmatching */ +void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { + cXyz spF8; + cXyz spEC; + cXyz spE0; + cXyz spD4; + cXyz spC8; + cXyz* vtxPos = getPos(); + s32 idx = param_2 * 7; + spC8.set(vtxPos[param_1 + idx]); + spD4.setall(0.0f); + + if (param_1 != 0) { + spF8 = vtxPos[idx - 1 + param_1] - spC8; + if (param_2 != 0) { + spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; + spE0 = spEC.outprod(spF8); + spE0 = spE0.normZC(); + spD4 += spE0; + } + if (param_2 != 11) { + spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; + spE0 = spF8.outprod(spEC); + spE0 = spE0.normZC(); + spD4 += spE0; + } + } + if (param_1 != 6) { + spF8 = vtxPos[param_1 + 1 + idx] - spC8; + if (param_2 != 0) { + spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; + spE0 = spF8.outprod(spEC); + spE0 = spE0.normZC(); + spD4 += spE0; + } + if (param_2 != 11) { + spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; + spE0 = spEC.outprod(spF8); + spE0 = spE0.normZC(); + spD4 += spE0; + } + } + + spD4 = spD4.normZC(); + + MtxPush(); + mDoMtx_YrotM(*calc_mtx, cM_ssin(-800 * (param_1 + param_2)) * 900.0f); + MtxPosition(&spD4, &spE0); + *param_0 = spE0.normZC(); + MtxPull(); } /* 00000870-000010D8 .text draw__15daSail_packet_cFv */ void daSail_packet_c::draw() { - /* Nonmatching */ - dComIfG_getObjectRes("Kaizokusen", KAIZOKUSEN_INDEX_BTI_TXA_KAIZOKU_HO); - dComIfG_getObjectRes("Cloth", CLOTH_BTI_CLOTHTOON); + j3dSys.reinitGX(); + +#if VERSION != VERSION_JPN + GXSetNumIndStages(0); +#endif + + dKy_GxFog_tevstr_set(mTevStr); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_INDEX8); + GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); + GXSetVtxDesc(GX_VA_TEX0, GX_INDEX8); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_POS_XY, GX_F32, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_POS_XYZ, GX_F32, 0); + + GXSetArray(GX_VA_POS, getPos(), sizeof(cXyz)); + GXSetArray(GX_VA_NRM, getNrm(), sizeof(cXyz)); + GXSetArray(GX_VA_TEX0, l_texCoord, sizeof(*l_texCoord)); + + GXTexObj texObj; + + ResTIMG* kaizokusen = (ResTIMG*)dComIfG_getObjectRes("Kaizokusen", KAIZOKUSEN_INDEX_BTI_TXA_KAIZOKU_HO); + GXInitTexObj(&texObj, (u8*)kaizokusen + kaizokusen->imageOffset, kaizokusen->width, kaizokusen->height, + (GXTexFmt)kaizokusen->format, (GXTexWrapMode)kaizokusen->wrapS, (GXTexWrapMode)kaizokusen->wrapT, + kaizokusen->mipmapCount > 1); + GXInitTexObjLOD(&texObj, (GXTexFilter)kaizokusen->minFilter, (GXTexFilter)kaizokusen->magFilter, + kaizokusen->minLOD * 0.125f, kaizokusen->maxLOD * 0.125f, kaizokusen->LODBias * 0.01f, + kaizokusen->biasClamp, kaizokusen->doEdgeLOD, (GXAnisotropy)kaizokusen->maxAnisotropy); + GXLoadTexObj(&texObj, GX_TEXMAP0); + + ResTIMG* cloth = (ResTIMG*)dComIfG_getObjectRes("Cloth", CLOTH_BTI_CLOTHTOON); + GXInitTexObj(&texObj, (u8*)cloth + cloth->imageOffset, cloth->width, cloth->height, + (GXTexFmt)cloth->format, (GXTexWrapMode)cloth->wrapS, (GXTexWrapMode)cloth->wrapT, + cloth->mipmapCount > 1); + GXInitTexObjLOD(&texObj, (GXTexFilter)cloth->minFilter, (GXTexFilter)cloth->magFilter, + cloth->minLOD * 0.125f, cloth->maxLOD * 0.125f, cloth->LODBias * 0.01f, + cloth->biasClamp, cloth->doEdgeLOD, (GXAnisotropy)cloth->maxAnisotropy); + GXLoadTexObj(&texObj, GX_TEXMAP1); + + GXSetNumChans(1); + + u8 numTevStages, lightMask; + if (mTevStr->mColorK1.a != 0) { + numTevStages = 3; + lightMask = GX_LIGHT0 | GX_LIGHT1; + } else { + numTevStages = 2; + lightMask = GX_LIGHT0; + } + + if (l_HIO.m05 != 0) { + GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); + GXSetNumTexGens(2); + GXLoadTexMtxImm(*getTexMtx(), 30, GX_MTX3x4); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); + GXSetTexCoordGen2(GX_TEXCOORD1, GX_TG_SRTG, GX_TG_COLOR0, 60, GX_FALSE, 125); + GXSetNumTevStages(numTevStages); + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP1); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_TEXC, GX_CC_CPREV, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); + GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + if (numTevStages == 3) { + GXSetTevSwapMode(GX_TEVSTAGE2, GX_TEV_SWAP0, GX_TEV_SWAP2); + GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE2, GX_CC_ZERO, GX_CC_C2, GX_CC_TEXC, GX_CC_CPREV); + GXSetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_APREV); + GXSetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + } + } else { + GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); + GXSetNumTexGens(1); + GXLoadTexMtxImm(*getTexMtx(), 30, GX_MTX3x4); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60, GX_FALSE, 125); + GXSetNumTevStages(numTevStages); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP1, GX_TEV_SWAP0); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_RASC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); + GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + if (numTevStages == 3) { + GXSetTevSwapMode(GX_TEVSTAGE2, GX_TEV_SWAP2, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE2, GX_CC_ZERO, GX_CC_C2, GX_CC_RASC, GX_CC_CPREV); + GXSetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_APREV); + GXSetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + } + } + + GXSetTevColorS10(GX_TEVREG0, mTevStr->mColorC0); + GXSetTevColor(GX_TEVREG1, mTevStr->mColorK0); + GXSetTevColor(GX_TEVREG2, mTevStr->mColorK1); + GXCallDisplayList(l_sail_matDL, 0x20); + + GXLoadPosMtxImm(*getMtx(), 0); + GXLoadNrmMtxImm(*getMtx(), 0); + + GXSetZCompLoc(GX_FALSE); + GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); + GXSetCullMode(GX_CULL_BACK); + GXCallDisplayList(l_sail_DL, 0x200); + + GXSetCullMode(GX_CULL_FRONT); + GXSetArray(GX_VA_NRM, getNrm() + 2 * 0x54, sizeof(cXyz)); + GXCallDisplayList(l_sail_DL, 0x200); + +#if VERSION != VERSION_JPN + J3DShape::sOldVcdVatCmd = NULL; +#endif } /* 000010D8-000013CC .text daSail_Draw__FP10sail_class */ static BOOL daSail_Draw(sail_class* i_this) { - /* Nonmatching */ + if (l_p_ship->m2CC == 0) { + return FALSE; + } + + i_this->tevStr = l_p_ship->tevStr; + + g_env_light.settingTevStruct(0, &i_this->current.pos, &i_this->tevStr); + g_env_light.setLightTevColorType(i_this->mSailPacket.mStickModel, &i_this->tevStr); + mDoExt_modelUpdateDL(i_this->mSailPacket.mStickModel); + + MtxTrans(i_this->current.pos.x, i_this->current.pos.y, i_this->current.pos.z, 0); + mDoMtx_YrotM(*calc_mtx, i_this->current.angle.y); + mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); + mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); + + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.getMtx()); + + cXyz* vtxPos = i_this->mSailPacket.getPos(); + MtxTrans( + i_this->current.pos.x, + i_this->current.pos.y + vtxPos[0x53].y, + i_this->current.pos.z, + 0 + ); + + mDoMtx_YrotM(*calc_mtx, i_this->current.angle.y); + mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); + mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); + + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.getStickMtx()); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.mStickModel->mBaseTransformMtx); + + MtxTrans(0.0f, 0.0f, 0.0f, 0); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.mTexMtx); + + i_this->mSailPacket.setTevStr(&i_this->tevStr); + + j3dSys.getDrawBuffer(0)->entryImm(&i_this->mSailPacket, 0); + + return TRUE; } /* 000013CC-00001CEC .text sail_pos_move__FP10sail_class */ static void sail_pos_move(sail_class* i_this) { - /* Nonmatching */ + cXyz* windVec = dKyw_get_wind_vec(); + s16 windAngle = cM_atan2s(windVec->x, windVec->z); + mDoMtx_YrotS(*calc_mtx, -(i_this->current.angle.y - windAngle)); + + cXyz sp28; + cXyz sp1C; + cXyz sp10; + + sp28.set(0.0f, 0.0f, 0.064f); + MtxPosition(&sp28, &sp1C); + + f32 f31 = (0.9f * std::fabsf(sp1C.z)) + 0.02f + (0.064f / 10.0f); + sp28.x = 0.0f; + sp28.z = 1.0f; + MtxPosition(&sp28, &sp1C); + + f32 f25 = (0.9f * std::fabsf(sp1C.z)) + 0.1f; + f32 f0 = std::fabsf(sp1C.x); + + i_this->mSailPacket.m1C40 += (s32)((1.0f - (i_this->mSailPacket.m1C44 * 0.95f)) * 4000.0f) * ((f25 * 0.85f) + 0.15f); + i_this->mSailPacket.m1C50 = ((f0 * 1.5f) + 1.0f) * 7500.0f; + i_this->mSailPacket.m1C52 = ((f25 * 0.95f) + 0.05f) * 7200.0f; + + cXyz* vtxPos = i_this->mSailPacket.getPos(); + f32 sp6C[7] = {}; + f32 sp34[7] = {}; + + f25 *= 1.0f - (0.5f * i_this->mSailPacket.m1C44 * i_this->mSailPacket.m1C4C); + f0 *= 1.0f - (0.75f * i_this->mSailPacket.m1C44); + + f32 ELEVEN = 11.0f; // this must be non-const + + for (int i = 0; i < 12; i++) { + f32 f12 = i - 6; + f32 f13 = i - 5.5f; + + sp10.z = f25 * (-ELEVEN * f12 * f12 + 396.0f); + + for (int j = 0; j < 7; j++, vtxPos++) { + f32 f24; + f32 f23 = j - 3; + f32 f22, f21, f20; // these are xyz components + f32 f17 = i * 5.0f; + + // these explicit casts are necessary + u32 r22 = (i_this->mSailPacket.m1C50 * (s32)f23) + (i_this->mSailPacket.m1C52 * (s32)f12); + + f20 = 1750.0f * ((f0 * f0) + 0.05f) * cM_ssin(-i_this->mSailPacket.m1C40 + r22) * f31; + f22 = 550.0f * ((f0 * f0) + 0.1f) * cM_scos(i_this->mSailPacket.m1C40 + r22) * f31; + f21 = std::sqrtf((f22 * f22) + (f20 * f20)) * 0.1f; + + f24 = (f25 * ((10.0f * f17) + (-f17 * f23 * f23))); + f24 += ((sp10.z * (18.0f - f23 * f23)) / 18.0f); + + f32 f15 = f24 - sp34[j]; + + f32 f16; + if (f15 > 100.0f) { + f16 = 100.0f; + sp34[j] += 100.0f; + } else { + f16 = -100.0f; + if (f15 < f16) { + sp34[j] -= 100.0f; + } else { + f16 = f15; + sp34[j] = f24; + } + } + + f32 f14 = 100.0f - std::sqrtf((125.0f * 125.0f) - (f16 * f16)); + sp6C[j] += f14 > -10.0f ? f14 : -10.0f; + + sp10.x = 0.0f; + sp10.y = 0.0f; + if (i < 3) { + f22 *= i * 0.33f; + f21 *= i * 0.33f; + f20 *= i * 0.33f; + } else if (i == 11 && std::fabsf(f23) == 3.0f) { + f22 = 0.0f; + f21 = 0.0f; + f20 = 0.0f; + } + + vtxPos->x = sp10.x + f22; + vtxPos->y = ((sp6C[j] + sp10.y + f21) - (i * 1.25f * (f23 * f23))); + vtxPos->z = f24 + f20; + + vtxPos->x += l_pos[i * 7 + j].x; + vtxPos->y += l_pos[i * 7 + j].y; + vtxPos->z += l_pos[i * 7 + j].z; + + vtxPos->y *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f)); + vtxPos->y *= ((ELEVEN - (i_this->mSailPacket.m1C44 * i)) / ELEVEN); + vtxPos->z *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f)); + vtxPos->z *= ((ELEVEN - (i_this->mSailPacket.m1C44 * i)) / ELEVEN); + + if (i_this->mSailPacket.m1C44 > 0.0f && i < 6) { + f32 f15_2 = i - 3; + f32 f20 = (9.0f - (f15_2 * f15_2)) / 9.0f; + vtxPos->z += (700.0f * f20 * i_this->mSailPacket.m1C44); + vtxPos->y -= (150.0f * f20 * i_this->mSailPacket.m1C44); + } + + vtxPos->y *= (0.3f * (j & 1) * i_this->mSailPacket.m1C44) + (1.0f - i_this->mSailPacket.m1C44); + vtxPos->z *= (0.15f * (j & 1) * i_this->mSailPacket.m1C44) + (1.0f - i_this->mSailPacket.m1C44); + } + } } /* 00001CEC-00001DB0 .text demo_move__FP10sail_class */ -static void demo_move(sail_class* i_this) { - /* Nonmatching */ +static BOOL demo_move(sail_class* i_this) { + if (i_this->demoActorID == 0) { + return FALSE; + } + dDemo_actor_c* demo = g_dComIfG_gameInfo.play.mDemo->mDemoObj.getActor(i_this->demoActorID); + if (demo != NULL) { + if (demo->checkEnable(0x40)) { + f32 frame = demo->mAnimationFrame; + frame = 0.6f - (frame * 0.006f); + i_this->mSailPacket.m1C44 = frame; + i_this->mSailPacket.m1C44 = cLib_minMaxLimit(i_this->mSailPacket.m1C44, 0.0f, 0.6f); + } + return TRUE; + } + return FALSE; } /* 00001DB0-00002094 .text sail_move__FP10sail_class */ static void sail_move(sail_class* i_this) { - /* Nonmatching */ + cXyz* windVec = dKyw_get_wind_vec(); + if (l_HIO.m06 == 0 && i_this->mSailPacket.m1C44 < 0.6f) { + if (i_this->mSailPacket.m1C48 <= 0.0f) { + i_this->mSailPacket.m1C48 = 0.015f; + } else { + i_this->mSailPacket.m1C48 -= 0.001f; + } + cLib_addCalc(&i_this->mSailPacket.m1C44, 0.6f, 0.1f, i_this->mSailPacket.m1C48, 0.01f); + } else { + if (l_HIO.m06 == 1 && i_this->mSailPacket.m1C44 > 0.0f) { + i_this->mSailPacket.m1C48 += 0.0075f; + cLib_addCalc(&i_this->mSailPacket.m1C44, 0.0f, 0.3f, i_this->mSailPacket.m1C48, 0.01f); + } else { + i_this->mSailPacket.m1C48 = 0.0f; + } + } + + if (i_this->mSailPacket.m1C44 > 1.0f) { + i_this->mSailPacket.m1C44 = 1.0f; + } else if (i_this->mSailPacket.m1C44 < 0.0f) { + i_this->mSailPacket.m1C44 = 0.0f; + } + + if (!demo_move(i_this) && l_HIO.m08 != 0) { + i_this->mSailPacket.m1C44 = l_HIO.m0C; + } + i_this->mSailPacket.m1C4C = (i_this->mSailPacket.m1C44 - 0.6f) * 15.0f; + + s16 windAngle = cM_atan2s(windVec->x, windVec->z); + mDoMtx_YrotS(*calc_mtx, -(i_this->current.angle.y - windAngle)); + + cXyz sp2C(0.0f, 0.0f, 0.064f); + cXyz sp20; + MtxPosition(&sp2C, &sp20); + + sp2C.x = 0.0f; + sp2C.z = 1.0f; + MtxPosition(&sp2C, &sp20); + + f32 f31_1 = std::fabsf(sp20.z); + sail_pos_move(i_this); + f32 f31_2 = f31_1 * (1.0f - (i_this->mSailPacket.m1C44 * 0.5f * i_this->mSailPacket.m1C4C)); + + cXyz* vtxPos = i_this->mSailPacket.getPos() + 3 * 0x54; + + s16 angleY = i_this->current.angle.y; + cXyz light; + dKy_FirstlightVec_get(&light); + s16 lightAngle = cM_atan2s(light.x, light.z); + + i_this->mSailPacket.setCorrectNrmAngle(lightAngle - angleY, f31_2); + + i_this->mSailPacket.setNrmMtx(); + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 7; j++) { + i_this->mSailPacket.setNrmVtx(vtxPos, j, i); + vtxPos++; + } + } + i_this->mSailPacket.setBackNrm(); + +#if VERSION == VERSION_JPN + DCStoreRangeNoSync(i_this->mSailPacket.getPos(), 0x14ac0); +#else + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 0 * 0x54, 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 3 * 0x54, 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 5 * 0x54, 0x03f0); +#endif } /* 00002094-00002154 .text daSail_Execute__FP10sail_class */ @@ -518,8 +961,8 @@ static BOOL daSail_checkCreateHeap(fopAc_ac_c* i_actor) { if (modelData == NULL) { return FALSE; } - i_this->mSailPacket.m1C3C = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000002); - if (i_this->mSailPacket.m1C3C) { + i_this->mSailPacket.mStickModel = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000002); + if (i_this->mSailPacket.mStickModel != NULL) { return TRUE; } else { return FALSE; @@ -528,20 +971,21 @@ static BOOL daSail_checkCreateHeap(fopAc_ac_c* i_actor) { /* 00002254-000024E4 .text daSail_Create__FP10fopAc_ac_c */ static s32 daSail_Create(fopAc_ac_c* i_actor) { - /* Nonmatching */ fopAcM_SetupActor(i_actor, sail_class); sail_class* i_this = (sail_class*)i_actor; - int phase_state = dComIfG_resLoad(&i_this->mClothPhase, "Cloth"); - if (phase_state != cPhs_COMPLEATE_e) { - return phase_state; - } - phase_state = dComIfG_resLoad(&i_this->mKaizokusenPhase, "Kaizokusen"); - if (phase_state != cPhs_COMPLEATE_e) { - return phase_state; + { + int phase_state = dComIfG_resLoad(&i_this->mClothPhase, "Cloth"); + if (phase_state != cPhs_COMPLEATE_e) { + return phase_state; + } + phase_state = dComIfG_resLoad(&i_this->mKaizokusenPhase, "Kaizokusen"); + if (phase_state != cPhs_COMPLEATE_e) { + return phase_state; + } } - phase_state = cPhs_COMPLEATE_e; + int phase_state = cPhs_COMPLEATE_e; if (fopAcM_entrySolidHeap(i_this, daSail_checkCreateHeap, 0x4C0)) { if (l_HIO.mChildID < 0) { l_HIO.mChildID = mDoHIO_root.m_subroot.createChild("海賊船の帆", &l_HIO); // "Pirate Ship's Sail" @@ -549,11 +993,11 @@ static s32 daSail_Create(fopAc_ac_c* i_actor) { i_this->mSailPacket.m1C44 = 0.0f; i_this->mSailPacket.m1C48 = 0.0f; - cXyz* r6 = &i_this->mSailPacket.m0884[0]; - cXyz* r7 = &i_this->mSailPacket.m00A4[i_this->mSailPacket.m1C3A * 0x54]; // this is probably one of daSail_packet_c's inlines - for (int i = 0; i < ARRAY_SIZE(l_pos); i++, r6++, r7++) { - r6->setall(0.0f); - r7->set(l_pos[i]); + cXyz* vtxPosSpd = i_this->mSailPacket.getPosSpd(); + cXyz* vtxPos = i_this->mSailPacket.getPos(); + for (int i = 0; i < ARRAY_SIZE(l_pos); i++, vtxPosSpd++, vtxPos++) { + vtxPosSpd->setall(0.0f); + vtxPos->set(l_pos[i]); } l_p_ship = (daObjPirateship::Act_c*)fopAcM_SearchByID(i_this->parentActorID);