Debian Codegraph @

code/game/g_items.c

raw ◀ ▶
1 Debian patch touch this file
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 #include "g_local.h"
24
25 /*
26
27 Items are any object that a player can touch to gain some effect.
28
29 Pickup will return the number of seconds until they should respawn.
30
31 all items should pop when dropped in lava or slime
32
33 Respawnable items don't actually go away when picked up, they are
34 just made invisible and untouchable. This allows them to ride
35 movers and respawn apropriately.
36 */
37
38
39 #define RESPAWN_ARMOR 25
40 #define RESPAWN_HEALTH 35
41 #define RESPAWN_AMMO 40
42 #define RESPAWN_HOLDABLE 60
43 #define RESPAWN_MEGAHEALTH 35//120
44 #define RESPAWN_POWERUP 120
45
46
47 //======================================================================
48
49 int Pickup_Powerup( gentity_t *ent, gentity_t *other ) {
50 int quantity;
51 int i;
52 gclient_t *client;
53
54 if ( !other->client->ps.powerups[ent->item->giTag] ) {
55 // round timing to seconds to make multiple powerup timers
56 // count in sync
57 other->client->ps.powerups[ent->item->giTag] =
58 level.time - ( level.time % 1000 );
59 }
60
61 if ( ent->count ) {
62 quantity = ent->count;
63 } else {
64 quantity = ent->item->quantity;
65 }
66
67 other->client->ps.powerups[ent->item->giTag] += quantity * 1000;
68
69 // give any nearby players a "denied" anti-reward
70 for ( i = 0 ; i < level.maxclients ; i++ ) {
71 vec3_t delta;
72 float len;
73 vec3_t forward;
74 trace_t tr;
75
76 client = &level.clients[i];
77 if ( client == other->client ) {
78 continue;
79 }
80 if ( client->pers.connected == CON_DISCONNECTED ) {
81 continue;
82 }
83 if ( client->ps.stats[STAT_HEALTH] <= 0 ) {
84 continue;
85 }
86
87 // if same team in team game, no sound
88 // cannot use OnSameTeam as it expects to g_entities, not clients
89 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt==0 && other->client->sess.sessionTeam == client->sess.sessionTeam ) {
90 continue;
91 }
92
93 // if too far away, no sound
94 VectorSubtract( ent->s.pos.trBase, client->ps.origin, delta );
95 len = VectorNormalize( delta );
96 if ( len > 192 ) {
97 continue;
98 }
99
100 // if not facing, no sound
101 AngleVectors( client->ps.viewangles, forward, NULL, NULL );
102 if ( DotProduct( delta, forward ) < 0.4 ) {
103 continue;
104 }
105
106 // if not line of sight, no sound
107 trap_Trace( &tr, client->ps.origin, NULL, NULL, ent->s.pos.trBase, ENTITYNUM_NONE, CONTENTS_SOLID );
108 if ( tr.fraction != 1.0 ) {
109 continue;
110 }
111
112 // anti-reward
113 client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_DENIEDREWARD;
114 }
115 return RESPAWN_POWERUP;
116 }
117
118 //======================================================================
119
120 int Pickup_PersistantPowerup( gentity_t *ent, gentity_t *other ) {
•121 #ifdef HAVE_STAT_PERSISTANT_POWERUP
122 int clientNum;
123 char userinfo[MAX_INFO_STRING];
124 float handicap;
125 int max;
126
127 other->client->ps.stats[STAT_PERSISTANT_POWERUP] = ent->item - bg_itemlist;
128 other->client->persistantPowerup = ent;
129
130 switch( ent->item->giTag ) {
131 case PW_GUARD:
132 clientNum = other->client->ps.clientNum;
133 trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
134 handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
135 if( handicap<=0.0f || handicap>100.0f) {
136 handicap = 100.0f;
137 }
138 max = (int)(2 * handicap);
139
140 other->health = max;
141 other->client->ps.stats[STAT_HEALTH] = max;
142 other->client->ps.stats[STAT_MAX_HEALTH] = max;
143 other->client->ps.stats[STAT_ARMOR] = max;
144 other->client->pers.maxHealth = max;
145
146 break;
147
148 case PW_SCOUT:
149 clientNum = other->client->ps.clientNum;
150 trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
151 handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
152 if( handicap<=0.0f || handicap>100.0f) {
153 handicap = 100.0f;
154 }
155 other->client->pers.maxHealth = handicap;
156 other->client->ps.stats[STAT_ARMOR] = 0;
157 break;
158
159 case PW_DOUBLER:
160 clientNum = other->client->ps.clientNum;
161 trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
162 handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
163 if( handicap<=0.0f || handicap>100.0f) {
164 handicap = 100.0f;
165 }
166 other->client->pers.maxHealth = handicap;
167 break;
168 case PW_AMMOREGEN:
169 clientNum = other->client->ps.clientNum;
170 trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
171 handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
172 if( handicap<=0.0f || handicap>100.0f) {
173 handicap = 100.0f;
174 }
175 other->client->pers.maxHealth = handicap;
176 memset(other->client->ammoTimes, 0, sizeof(other->client->ammoTimes));
177 break;
178 default:
179 clientNum = other->client->ps.clientNum;
180 trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
181 handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
182 if( handicap<=0.0f || handicap>100.0f) {
183 handicap = 100.0f;
184 }
185 other->client->pers.maxHealth = handicap;
186 break;
187 }
188
•189 #endif
190 return -1;
191 }
192
193 //======================================================================
194
195 int Pickup_Holdable( gentity_t *ent, gentity_t *other ) {
196
197 other->client->ps.stats[STAT_HOLDABLE_ITEM] = ent->item - bg_itemlist;
198
199 if( ent->item->giTag == HI_KAMIKAZE ) {
200 other->client->ps.eFlags |= EF_KAMIKAZE;
201 }
202
203 return RESPAWN_HOLDABLE;
204 }
205
206
207 //======================================================================
208
209 void Add_Ammo (gentity_t *ent, int weapon, int count)
210 {
211 ent->client->ps.ammo[weapon] += count;
212 if ( ent->client->ps.ammo[weapon] > 200 ) {
213 ent->client->ps.ammo[weapon] = 200;
214 }
215 }
216
217 int Pickup_Ammo (gentity_t *ent, gentity_t *other)
218 {
219 int quantity;
220
221 if ( ent->count ) {
222 quantity = ent->count;
223 } else {
224 quantity = ent->item->quantity;
225 }
226
227 Add_Ammo (other, ent->item->giTag, quantity);
228
229 return RESPAWN_AMMO;
230 }
231
232 //======================================================================
233
234
235 int Pickup_Weapon (gentity_t *ent, gentity_t *other) {
236 int quantity;
237
238 if ( ent->count < 0 ) {
239 quantity = 0; // None for you, sir!
240 } else {
241 if ( ent->count ) {
242 quantity = ent->count;
243 } else {
244 quantity = ent->item->quantity;
245 }
246
247 // dropped items and teamplay weapons always have full ammo
248 if ( ! (ent->flags & FL_DROPPED_ITEM) && g_gametype.integer != GT_TEAM ) {
249 // respawning rules
250 // drop the quantity if the already have over the minimum
251 if ( other->client->ps.ammo[ ent->item->giTag ] < quantity ) {
252 quantity = quantity - other->client->ps.ammo[ ent->item->giTag ];
253 } else {
254 quantity = 1; // only add a single shot
255 }
256 }
257 }
258
259 // add the weapon
260 other->client->ps.stats[STAT_WEAPONS] |= ( 1 << ent->item->giTag );
261
262 Add_Ammo( other, ent->item->giTag, quantity );
263
264 if (ent->item->giTag == WP_GRAPPLING_HOOK)
265 other->client->ps.ammo[ent->item->giTag] = -1; // unlimited ammo
266
267 // team deathmatch has slow weapon respawns
268 if ( g_gametype.integer == GT_TEAM ) {
269 return g_weaponTeamRespawn.integer;
270 }
271
272 return g_weaponRespawn.integer;
273 }
274
275
276 //======================================================================
277
278 int Pickup_Health (gentity_t *ent, gentity_t *other) {
279 int max;
280 int quantity;
281
282 if( !other->client)
283 return RESPAWN_HEALTH;
284
•285 #ifdef HAVE_STAT_PERSISTANT_POWERUP
286 // small and mega healths will go over the max
287 if( other->client && bg_itemlist[other->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
288 max = other->client->ps.stats[STAT_MAX_HEALTH];
289 }
290 else
•291 #endif
292 if ( ent->item->quantity != 5 && ent->item->quantity != 100 ) {
293 max = other->client->ps.stats[STAT_MAX_HEALTH];
294 } else {
295 max = other->client->ps.stats[STAT_MAX_HEALTH] * 2;
296 }
297
298 if ( ent->count ) {
299 quantity = ent->count;
300 } else {
301 quantity = ent->item->quantity;
302 }
303
304 other->health += quantity;
305
306 if (other->health > max ) {
307 other->health = max;
308 }
309 other->client->ps.stats[STAT_HEALTH] = other->health;
310
311 if ( ent->item->quantity == 100 ) { // mega health respawns slow
312 return RESPAWN_MEGAHEALTH;
313 }
314
315 return RESPAWN_HEALTH;
316 }
317
318 //======================================================================
319
320 int Pickup_Armor( gentity_t *ent, gentity_t *other ) {
321 int upperBound;
322
323 other->client->ps.stats[STAT_ARMOR] += ent->item->quantity;
324
•325 #ifdef HAVE_STAT_PERSISTANT_POWERUP
326 if( other->client && bg_itemlist[other->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
327 upperBound = other->client->ps.stats[STAT_MAX_HEALTH];
328 }
•329 else
330 #endif
331 {
332 upperBound = other->client->ps.stats[STAT_MAX_HEALTH] * 2;
333 }
334
335 if ( other->client->ps.stats[STAT_ARMOR] > upperBound ) {
336 other->client->ps.stats[STAT_ARMOR] = upperBound;
337 }
338
339 return RESPAWN_ARMOR;
340 }
341
342 //======================================================================
343
344 /*
345 ===============
346 RespawnItem
347 ===============
348 */
349 void RespawnItem( gentity_t *ent ) {
350 //Don't spawn quad if quadfactor are 1.0 or less
351 if(ent->item->giType == IT_POWERUP && ent->item->giTag == PW_QUAD && g_quadfactor.value <= 1.0)
352 return;
353
354 // randomly select from teamed entities
355 if (ent->team) {
356 gentity_t *master;
357 int count;
358 int choice;
359
360 if ( !ent->teammaster ) {
361 G_Error( "RespawnItem: bad teammaster");
362 }
363 master = ent->teammaster;
364
365 for (count = 0, ent = master; ent; ent = ent->teamchain, count++)
366 ;
367
368 choice = (count > 0)? rand()%count : 0;
369
370 for (count = 0, ent = master; count < choice; ent = ent->teamchain, count++)
371 ;
372 }
373
374 ent->r.contents = CONTENTS_TRIGGER;
375 ent->s.eFlags &= ~EF_NODRAW;
376 ent->r.svFlags &= ~SVF_NOCLIENT;
377 trap_LinkEntity (ent);
378
379 if ( ent->item->giType == IT_POWERUP ) {
380 // play powerup spawn sound to all clients
381 gentity_t *te;
382
383 // if the powerup respawn sound should Not be global
384 if (ent->speed) {
385 te = G_TempEntity( ent->s.pos.trBase, EV_GENERAL_SOUND );
386 }
387 else {
388 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_SOUND );
389 }
390 te->s.eventParm = G_SoundIndex( "sound/items/poweruprespawn.wav" );
391 te->r.svFlags |= SVF_BROADCAST;
392 }
393
394 if ( ent->item->giType == IT_HOLDABLE && ent->item->giTag == HI_KAMIKAZE ) {
395 // play powerup spawn sound to all clients
396 gentity_t *te;
397
398 // if the powerup respawn sound should Not be global
399 if (ent->speed) {
400 te = G_TempEntity( ent->s.pos.trBase, EV_GENERAL_SOUND );
401 }
402 else {
403 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_SOUND );
404 }
405 te->s.eventParm = G_SoundIndex( "sound/items/kamikazerespawn.wav" );
406 te->r.svFlags |= SVF_BROADCAST;
407 }
408
409 // play the normal respawn sound only to nearby clients
410 G_AddEvent( ent, EV_ITEM_RESPAWN, 0 );
411
412 ent->nextthink = 0;
413 }
414
415
416 /*
417 ===============
418 Touch_Item
419 ===============
420 */
421 void Touch_Item (gentity_t *ent, gentity_t *other, trace_t *trace) {
422 int respawn;
423 qboolean predict;
424
425 //instant gib
426 if ((g_instantgib.integer || g_rockets.integer || g_gametype.integer == GT_CTF_ELIMINATION || g_elimination_allgametypes.integer)
427 && ent->item->giType != IT_TEAM)
428 return;
429
430 //Cannot touch flag before round starts
431 if(g_gametype.integer == GT_CTF_ELIMINATION && level.roundNumber != level.roundNumberStarted)
432 return;
433
434 //Cannot take ctf elimination oneway
435 if(g_gametype.integer == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer!=0 && (
436 (other->client->sess.sessionTeam==TEAM_BLUE && (level.eliminationSides+level.roundNumber)%2 == 0 ) ||
437 (other->client->sess.sessionTeam==TEAM_RED && (level.eliminationSides+level.roundNumber)%2 != 0 ) ))
438 return;
439
440 if (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_LMS)
441 return; //nothing to pick up in elimination
442
443 if (!other->client)
444 return;
445 if (other->health < 1)
446 return; // dead people can't pickup
447
448 // the same pickup rules are used for client side and server side
449 if ( !BG_CanItemBeGrabbed( g_gametype.integer, &ent->s, &other->client->ps ) ) {
450 return;
451 }
452
453 //In double DD we cannot "pick up" a flag we already got
454 if(g_gametype.integer == GT_DOUBLE_D) {
455 if( strcmp(ent->classname, "team_CTF_redflag") == 0 )
456 if(other->client->sess.sessionTeam == level.pointStatusA)
457 return;
458 if( strcmp(ent->classname, "team_CTF_blueflag") == 0 )
459 if(other->client->sess.sessionTeam == level.pointStatusB)
460 return;
461 }
462
463 G_LogPrintf( "Item: %i %s\n", other->s.number, ent->item->classname );
464
465 predict = other->client->pers.predictItemPickup;
466
467 // call the item-specific pickup function
468 switch( ent->item->giType ) {
469 case IT_WEAPON:
470 respawn = Pickup_Weapon(ent, other);
471 // predict = qfalse;
472 break;
473 case IT_AMMO:
474 respawn = Pickup_Ammo(ent, other);
475 // predict = qfalse;
476 break;
477 case IT_ARMOR:
478 respawn = Pickup_Armor(ent, other);
479 break;
480 case IT_HEALTH:
481 respawn = Pickup_Health(ent, other);
482 break;
483 case IT_POWERUP:
484 respawn = Pickup_Powerup(ent, other);
485 predict = qfalse;
486 break;
487 case IT_PERSISTANT_POWERUP:
488 respawn = Pickup_PersistantPowerup(ent, other);
489 break;
490 case IT_TEAM:
491 respawn = Pickup_Team(ent, other);
492 //If touching a team item remove spawnprotection
493 if(other->client->spawnprotected)
494 other->client->spawnprotected = qfalse;
495 break;
496 case IT_HOLDABLE:
497 respawn = Pickup_Holdable(ent, other);
498 break;
499 default:
500 return;
501 }
502
503 if ( !respawn ) {
504 return;
505 }
506
507 // play the normal pickup sound
508 if (predict) {
509 G_AddPredictableEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
510 } else {
511 G_AddEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
512 }
513
514 // powerup pickups are global broadcasts
515 if ( ent->item->giType == IT_POWERUP || ent->item->giType == IT_TEAM) {
516 // if we want the global sound to play
517 if (!ent->speed) {
518 gentity_t *te;
519
520 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP );
521 te->s.eventParm = ent->s.modelindex;
522 te->r.svFlags |= SVF_BROADCAST;
523 } else {
524 gentity_t *te;
525
526 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP );
527 te->s.eventParm = ent->s.modelindex;
528 // only send this temp entity to a single client
529 te->r.svFlags |= SVF_SINGLECLIENT;
530 te->r.singleClient = other->s.number;
531 }
532 }
533
534 // fire item targets
535 G_UseTargets (ent, other);
536
537 // wait of -1 will not respawn
538 if ( ent->wait == -1 ) {
539 ent->r.svFlags |= SVF_NOCLIENT;
540 ent->s.eFlags |= EF_NODRAW;
541 ent->r.contents = 0;
542 ent->unlinkAfterEvent = qtrue;
543 return;
544 }
545
546 // non zero wait overrides respawn time
547 if ( ent->wait ) {
548 respawn = ent->wait;
549 }
550
551 // random can be used to vary the respawn time
552 if ( ent->random ) {
553 respawn += crandom() * ent->random;
554 if ( respawn < 1 ) {
555 respawn = 1;
556 }
557 }
558
559 // dropped items will not respawn
560 if ( ent->flags & FL_DROPPED_ITEM ) {
561 ent->freeAfterEvent = qtrue;
562 }
563
564 // picked up items still stay around, they just don't
565 // draw anything. This allows respawnable items
566 // to be placed on movers.
567 ent->r.svFlags |= SVF_NOCLIENT;
568 ent->s.eFlags |= EF_NODRAW;
569 ent->r.contents = 0;
570
571 // ZOID
572 // A negative respawn times means to never respawn this item (but don't
573 // delete it). This is used by items that are respawned by third party
574 // events such as ctf flags
575 if ( respawn <= 0 ) {
576 ent->nextthink = 0;
577 ent->think = 0;
578 } else {
579 ent->nextthink = level.time + respawn * 1000;
580 ent->think = RespawnItem;
581 }
582 trap_LinkEntity( ent );
583 }
584
585
586 //======================================================================
587
588 /*
589 ================
590 LaunchItem
591
592 Spawns an item and tosses it forward
593 ================
594 */
595 gentity_t *LaunchItem( gitem_t *item, vec3_t origin, vec3_t velocity ) {
596 gentity_t *dropped;
597
598 dropped = G_Spawn();
599
600 dropped->s.eType = ET_ITEM;
601 dropped->s.modelindex = item - bg_itemlist; // store item number in modelindex
602 dropped->s.modelindex2 = 1; // This is non-zero is it's a dropped item
603
604 dropped->classname = item->classname;
605 dropped->item = item;
606 VectorSet (dropped->r.mins, -ITEM_RADIUS, -ITEM_RADIUS, -ITEM_RADIUS);
607 VectorSet (dropped->r.maxs, ITEM_RADIUS, ITEM_RADIUS, ITEM_RADIUS);
608 dropped->r.contents = CONTENTS_TRIGGER;
609
610 dropped->touch = Touch_Item;
611
612 G_SetOrigin( dropped, origin );
613 dropped->s.pos.trType = TR_GRAVITY;
614 dropped->s.pos.trTime = level.time;
615 VectorCopy( velocity, dropped->s.pos.trDelta );
616
617 dropped->s.eFlags |= EF_BOUNCE_HALF;
618 if ((g_gametype.integer == GT_CTF || g_gametype.integer == GT_1FCTF || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_DOUBLE_D) && item->giType == IT_TEAM) { // Special case for CTF flags
619 dropped->think = Team_DroppedFlagThink;
620 dropped->nextthink = level.time + 30000;
621 Team_CheckDroppedItem( dropped );
622 } else { // auto-remove after 30 seconds
623 dropped->think = G_FreeEntity;
624 dropped->nextthink = level.time + 30000;
625 }
626
627 dropped->flags = FL_DROPPED_ITEM;
628
629 trap_LinkEntity (dropped);
630
631 return dropped;
632 }
633
634 /*
635 ================
636 Drop_Item
637
638 Spawns an item and tosses it forward
639 ================
640 */
641 gentity_t *Drop_Item( gentity_t *ent, gitem_t *item, float angle ) {
642 vec3_t velocity;
643 vec3_t angles;
644
645 VectorCopy( ent->s.apos.trBase, angles );
646 angles[YAW] += angle;
647 angles[PITCH] = 0; // always forward
648
649 AngleVectors( angles, velocity, NULL, NULL );
650 VectorScale( velocity, 150, velocity );
651 velocity[2] += 200 + crandom() * 50;
652
653 return LaunchItem( item, ent->s.pos.trBase, velocity );
654 }
655
656
657 /*
658 ================
659 Use_Item
660
661 Respawn the item
662 ================
663 */
664 void Use_Item( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
665 RespawnItem( ent );
666 }
667
668 //======================================================================
669
670 /*
671 ================
672 FinishSpawningItem
673
674 Traces down to find where an item should rest, instead of letting them
675 free fall from their spawn points
676 ================
677 */
678 void FinishSpawningItem( gentity_t *ent ) {
679 trace_t tr;
680 vec3_t dest;
681
682 VectorSet( ent->r.mins, -ITEM_RADIUS, -ITEM_RADIUS, -ITEM_RADIUS );
683 VectorSet( ent->r.maxs, ITEM_RADIUS, ITEM_RADIUS, ITEM_RADIUS );
684
685 ent->s.eType = ET_ITEM;
686 ent->s.modelindex = ent->item - bg_itemlist; // store item number in modelindex
687 ent->s.modelindex2 = 0; // zero indicates this isn't a dropped item
688
689 ent->r.contents = CONTENTS_TRIGGER;
690 ent->touch = Touch_Item;
691 // useing an item causes it to respawn
692 ent->use = Use_Item;
693
694 if ( ent->spawnflags & 1 ) {
695 // suspended
696 G_SetOrigin( ent, ent->s.origin );
697 } else {
698 // drop to floor
699 VectorSet( dest, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] - 4096 );
700 trap_Trace( &tr, ent->s.origin, ent->r.mins, ent->r.maxs, dest, ent->s.number, MASK_SOLID );
701 if ( tr.startsolid ) {
702 G_Printf ("FinishSpawningItem: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin));
703 G_FreeEntity( ent );
704 return;
705 }
706
707 // allow to ride movers
708 ent->s.groundEntityNum = tr.entityNum;
709
710 G_SetOrigin( ent, tr.endpos );
711 }
712
713 // team slaves and targeted items aren't present at start
714 if ( ( ent->flags & FL_TEAMSLAVE ) || ent->targetname ) {
715 ent->s.eFlags |= EF_NODRAW;
716 ent->r.contents = 0;
717 return;
718 }
719
720
721 // powerups don't spawn in for a while (but not in elimination)
722 if(g_gametype.integer != GT_ELIMINATION && g_gametype.integer != GT_CTF_ELIMINATION && g_gametype.integer != GT_LMS
723 && !g_instantgib.integer && !g_elimination_allgametypes.integer && !g_rockets.integer )
724 if ( ent->item->giType == IT_POWERUP ) {
725 float respawn;
726
727 respawn = 45 + crandom() * 15;
728 ent->s.eFlags |= EF_NODRAW;
729 ent->r.contents = 0;
730 ent->nextthink = level.time + respawn * 1000;
731 ent->think = RespawnItem;
732 return;
733 }
734
735
736 trap_LinkEntity (ent);
737 }
738
739
740 qboolean itemRegistered[MAX_ITEMS];
741
742 /*
743 ==================
744 G_CheckTeamItems
745 ==================
746 */
747 void G_CheckTeamItems( void ) {
748
749 // Set up team stuff
750 Team_InitGame();
751
752 if( g_gametype.integer == GT_CTF || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_DOUBLE_D) {
753 gitem_t *item;
754
755 // check for the two flags
756 item = BG_FindItem( "Red Flag" );
757 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
758 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_redflag in map\n" );
759 }
760 item = BG_FindItem( "Blue Flag" );
761 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
762 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_blueflag in map\n" );
763 }
764 }
765 if( g_gametype.integer == GT_1FCTF ) {
766 gitem_t *item;
767
768 // check for all three flags
769 item = BG_FindItem( "Red Flag" );
770 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
771 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_redflag in map\n" );
772 }
773 item = BG_FindItem( "Blue Flag" );
774 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
775 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_blueflag in map\n" );
776 }
777 item = BG_FindItem( "Neutral Flag" );
778 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
779 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_neutralflag in map\n" );
780 }
781 }
782
783 if( g_gametype.integer == GT_OBELISK ) {
784 gentity_t *ent;
785
786 // check for the two obelisks
787 ent = NULL;
788 ent = G_Find( ent, FOFS(classname), "team_redobelisk" );
789 if( !ent ) {
790 G_Printf( S_COLOR_YELLOW "WARNING: No team_redobelisk in map\n" );
791 }
792
793 ent = NULL;
794 ent = G_Find( ent, FOFS(classname), "team_blueobelisk" );
795 if( !ent ) {
796 G_Printf( S_COLOR_YELLOW "WARNING: No team_blueobelisk in map\n" );
797 }
798 }
799
800 if( g_gametype.integer == GT_HARVESTER ) {
801 gentity_t *ent;
802
803 // check for all three obelisks
804 ent = NULL;
805 ent = G_Find( ent, FOFS(classname), "team_redobelisk" );
806 if( !ent ) {
807 G_Printf( S_COLOR_YELLOW "WARNING: No team_redobelisk in map\n" );
808 }
809
810 ent = NULL;
811 ent = G_Find( ent, FOFS(classname), "team_blueobelisk" );
812 if( !ent ) {
813 G_Printf( S_COLOR_YELLOW "WARNING: No team_blueobelisk in map\n" );
814 }
815
816 ent = NULL;
817 ent = G_Find( ent, FOFS(classname), "team_neutralobelisk" );
818 if( !ent ) {
819 G_Printf( S_COLOR_YELLOW "WARNING: No team_neutralobelisk in map\n" );
820 }
821 }
822 }
823
824 /*
825 ==============
826 ClearRegisteredItems
827 ==============
828 */
829 void ClearRegisteredItems( void ) {
830 memset( itemRegistered, 0, sizeof( itemRegistered ) );
831
832 if(g_instantgib.integer) {
833 if(g_instantgib.integer & 2)
834 RegisterItem( BG_FindItemForWeapon( WP_GAUNTLET ) );
835 //RegisterItem( BG_FindItemForWeapon( WP_MACHINEGUN ) );
836 RegisterItem( BG_FindItemForWeapon( WP_RAILGUN ) );
837 }
838 else
839 if(g_rockets.integer) {
840 //RegisterItem( BG_FindItemForWeapon( WP_GAUNTLET ) );
841 //RegisterItem( BG_FindItemForWeapon( WP_MACHINEGUN ) );
842 RegisterItem( BG_FindItemForWeapon( WP_ROCKET_LAUNCHER ) );
843 }
844 else
845 {
846 // players always start with the base weapon
847 RegisterItem( BG_FindItemForWeapon( WP_MACHINEGUN ) );
848 RegisterItem( BG_FindItemForWeapon( WP_GAUNTLET ) );
849 if(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION
850 || g_gametype.integer == GT_LMS || g_elimination_allgametypes.integer)
851 {
852 RegisterItem( BG_FindItemForWeapon( WP_SHOTGUN ) );
853 RegisterItem( BG_FindItemForWeapon( WP_GRENADE_LAUNCHER ) );
854 RegisterItem( BG_FindItemForWeapon( WP_ROCKET_LAUNCHER ) );
855 RegisterItem( BG_FindItemForWeapon( WP_LIGHTNING ) );
856 RegisterItem( BG_FindItemForWeapon( WP_RAILGUN ) );
857 RegisterItem( BG_FindItemForWeapon( WP_PLASMAGUN ) );
858 RegisterItem( BG_FindItemForWeapon( WP_BFG ) );
859 RegisterItem( BG_FindItemForWeapon( WP_NAILGUN ) );
860 RegisterItem( BG_FindItemForWeapon( WP_PROX_LAUNCHER ) );
861 RegisterItem( BG_FindItemForWeapon( WP_CHAINGUN ) );
862 }
863 }
864 if( g_gametype.integer == GT_HARVESTER ) {
865 RegisterItem( BG_FindItem( "Red Cube" ) );
866 RegisterItem( BG_FindItem( "Blue Cube" ) );
867 }
868
869 if(g_gametype.integer == GT_DOUBLE_D ) {
870 RegisterItem( BG_FindItem( "Point A (Blue)" ) );
871 RegisterItem( BG_FindItem( "Point A (Red)" ) );
872 RegisterItem( BG_FindItem( "Point A (White)" ) );
873 RegisterItem( BG_FindItem( "Point B (Blue)" ) );
874 RegisterItem( BG_FindItem( "Point B (Red)" ) );
875 RegisterItem( BG_FindItem( "Point B (White)" ) );
876 }
877
878 if(g_gametype.integer == GT_DOMINATION ) {
879 RegisterItem( BG_FindItem( "Neutral domination point" ) );
880 RegisterItem( BG_FindItem( "Red domination point" ) );
881 RegisterItem( BG_FindItem( "Blue domination point" ) );
882 }
883
884 }
885
886 /*
887 ===============
888 RegisterItem
889
890 The item will be added to the precache list
891 ===============
892 */
893 void RegisterItem( gitem_t *item ) {
894 if ( !item ) {
895 G_Error( "RegisterItem: NULL" );
896 }
897 itemRegistered[ item - bg_itemlist ] = qtrue;
898 }
899
900
901 /*
902 ===============
903 SaveRegisteredItems
904
905 Write the needed items to a config string
906 so the client will know which ones to precache
907 ===============
908 */
909 void SaveRegisteredItems( void ) {
910 char string[MAX_ITEMS+1];
911 int i;
912 int count;
913
914 count = 0;
915 for ( i = 0 ; i < bg_numItems ; i++ ) {
916 if ( itemRegistered[i] ) {
917 count++;
918 string[i] = '1';
919 } else {
920 string[i] = '0';
921 }
922 }
923 string[ bg_numItems ] = 0;
924 G_Printf( "%i items registered\n", count );
925 trap_SetConfigstring(CS_ITEMS, string);
926 }
927
928 /*
929 ============
930 G_ItemDisabled
931 ============
932 */
933 int G_ItemDisabled( gitem_t *item ) {
934
935 char name[128];
936
937 Com_sprintf(name, sizeof(name), "disable_%s", item->classname);
938 return trap_Cvar_VariableIntegerValue( name );
939 }
940
941 /*
942 ============
943 G_SpawnItem
944
945 Sets the clipping size and plants the object on the floor.
946
947 Items can't be immediately dropped to floor, because they might
948 be on an entity that hasn't spawned yet.
949 ============
950 */
951 void G_SpawnItem (gentity_t *ent, gitem_t *item) {
952 G_SpawnFloat( "random", "0", &ent->random );
953 G_SpawnFloat( "wait", "0", &ent->wait );
954
955 if((item->giType == IT_TEAM && (g_instantgib.integer || g_rockets.integer) ) || (!g_instantgib.integer && !g_rockets.integer) )
956 {
957 //Don't load pickups in Elimination (or maybe... gives warnings)
958 if (g_gametype.integer != GT_ELIMINATION && g_gametype.integer != GT_CTF_ELIMINATION && g_gametype.integer != GT_LMS)
959 RegisterItem( item );
960 //Registrer flags anyway in CTF Elimination:
961 if (g_gametype.integer == GT_CTF_ELIMINATION && item->giType == IT_TEAM)
962 RegisterItem( item );
963 if ( G_ItemDisabled(item) )
964 return;
965 }
966 if(!g_persistantpowerups.integer && item->giType == IT_PERSISTANT_POWERUP)
967 return;
968
969 ent->item = item;
970 // some movers spawn on the second frame, so delay item
971 // spawns until the third frame so they can ride trains
972 ent->nextthink = level.time + FRAMETIME * 2;
973 ent->think = FinishSpawningItem;
974
975 ent->physicsBounce = 0.50; // items are bouncy
976
977 if (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_LMS ||
978 ( item->giType != IT_TEAM && (g_instantgib.integer || g_rockets.integer || g_elimination_allgametypes.integer || g_gametype.integer==GT_CTF_ELIMINATION) ) ) {
979 ent->s.eFlags |= EF_NODRAW; //Invisible in elimination
980 ent->r.svFlags |= SVF_NOCLIENT; //Don't broadcast
981 }
982
983 if(g_gametype.integer == GT_DOUBLE_D && (strcmp(ent->classname, "team_CTF_redflag")==0 || strcmp(ent->classname, "team_CTF_blueflag")==0 || strcmp(ent->classname, "team_CTF_neutralflag") == 0 || item->giType == IT_PERSISTANT_POWERUP ))
984 ent->s.eFlags |= EF_NODRAW; //Don't draw the flag models/persistant powerups
985
986 if( g_gametype.integer != GT_1FCTF && strcmp(ent->classname, "team_CTF_neutralflag") == 0)
987 ent->s.eFlags |= EF_NODRAW; // Don't draw the flag in CTF_elimination
988
989 if(strcmp(ent->classname, "domination_point") == 0)
990 ent->s.eFlags |= EF_NODRAW; // Don't draw domination_point. It is just a pointer to where the Domination points should be placed
991 if ( item->giType == IT_POWERUP ) {
992 G_SoundIndex( "sound/items/poweruprespawn.wav" );
993 G_SpawnFloat( "noglobalsound", "0", &ent->speed);
994 }
995
996 if ( item->giType == IT_PERSISTANT_POWERUP ) {
997 ent->s.generic1 = ent->spawnflags;
998 }
999 }
1000
1001
1002 /*
1003 ================
1004 G_BounceItem
1005
1006 ================
1007 */
1008 void G_BounceItem( gentity_t *ent, trace_t *trace ) {
1009 vec3_t velocity;
1010 float dot;
1011 int hitTime;
1012
1013 // reflect the velocity on the trace plane
1014 hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
1015 BG_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
1016 dot = DotProduct( velocity, trace->plane.normal );
1017 VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
1018
1019 // cut the velocity to keep from bouncing forever
1020 VectorScale( ent->s.pos.trDelta, ent->physicsBounce, ent->s.pos.trDelta );
1021
1022 // check for stop
1023 if ( trace->plane.normal[2] > 0 && ent->s.pos.trDelta[2] < 40 ) {
1024 trace->endpos[2] += 1.0; // make sure it is off ground
1025 SnapVector( trace->endpos );
1026 G_SetOrigin( ent, trace->endpos );
1027 ent->s.groundEntityNum = trace->entityNum;
1028 return;
1029 }
1030
1031 VectorAdd( ent->r.currentOrigin, trace->plane.normal, ent->r.currentOrigin);
1032 VectorCopy( ent->r.currentOrigin, ent->s.pos.trBase );
1033 ent->s.pos.trTime = level.time;
1034 }
1035
1036
1037 /*
1038 ================
1039 G_RunItem
1040
1041 ================
1042 */
1043 void G_RunItem( gentity_t *ent ) {
1044 vec3_t origin;
1045 trace_t tr;
1046 int contents;
1047 int mask;
1048
1049 // if groundentity has been set to -1, it may have been pushed off an edge
1050 if ( ent->s.groundEntityNum == -1 ) {
1051 if ( ent->s.pos.trType != TR_GRAVITY ) {
1052 ent->s.pos.trType = TR_GRAVITY;
1053 ent->s.pos.trTime = level.time;
1054 }
1055 }
1056
1057 if ( ent->s.pos.trType == TR_STATIONARY ) {
1058 // check think function
1059 G_RunThink( ent );
1060 return;
1061 }
1062
1063 // get current position
1064 BG_EvaluateTrajectory( &ent->s.pos, level.time, origin );
1065
1066 // trace a line from the previous position to the current position
1067 if ( ent->clipmask ) {
1068 mask = ent->clipmask;
1069 } else {
1070 mask = MASK_PLAYERSOLID & ~CONTENTS_BODY;//MASK_SOLID;
1071 }
1072 trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, origin,
1073 ent->r.ownerNum, mask );
1074
1075 VectorCopy( tr.endpos, ent->r.currentOrigin );
1076
1077 if ( tr.startsolid ) {
1078 tr.fraction = 0;
1079 }
1080
1081 trap_LinkEntity( ent ); // FIXME: avoid this for stationary?
1082
1083 // check think function
1084 G_RunThink( ent );
1085
1086 if ( tr.fraction == 1 ) {
1087 return;
1088 }
1089
1090 // if it is in a nodrop volume, remove it
1091 contents = trap_PointContents( ent->r.currentOrigin, -1 );
1092 if ( contents & CONTENTS_NODROP ) {
1093 if (ent->item && ent->item->giType == IT_TEAM) {
1094 Team_FreeEntity(ent);
1095 } else {
1096 G_FreeEntity( ent );
1097 }
1098 return;
1099 }
1100
1101 G_BounceItem( ent, &tr );
1102 }
1103