Line data Source code
1 : #include "core/animations/states/BodyProneMoveAnimationState.hpp"
2 :
3 : #include "core/animations/states/BodyChangeAnimationState.hpp"
4 : #include "core/animations/states/BodyGetUpAnimationState.hpp"
5 : #include "core/animations/states/BodyProneAnimationState.hpp"
6 : #include "core/animations/states/BodyRollAnimationState.hpp"
7 : #include "core/animations/states/BodyRollBackAnimationState.hpp"
8 : #include "core/animations/states/BodyThrowWeaponAnimationState.hpp"
9 :
10 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
11 :
12 : #include "core/animations/AnimationData.hpp"
13 : #include "core/entities/Soldier.hpp"
14 : #include "core/physics/Constants.hpp"
15 :
16 : namespace Soldank
17 : {
18 0 : BodyProneMoveAnimationState::BodyProneMoveAnimationState(
19 0 : const AnimationDataManager& animation_data_manager)
20 0 : : AnimationState(animation_data_manager.Get(AnimationType::ProneMove))
21 0 : , animation_data_manager_(animation_data_manager)
22 : {
23 0 : }
24 :
25 0 : std::optional<std::shared_ptr<AnimationState>> BodyProneMoveAnimationState::HandleInput(
26 : Soldier& soldier)
27 : {
28 0 : if (soldier.control.prone || soldier.direction != soldier.old_direction) {
29 0 : auto new_state = std::make_shared<BodyGetUpAnimationState>(animation_data_manager_);
30 0 : new_state->SetFrame(9);
31 0 : return new_state;
32 0 : }
33 :
34 0 : if (soldier.on_ground) {
35 0 : if (soldier.control.down && (soldier.control.left || soldier.control.right)) {
36 0 : if (soldier.legs_animation->GetType() == AnimationType::Roll) {
37 0 : return std::make_shared<BodyRollAnimationState>(animation_data_manager_);
38 : }
39 :
40 0 : if (soldier.legs_animation->GetType() == AnimationType::RollBack) {
41 0 : return std::make_shared<BodyRollBackAnimationState>(animation_data_manager_);
42 : }
43 : }
44 : }
45 :
46 0 : if (soldier.control.change) {
47 0 : return std::make_shared<BodyChangeAnimationState>(animation_data_manager_);
48 : }
49 :
50 0 : if (soldier.control.drop &&
51 0 : soldier.weapons[0].GetWeaponParameters().kind != WeaponType::NoWeapon) {
52 0 : return std::make_shared<BodyThrowWeaponAnimationState>(animation_data_manager_);
53 : }
54 :
55 : auto maybe_throw_grenade_animation_state =
56 : CommonAnimationStateTransitions::TryTransitionToThrowingGrenade(soldier,
57 0 : animation_data_manager_);
58 0 : if (maybe_throw_grenade_animation_state.has_value()) {
59 0 : return *maybe_throw_grenade_animation_state;
60 : }
61 :
62 0 : if (!soldier.control.left && !soldier.control.right) {
63 0 : auto new_state = std::make_shared<BodyProneAnimationState>(animation_data_manager_);
64 0 : new_state->SetFrame(26);
65 0 : return new_state;
66 0 : }
67 :
68 0 : if (GetFrame() == GetFramesCount()) {
69 0 : auto new_state = std::make_shared<BodyProneAnimationState>(animation_data_manager_);
70 0 : new_state->SetFrame(26);
71 0 : return new_state;
72 0 : }
73 :
74 0 : return std::nullopt;
75 0 : }
76 : } // namespace Soldank
|