home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 02 Useful Techniques / 02 Orkin / TriggerSystem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-05  |  1.7 KB  |  64 lines

  1. #ifndef __TRIGGER_SYSTEM_H__
  2. #define __TRIGGER_SYSTEM_H__
  3.  
  4. #include "Vector.h"
  5.  
  6. #pragma warning(disable:4786)
  7. #include <Map>
  8.  
  9.  
  10. enum EnumTriggerType
  11. {
  12.     kTrig_None            = 0,
  13.     kTrig_Explosion        = (1 << 0),
  14.     kTrig_EnemyNear        = (1 << 1),
  15.     kTrig_Gunfire        = (1 << 2),
  16. };
  17.  
  18.  
  19. struct TriggerRecordStruct
  20. {
  21.     TriggerRecordStruct(EnumTriggerType _eTriggerType, 
  22.         unsigned long _idSource, const Vector& _vPos, 
  23.         float _fRadius, float _fDuration, bool _bDynamicSourcePos);
  24.  
  25.     EnumTriggerType        eTriggerType;        // Type of trigger.
  26.     unsigned long        nTriggerID;            // Registration ID assigned by the TriggerSystem.
  27.     unsigned long        idSource;            // ID of source of trigger.
  28.     Vector                vPos;                // Position in world of trigger.
  29.     float                fRadius;            // Distance from source that trigger affects.
  30.     unsigned long        nTimeStamp;            // When trigger occured.
  31.     unsigned long        nExpirationTime;    // When trigger expires.
  32.     bool                bDynamicSourcePos;    // Lookup position of trigger source every update.
  33.  
  34.     static unsigned long s_nNextTriggerID;    // Next unique Registration ID for trigger.
  35. };
  36.  
  37.  
  38. typedef std::multimap<unsigned short /*nPriority*/, TriggerRecordStruct*, std::greater<unsigned short> > TRIGGER_MAP;
  39.  
  40.  
  41. class CTriggerSystem
  42. {
  43.     public :
  44.  
  45.          CTriggerSystem();
  46.         ~CTriggerSystem();
  47.  
  48.         unsigned long    RegisterTrigger(EnumTriggerType _eTriggerType, unsigned long _nPriority,
  49.                                         unsigned long _idSource, const Vector& _vPos, float _fRadius, 
  50.                                         float _fDuration, bool _bDynamicSourcePos);
  51.  
  52.         void    RemoveTrigger(unsigned long nTriggerID);
  53.  
  54.         void    Update();
  55.  
  56.     private : 
  57.  
  58.         TRIGGER_MAP        m_mapTriggerMap;    // List of existing triggers, sorted by priority.
  59.  
  60.         bool            m_bTriggerCriticalSection;
  61. };
  62.  
  63. #endif
  64.