|
1 | 1 | #include "d/t/d_t_barrel.h" |
2 | 2 |
|
| 3 | +#include "common.h" |
| 4 | +#include "d/a/d_a_base.h" |
| 5 | +#include "d/a/d_a_player.h" |
| 6 | +#include "d/a/obj/d_a_obj_barrel.h" |
| 7 | +#include "d/a/obj/d_a_obj_base.h" |
| 8 | +#include "d/a/obj/d_a_obj_stage_sink.h" |
| 9 | +#include "d/flag/sceneflag_manager.h" |
| 10 | +#include "d/t/d_t_barrel_pos.h" |
| 11 | +#include "f/f_base.h" |
| 12 | +#include "f/f_manager.h" |
| 13 | +#include "f/f_profile_name.h" |
| 14 | +#include "m/m_angle.h" |
| 15 | +#include "m/m_mtx.h" |
| 16 | +#include "m/m_vec.h" |
| 17 | +#include "s/s_Math.h" |
| 18 | + |
3 | 19 | SPECIAL_ACTOR_PROFILE(TAG_BARREL, dTgBarrel_c, fProfile::TAG_BARREL, 0x221, 0, 0); |
4 | 20 |
|
5 | 21 | STATE_DEFINE(dTgBarrel_c, Wait); |
6 | 22 | STATE_DEFINE(dTgBarrel_c, Stop); |
7 | 23 |
|
| 24 | +// Weak function ordering issue of the ctor and dtor of the objects |
| 25 | +// for the following in the member arrays |
| 26 | +// dAcRef_c<dTgBarrelPos_c> |
| 27 | +// dAcRef_c<dAcOBarrel_c> |
| 28 | + |
| 29 | +int dTgBarrel_c::actorCreate() { |
| 30 | + mStopFlag = getFromParams(0, 0xFF); |
| 31 | + mLinkId = getFromParams(16, 0xF); |
| 32 | + mSpawnInterval = getFromParams(8, 0xFF); |
| 33 | + mSpawnTimer = 1; |
| 34 | + |
| 35 | + mStageRef.link(dAcOstageSink_c::GetInstance()); |
| 36 | + mSpawnPosition = mPosition; |
| 37 | + |
| 38 | + for (int i = 0; i < (int)ARRAY_LENGTH(mBarrelArr); ++i) { |
| 39 | + mBarrelArr[i].unlink(); |
| 40 | + } |
| 41 | + |
| 42 | + mStateMgr.changeState(StateID_Wait); |
| 43 | + |
| 44 | + return SUCCEEDED; |
| 45 | +} |
| 46 | + |
| 47 | +int dTgBarrel_c::actorPostCreate() { |
| 48 | + dTgBarrelPos_c *pTgBarrelPos = nullptr; |
| 49 | + do { |
| 50 | + pTgBarrelPos = |
| 51 | + static_cast<dTgBarrelPos_c *>(fManager_c::searchBaseByProfName(fProfile::TAG_BARREL_POS, pTgBarrelPos)); |
| 52 | + |
| 53 | + if (pTgBarrelPos != nullptr) { |
| 54 | + u8 index = pTgBarrelPos->getLinkIndex(); |
| 55 | + if (mLinkId == pTgBarrelPos->getLinkId()) { |
| 56 | + mTgBarrelPosArr[index].link(pTgBarrelPos); |
| 57 | + if (index >= mBarrelPosCount) { |
| 58 | + mBarrelPosCount = index + 1; |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + } while (pTgBarrelPos != nullptr); |
| 64 | + |
| 65 | + return SUCCEEDED; |
| 66 | +} |
| 67 | + |
| 68 | +int dTgBarrel_c::doDelete() { |
| 69 | + return SUCCEEDED; |
| 70 | +} |
| 71 | + |
| 72 | +int dTgBarrel_c::actorExecute() { |
| 73 | + mStateMgr.executeState(); |
| 74 | + return SUCCEEDED; |
| 75 | +} |
| 76 | + |
| 77 | +int dTgBarrel_c::draw() { |
| 78 | + return SUCCEEDED; |
| 79 | +} |
| 80 | + |
8 | 81 | void dTgBarrel_c::initializeState_Wait() {} |
9 | | -void dTgBarrel_c::executeState_Wait() {} |
| 82 | +void dTgBarrel_c::executeState_Wait() { |
| 83 | + if (SceneflagManager::sInstance->checkBoolFlag(mRoomID, mStopFlag)) { |
| 84 | + mStateMgr.changeState(StateID_Stop); |
| 85 | + return; |
| 86 | + } |
| 87 | + dAcOstageSink_c *pStage = mStageRef.get(); |
| 88 | + |
| 89 | + mVec3_c pos = pStage->mPosition; |
| 90 | + mAng3_c rot = pStage->mRotation; |
| 91 | + |
| 92 | + mVec3_c stageDist = mSpawnPosition - pos; |
| 93 | + mMtx_c m; |
| 94 | + m.transS(pos); |
| 95 | + m.ZXYrotM(rot); |
| 96 | + m.multVecSR(stageDist, mPosition); |
| 97 | + |
| 98 | + mPosition += pos; |
| 99 | + |
| 100 | + if (checkPlayerPos(dAcPy_c::GetLink()->mPosition)) { |
| 101 | + if (0 == sLib::calcTimer(&mSpawnTimer)) { |
| 102 | + mSpawnActive = true; |
| 103 | + |
| 104 | + u8 idx = 0xFF; |
| 105 | + for (int i = 0; i < (int)ARRAY_LENGTH(mBarrelArr); ++i) { |
| 106 | + if (!mBarrelArr[i].isLinked()) { |
| 107 | + idx = i; |
| 108 | + // I think they forgor a break here |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + if (idx != 0xFF) { |
| 113 | + dTgBarrelPos_c *pTgBarrelPos = mTgBarrelPosArr[mBarrelPosIndex].get(); |
| 114 | + if (pTgBarrelPos != nullptr) { |
| 115 | + mVec3_c spawnPos = pTgBarrelPos->mPosition; |
| 116 | + mAng3_c spawnRot(0, 0x4000, 0); |
| 117 | + dAcObjBase_c *pObj = dAcObjBase_c::create( |
| 118 | + fProfile::OBJ_BARREL, mRoomID, 0xFF00FF2, &spawnPos, &spawnRot, nullptr, 0xFFFFFFFF |
| 119 | + ); |
| 120 | + mBarrelArr[idx].link(static_cast<dAcOBarrel_c *>(pObj)); |
| 121 | + } |
| 122 | + if (++mBarrelPosIndex >= mBarrelPosCount) { |
| 123 | + mBarrelPosIndex = 0; |
| 124 | + } |
| 125 | + } |
| 126 | + mSpawnTimer = mSpawnInterval * 30; |
| 127 | + } |
| 128 | + } else { |
| 129 | + if (mSpawnActive) { |
| 130 | + mSpawnTimer = mSpawnInterval * 30; |
| 131 | + } |
| 132 | + } |
| 133 | +} |
10 | 134 | void dTgBarrel_c::finalizeState_Wait() {} |
| 135 | + |
11 | 136 | void dTgBarrel_c::initializeState_Stop() {} |
12 | | -void dTgBarrel_c::executeState_Stop() {} |
| 137 | +void dTgBarrel_c::executeState_Stop() { |
| 138 | + if (!SceneflagManager::sInstance->checkBoolFlag(mRoomID, mStopFlag)) { |
| 139 | + mStateMgr.changeState(StateID_Wait); |
| 140 | + } |
| 141 | +} |
13 | 142 | void dTgBarrel_c::finalizeState_Stop() {} |
| 143 | + |
| 144 | +bool dTgBarrel_c::checkPlayerPos(const mVec3_c &playerPos) { |
| 145 | + f32 scale = 0.5f; |
| 146 | + |
| 147 | + mVec3_c pos = playerPos - (mPosition + (mVec3_c::Ey * mScale.y * scale)); |
| 148 | + mAng rot = mStageRef.get()->mRotation.z; |
| 149 | + |
| 150 | + pos.x = pos.x / mScale.x; |
| 151 | + pos.y = pos.y / mScale.y; |
| 152 | + pos.z = pos.z / mScale.z; |
| 153 | + |
| 154 | + f32 halfCos = rot.cos() * scale; |
| 155 | + if (rot.cos() != 0.f) { |
| 156 | + scale = mScale.x * ((pos.x * rot.sin()) / rot.cos()) / mScale.y; |
| 157 | + } |
| 158 | + |
| 159 | + return ( |
| 160 | + (pos.x <= halfCos && pos.x >= -halfCos) // |
| 161 | + && pos.y <= scale + 0.5f + 1e-6f && pos.y >= scale + -0.5f - 1e-6f // |
| 162 | + && pos.z <= 0.5f && pos.z >= -0.5f |
| 163 | + ); |
| 164 | +} |
0 commit comments