| 1 | #include "Library/MapObj/SwingMapParts.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorActionFunction.h" |
| 4 | #include "Library/LiveActor/ActorAreaFunction.h" |
| 5 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 6 | #include "Library/LiveActor/ActorInitUtil.h" |
| 7 | #include "Library/LiveActor/ActorModelFunction.h" |
| 8 | #include "Library/LiveActor/ActorMovementFunction.h" |
| 9 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 10 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 11 | #include "Library/MapObj/ChildStep.h" |
| 12 | #include "Library/Movement/SwingMovement.h" |
| 13 | #include "Library/Nerve/NerveSetupUtil.h" |
| 14 | #include "Library/Nerve/NerveUtil.h" |
| 15 | #include "Library/Placement/PlacementFunction.h" |
| 16 | #include "Library/Stage/StageSwitchUtil.h" |
| 17 | #include "Library/Thread/FunctorV0M.h" |
| 18 | |
| 19 | namespace { |
| 20 | using namespace al; |
| 21 | |
| 22 | NERVE_ACTION_IMPL(SwingMapParts, StandBy) |
| 23 | NERVE_ACTION_IMPL(SwingMapParts, MoveRight) |
| 24 | NERVE_ACTION_IMPL(SwingMapParts, MoveLeft) |
| 25 | NERVE_ACTION_IMPL(SwingMapParts, Stop) |
| 26 | |
| 27 | NERVE_ACTIONS_MAKE_STRUCT(SwingMapParts, StandBy, MoveRight, MoveLeft, Stop) |
| 28 | } // namespace |
| 29 | |
| 30 | namespace al { |
| 31 | SwingMapParts::SwingMapParts(const char* name) : LiveActor(name) {} |
| 32 | |
| 33 | void SwingMapParts::init(const ActorInitInfo& info) { |
| 34 | using SwingMapPartsFunctor = FunctorV0M<SwingMapParts*, void (SwingMapParts::*)()>; |
| 35 | |
| 36 | mSwingMovement = new SwingMovement(info); |
| 37 | |
| 38 | if (mSwingMovement->isLeft()) |
| 39 | initNerveAction(actor: this, actionName: "MoveLeft" , collector: &NrvSwingMapParts.collector, maxStates: 0); |
| 40 | else |
| 41 | initNerveAction(actor: this, actionName: "MoveRight" , collector: &NrvSwingMapParts.collector, maxStates: 0); |
| 42 | |
| 43 | tryInitSubActorKeeperChildStep(actor: this, info); |
| 44 | initMapPartsActor(actor: this, initInfo: info, suffix: nullptr); |
| 45 | tryGetQuatPtr(actor: this); |
| 46 | registerAreaHostMtx(actor: this, initInfo: info); |
| 47 | |
| 48 | mQuat = getQuat(actor: this); |
| 49 | |
| 50 | createChildStep(info, parent: this, isSyncClipping: true); |
| 51 | tryGetArg(arg: (s32*)&mRotateAxis, initInfo: info, key: "RotateAxis" ); |
| 52 | tryGetArg(arg: &mIsFloorTouchStart, initInfo: info, key: "IsFloorTouchStart" ); |
| 53 | |
| 54 | if (mIsFloorTouchStart || |
| 55 | listenStageSwitchOnStart(user: this, action: SwingMapPartsFunctor(this, &SwingMapParts::start))) |
| 56 | startNerveAction(actor: this, actionName: "StandBy" ); |
| 57 | |
| 58 | rotateQuatLocalDirDegree(actor: this, quat: mQuat, axis: (s32)mRotateAxis, deg: mSwingMovement->getCurrentAngle()); |
| 59 | trySyncStageSwitchAppear(actor: this); |
| 60 | } |
| 61 | |
| 62 | void SwingMapParts::start() { |
| 63 | if (!isNerve(user: this, nerve: NrvSwingMapParts.StandBy.data())) |
| 64 | return; |
| 65 | |
| 66 | if (mSwingMovement->isLeft()) |
| 67 | startNerveAction(actor: this, actionName: "MoveLeft" ); |
| 68 | else |
| 69 | startNerveAction(actor: this, actionName: "MoveRight" ); |
| 70 | } |
| 71 | |
| 72 | void SwingMapParts::initAfterPlacement() { |
| 73 | tryExpandClippingByDepthShadowLength(actor: this, &mDepthShadowLength); |
| 74 | } |
| 75 | |
| 76 | bool SwingMapParts::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) { |
| 77 | if (mIsFloorTouchStart && isMsgFloorTouch(msg: message) && |
| 78 | isNerve(user: this, nerve: NrvSwingMapParts.StandBy.data())) { |
| 79 | if (mSwingMovement->isLeft()) |
| 80 | startNerveAction(actor: this, actionName: "MoveLeft" ); |
| 81 | else |
| 82 | startNerveAction(actor: this, actionName: "MoveRight" ); |
| 83 | |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | if (isMsgShowModel(msg: message)) { |
| 88 | showModelIfHide(actor: this); |
| 89 | |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | if (isMsgHideModel(msg: message)) { |
| 94 | hideModelIfShow(actor: this); |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | void SwingMapParts::control() { |
| 103 | rotateQuatLocalDirDegree(actor: this, quat: mQuat, axis: (s32)mRotateAxis, deg: mSwingMovement->getCurrentAngle()); |
| 104 | } |
| 105 | |
| 106 | void SwingMapParts::exeStandBy() {} |
| 107 | |
| 108 | void SwingMapParts::exeMoveRight() { |
| 109 | mSwingMovement->updateNerve(); |
| 110 | |
| 111 | if (mSwingMovement->isStop()) |
| 112 | startNerveAction(actor: this, actionName: "Stop" ); |
| 113 | } |
| 114 | |
| 115 | void SwingMapParts::exeMoveLeft() { |
| 116 | mSwingMovement->updateNerve(); |
| 117 | |
| 118 | if (mSwingMovement->isStop()) |
| 119 | startNerveAction(actor: this, actionName: "Stop" ); |
| 120 | } |
| 121 | |
| 122 | void SwingMapParts::exeStop() { |
| 123 | mSwingMovement->updateNerve(); |
| 124 | |
| 125 | if (!mSwingMovement->isStop()) { |
| 126 | if (mSwingMovement->isLeft()) |
| 127 | startNerveAction(actor: this, actionName: "MoveLeft" ); |
| 128 | else |
| 129 | startNerveAction(actor: this, actionName: "MoveRight" ); |
| 130 | } |
| 131 | } |
| 132 | } // namespace al |
| 133 | |