Line data Source code
1 :
2 : #include "core/entities/Soldier.hpp"
3 :
4 : #include "core/entities/WeaponParametersFactory.hpp"
5 : #include "core/physics/Particles.hpp"
6 : #include "core/types/WeaponType.hpp"
7 : #include "core/animations/states/LegsStandAnimationState.hpp"
8 : #include "core/animations/states/BodyStandAnimationState.hpp"
9 :
10 : #include "spdlog/spdlog.h"
11 :
12 : #include <utility>
13 :
14 : const float GRAV = 0.06F;
15 :
16 : namespace Soldank
17 : {
18 0 : Soldier::Soldier(std::uint8_t soldier_id,
19 : const AnimationDataManager& animation_data_manager,
20 : std::shared_ptr<ParticleSystem> skeleton,
21 0 : const std::vector<Weapon>& initial_weapons)
22 0 : : id(soldier_id)
23 0 : , num(1)
24 0 : , visible(1)
25 0 : , direction(1)
26 0 : , old_direction(1)
27 0 : , health(150.0)
28 0 : , alpha(255.0)
29 0 : , has_cigar(1)
30 0 : , collider_distance(255)
31 0 : , skeleton(std::move(skeleton))
32 0 : , legs_animation(std::make_shared<LegsStandAnimationState>(animation_data_manager))
33 0 : , body_animation(std::make_shared<BodyStandAnimationState>(animation_data_manager))
34 0 : , control()
35 0 : , weapons{ initial_weapons }
36 0 : , weapon_choices{ WeaponType::DesertEagles, WeaponType::Knife }
37 0 : , particle(false,
38 : { 0.0F, 0.0F },
39 : { 0.0F, 0.0F },
40 : glm::vec2(0.0F, 0.0F),
41 : glm::vec2(0.0F, 0.0F),
42 : 1.0F,
43 : 1.0F,
44 : GRAV,
45 : 0.99,
46 0 : 0.0F)
47 : {
48 0 : }
49 :
50 0 : void Soldier::SetDefaultValues()
51 : {
52 0 : active = false;
53 0 : dead_meat = true;
54 0 : style = 0;
55 0 : num = 1;
56 0 : visible = 1;
57 0 : on_ground = false;
58 0 : on_ground_for_law = false;
59 0 : on_ground_last_frame = false;
60 0 : on_ground_permanent = false;
61 0 : direction = 1;
62 0 : old_direction = 1;
63 0 : health = 150.0;
64 0 : alpha = 255.0;
65 0 : jets_count = 0;
66 0 : jets_count_prev = 0;
67 0 : wear_helmet = 0;
68 0 : has_cigar = 1;
69 0 : vest = 0.0;
70 0 : idle_time = 0;
71 0 : idle_random = 0;
72 0 : stance = 0;
73 0 : on_fire = 0;
74 0 : collider_distance = 255;
75 0 : half_dead = false;
76 0 : is_shooting = false;
77 0 : }
78 :
79 0 : SoldierSnapshot::SoldierSnapshot(const Soldier& soldier)
80 0 : : body_animation_type_(soldier.body_animation->GetType())
81 0 : , legs_animation_type_(soldier.legs_animation->GetType())
82 0 : , body_animation_frame_(soldier.body_animation->GetFrame())
83 0 : , legs_animation_frame_(soldier.legs_animation->GetFrame())
84 0 : , body_animation_speed_(soldier.body_animation->GetSpeed())
85 0 : , legs_animation_speed_(soldier.legs_animation->GetSpeed())
86 0 : , body_animation_count_(soldier.body_animation->GetCount())
87 0 : , legs_animation_count_(soldier.legs_animation->GetCount())
88 0 : , on_ground_(soldier.on_ground)
89 0 : , control_(soldier.control)
90 0 : , position_(soldier.particle.position)
91 0 : , old_position_(soldier.particle.old_position)
92 0 : , jets_count_(soldier.jets_count)
93 0 : , jets_count_prev_(soldier.jets_count_prev)
94 0 : , stance_(soldier.stance)
95 0 : , velocity_(soldier.particle.GetVelocity())
96 0 : , force_(soldier.particle.GetForce())
97 : {
98 0 : }
99 0 : void SoldierSnapshot::CompareAndLog(const Soldier& other_soldier)
100 : {
101 0 : if (body_animation_type_ != other_soldier.body_animation->GetType()) {
102 0 : spdlog::debug("body_animation type difference: {} != {}",
103 0 : std::to_underlying(body_animation_type_),
104 0 : std::to_underlying(other_soldier.body_animation->GetType()));
105 : }
106 0 : if (legs_animation_type_ != other_soldier.legs_animation->GetType()) {
107 0 : spdlog::debug("legs_animation type difference: {} != {}",
108 0 : std::to_underlying(legs_animation_type_),
109 0 : std::to_underlying(other_soldier.legs_animation->GetType()));
110 : }
111 :
112 0 : if (body_animation_frame_ != other_soldier.body_animation->GetFrame()) {
113 0 : spdlog::debug("body_animation_frame difference: {} != {}",
114 0 : body_animation_frame_,
115 0 : other_soldier.body_animation->GetFrame());
116 : }
117 0 : if (legs_animation_frame_ != other_soldier.legs_animation->GetFrame()) {
118 0 : spdlog::debug("legs_animation_frame difference: {} != {}",
119 0 : legs_animation_frame_,
120 0 : other_soldier.legs_animation->GetFrame());
121 : }
122 :
123 0 : if (body_animation_speed_ != other_soldier.body_animation->GetSpeed()) {
124 0 : spdlog::debug("body_animation_speed difference: {} != {}",
125 0 : body_animation_speed_,
126 0 : other_soldier.body_animation->GetSpeed());
127 : }
128 0 : if (legs_animation_speed_ != other_soldier.legs_animation->GetSpeed()) {
129 0 : spdlog::debug("legs_animation_speed difference: {} != {}",
130 0 : legs_animation_speed_,
131 0 : other_soldier.legs_animation->GetSpeed());
132 : }
133 :
134 0 : if (body_animation_count_ != other_soldier.body_animation->GetCount()) {
135 0 : spdlog::debug("body_animation_count difference: {} != {}",
136 0 : body_animation_count_,
137 0 : other_soldier.body_animation->GetCount());
138 : }
139 0 : if (legs_animation_count_ != other_soldier.legs_animation->GetCount()) {
140 0 : spdlog::debug("legs_animation_count difference: {} != {}",
141 0 : legs_animation_count_,
142 0 : other_soldier.legs_animation->GetCount());
143 : }
144 :
145 0 : if (on_ground_ != other_soldier.on_ground) {
146 0 : spdlog::debug("on_ground difference: {} != {}", on_ground_, other_soldier.on_ground);
147 : }
148 :
149 0 : if (control_.jets != other_soldier.control.jets) {
150 0 : spdlog::debug(
151 0 : "control.jets difference: {} != {}", control_.jets, other_soldier.control.jets);
152 : }
153 0 : if (control_.left != other_soldier.control.left) {
154 0 : spdlog::debug(
155 0 : "control.left difference: {} != {}", control_.left, other_soldier.control.left);
156 : }
157 0 : if (control_.right != other_soldier.control.right) {
158 0 : spdlog::debug(
159 0 : "control.right difference: {} != {}", control_.right, other_soldier.control.right);
160 : }
161 0 : if (control_.down != other_soldier.control.down) {
162 0 : spdlog::debug(
163 0 : "control.down difference: {} != {}", control_.down, other_soldier.control.down);
164 : }
165 0 : if (control_.up != other_soldier.control.up) {
166 0 : spdlog::debug("control.up difference: {} != {}", control_.up, other_soldier.control.up);
167 : }
168 0 : if (control_.prone != other_soldier.control.prone) {
169 0 : spdlog::debug(
170 0 : "control.prone difference: {} != {}", control_.prone, other_soldier.control.prone);
171 : }
172 :
173 0 : if ((std::abs(position_.x - other_soldier.particle.position.x) > 0.001F) ||
174 0 : (std::abs(position_.y - other_soldier.particle.position.y) > 0.001F)) {
175 0 : spdlog::debug("position difference: ({}, {}) != ({}, {})",
176 0 : position_.x,
177 0 : position_.y,
178 0 : other_soldier.particle.position.x,
179 0 : other_soldier.particle.position.y);
180 : }
181 0 : if ((std::abs(old_position_.x - other_soldier.particle.old_position.x) > 0.001F) ||
182 0 : (std::abs(old_position_.y - other_soldier.particle.old_position.y) > 0.001F)) {
183 0 : spdlog::debug("old_position difference: ({}, {}) != ({}, {})",
184 0 : old_position_.x,
185 0 : old_position_.y,
186 0 : other_soldier.particle.old_position.x,
187 0 : other_soldier.particle.old_position.y);
188 : }
189 :
190 0 : if (jets_count_ != other_soldier.jets_count) {
191 0 : spdlog::debug("jets_count difference: {} != {}", jets_count_, other_soldier.jets_count);
192 : }
193 0 : if (jets_count_prev_ != other_soldier.jets_count_prev) {
194 0 : spdlog::debug(
195 0 : "jets_count_prev difference: {} != {}", jets_count_prev_, other_soldier.jets_count_prev);
196 : }
197 :
198 0 : if (stance_ != other_soldier.stance) {
199 0 : spdlog::debug("stance difference: {} != {}", stance_, other_soldier.stance);
200 : }
201 :
202 0 : if ((std::abs(velocity_.x - other_soldier.particle.GetVelocity().x) > 0.001F) ||
203 0 : (std::abs(velocity_.y - other_soldier.particle.GetVelocity().y) > 0.001F)) {
204 0 : spdlog::debug("velocity difference: ({}, {}) != ({}, {})",
205 0 : velocity_.x,
206 0 : velocity_.y,
207 0 : other_soldier.particle.GetVelocity().x,
208 0 : other_soldier.particle.GetVelocity().y);
209 : }
210 :
211 0 : if ((std::abs(force_.x - other_soldier.particle.GetForce().x) > 0.001F) ||
212 0 : (std::abs(force_.y - other_soldier.particle.GetForce().y) > 0.001F)) {
213 0 : spdlog::debug("velocity difference: ({}, {}) != ({}, {})",
214 0 : force_.x,
215 0 : force_.y,
216 0 : other_soldier.particle.GetForce().x,
217 0 : other_soldier.particle.GetForce().y);
218 : }
219 0 : }
220 : } // namespace Soldank
|