Add the possibility to exclude owned projectiles from the nearby projectiles count

This commit is contained in:
Alayan 2018-10-05 17:50:43 +02:00
parent 6445fb059d
commit 68916b0adf
3 changed files with 13 additions and 2 deletions

View File

@ -224,6 +224,10 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the type of flyable. */ /** Returns the type of flyable. */
PowerupManager::PowerupType getType() const {return m_type;} PowerupManager::PowerupType getType() const {return m_type;}
// ------------------------------------------------------------------------
/** Returns the owner's kart */
AbstractKart *getOwner() const { return m_owner;}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Sets wether Flyable should update TerrainInfo as part of its update /** Sets wether Flyable should update TerrainInfo as part of its update
* call, or if the inheriting object will update TerrainInfo itself * call, or if the inheriting object will update TerrainInfo itself

View File

@ -201,7 +201,8 @@ bool ProjectileManager::projectileIsClose(const AbstractKart * const kart,
* \param type The type of projectile checked * \param type The type of projectile checked
*/ */
int ProjectileManager::getNearbyProjectileCount(const AbstractKart * const kart, int ProjectileManager::getNearbyProjectileCount(const AbstractKart * const kart,
float radius, PowerupManager::PowerupType type) float radius, PowerupManager::PowerupType type,
bool exclude_owned)
{ {
float r2 = radius * radius; float r2 = radius * radius;
int projectile_count = 0; int projectile_count = 0;
@ -212,6 +213,9 @@ int ProjectileManager::getNearbyProjectileCount(const AbstractKart * const kart,
continue; continue;
if (i->second->getType() == type) if (i->second->getType() == type)
{ {
if (exclude_owned && (i->second->getOwner() == kart))
continue;
float dist2 = i->second->getXYZ().distance2(kart->getXYZ()); float dist2 = i->second->getXYZ().distance2(kart->getXYZ());
if (dist2 < r2) if (dist2 < r2)
{ {
@ -310,3 +314,4 @@ std::shared_ptr<Rewinder>
return nullptr; return nullptr;
} }
} // addProjectileFromNetworkState } // addProjectileFromNetworkState

View File

@ -72,7 +72,8 @@ public:
float radius); float radius);
int getNearbyProjectileCount(const AbstractKart * const kart, int getNearbyProjectileCount(const AbstractKart * const kart,
float radius, PowerupManager::PowerupType type); float radius, PowerupManager::PowerupType type,
bool exclude_owned=false);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Adds a special hit effect to be shown. /** Adds a special hit effect to be shown.
* \param hit_effect The hit effect to be added. */ * \param hit_effect The hit effect to be added. */
@ -100,3 +101,4 @@ extern ProjectileManager *projectile_manager;
#endif #endif
/* EOF */ /* EOF */