| 1 | #include "Library/MapObj/WheelMapParts.h" |
| 2 | |
| 3 | #include "Library/Area/SwitchKeepOnAreaGroup.h" |
| 4 | #include "Library/Area/SwitchOnAreaGroup.h" |
| 5 | #include "Library/Effect/EffectSystemInfo.h" |
| 6 | #include "Library/LiveActor/ActorActionFunction.h" |
| 7 | #include "Library/LiveActor/ActorAreaFunction.h" |
| 8 | #include "Library/LiveActor/ActorInitUtil.h" |
| 9 | #include "Library/LiveActor/ActorModelFunction.h" |
| 10 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 11 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 12 | #include "Library/MapObj/ChildStep.h" |
| 13 | #include "Library/Math/MathUtil.h" |
| 14 | #include "Library/Matrix/MatrixUtil.h" |
| 15 | #include "Library/Movement/WheelMovement.h" |
| 16 | #include "Library/Nerve/NerveSetupUtil.h" |
| 17 | #include "Library/Nerve/NerveUtil.h" |
| 18 | #include "Library/Se/SeFunction.h" |
| 19 | |
| 20 | namespace { |
| 21 | using namespace al; |
| 22 | |
| 23 | NERVE_ACTION_IMPL(WheelMapParts, Wait) |
| 24 | NERVE_ACTION_IMPL(WheelMapParts, Move) |
| 25 | NERVE_ACTION_IMPL(WheelMapParts, AssistStop) |
| 26 | |
| 27 | NERVE_ACTIONS_MAKE_STRUCT(WheelMapParts, Wait, Move, AssistStop) |
| 28 | } // namespace |
| 29 | |
| 30 | namespace al { |
| 31 | WheelMapParts::WheelMapParts(const char* name) : LiveActor(name) {} |
| 32 | |
| 33 | void WheelMapParts::init(const ActorInitInfo& info) { |
| 34 | tryInitSubActorKeeperChildStep(actor: this, info); |
| 35 | initNerveAction(actor: this, actionName: "Wait" , collector: &NrvWheelMapParts.collector, maxStates: 0); |
| 36 | initMapPartsActor(actor: this, initInfo: info, suffix: nullptr); |
| 37 | tryGetQuatPtr(actor: this); |
| 38 | registerAreaHostMtx(actor: this, initInfo: info); |
| 39 | |
| 40 | mWheelMovement = new WheelMovement(this, info); |
| 41 | |
| 42 | initMaterialCode(actor: this, initInfo: info); |
| 43 | trySetEffectNamedMtxPtr(this, "Surface" , &mSurfaceEffectMtx); |
| 44 | createChildStep(info, parent: this, isSyncClipping: true); |
| 45 | |
| 46 | mSwitchKeepOnAreaGroup = tryCreateSwitchKeepOnAreaGroup(actor: this, initInfo: info); |
| 47 | mSwitchOnAreaGroup = tryCreateSwitchOnAreaGroup(actor: this, initInfo: info); |
| 48 | |
| 49 | trySyncStageSwitchAppear(actor: this); |
| 50 | } |
| 51 | |
| 52 | void WheelMapParts::control() { |
| 53 | sead::Vector3f moveDir = mWheelMovement->getMoveDir(); |
| 54 | if (mWheelMovement->get_50() < 0.0f) |
| 55 | moveDir *= -1; |
| 56 | |
| 57 | makeMtxUpFrontPos(outMtx: &mSurfaceEffectMtx, up: sead::Vector3f::ey, front: moveDir, pos: getTrans(actor: this)); |
| 58 | |
| 59 | if (mSwitchKeepOnAreaGroup != nullptr) |
| 60 | mSwitchKeepOnAreaGroup->update(playerPos: getTrans(actor: this)); |
| 61 | |
| 62 | if (mSwitchOnAreaGroup != nullptr) |
| 63 | mSwitchOnAreaGroup->update(trans: getTrans(actor: this)); |
| 64 | } |
| 65 | |
| 66 | bool WheelMapParts::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) { |
| 67 | if (isMsgTouchAssist(msg: message)) { |
| 68 | mAssistStopTimer = 45; |
| 69 | if (!isNerve(user: this, nerve: NrvWheelMapParts.AssistStop.data())) |
| 70 | startNerveAction(actor: this, actionName: "AssistStop" ); |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | if (mWheelMovement->receiveMsg(actor: this, message, other, self)) |
| 76 | return true; |
| 77 | |
| 78 | if (isMsgShowModel(msg: message)) { |
| 79 | showModelIfHide(actor: this); |
| 80 | |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | if (isMsgHideModel(msg: message)) { |
| 85 | hideModelIfShow(actor: this); |
| 86 | |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | if (isMsgRestart(msg: message)) { |
| 91 | appearAndSetStart(); |
| 92 | |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | void WheelMapParts::appearAndSetStart() { |
| 100 | mAssistStopTimer = 0; |
| 101 | mWheelMovement->reset(actor: this); |
| 102 | |
| 103 | makeActorAlive(); |
| 104 | } |
| 105 | |
| 106 | void WheelMapParts::exeWait() { |
| 107 | mWheelMovement->update(actor: this); |
| 108 | |
| 109 | if (mWheelMovement->get_66()) |
| 110 | startHitReaction(actor: this, name: "端点接触" ); |
| 111 | |
| 112 | if (!isNearZero(value: mWheelMovement->get_48(), tolerance: 0.2f)) |
| 113 | startNerveAction(actor: this, actionName: "Move" ); |
| 114 | } |
| 115 | |
| 116 | void WheelMapParts::exeMove() { |
| 117 | mWheelMovement->update(actor: this); |
| 118 | |
| 119 | if (mWheelMovement->get_66()) |
| 120 | startHitReaction(actor: this, name: "端点接触" ); |
| 121 | |
| 122 | f32 fVar3 = mWheelMovement->get_48(); |
| 123 | if (isNearZero(value: fVar3, tolerance: 0.2f)) |
| 124 | startNerveAction(actor: this, actionName: "Wait" ); |
| 125 | else |
| 126 | tryHoldSeWithParam(this, "Rotate" , sead::Mathf::abs(x: fVar3), "回転速度" ); |
| 127 | } |
| 128 | |
| 129 | void WheelMapParts::exeAssistStop() { |
| 130 | mAssistStopTimer--; |
| 131 | if (mAssistStopTimer <= 0) { |
| 132 | mAssistStopTimer = 0; |
| 133 | startNerveAction(actor: this, actionName: "Wait" ); |
| 134 | } |
| 135 | } |
| 136 | } // namespace al |
| 137 | |