| 1 | #include "Library/MapObj/RailMoveMapParts.h" |
| 2 | |
| 3 | #include "Library/Area/SwitchKeepOnAreaGroup.h" |
| 4 | #include "Library/Area/SwitchOnAreaGroup.h" |
| 5 | #include "Library/LiveActor/ActorActionFunction.h" |
| 6 | #include "Library/LiveActor/ActorAreaFunction.h" |
| 7 | #include "Library/LiveActor/ActorClippingFunction.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/Movement/RailMoveMovement.h" |
| 13 | #include "Library/Nerve/NerveSetupUtil.h" |
| 14 | #include "Library/Nerve/NerveStateCtrl.h" |
| 15 | #include "Library/Nerve/NerveUtil.h" |
| 16 | #include "Library/Rail/RailUtil.h" |
| 17 | #include "Library/Stage/StageSwitchUtil.h" |
| 18 | #include "Library/Thread/FunctorV0M.h" |
| 19 | |
| 20 | namespace al { |
| 21 | namespace { |
| 22 | NERVE_ACTION_IMPL(RailMoveMapParts, StandBy) |
| 23 | NERVE_ACTION_IMPL(RailMoveMapParts, MoveSign) |
| 24 | NERVE_ACTION_IMPL(RailMoveMapParts, Move) |
| 25 | |
| 26 | NERVE_ACTIONS_MAKE_STRUCT(RailMoveMapParts, StandBy, MoveSign, Move) |
| 27 | } // namespace |
| 28 | |
| 29 | RailMoveMapParts::RailMoveMapParts(const char* name) : LiveActor(name) {} |
| 30 | |
| 31 | void RailMoveMapParts::init(const ActorInitInfo& info) { |
| 32 | using RailMoveMapPartsFunctor = FunctorV0M<RailMoveMapParts*, void (RailMoveMapParts::*)()>; |
| 33 | |
| 34 | initNerveAction(actor: this, actionName: "StandBy" , collector: &NrvRailMoveMapParts.collector, maxStates: 1); |
| 35 | initMapPartsActor(actor: this, initInfo: info, suffix: nullptr); |
| 36 | registerAreaHostMtx(actor: this, initInfo: info); |
| 37 | |
| 38 | if (isExistRail(railHolder: this)) { |
| 39 | f32 radius = getClippingRadius(actor: this); |
| 40 | setSyncRailToNearestPos(this); |
| 41 | mRailCoord = getRailCoord(railHolder: this); |
| 42 | setRailClippingInfo(&mRailPos, actor: this, 100.0f, radius); |
| 43 | } |
| 44 | |
| 45 | RailMoveMovement* railMoveMovement = new RailMoveMovement(this, info); |
| 46 | initNerveState(user: this, state: railMoveMovement, nerve: NrvRailMoveMapParts.Move.data(), hostName: "レール移動" ); |
| 47 | initMaterialCode(actor: this, initInfo: info); |
| 48 | |
| 49 | if (!listenStageSwitchOnStart(user: this, action: RailMoveMapPartsFunctor(this, &RailMoveMapParts::start))) |
| 50 | start(); |
| 51 | |
| 52 | if (listenStageSwitchOnStop(user: this, action: RailMoveMapPartsFunctor(this, &RailMoveMapParts::stop))) |
| 53 | stop(); |
| 54 | |
| 55 | mSwitchKeepOnAreaGroup = tryCreateSwitchKeepOnAreaGroup(actor: this, initInfo: info); |
| 56 | mSwitchOnAreaGroup = tryCreateSwitchOnAreaGroup(actor: this, initInfo: info); |
| 57 | |
| 58 | trySyncStageSwitchAppear(actor: this); |
| 59 | tryListenStageSwitchKill(actor: this); |
| 60 | } |
| 61 | |
| 62 | void RailMoveMapParts::start() { |
| 63 | if (isNerve(user: this, nerve: NrvRailMoveMapParts.StandBy.data())) |
| 64 | startNerveAction(actor: this, actionName: "MoveSign" ); |
| 65 | } |
| 66 | |
| 67 | void RailMoveMapParts::stop() { |
| 68 | if (isNerve(user: this, nerve: NrvRailMoveMapParts.Move.data())) |
| 69 | startNerveAction(actor: this, actionName: "StandBy" ); |
| 70 | } |
| 71 | |
| 72 | bool RailMoveMapParts::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) { |
| 73 | if (isMsgShowModel(msg: message)) { |
| 74 | showModelIfHide(actor: this); |
| 75 | |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | if (isMsgHideModel(msg: message)) { |
| 80 | hideModelIfShow(actor: this); |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | void RailMoveMapParts::control() { |
| 89 | if (mSwitchKeepOnAreaGroup != nullptr) |
| 90 | mSwitchKeepOnAreaGroup->update(playerPos: getTrans(actor: this)); |
| 91 | |
| 92 | if (mSwitchOnAreaGroup != nullptr) |
| 93 | mSwitchOnAreaGroup->update(trans: getTrans(actor: this)); |
| 94 | } |
| 95 | |
| 96 | void RailMoveMapParts::appearAndSetStart() { |
| 97 | setSyncRailToCoord(actor: this, coord: mRailCoord); |
| 98 | startNerveAction(actor: this, actionName: "MoveSign" ); |
| 99 | } |
| 100 | |
| 101 | void RailMoveMapParts::exeStandBy() {} |
| 102 | |
| 103 | void RailMoveMapParts::exeMoveSign() { |
| 104 | if ((isFirstStep(user: this) && !tryStartAction(actor: this, actionName: "MoveSign" )) || isActionEnd(actor: this)) |
| 105 | startNerveAction(actor: this, actionName: "Move" ); |
| 106 | } |
| 107 | |
| 108 | void RailMoveMapParts::exeMove() { |
| 109 | updateNerveState(user: this); |
| 110 | } |
| 111 | } // namespace al |
| 112 | |