From ac583cbb2d5593880aefd52a9dd562c6e2a887b7 Mon Sep 17 00:00:00 2001 From: Cesar Canassa Date: Mon, 18 Jul 2022 02:06:09 +0200 Subject: [PATCH] :sparkles: Adds isSameSource Missile method (#5036) --- Source/missiles.cpp | 4 ++-- Source/missiles.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 71d584af6..befc8e3aa 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1490,7 +1490,7 @@ void AddSearch(Missile &missile, const AddMissileParameter & /*parameter*/) UseMana(player, SPL_SEARCH); for (auto &other : Missiles) { - if (&other != &missile && other._misource == missile._misource && other._mitype == MIS_SEARCH) { + if (&other != &missile && missile.isSameSource(other) && other._mitype == MIS_SEARCH) { int r1 = missile._mirange; int r2 = other._mirange; if (r2 < INT_MAX - r1) @@ -1868,7 +1868,7 @@ void AddTown(Missile &missile, const AddMissileParameter ¶meter) missile._mirange = 100; missile.var1 = missile._mirange - missile._miAnimLen; for (auto &other : Missiles) { - if (other._mitype == MIS_TOWN && &other != &missile && other._misource == missile._misource) + if (other._mitype == MIS_TOWN && &other != &missile && missile.isSameSource(other)) other._mirange = 0; } PutMissile(missile); diff --git a/Source/missiles.h b/Source/missiles.h index f49dc2368..ba79d7333 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -153,6 +153,11 @@ struct Missile { return &Monsters[_misource]; } + [[nodiscard]] bool isSameSource(Missile &missile) + { + return sourceType() == missile.sourceType() && _misource == missile._misource; + } + MissileSource sourceType() { if (_misource == -1)