Line data Source code
1 : #include "core/animations/states/BodyStandAnimationState.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/BodyThrowAnimationState.hpp"
10 : #include "core/animations/states/BodyThrowWeaponAnimationState.hpp"
11 :
12 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
13 :
14 : #include "core/animations/AnimationData.hpp"
15 : #include "core/entities/Soldier.hpp"
16 : #include "core/physics/Constants.hpp"
17 : #include <memory>
18 :
19 : namespace Soldank
20 : {
21 0 : BodyStandAnimationState::BodyStandAnimationState(const AnimationDataManager& animation_data_manager)
22 0 : : AnimationState(animation_data_manager.Get(AnimationType::Stand))
23 0 : , animation_data_manager_(animation_data_manager)
24 : {
25 0 : }
26 :
27 0 : std::optional<std::shared_ptr<AnimationState>> BodyStandAnimationState::HandleInput(
28 : Soldier& soldier)
29 : {
30 0 : if (soldier.legs_animation->GetType() == AnimationType::Roll) {
31 0 : return std::make_shared<BodyRollAnimationState>(animation_data_manager_);
32 : }
33 :
34 0 : if (soldier.legs_animation->GetType() == AnimationType::RollBack) {
35 0 : return std::make_shared<BodyRollBackAnimationState>(animation_data_manager_);
36 : }
37 :
38 0 : if (soldier.control.change) {
39 0 : return std::make_shared<BodyChangeAnimationState>(animation_data_manager_);
40 : }
41 :
42 0 : if (soldier.control.drop &&
43 0 : soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind != WeaponType::NoWeapon) {
44 0 : return std::make_shared<BodyThrowWeaponAnimationState>(animation_data_manager_);
45 : }
46 :
47 : auto maybe_throw_grenade_animation_state =
48 : CommonAnimationStateTransitions::TryTransitionToThrowingGrenade(soldier,
49 0 : animation_data_manager_);
50 0 : if (maybe_throw_grenade_animation_state.has_value()) {
51 0 : return *maybe_throw_grenade_animation_state;
52 : }
53 :
54 0 : if (soldier.control.fire &&
55 0 : (soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind ==
56 0 : WeaponType::NoWeapon ||
57 0 : soldier.weapons[soldier.active_weapon].GetWeaponParameters().kind == WeaponType::Knife)) {
58 0 : return std::make_shared<BodyPunchAnimationState>(animation_data_manager_);
59 : }
60 :
61 0 : if (soldier.stance == PhysicsConstants::STANCE_CROUCH) {
62 0 : return std::make_shared<BodyAimAnimationState>(animation_data_manager_);
63 : }
64 :
65 0 : if (soldier.stance == PhysicsConstants::STANCE_PRONE) {
66 0 : return std::make_shared<BodyProneAnimationState>(animation_data_manager_);
67 : }
68 :
69 0 : return std::nullopt;
70 0 : }
71 : } // namespace Soldank
|