File: g_alarm.c

package info (click to toggle)
iortcw 1.51.c%2Bdfsg1-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 25,304 kB
  • sloc: ansic: 457,326; cpp: 6,507; makefile: 4,737; sh: 1,292; asm: 1,176; xml: 31
file content (259 lines) | stat: -rw-r--r-- 6,695 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
===========================================================================

Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. 

This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (“RTCW MP Source Code”).  

RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with RTCW MP Source Code.  If not, see <http://www.gnu.org/licenses/>.

In addition, the RTCW MP 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 RTCW MP Source Code.  If not, please request a copy in writing from id Software at the address below.

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.

===========================================================================
*/

#include "g_local.h"


/*
==============
alarmExplosion
	copied from propExplosion
==============
*/
void alarmExplosion( gentity_t *ent ) {
	gentity_t *bolt;

	extern void G_ExplodeMissile( gentity_t * ent );
	bolt = G_Spawn();
	bolt->classname = "props_explosion";
	bolt->nextthink = level.time + FRAMETIME;
	bolt->think = G_ExplodeMissile;
	bolt->s.eType = ET_MISSILE;
	bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;

	bolt->s.weapon = WP_NONE;

	bolt->s.eFlags = EF_BOUNCE_HALF;
	bolt->r.ownerNum = ent->s.number;
	bolt->parent = ent;
	bolt->damage = ent->health;
	bolt->splashDamage = ent->health;
	bolt->splashRadius = ent->health * 1.5;
	bolt->methodOfDeath = MOD_GRENADE;
	bolt->splashMethodOfDeath = MOD_GRENADE_SPLASH;
	bolt->clipmask = MASK_SHOT;

	VectorCopy( ent->r.currentOrigin, bolt->s.pos.trBase );
	VectorCopy( ent->r.currentOrigin, bolt->r.currentOrigin );
}


/*
==============
alarmbox_updateparts
==============
*/
void alarmbox_updateparts( gentity_t *ent, qboolean matestoo ) {
	gentity_t   *t, *mate;
	qboolean alarming;

	if ( !ent ) {
		return;
	}

	alarming = ( ent->s.frame == 1 );

	// update teammates
	if ( matestoo ) {
		for ( mate = ent->teammaster; mate; mate = mate->teamchain )
		{
			if ( mate == ent ) {
				continue;
			}

			if ( !( mate->active ) ) { // don't update dead alarm boxes, they stay dead
				continue;
			}

			if ( !( ent->active ) ) { // destroyed, so just turn teammates off
				mate->s.frame = 0;
			} else {
				mate->s.frame = ent->s.frame;
			}

			alarmbox_updateparts( mate, qfalse );
		}
	}

	// update lights
	if ( !ent->target ) {
		return;
	}

	t = NULL;
	while ( ( t = G_Find( t, FOFS( targetname ), ent->target ) ) != NULL )
	{
		if ( t == ent ) {
			G_Printf( "WARNING: Entity used itself.\n" );
		} else
		{
			// give the dlight the sound
			if ( !Q_stricmp( t->classname, "dlight" ) ) {
				t->soundLoop = ent->soundLoop;

				if ( alarming ) {
					if ( !( t->r.linked ) ) {
						t->use( t, ent, 0 );
					}
				} else
				{
					if ( t->r.linked ) {
						t->use( t, ent, 0 );
					}
				}
			}
			// alarmbox can tell script_trigger about activation
			// (but don't trigger if dying, only activation)
			else if ( !Q_stricmp( t->classname, "target_script_trigger" ) ) {
				if ( ent->active ) { // not dead
					t->use( t, ent, 0 );
				}
			}
		}
	}
}

/*
==============
alarmbox_use
==============
*/
void alarmbox_use( gentity_t *ent, gentity_t *other, gentity_t *foo ) {
	if ( !( ent->active ) ) {
		return;
	}

	if ( ent->s.frame ) {
		ent->s.frame = 0;
	} else {
		ent->s.frame = 1;
	}

	alarmbox_updateparts( ent, qtrue );
	if ( other->client ) {
		G_AddEvent( ent, EV_GENERAL_SOUND, ent->soundPos3 );
	}
//	G_Printf("touched alarmbox\n");

}


/*
==============
alarmbox_die
==============
*/
void alarmbox_die( gentity_t *ent, gentity_t *inflictor, gentity_t *attacker, int damage, int mod ) {
	alarmExplosion( ent );
	ent->s.frame    = 2;
	ent->active     = qfalse;
	ent->takedamage = qfalse;
	alarmbox_updateparts( ent, qtrue );
}




/*
==============
alarmbox_finishspawning
==============
*/
void alarmbox_finishspawning( gentity_t *ent ) {
	gentity_t *mate;

	// make sure they all have the same master (picked arbitrarily.  last spawned)
	for ( mate = ent; mate; mate = mate->teamchain )
		mate->teammaster = ent->teammaster;

	// find lights and set their state
	alarmbox_updateparts( ent, qtrue );
}


/*QUAKED alarm_box (1 0 1) START_ON
You need to have an origin brush as part of this entity
current alarm box model is (8 x 16 x 28)
"health" defaults to 10

"noise" the sound to play over the system (this would be the siren sound)

START_ON means the button is pushed in, any dlights are cycling, and alarms are sounding

"team" key/value is valid for teamed alarm boxes
teamed alarm_boxes work in tandem (switches/lights syncronize)
target a box to dlights to have them activate/deactivate with the system (use a stylestring that matches the cycletime for the alarmbox sound)
alarm sound locations are also placed in the dlights, so wherever you place an attached dlight, you will hear the alarm
model: the model used is "models/mapobjects/electronics/alarmbox.md3"
place the origin at the center of your trigger box
*/
void SP_alarm_box( gentity_t *ent ) {
	char *s;

	if ( !ent->model ) {
		G_Printf( S_COLOR_RED "alarm_box with NULL model\n" );
		return;
	}

	// model
	trap_SetBrushModel( ent, ent->model );
	ent->s.modelindex2 = G_ModelIndex( "models/mapobjects/electronics/alarmbox.md3" );

	// sound
	if ( G_SpawnString( "noise", "0", &s ) ) {
		ent->soundLoop = G_SoundIndex( s );
	}

	ent->soundPos3 = G_SoundIndex( "sound/world/alarmswitch.wav" );


	G_SetOrigin( ent, ent->s.origin );
	G_SetAngle( ent, ent->s.angles );

	if ( !ent->health ) {
		ent->health = 10;
	}

	if ( ent->spawnflags & 1 ) {
		ent->s.frame = 1;
	} else {
		ent->s.frame = 0;
	}

	ent->active     = qtrue;
	ent->s.eType    = ET_ALARMBOX;
	ent->takedamage = qtrue;
	ent->die        = alarmbox_die;
	ent->use        = alarmbox_use;
	ent->think      = alarmbox_finishspawning;
	ent->nextthink  = level.time + FRAMETIME;

	trap_LinkEntity( ent );
}