| 1 | #include "Library/MapObj/ConveyerStep.h" |
| 2 | |
| 3 | #include "Library/Base/StringUtil.h" |
| 4 | #include "Library/LiveActor/ActorActionFunction.h" |
| 5 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 6 | #include "Library/LiveActor/ActorCollisionFunction.h" |
| 7 | #include "Library/LiveActor/ActorInitUtil.h" |
| 8 | #include "Library/LiveActor/ActorModelFunction.h" |
| 9 | #include "Library/LiveActor/ActorMovementFunction.h" |
| 10 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 11 | #include "Library/Math/MathUtil.h" |
| 12 | #include "Library/Nerve/NerveSetupUtil.h" |
| 13 | #include "Library/Placement/PlacementFunction.h" |
| 14 | #include "Project/LiveActor/ConveyerKeyKeeper.h" |
| 15 | |
| 16 | namespace { |
| 17 | using namespace al; |
| 18 | |
| 19 | NERVE_IMPL(ConveyerStep, Wait) |
| 20 | |
| 21 | NERVES_MAKE_STRUCT(ConveyerStep, Wait) |
| 22 | } // namespace |
| 23 | |
| 24 | namespace al { |
| 25 | ConveyerStep::ConveyerStep(const char* name) : LiveActor(name) {} |
| 26 | |
| 27 | void ConveyerStep::init(const ActorInitInfo& info) { |
| 28 | initMapPartsActor(actor: this, initInfo: info, suffix: nullptr); |
| 29 | initNerve(actor: this, nerve: &NrvConveyerStep.Wait, maxStates: 0); |
| 30 | onDrawClipping(actor: this); |
| 31 | |
| 32 | makeActorAlive(); |
| 33 | } |
| 34 | |
| 35 | bool ConveyerStep::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) { |
| 36 | if (mHost != nullptr) |
| 37 | return mHost->receiveMsg(message, other, self); |
| 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | void ConveyerStep::setHost(LiveActor* host) { |
| 43 | mHost = host; |
| 44 | } |
| 45 | |
| 46 | void ConveyerStep::setConveyerKeyKeeper(const ConveyerKeyKeeper* conveyerKeyKeeper, f32 coord) { |
| 47 | mConveyerKeyKeeper = conveyerKeyKeeper; |
| 48 | mMaxCoord = coord; |
| 49 | } |
| 50 | |
| 51 | void ConveyerStep::setTransByCoord(f32 coord, bool isForwards) { |
| 52 | setTransByCoord(coord, isForwards, isForceReset: false); |
| 53 | } |
| 54 | |
| 55 | void ConveyerStep::setTransByCoord(f32 coord, bool isForwards, bool isForceReset) { |
| 56 | f32 newCoord = modf(a: mMaxCoord + coord, b: mMaxCoord) + 0.0f; |
| 57 | s32 index = -1; |
| 58 | |
| 59 | mConveyerKeyKeeper->calcPosAndQuat(pos: getTransPtr(actor: this), quat: getQuatPtr(actor: this), index: &index, coord: newCoord); |
| 60 | |
| 61 | const char* keyHitReactionName = nullptr; |
| 62 | const char* actionName = nullptr; |
| 63 | |
| 64 | if (index > -1) { |
| 65 | const ConveyerKey* conveyerKey = mConveyerKeyKeeper->getConveyerKey(index); |
| 66 | |
| 67 | if (tryGetStringArg(arg: &keyHitReactionName, initInfo: conveyerKey->placementInfo, |
| 68 | key: "KeyHitReactionName" ) && |
| 69 | (mKeyHitReactionName == nullptr || |
| 70 | !isEqualString(str1: mKeyHitReactionName, str2: keyHitReactionName))) |
| 71 | startHitReaction(actor: this, name: keyHitReactionName); |
| 72 | |
| 73 | if (tryGetStringArg(arg: &actionName, initInfo: conveyerKey->placementInfo, key: "ActionName" ) && |
| 74 | (mActionName == nullptr || !isEqualString(str1: mActionName, str2: actionName))) |
| 75 | startAction(actor: this, actionName); |
| 76 | } |
| 77 | |
| 78 | mKeyHitReactionName = keyHitReactionName; |
| 79 | mActionName = actionName; |
| 80 | |
| 81 | if ((isForwards && newCoord < mCurrentCoord) || (!isForwards && newCoord > mCurrentCoord) || |
| 82 | isForceReset) |
| 83 | resetPosition(actor: this); |
| 84 | |
| 85 | if (newCoord > mConveyerKeyKeeper->getTotalMoveDistance()) { |
| 86 | if (mIsExist) { |
| 87 | mIsExist = false; |
| 88 | if (getModelKeeper() != nullptr && !isHideModel(actor: this)) |
| 89 | hideModel(actor: this); |
| 90 | if (isExistCollisionParts(this)) |
| 91 | invalidateCollisionParts(this); |
| 92 | } |
| 93 | } else if (!mIsExist) { |
| 94 | mIsExist = true; |
| 95 | if (getModelKeeper() != nullptr && isHideModel(actor: this)) |
| 96 | showModel(actor: this); |
| 97 | if (isExistCollisionParts(this)) |
| 98 | validateCollisionParts(this); |
| 99 | } |
| 100 | |
| 101 | mCurrentCoord = newCoord; |
| 102 | } |
| 103 | |
| 104 | void ConveyerStep::setTransAndResetByCoord(f32 coord) { |
| 105 | setTransByCoord(coord, isForwards: true, isForceReset: true); |
| 106 | } |
| 107 | |
| 108 | void ConveyerStep::exeWait() {} |
| 109 | } // namespace al |
| 110 | |