home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / spawner.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  3KB  |  121 lines

  1. /*
  2. ================
  3.  
  4. Spawner.h
  5.  
  6. ================
  7. */
  8.  
  9. #ifndef __GAME_SPAWNER_H__
  10. #define __GAME_SPAWNER_H__
  11.  
  12. const int MAX_SPAWN_TYPES    = 32;
  13.  
  14. class rvSpawner;
  15.  
  16. typedef void (*spawnerCallbackProc_t) ( rvSpawner* spawner, idEntity* spawned, int userdata );
  17.  
  18. typedef struct {
  19.     idEntityPtr<idEntity>    ent;
  20.     idStr                    event;
  21. } spawnerCallback_t;
  22.  
  23. /*
  24. ===============================================================================
  25.  
  26.   rvSpawner
  27.  
  28. ===============================================================================
  29. */
  30. class rvSpawner : public idEntity {
  31. public:
  32.     CLASS_PROTOTYPE( rvSpawner );
  33.  
  34.     void                Spawn                    ( void );
  35.     void                Think                    ( void );
  36.  
  37.     void                Attach                    ( idEntity* ent );
  38.     void                Detach                    ( idEntity* ent );
  39.  
  40.     void                Save                    ( idSaveGame *savefile ) const;
  41.     void                Restore                    ( idRestoreGame *savefile );
  42.  
  43.     void                AddSpawnPoint            ( idEntity* point );
  44.     void                RemoveSpawnPoint        ( idEntity* point );
  45.  
  46.     int                    GetNumSpawnPoints        ( void ) const;
  47.     int                    GetNumActive            ( void ) const;
  48.     int                    GetMaxActive            ( void ) const;
  49.     idEntity*            GetSpawnPoint            ( int index );
  50.  
  51.     virtual void        FindTargets                ( void );
  52.     bool                ActiveListChanged        ( void );
  53.  
  54.     void                CallScriptEvents        ( const char* prefixKey, idEntity* parm );
  55.  
  56.     void                AddCallback                ( idEntity* owner, const idEventDef* ev );
  57.  
  58. protected:
  59.  
  60.     int                                numSpawned;
  61.     int                                maxToSpawn;
  62.     float                            nextSpawnTime;
  63.     int                                maxActive;
  64.     idList< idEntityPtr<idEntity> >    currentActive;
  65.     int                                spawnWaves;
  66.     int                                spawnDelay;
  67.     bool                            skipVisible;
  68.     idStrList                        spawnTypes;
  69.  
  70.     idList< idEntityPtr<idEntity> >    spawnPoints;
  71.     
  72.     idList< spawnerCallback_t >        callbacks;
  73.  
  74.     // Check to see if its time to spawn
  75.     void                CheckSpawn                ( void );
  76.     
  77.     // Spawn a new entity
  78.     bool                SpawnEnt                ( void );
  79.  
  80.     // Populate the spawnType list with the available spawn types
  81.     void                FindSpawnTypes            ( void );
  82.  
  83.     // Get a random spawnpoint to spawn at
  84.     idEntity*            GetSpawnPoint            ( void );
  85.     
  86.     // Get a random spawn type
  87.     const char*            GetSpawnType            ( idEntity* spawnPoint );
  88.     
  89.     // Validate the given spawn point for spawning
  90.     bool                ValidateSpawnPoint        ( const idVec3 origin, const idBounds &bounds );
  91.  
  92.     // Copy key/values from the given entity to the given dictionary using the specified prefix
  93.     void                CopyPrefixedSpawnArgs    ( idEntity *src, const char *prefix, idDict &args );
  94.  
  95. private:
  96.  
  97.     void                Event_Activate            ( idEntity *activator );
  98.     void                Event_RemoveNullActiveEntities( void );
  99.     void                Event_NumActiveEntities    ( void );
  100.     void                Event_GetActiveEntity    ( int index );
  101. };
  102.  
  103.  
  104. ID_INLINE int rvSpawner::GetNumSpawnPoints( void ) const {
  105.     return spawnPoints.Num ( );
  106. }
  107.  
  108. ID_INLINE idEntity* rvSpawner::GetSpawnPoint( int index ) {
  109.     return spawnPoints[index];
  110. }
  111.  
  112. ID_INLINE int rvSpawner::GetNumActive( void ) const {
  113.     return currentActive.Num();
  114. }
  115.  
  116. ID_INLINE int rvSpawner::GetMaxActive( void ) const {
  117.     return maxActive;
  118. }
  119.  
  120. #endif // __GAME_SPAWNER_H__
  121.