1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef _EXPLOSION_LISTENER_H 4 #define _EXPLOSION_LISTENER_H 5 6 #include "System/float3.h" 7 8 #include <set> 9 10 struct WeaponDef; 11 12 13 class CExplosionEvent { 14 public: CExplosionEvent(const float3 & pos,float damage,float radius,const WeaponDef * weaponDef)15 CExplosionEvent(const float3& pos, float damage, float radius, 16 const WeaponDef* weaponDef) 17 : pos(pos) 18 , damage(damage) 19 , radius(radius) 20 , weaponDef(weaponDef) 21 {} 22 GetPos()23 const float3& GetPos() const { return pos; } GetDamage()24 float GetDamage() const { return damage; } GetRadius()25 float GetRadius() const { return radius; } GetWeaponDef()26 const WeaponDef* GetWeaponDef() const { return weaponDef; } 27 28 private: 29 float3 pos; 30 float damage; 31 float radius; 32 const WeaponDef* weaponDef; 33 }; 34 35 36 class IExplosionListener 37 { 38 public: 39 /** 40 * Informs listeners about an explosion that has occured. 41 * @see EventClient#Explosion 42 */ 43 virtual void ExplosionOccurred(const CExplosionEvent& event) = 0; 44 protected: 45 ~IExplosionListener(); 46 }; 47 48 49 /** 50 * Base 51 */ 52 class CExplosionCreator 53 { 54 public: 55 static void AddExplosionListener(IExplosionListener* listener); 56 static void RemoveExplosionListener(IExplosionListener* listener); 57 58 /** 59 * Sends the event to all registered listeners. 60 */ 61 static void FireExplosionEvent(const CExplosionEvent& event); 62 63 private: 64 static std::set<IExplosionListener*> explosionListeners; 65 }; 66 67 #endif /* _EXPLOSION_LISTENER_H */ 68