Line data Source code
1 : #include "core/animations/states/LegsGetUpAnimationState.hpp"
2 :
3 : #include "core/animations/states/LegsJumpSideAnimationState.hpp"
4 : #include "core/animations/states/LegsJumpAnimationState.hpp"
5 : #include "core/animations/states/LegsStandAnimationState.hpp"
6 : #include "core/animations/states/LegsFallAnimationState.hpp"
7 : #include "core/animations/states/LegsRunAnimationState.hpp"
8 :
9 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
10 :
11 : #include "core/physics/Constants.hpp"
12 : #include "core/entities/Soldier.hpp"
13 :
14 : namespace Soldank
15 : {
16 0 : LegsGetUpAnimationState::LegsGetUpAnimationState(const AnimationDataManager& animation_data_manager)
17 0 : : AnimationState(animation_data_manager.Get(AnimationType::GetUp))
18 0 : , animation_data_manager_(animation_data_manager)
19 : {
20 0 : }
21 :
22 0 : std::optional<std::shared_ptr<AnimationState>> LegsGetUpAnimationState::HandleInput(
23 : Soldier& soldier)
24 : {
25 0 : if (ShouldCancelAnimation(soldier) || GetFrame() == GetFramesCount()) {
26 0 : if (soldier.on_ground) {
27 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
28 : }
29 :
30 0 : return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
31 : }
32 :
33 : // Immediately switch from unprone to jump/sidejump, because the end of the
34 : // unprone animation can be seen as the "wind up" for the jump
35 0 : if (ShouldCancelAnimation(soldier) || (GetFrame() > 20 && soldier.on_ground)) {
36 0 : if (soldier.control.up) {
37 0 : if (soldier.control.left || soldier.control.right) {
38 : // Set sidejump frame 1 to 4 depending on which unprone frame we're in
39 0 : auto id = GetFrame() - 20;
40 : auto new_state =
41 0 : std::make_shared<LegsJumpSideAnimationState>(animation_data_manager_);
42 0 : new_state->SetFrame(id);
43 0 : return new_state;
44 0 : }
45 :
46 : // Set jump frame 6 to 9 depending on which unprone frame we're in
47 0 : auto id = GetFrame() - (23 - (9 - 1));
48 0 : auto new_state = std::make_shared<LegsJumpAnimationState>(animation_data_manager_);
49 0 : new_state->SetFrame(id);
50 0 : return new_state;
51 0 : }
52 0 : } else if (ShouldCancelAnimation(soldier) || GetFrame() > 23) {
53 : auto maybe_running_animation_state =
54 0 : CommonAnimationStateTransitions::TryTransitionToRunning(soldier, animation_data_manager_);
55 0 : if (maybe_running_animation_state.has_value()) {
56 0 : return *maybe_running_animation_state;
57 : }
58 :
59 0 : if (!soldier.on_ground && soldier.control.up) {
60 0 : return std::make_shared<LegsRunAnimationState>(animation_data_manager_);
61 : }
62 0 : }
63 0 : return std::nullopt;
64 : }
65 :
66 0 : void LegsGetUpAnimationState::Update(Soldier& soldier, const PhysicsEvents& physics_events)
67 : {
68 0 : soldier.stance = PhysicsConstants::STANCE_STAND;
69 0 : }
70 :
71 0 : bool LegsGetUpAnimationState::ShouldCancelAnimation(const Soldier& soldier)
72 : {
73 0 : if (soldier.control.throw_grenade) {
74 0 : return true;
75 : }
76 :
77 0 : if (soldier.control.fire &&
78 0 : (soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind ==
79 0 : WeaponType::NoWeapon ||
80 0 : soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind == WeaponType::Knife)) {
81 0 : return true;
82 : }
83 :
84 0 : return false;
85 : }
86 : } // namespace Soldank
|