Line data Source code
1 : #include "core/animations/states/BodyThrowWeaponAnimationState.hpp"
2 :
3 : #include "core/animations/states/BodyAimAnimationState.hpp"
4 : #include "core/animations/states/BodyChangeAnimationState.hpp"
5 : #include "core/animations/states/BodyProneAnimationState.hpp"
6 : #include "core/animations/states/BodyPunchAnimationState.hpp"
7 : #include "core/animations/states/BodyRollAnimationState.hpp"
8 : #include "core/animations/states/BodyRollBackAnimationState.hpp"
9 : #include "core/animations/states/BodyStandAnimationState.hpp"
10 :
11 : #include "core/animations/states/BodyThrowAnimationState.hpp"
12 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
13 :
14 : #include "core/animations/AnimationData.hpp"
15 : #include "core/entities/Soldier.hpp"
16 : #include "core/physics/PhysicsEvents.hpp"
17 : #include "core/physics/Constants.hpp"
18 :
19 : #include <memory>
20 :
21 : namespace Soldank
22 : {
23 0 : BodyThrowWeaponAnimationState::BodyThrowWeaponAnimationState(
24 0 : const AnimationDataManager& animation_data_manager)
25 0 : : AnimationState(animation_data_manager.Get(AnimationType::ThrowWeapon))
26 0 : , animation_data_manager_(animation_data_manager)
27 0 : , should_throw_weapon_(true)
28 : {
29 0 : }
30 :
31 0 : void BodyThrowWeaponAnimationState::Enter(Soldier& soldier)
32 : {
33 0 : if (soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind == WeaponType::Knife) {
34 0 : SetSpeed(2);
35 : }
36 0 : }
37 :
38 0 : std::optional<std::shared_ptr<AnimationState>> BodyThrowWeaponAnimationState::HandleInput(
39 : Soldier& soldier)
40 : {
41 0 : should_throw_weapon_ = true;
42 :
43 0 : if (soldier.legs_animation->GetType() == AnimationType::Roll) {
44 0 : should_throw_weapon_ = false;
45 0 : return std::make_shared<BodyRollAnimationState>(animation_data_manager_);
46 : }
47 :
48 0 : if (soldier.legs_animation->GetType() == AnimationType::RollBack) {
49 0 : should_throw_weapon_ = false;
50 0 : return std::make_shared<BodyRollBackAnimationState>(animation_data_manager_);
51 : }
52 :
53 0 : if (soldier.control.throw_grenade) {
54 0 : should_throw_weapon_ = false;
55 0 : return std::make_shared<BodyThrowAnimationState>(animation_data_manager_);
56 : }
57 :
58 0 : if (soldier.control.change) {
59 0 : should_throw_weapon_ = false;
60 0 : return std::make_shared<BodyChangeAnimationState>(animation_data_manager_);
61 : }
62 :
63 0 : if (soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind == WeaponType::Knife) {
64 0 : if (soldier.control.fire && soldier.control.drop) {
65 0 : should_throw_weapon_ = false;
66 0 : return std::make_shared<BodyThrowWeaponAnimationState>(animation_data_manager_);
67 : }
68 :
69 0 : if (soldier.control.fire) {
70 0 : should_throw_weapon_ = false;
71 0 : return std::make_shared<BodyPunchAnimationState>(animation_data_manager_);
72 : }
73 : }
74 :
75 0 : if ((soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind == WeaponType::Knife &&
76 0 : (!soldier.control.drop || GetFrame() == 16)) ||
77 0 : GetFrame() == GetFramesCount()) {
78 :
79 0 : if (soldier.stance == PhysicsConstants::STANCE_CROUCH) {
80 0 : return std::make_shared<BodyAimAnimationState>(animation_data_manager_);
81 : }
82 :
83 0 : if (soldier.stance == PhysicsConstants::STANCE_PRONE) {
84 : auto prone_animation_state =
85 0 : std::make_shared<BodyProneAnimationState>(animation_data_manager_);
86 0 : prone_animation_state->SetFrame(26);
87 0 : return prone_animation_state;
88 0 : }
89 :
90 0 : if (soldier.stance == PhysicsConstants::STANCE_STAND) {
91 0 : return std::make_shared<BodyStandAnimationState>(animation_data_manager_);
92 : }
93 : }
94 :
95 0 : return std::nullopt;
96 : }
97 :
98 0 : void BodyThrowWeaponAnimationState::Exit(Soldier& soldier, const PhysicsEvents& physics_events)
99 : {
100 0 : if (should_throw_weapon_) {
101 0 : physics_events.soldier_throws_active_weapon.Notify(soldier);
102 : }
103 0 : }
104 : } // namespace Soldank
|