1#include "Library/Movement/SwingMovement.h"
2
3#include "Library/Math/MathUtil.h"
4#include "Library/Nerve/NerveSetupUtil.h"
5#include "Library/Nerve/NerveUtil.h"
6#include "Library/Placement/PlacementFunction.h"
7
8namespace {
9using namespace al;
10
11NERVE_IMPL(SwingMovement, Move)
12NERVE_IMPL(SwingMovement, Stop)
13
14NERVES_MAKE_NOSTRUCT(SwingMovement, Move, Stop)
15} // namespace
16
17namespace al {
18SwingMovement::SwingMovement() : NerveExecutor("スイング動作計算") {
19 initNerve(nerve: &Move, stateCount: 0);
20}
21
22SwingMovement::SwingMovement(const ActorInitInfo& info) : NerveExecutor("スイング動作計算") {
23 tryGetArg(arg: &mSwingAngle, initInfo: info, key: "SwingAngle");
24 tryGetArg(arg: &mSwingCycle, initInfo: info, key: "SwingCycle");
25 tryGetArg(arg: &mDelayRate, initInfo: info, key: "DelayRate");
26 tryGetArg(arg: &mStopTime, initInfo: info, key: "StopTime");
27 tryGetArg(arg: &mOffsetRotate, initInfo: info, key: "OffsetRotate");
28
29 mFrameInCycle = (s32)(((f32)mDelayRate - 25.0f) / 100.0f * (f32)mSwingCycle);
30 updateRotate();
31
32 initNerve(nerve: &Move, stateCount: 0);
33}
34
35bool SwingMovement::updateRotate() {
36 f32 degree = (f32)mFrameInCycle * 360.0f / (f32)mSwingCycle;
37
38 f32 swingAngle = sead::Mathf::abs(x: mSwingAngle);
39 if (swingAngle < 180.0f) {
40 mCurrentAngle =
41 sead::Mathf::sin(t: sead::Mathf::deg2rad(deg: degree)) * mSwingAngle + mOffsetRotate;
42
43 return mFrameInCycle % mSwingCycle == mSwingCycle / 4 ||
44 mFrameInCycle % mSwingCycle == 3 * mSwingCycle / 4;
45 }
46
47 f32 swingAngleSign = sign(x: mSwingAngle);
48 if (swingAngle < 360.0f) {
49 f32 rad = sead::Mathf::deg2rad(deg: modf(a: degree + 90.0f + 180.0f, b: 180.0f) - 90.0f);
50 mCurrentAngle = swingAngleSign * sead::Mathf::sin(t: rad) * 180.0f + mOffsetRotate;
51 } else {
52 mCurrentAngle = swingAngleSign * (modf(a: degree * 2 + 360.0f, b: 360.0f) + 0.0f) + mOffsetRotate;
53 }
54
55 return false;
56}
57
58void SwingMovement::exeMove() {
59 if (updateRotate())
60 setNerve(user: this, nerve: &Stop);
61
62 mFrameInCycle = modi(a: (mFrameInCycle + 1) + mSwingCycle, b: mSwingCycle);
63}
64
65void SwingMovement::exeStop() {
66 if (isGreaterEqualStep(user: this, step: mStopTime))
67 setNerve(user: this, nerve: &Move);
68}
69
70bool SwingMovement::isLeft() const {
71 f32 angle = (f32)mFrameInCycle * 360.0f / (f32)mSwingCycle;
72
73 return 90.0f <= angle && angle < 270.0f;
74}
75
76bool SwingMovement::isStop() const {
77 return isNerve(user: this, nerve: &Stop);
78}
79} // namespace al
80