Debian Codegraph @

code/game/g_misc.c

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // g_misc.c
24
25 #include "g_local.h"
26
27
28 /*QUAKED func_group (0 0 0) ?
29 Used to group brushes together just for editor convenience. They are turned into normal brushes by the utilities.
30 */
31
32
33 /*QUAKED info_camp (0 0.5 0) (-4 -4 -4) (4 4 4)
34 Used as a positional target for calculations in the utilities (spotlights, etc), but removed during gameplay.
35 */
36 void SP_info_camp( gentity_t *self ) {
37 G_SetOrigin( self, self->s.origin );
38 }
39
40
41 /*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
42 Used as a positional target for calculations in the utilities (spotlights, etc), but removed during gameplay.
43 */
44 void SP_info_null( gentity_t *self ) {
45 G_FreeEntity( self );
46 }
47
48
49 /*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
50 Used as a positional target for in-game calculation, like jumppad targets.
51 target_position does the same thing
52 */
53 void SP_info_notnull( gentity_t *self ){
54 G_SetOrigin( self, self->s.origin );
55 }
56
57
58 /*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) linear
59 Non-displayed light.
60 "light" overrides the default 300 intensity.
61 Linear checbox gives linear falloff instead of inverse square
62 Lights pointed at a target will be spotlights.
63 "radius" overrides the default 64 unit radius of a spotlight at the target point.
64 */
65 void SP_light( gentity_t *self ) {
66 G_FreeEntity( self );
67 }
68
69
70
71 /*
72 =================================================================================
73
74 TELEPORTERS
75
76 =================================================================================
77 */
78
79 void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles ) {
80 gentity_t *tent;
81 qboolean noAngles;
82
83 noAngles = (angles[0] > 999999.0);
84 // use temp events at source and destination to prevent the effect
85 // from getting dropped by a second player event
86 if ( player->client->sess.sessionTeam != TEAM_SPECTATOR && player->client->ps.pm_type != PM_SPECTATOR) {
87 tent = G_TempEntity( player->client->ps.origin, EV_PLAYER_TELEPORT_OUT );
88 tent->s.clientNum = player->s.clientNum;
89
90 tent = G_TempEntity( origin, EV_PLAYER_TELEPORT_IN );
91 tent->s.clientNum = player->s.clientNum;
92 }
93
94 // unlink to make sure it can't possibly interfere with G_KillBox
95 trap_UnlinkEntity (player);
96
97 VectorCopy ( origin, player->client->ps.origin );
98 player->client->ps.origin[2] += 1;
99
100 if (!noAngles) {
101 // spit the player out
102 AngleVectors( angles, player->client->ps.velocity, NULL, NULL );
103 VectorScale( player->client->ps.velocity, 400, player->client->ps.velocity );
104 player->client->ps.pm_time = 160; // hold time
105 player->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
106
107 // set angles
108 SetClientViewAngle(player, angles);
109 }
110
111 // toggle the teleport bit so the client knows to not lerp
112 player->client->ps.eFlags ^= EF_TELEPORT_BIT;
113
114 //unlagged - backward reconciliation #3
115 // we don't want players being backward-reconciled back through teleporters
116 G_ResetHistory( player );
117 //unlagged - backward reconciliation #3
118
119 // kill anything at the destination
120 if ( player->client->sess.sessionTeam != TEAM_SPECTATOR && player->client->ps.pm_type != PM_SPECTATOR ) {
121 G_KillBox (player);
122 }
123
124 // save results of pmove
125 BG_PlayerStateToEntityState( &player->client->ps, &player->s, qtrue );
126
127 // use the precise origin for linking
128 VectorCopy( player->client->ps.origin, player->r.currentOrigin );
129
130 if ( player->client->sess.sessionTeam != TEAM_SPECTATOR && player->client->ps.pm_type != PM_SPECTATOR ) {
131 trap_LinkEntity (player);
132 }
133 }
134
135
136 /*QUAKED misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16)
137 Point teleporters at these.
138 Now that we don't have teleport destination pads, this is just
139 an info_notnull
140 */
141 void SP_misc_teleporter_dest( gentity_t *ent ) {
142 }
143
144
145 //===========================================================
146
147 /*QUAKED misc_model (1 0 0) (-16 -16 -16) (16 16 16)
148 "model" arbitrary .md3 file to display
149 */
150 void SP_misc_model( gentity_t *ent ) {
151
152 #if 0
153 ent->s.modelindex = G_ModelIndex( ent->model );
154 VectorSet (ent->mins, -16, -16, -16);
155 VectorSet (ent->maxs, 16, 16, 16);
156 trap_LinkEntity (ent);
157
158 G_SetOrigin( ent, ent->s.origin );
159 VectorCopy( ent->s.angles, ent->s.apos.trBase );
160 #else
161 G_FreeEntity( ent );
162 #endif
163 }
164
165 //===========================================================
166
167 void locateCamera( gentity_t *ent ) {
168 vec3_t dir;
169 gentity_t *target;
170 gentity_t *owner;
171
172 owner = G_PickTarget( ent->target );
173 if ( !owner ) {
174 G_Printf( "Couldn't find target for misc_partal_surface\n" );
175 G_FreeEntity( ent );
176 return;
177 }
178 ent->r.ownerNum = owner->s.number;
179
180 // frame holds the rotate speed
181 if ( owner->spawnflags & 1 ) {
182 ent->s.frame = 25;
183 } else if ( owner->spawnflags & 2 ) {
184 ent->s.frame = 75;
185 }
186
187 // swing camera ?
188 if ( owner->spawnflags & 4 ) {
189 // set to 0 for no rotation at all
190 ent->s.powerups = 0;
191 }
192 else {
193 ent->s.powerups = 1;
194 }
195
196 // clientNum holds the rotate offset
197 ent->s.clientNum = owner->s.clientNum;
198
199 VectorCopy( owner->s.origin, ent->s.origin2 );
200
201 // see if the portal_camera has a target
202 target = G_PickTarget( owner->target );
203 if ( target ) {
204 VectorSubtract( target->s.origin, owner->s.origin, dir );
205 VectorNormalize( dir );
206 } else {
207 G_SetMovedir( owner->s.angles, dir );
208 }
209
210 ent->s.eventParm = DirToByte( dir );
211 }
212
213 /*QUAKED misc_portal_surface (0 0 1) (-8 -8 -8) (8 8 8)
214 The portal surface nearest this entity will show a view from the targeted misc_portal_camera, or a mirror view if untargeted.
215 This must be within 64 world units of the surface!
216 */
217 void SP_misc_portal_surface(gentity_t *ent) {
218 VectorClear( ent->r.mins );
219 VectorClear( ent->r.maxs );
220 trap_LinkEntity (ent);
221
222 ent->r.svFlags = SVF_PORTAL;
223 ent->s.eType = ET_PORTAL;
224
225 if ( !ent->target ) {
226 VectorCopy( ent->s.origin, ent->s.origin2 );
227 } else {
228 ent->think = locateCamera;
229 ent->nextthink = level.time + 100;
230 }
231 }
232
233 /*QUAKED misc_portal_camera (0 0 1) (-8 -8 -8) (8 8 8) slowrotate fastrotate noswing
234 The target for a misc_portal_director. You can set either angles or target another entity to determine the direction of view.
235 "roll" an angle modifier to orient the camera around the target vector;
236 */
237 void SP_misc_portal_camera(gentity_t *ent) {
238 float roll;
239
240 VectorClear( ent->r.mins );
241 VectorClear( ent->r.maxs );
242 trap_LinkEntity (ent);
243
244 G_SpawnFloat( "roll", "0", &roll );
245
246 ent->s.clientNum = roll/360.0 * 256;
247 }
248
249 /*
250 ======================================================================
251
252 SHOOTERS
253
254 ======================================================================
255 */
256
257 void Use_Shooter( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
258 vec3_t dir;
259 float deg;
260 vec3_t up, right;
261
262 // see if we have a target
263 if ( ent->enemy ) {
264 VectorSubtract( ent->enemy->r.currentOrigin, ent->s.origin, dir );
265 VectorNormalize( dir );
266 } else {
267 VectorCopy( ent->movedir, dir );
268 }
269
270 // randomize a bit
271 PerpendicularVector( up, dir );
272 CrossProduct( up, dir, right );
273
274 deg = crandom() * ent->random;
275 VectorMA( dir, deg, up, dir );
276
277 deg = crandom() * ent->random;
278 VectorMA( dir, deg, right, dir );
279
280 VectorNormalize( dir );
281
282 switch ( ent->s.weapon ) {
283 case WP_GRENADE_LAUNCHER:
284 fire_grenade( ent, ent->s.origin, dir );
285 break;
286 case WP_ROCKET_LAUNCHER:
287 fire_rocket( ent, ent->s.origin, dir );
288 break;
289 case WP_PLASMAGUN:
290 fire_plasma( ent, ent->s.origin, dir );
291 break;
292 }
293
294 G_AddEvent( ent, EV_FIRE_WEAPON, 0 );
295 }
296
297
298 static void InitShooter_Finish( gentity_t *ent ) {
299 ent->enemy = G_PickTarget( ent->target );
300 ent->think = 0;
301 ent->nextthink = 0;
302 }
303
304 void InitShooter( gentity_t *ent, int weapon ) {
305 ent->use = Use_Shooter;
306 ent->s.weapon = weapon;
307
308 RegisterItem( BG_FindItemForWeapon( weapon ) );
309
310 G_SetMovedir( ent->s.angles, ent->movedir );
311
312 if ( !ent->random ) {
313 ent->random = 1.0;
314 }
315 ent->random = sin( M_PI * ent->random / 180 );
316 // target might be a moving object, so we can't set movedir for it
317 if ( ent->target ) {
318 ent->think = InitShooter_Finish;
319 ent->nextthink = level.time + 500;
320 }
321 trap_LinkEntity( ent );
322 }
323
324 /*QUAKED shooter_rocket (1 0 0) (-16 -16 -16) (16 16 16)
325 Fires at either the target or the current direction.
326 "random" the number of degrees of deviance from the taget. (1.0 default)
327 */
328 void SP_shooter_rocket( gentity_t *ent ) {
329 InitShooter( ent, WP_ROCKET_LAUNCHER );
330 }
331
332 /*QUAKED shooter_plasma (1 0 0) (-16 -16 -16) (16 16 16)
333 Fires at either the target or the current direction.
334 "random" is the number of degrees of deviance from the taget. (1.0 default)
335 */
336 void SP_shooter_plasma( gentity_t *ent ) {
337 InitShooter( ent, WP_PLASMAGUN);
338 }
339
340 /*QUAKED shooter_grenade (1 0 0) (-16 -16 -16) (16 16 16)
341 Fires at either the target or the current direction.
342 "random" is the number of degrees of deviance from the taget. (1.0 default)
343 */
344 void SP_shooter_grenade( gentity_t *ent ) {
345 InitShooter( ent, WP_GRENADE_LAUNCHER);
346 }
347
348 static void PortalDie (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod) {
349 G_FreeEntity( self );
350 //FIXME do something more interesting
351 }
352
353
354 void DropPortalDestination( gentity_t *player ) {
355 gentity_t *ent;
356 vec3_t snapped;
357
358 // create the portal destination
359 ent = G_Spawn();
360 ent->s.modelindex = G_ModelIndex( "models/powerups/teleporter/tele_exit.md3" );
361
362 VectorCopy( player->s.pos.trBase, snapped );
363 SnapVector( snapped );
364 G_SetOrigin( ent, snapped );
365 VectorCopy( player->r.mins, ent->r.mins );
366 VectorCopy( player->r.maxs, ent->r.maxs );
367
368 ent->classname = "hi_portal destination";
369 ent->s.pos.trType = TR_STATIONARY;
370
371 ent->r.contents = CONTENTS_CORPSE;
372 ent->takedamage = qtrue;
373 ent->health = 200;
374 ent->die = PortalDie;
375
376 VectorCopy( player->s.apos.trBase, ent->s.angles );
377
378 ent->think = G_FreeEntity;
379 ent->nextthink = level.time + 2 * 60 * 1000;
380
381 trap_LinkEntity( ent );
382
383 player->client->portalID = ++level.portalSequence;
384 ent->count = player->client->portalID;
385
386 // give the item back so they can drop the source now
387 player->client->ps.stats[STAT_HOLDABLE_ITEM] = BG_FindItem( "Portal" ) - bg_itemlist;
388 }
389
390
391 static void PortalTouch( gentity_t *self, gentity_t *other, trace_t *trace) {
392 gentity_t *destination;
393
394 // see if we will even let other try to use it
395 if( other->health <= 0 ) {
396 return;
397 }
398 if( !other->client ) {
399 return;
400 }
401 // if( other->client->ps.persistant[PERS_TEAM] != self->spawnflags ) {
402 // return;
403 // }
404
405 if ( other->client->ps.powerups[PW_NEUTRALFLAG] ) { // only happens in One Flag CTF
406 Drop_Item( other, BG_FindItemForPowerup( PW_NEUTRALFLAG ), 0 );
407 other->client->ps.powerups[PW_NEUTRALFLAG] = 0;
408 }
409 else if ( other->client->ps.powerups[PW_REDFLAG] ) { // only happens in standard CTF
410 Drop_Item( other, BG_FindItemForPowerup( PW_REDFLAG ), 0 );
411 other->client->ps.powerups[PW_REDFLAG] = 0;
412 }
413 else if ( other->client->ps.powerups[PW_BLUEFLAG] ) { // only happens in standard CTF
414 Drop_Item( other, BG_FindItemForPowerup( PW_BLUEFLAG ), 0 );
415 other->client->ps.powerups[PW_BLUEFLAG] = 0;
416 }
417
418 // find the destination
419 destination = NULL;
420 while( (destination = G_Find(destination, FOFS(classname), "hi_portal destination")) != NULL ) {
421 if( destination->count == self->count ) {
422 break;
423 }
424 }
425
426 // if there is not one, die!
427 if( !destination ) {
428 if( self->pos1[0] || self->pos1[1] || self->pos1[2] ) {
429 TeleportPlayer( other, self->pos1, self->s.angles );
430 }
431 G_Damage( other, other, other, NULL, NULL, 100000, DAMAGE_NO_PROTECTION, MOD_TELEFRAG );
432 return;
433 }
434
435 TeleportPlayer( other, destination->s.pos.trBase, destination->s.angles );
436 }
437
438
439 static void PortalEnable( gentity_t *self ) {
440 self->touch = PortalTouch;
441 self->think = G_FreeEntity;
442 self->nextthink = level.time + 2 * 60 * 1000;
443 }
444
445
446 void DropPortalSource( gentity_t *player ) {
447 gentity_t *ent;
448 gentity_t *destination;
449 vec3_t snapped;
450
451 // create the portal source
452 ent = G_Spawn();
453 ent->s.modelindex = G_ModelIndex( "models/powerups/teleporter/tele_enter.md3" );
454
455 VectorCopy( player->s.pos.trBase, snapped );
456 SnapVector( snapped );
457 G_SetOrigin( ent, snapped );
458 VectorCopy( player->r.mins, ent->r.mins );
459 VectorCopy( player->r.maxs, ent->r.maxs );
460
461 ent->classname = "hi_portal source";
462 ent->s.pos.trType = TR_STATIONARY;
463
464 ent->r.contents = CONTENTS_CORPSE | CONTENTS_TRIGGER;
465 ent->takedamage = qtrue;
466 ent->health = 200;
467 ent->die = PortalDie;
468
469 trap_LinkEntity( ent );
470
471 ent->count = player->client->portalID;
472 player->client->portalID = 0;
473
474 // ent->spawnflags = player->client->ps.persistant[PERS_TEAM];
475
476 ent->nextthink = level.time + 1000;
477 ent->think = PortalEnable;
478
479 // find the destination
480 destination = NULL;
481 while( (destination = G_Find(destination, FOFS(classname), "hi_portal destination")) != NULL ) {
482 if( destination->count == ent->count ) {
483 VectorCopy( destination->s.pos.trBase, ent->pos1 );
484 break;
485 }
486 }
487
488 }