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