Trigger.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_TRIGGER_H__
  21. #define __GAME_TRIGGER_H__
  22. extern const idEventDef EV_Enable;
  23. extern const idEventDef EV_Disable;
  24. /*
  25. ===============================================================================
  26. Trigger base.
  27. ===============================================================================
  28. */
  29. class idTrigger : public idEntity {
  30. public:
  31. CLASS_PROTOTYPE( idTrigger );
  32. static void DrawDebugInfo( void );
  33. idTrigger();
  34. void Spawn( void );
  35. const function_t * GetScriptFunction( void ) const;
  36. void Save( idSaveGame *savefile ) const;
  37. void Restore( idRestoreGame *savefile );
  38. virtual void Enable( void );
  39. virtual void Disable( void );
  40. protected:
  41. void CallScript( void ) const;
  42. void Event_Enable( void );
  43. void Event_Disable( void );
  44. const function_t * scriptFunction;
  45. };
  46. /*
  47. ===============================================================================
  48. Trigger which can be activated multiple times.
  49. ===============================================================================
  50. */
  51. class idTrigger_Multi : public idTrigger {
  52. public:
  53. CLASS_PROTOTYPE( idTrigger_Multi );
  54. idTrigger_Multi( void );
  55. void Spawn( void );
  56. void Save( idSaveGame *savefile ) const;
  57. void Restore( idRestoreGame *savefile );
  58. #ifdef CTF
  59. protected:
  60. #else
  61. private:
  62. #endif
  63. float wait;
  64. float random;
  65. float delay;
  66. float random_delay;
  67. int nextTriggerTime;
  68. idStr requires;
  69. int removeItem;
  70. bool touchClient;
  71. bool touchOther;
  72. bool triggerFirst;
  73. bool triggerWithSelf;
  74. bool CheckFacing( idEntity *activator );
  75. void TriggerAction( idEntity *activator );
  76. void Event_TriggerAction( idEntity *activator );
  77. void Event_Trigger( idEntity *activator );
  78. void Event_Touch( idEntity *other, trace_t *trace );
  79. };
  80. /*
  81. ===============================================================================
  82. Trigger which can only be activated by an entity with a specific name.
  83. ===============================================================================
  84. */
  85. class idTrigger_EntityName : public idTrigger {
  86. public:
  87. CLASS_PROTOTYPE( idTrigger_EntityName );
  88. idTrigger_EntityName( void );
  89. void Save( idSaveGame *savefile ) const;
  90. void Restore( idRestoreGame *savefile );
  91. void Spawn( void );
  92. private:
  93. float wait;
  94. float random;
  95. float delay;
  96. float random_delay;
  97. int nextTriggerTime;
  98. bool triggerFirst;
  99. idStr entityName;
  100. void TriggerAction( idEntity *activator );
  101. void Event_TriggerAction( idEntity *activator );
  102. void Event_Trigger( idEntity *activator );
  103. void Event_Touch( idEntity *other, trace_t *trace );
  104. };
  105. /*
  106. ===============================================================================
  107. Trigger which repeatedly fires targets.
  108. ===============================================================================
  109. */
  110. class idTrigger_Timer : public idTrigger {
  111. public:
  112. CLASS_PROTOTYPE( idTrigger_Timer );
  113. idTrigger_Timer( void );
  114. void Save( idSaveGame *savefile ) const;
  115. void Restore( idRestoreGame *savefile );
  116. void Spawn( void );
  117. virtual void Enable( void );
  118. virtual void Disable( void );
  119. private:
  120. float random;
  121. float wait;
  122. bool on;
  123. float delay;
  124. idStr onName;
  125. idStr offName;
  126. void Event_Timer( void );
  127. void Event_Use( idEntity *activator );
  128. };
  129. /*
  130. ===============================================================================
  131. Trigger which fires targets after being activated a specific number of times.
  132. ===============================================================================
  133. */
  134. class idTrigger_Count : public idTrigger {
  135. public:
  136. CLASS_PROTOTYPE( idTrigger_Count );
  137. idTrigger_Count( void );
  138. void Save( idSaveGame *savefile ) const;
  139. void Restore( idRestoreGame *savefile );
  140. void Spawn( void );
  141. private:
  142. int goal;
  143. int count;
  144. float delay;
  145. void Event_Trigger( idEntity *activator );
  146. void Event_TriggerAction( idEntity *activator );
  147. };
  148. /*
  149. ===============================================================================
  150. Trigger which hurts touching entities.
  151. ===============================================================================
  152. */
  153. class idTrigger_Hurt : public idTrigger {
  154. public:
  155. CLASS_PROTOTYPE( idTrigger_Hurt );
  156. idTrigger_Hurt( void );
  157. void Save( idSaveGame *savefile ) const;
  158. void Restore( idRestoreGame *savefile );
  159. void Spawn( void );
  160. private:
  161. bool on;
  162. float delay;
  163. int nextTime;
  164. void Event_Touch( idEntity *other, trace_t *trace );
  165. void Event_Toggle( idEntity *activator );
  166. };
  167. /*
  168. ===============================================================================
  169. Trigger which fades the player view.
  170. ===============================================================================
  171. */
  172. class idTrigger_Fade : public idTrigger {
  173. public:
  174. CLASS_PROTOTYPE( idTrigger_Fade );
  175. private:
  176. void Event_Trigger( idEntity *activator );
  177. };
  178. /*
  179. ===============================================================================
  180. Trigger which continuously tests whether other entities are touching it.
  181. ===============================================================================
  182. */
  183. class idTrigger_Touch : public idTrigger {
  184. public:
  185. CLASS_PROTOTYPE( idTrigger_Touch );
  186. idTrigger_Touch( void );
  187. void Spawn( void );
  188. virtual void Think( void );
  189. void Save( idSaveGame *savefile );
  190. void Restore( idRestoreGame *savefile );
  191. virtual void Enable( void );
  192. virtual void Disable( void );
  193. void TouchEntities( void );
  194. private:
  195. idClipModel * clipModel;
  196. void Event_Trigger( idEntity *activator );
  197. };
  198. #ifdef CTF
  199. /*
  200. ===============================================================================
  201. Trigger that responces to CTF flags
  202. ===============================================================================
  203. */
  204. class idTrigger_Flag : public idTrigger_Multi {
  205. public:
  206. CLASS_PROTOTYPE( idTrigger_Flag );
  207. idTrigger_Flag( void );
  208. void Spawn( void );
  209. private:
  210. int team;
  211. bool player; // flag must be attached/carried by player
  212. const idEventDef * eventFlag;
  213. void Event_Touch( idEntity *other, trace_t *trace );
  214. };
  215. #endif /* CTF */
  216. #endif /* !__GAME_TRIGGER_H__ */