DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Trigger.h (7664B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #ifndef __GAME_TRIGGER_H__
     30 #define __GAME_TRIGGER_H__
     31 
     32 extern const idEventDef EV_Enable;
     33 extern const idEventDef EV_Disable;
     34 
     35 /*
     36 ===============================================================================
     37 
     38   Trigger base.
     39 
     40 ===============================================================================
     41 */
     42 
     43 class idTrigger : public idEntity {
     44 public:
     45 	CLASS_PROTOTYPE( idTrigger );
     46 
     47 	static void			DrawDebugInfo();
     48 
     49 						idTrigger();
     50 	void				Spawn();
     51 
     52 	const function_t *	GetScriptFunction() const;
     53 
     54 	void				Save( idSaveGame *savefile ) const;
     55 	void				Restore( idRestoreGame *savefile );
     56 
     57 	virtual void		Enable();
     58 	virtual void		Disable();
     59 
     60 protected:
     61 	void				CallScript() const;
     62 
     63 	void				Event_Enable();
     64 	void				Event_Disable();
     65 
     66 	const function_t *	scriptFunction;
     67 };
     68 
     69 
     70 /*
     71 ===============================================================================
     72 
     73   Trigger which can be activated multiple times.
     74 
     75 ===============================================================================
     76 */
     77 
     78 class idTrigger_Multi : public idTrigger {
     79 public:
     80 	CLASS_PROTOTYPE( idTrigger_Multi );
     81 
     82 						idTrigger_Multi();
     83 
     84 	void				Spawn();
     85 
     86 	void				Save( idSaveGame *savefile ) const;
     87 	void				Restore( idRestoreGame *savefile );
     88 
     89 protected:
     90 
     91 	float				wait;
     92 	float				random;
     93 	float				delay;
     94 	float				random_delay;
     95 	int					nextTriggerTime;
     96 	idStr				requires;
     97 	int					removeItem;
     98 	bool				touchClient;
     99 	bool				touchOther;
    100 	bool				triggerFirst;
    101 	bool				triggerWithSelf;
    102 
    103 	bool				CheckFacing( idEntity *activator );
    104 	void				TriggerAction( idEntity *activator );
    105 	void				Event_TriggerAction( idEntity *activator );
    106 	void				Event_Trigger( idEntity *activator );
    107 	void				Event_Touch( idEntity *other, trace_t *trace );
    108 };
    109 
    110 
    111 /*
    112 ===============================================================================
    113 
    114   Trigger which can only be activated by an entity with a specific name.
    115 
    116 ===============================================================================
    117 */
    118 
    119 class idTrigger_EntityName : public idTrigger {
    120 public:
    121 	CLASS_PROTOTYPE( idTrigger_EntityName );
    122 
    123 						idTrigger_EntityName();
    124 
    125 	void				Save( idSaveGame *savefile ) const;
    126 	void				Restore( idRestoreGame *savefile );
    127 
    128 	void				Spawn();
    129 
    130 private:
    131 	float				wait;
    132 	float				random;
    133 	float				delay;
    134 	float				random_delay;
    135 	int					nextTriggerTime;
    136 	bool				triggerFirst;
    137 	idStr				entityName;
    138 	bool				testPartialName;
    139 
    140 	void				TriggerAction( idEntity *activator );
    141 	void				Event_TriggerAction( idEntity *activator );
    142 	void				Event_Trigger( idEntity *activator );
    143 	void				Event_Touch( idEntity *other, trace_t *trace );
    144 };
    145 
    146 /*
    147 ===============================================================================
    148 
    149   Trigger which repeatedly fires targets.
    150 
    151 ===============================================================================
    152 */
    153 
    154 class idTrigger_Timer : public idTrigger {
    155 public:
    156 	CLASS_PROTOTYPE( idTrigger_Timer );
    157 
    158 						idTrigger_Timer();
    159 
    160 	void				Save( idSaveGame *savefile ) const;
    161 	void				Restore( idRestoreGame *savefile );
    162 
    163 	void				Spawn();
    164 
    165 	virtual void		Enable();
    166 	virtual void		Disable();
    167 
    168 private:
    169 	float				random;
    170 	float				wait;
    171 	bool				on;
    172 	float				delay;
    173 	idStr				onName;
    174 	idStr				offName;
    175 
    176 	void				Event_Timer();
    177 	void				Event_Use( idEntity *activator );
    178 };
    179 
    180 
    181 /*
    182 ===============================================================================
    183 
    184   Trigger which fires targets after being activated a specific number of times.
    185 
    186 ===============================================================================
    187 */
    188 
    189 class idTrigger_Count : public idTrigger {
    190 public:
    191 	CLASS_PROTOTYPE( idTrigger_Count );
    192 
    193 						idTrigger_Count();
    194 
    195 	void				Save( idSaveGame *savefile ) const;
    196 	void				Restore( idRestoreGame *savefile );
    197 
    198 	void				Spawn();
    199 
    200 private:
    201 	int					goal;
    202 	int					count;
    203 	float				delay;
    204 
    205 	void				Event_Trigger( idEntity *activator );
    206 	void				Event_TriggerAction( idEntity *activator );
    207 };
    208 
    209 
    210 /*
    211 ===============================================================================
    212 
    213   Trigger which hurts touching entities.
    214 
    215 ===============================================================================
    216 */
    217 
    218 class idTrigger_Hurt : public idTrigger {
    219 public:
    220 	CLASS_PROTOTYPE( idTrigger_Hurt );
    221 
    222 						idTrigger_Hurt();
    223 
    224 	void				Save( idSaveGame *savefile ) const;
    225 	void				Restore( idRestoreGame *savefile );
    226 
    227 	void				Spawn();
    228 
    229 private:
    230 	bool				on;
    231 	float				delay;
    232 	int					nextTime;
    233 
    234 	void				Event_Touch( idEntity *other, trace_t *trace );
    235 	void				Event_Toggle( idEntity *activator );
    236 };
    237 
    238 
    239 /*
    240 ===============================================================================
    241 
    242   Trigger which fades the player view.
    243 
    244 ===============================================================================
    245 */
    246 
    247 class idTrigger_Fade : public idTrigger {
    248 public:
    249 
    250 	CLASS_PROTOTYPE( idTrigger_Fade );
    251 
    252 private:
    253 	void				Event_Trigger( idEntity *activator );
    254 };
    255 
    256 
    257 /*
    258 ===============================================================================
    259 
    260   Trigger which continuously tests whether other entities are touching it.
    261 
    262 ===============================================================================
    263 */
    264 
    265 class idTrigger_Touch : public idTrigger {
    266 public:
    267 
    268 	CLASS_PROTOTYPE( idTrigger_Touch );
    269 
    270 						idTrigger_Touch();
    271 
    272 	void				Spawn();
    273 	virtual void		Think();
    274 
    275 	void				Save( idSaveGame *savefile );
    276 	void				Restore( idRestoreGame *savefile );
    277 
    278 	virtual void		Enable();
    279 	virtual void		Disable();
    280 
    281 	void				TouchEntities();
    282 
    283 private:
    284 	idClipModel *		clipModel;
    285 
    286 	void				Event_Trigger( idEntity *activator );
    287 };
    288 
    289 /*
    290 ===============================================================================
    291 
    292   Trigger that responces to CTF flags
    293 
    294 ===============================================================================
    295 */
    296 class idTrigger_Flag : public idTrigger_Multi {
    297 public:
    298 	CLASS_PROTOTYPE( idTrigger_Flag );
    299 
    300 						idTrigger_Flag();
    301 	void				Spawn();
    302 
    303 private:
    304 	int					team;
    305 	bool				player;			// flag must be attached/carried by player
    306 
    307 	const idEventDef *	eventFlag;
    308 
    309 	void				Event_Touch( idEntity *other, trace_t *trace );
    310 };
    311 
    312 #endif /* !__GAME_TRIGGER_H__ */