Debian Codegraph @

code/game/g_items.c

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