Skip to content

Commit 9069838

Browse files
committed
Make damage infliction work like in the original
Loop through shootables and for each one, find one inflictor, instead of the other way around. Closes #611
1 parent c561476 commit 9069838

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/game_logic/damage_infliction_system.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,23 @@ DamageInflictionSystem::DamageInflictionSystem(
6565

6666
void DamageInflictionSystem::update(ex::EntityManager& es)
6767
{
68-
es.each<DamageInflicting, WorldPosition, BoundingBox>(
68+
es.each<Shootable, WorldPosition, BoundingBox>(
6969
[this, &es](
70-
ex::Entity inflictorEntity,
71-
DamageInflicting& damage,
72-
const WorldPosition& inflictorPosition,
73-
const BoundingBox& bbox) {
74-
const auto inflictorBbox = engine::toWorldSpace(bbox, inflictorPosition);
75-
76-
ex::ComponentHandle<Shootable> shootable;
77-
ex::ComponentHandle<WorldPosition> shootablePos;
78-
ex::ComponentHandle<BoundingBox> shootableBboxLocal;
79-
for (auto shootableEntity : es.entities_with_components(
80-
shootable, shootablePos, shootableBboxLocal))
70+
ex::Entity shootableEntity,
71+
Shootable& shootable,
72+
const WorldPosition& shootablePos,
73+
const BoundingBox& shootableBboxLocal) {
74+
const auto shootableBbox =
75+
engine::toWorldSpace(shootableBboxLocal, shootablePos);
76+
77+
ex::ComponentHandle<DamageInflicting> damage;
78+
ex::ComponentHandle<WorldPosition> inflictorPosition;
79+
ex::ComponentHandle<BoundingBox> inflictorBboxLocal;
80+
for (auto inflictorEntity : es.entities_with_components(
81+
damage, inflictorPosition, inflictorBboxLocal))
8182
{
82-
const auto shootableBbox =
83-
engine::toWorldSpace(*shootableBboxLocal, *shootablePos);
83+
const auto inflictorBbox =
84+
engine::toWorldSpace(*inflictorBboxLocal, *inflictorPosition);
8485

8586
const auto shootableOnScreen =
8687
shootableEntity.has_component<Active>() &&
@@ -89,17 +90,12 @@ void DamageInflictionSystem::update(ex::EntityManager& es)
8990
// clang-format off
9091
if (
9192
shootableBbox.intersects(inflictorBbox) &&
92-
!shootable->mInvincible &&
93-
(shootableOnScreen || shootable->mCanBeHitWhenOffscreen))
93+
!shootable.mInvincible &&
94+
(shootableOnScreen || shootable.mCanBeHitWhenOffscreen))
9495
// clang-format on
9596
{
96-
const auto destroyOnContact =
97-
damage.mDestroyOnContact || shootable->mAlwaysConsumeInflictor;
98-
inflictDamage(inflictorEntity, damage, shootableEntity, *shootable);
99-
if (destroyOnContact)
100-
{
101-
break;
102-
}
97+
inflictDamage(inflictorEntity, *damage, shootableEntity, shootable);
98+
break;
10399
}
104100
}
105101
});

0 commit comments

Comments
 (0)