Debian Codegraph @

code/game/g_items.c

raw symbols SCIP
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 appropriately.
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 && 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 #ifdef MISSIONPACK
121 int Pickup_PersistantPowerup( gentity_t *ent, gentity_t *other ) {
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 return -1;
190 }
191
192 //======================================================================
193 #endif
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 // small and mega healths will go over the max
283 #ifdef MISSIONPACK
284 if( 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 #endif
289 if ( ent->item->quantity != 5 && ent->item->quantity != 100 ) {
290 max = other->client->ps.stats[STAT_MAX_HEALTH];
291 } else {
292 max = other->client->ps.stats[STAT_MAX_HEALTH] * 2;
293 }
294
295 if ( ent->count ) {
296 quantity = ent->count;
297 } else {
298 quantity = ent->item->quantity;
299 }
300
301 other->health += quantity;
302
303 if (other->health > max ) {
304 other->health = max;
305 }
306 other->client->ps.stats[STAT_HEALTH] = other->health;
307
308 if ( ent->item->quantity == 100 ) { // mega health respawns slow
309 return RESPAWN_MEGAHEALTH;
310 }
311
312 return RESPAWN_HEALTH;
313 }
314
315 //======================================================================
316
317 int Pickup_Armor( gentity_t *ent, gentity_t *other ) {
318 #ifdef MISSIONPACK
319 int upperBound;
320
321 other->client->ps.stats[STAT_ARMOR] += ent->item->quantity;
322
323 if( other->client && bg_itemlist[other->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
324 upperBound = other->client->ps.stats[STAT_MAX_HEALTH];
325 }
326 else {
327 upperBound = other->client->ps.stats[STAT_MAX_HEALTH] * 2;
328 }
329
330 if ( other->client->ps.stats[STAT_ARMOR] > upperBound ) {
331 other->client->ps.stats[STAT_ARMOR] = upperBound;
332 }
333 #else
334 other->client->ps.stats[STAT_ARMOR] += ent->item->quantity;
335 if ( other->client->ps.stats[STAT_ARMOR] > other->client->ps.stats[STAT_MAX_HEALTH] * 2 ) {
336 other->client->ps.stats[STAT_ARMOR] = other->client->ps.stats[STAT_MAX_HEALTH] * 2;
337 }
338 #endif
339
340 return RESPAWN_ARMOR;
341 }
342
343 //======================================================================
344
345 /*
346 ===============
347 RespawnItem
348 ===============
349 */
350 void RespawnItem( gentity_t *ent ) {
351 if (!ent) {
352 return;
353 }
354
355 // randomly select from teamed entities
356 if (ent->team) {
357 gentity_t *master;
358 int count;
359 int choice;
360
361 if ( !ent->teammaster ) {
362 G_Error( "RespawnItem: bad teammaster");
363 }
364 master = ent->teammaster;
365
366 for (count = 0, ent = master; ent; ent = ent->teamchain, count++)
367 ;
368
369 choice = rand() % count;
370
371 for (count = 0, ent = master; ent && count < choice; ent = ent->teamchain, count++)
372 ;
373 }
374
375 if (!ent) {
376 return;
377 }
378
379 ent->r.contents = CONTENTS_TRIGGER;
380 ent->s.eFlags &= ~EF_NODRAW;
381 ent->r.svFlags &= ~SVF_NOCLIENT;
382 trap_LinkEntity (ent);
383
384 if ( ent->item->giType == IT_POWERUP ) {
385 // play powerup spawn sound to all clients
386 gentity_t *te;
387
388 // if the powerup respawn sound should Not be global
389 if (ent->speed) {
390 te = G_TempEntity( ent->s.pos.trBase, EV_GENERAL_SOUND );
391 }
392 else {
393 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_SOUND );
394 }
395 te->s.eventParm = G_SoundIndex( "sound/items/poweruprespawn.wav" );
396 te->r.svFlags |= SVF_BROADCAST;
397 }
398
399 if ( ent->item->giType == IT_HOLDABLE && ent->item->giTag == HI_KAMIKAZE ) {
400 // play powerup spawn sound to all clients
401 gentity_t *te;
402
403 // if the powerup respawn sound should Not be global
404 if (ent->speed) {
405 te = G_TempEntity( ent->s.pos.trBase, EV_GENERAL_SOUND );
406 }
407 else {
408 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_SOUND );
409 }
410 te->s.eventParm = G_SoundIndex( "sound/items/kamikazerespawn.wav" );
411 te->r.svFlags |= SVF_BROADCAST;
412 }
413
414 // play the normal respawn sound only to nearby clients
415 G_AddEvent( ent, EV_ITEM_RESPAWN, 0 );
416
417 ent->nextthink = 0;
418 }
419
420
421 /*
422 ===============
423 Touch_Item
424 ===============
425 */
426 void Touch_Item (gentity_t *ent, gentity_t *other, trace_t *trace) {
427 int respawn;
428 qboolean predict;
429
430 if (!other->client)
431 return;
432 if (other->health < 1)
433 return; // dead people can't pickup
434
435 // the same pickup rules are used for client side and server side
436 if ( !BG_CanItemBeGrabbed( g_gametype.integer, &ent->s, &other->client->ps ) ) {
437 return;
438 }
439
440 G_LogPrintf( "Item: %i %s\n", other->s.number, ent->item->classname );
441
442 predict = other->client->pers.predictItemPickup;
443
444 // call the item-specific pickup function
445 switch( ent->item->giType ) {
446 case IT_WEAPON:
447 respawn = Pickup_Weapon(ent, other);
448 // predict = qfalse;
449 break;
450 case IT_AMMO:
451 respawn = Pickup_Ammo(ent, other);
452 // predict = qfalse;
453 break;
454 case IT_ARMOR:
455 respawn = Pickup_Armor(ent, other);
456 break;
457 case IT_HEALTH:
458 respawn = Pickup_Health(ent, other);
459 break;
460 case IT_POWERUP:
461 respawn = Pickup_Powerup(ent, other);
462 predict = qfalse;
463 break;
464 #ifdef MISSIONPACK
465 case IT_PERSISTANT_POWERUP:
466 respawn = Pickup_PersistantPowerup(ent, other);
467 break;
468 #endif
469 case IT_TEAM:
470 respawn = Pickup_Team(ent, other);
471 break;
472 case IT_HOLDABLE:
473 respawn = Pickup_Holdable(ent, other);
474 break;
475 default:
476 return;
477 }
478
479 if ( !respawn ) {
480 return;
481 }
482
483 // play the normal pickup sound
484 if (predict) {
485 G_AddPredictableEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
486 } else {
487 G_AddEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
488 }
489
490 // powerup pickups are global broadcasts
491 if ( ent->item->giType == IT_POWERUP || ent->item->giType == IT_TEAM) {
492 // if we want the global sound to play
493 if (!ent->speed) {
494 gentity_t *te;
495
496 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP );
497 te->s.eventParm = ent->s.modelindex;
498 te->r.svFlags |= SVF_BROADCAST;
499 } else {
500 gentity_t *te;
501
502 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP );
503 te->s.eventParm = ent->s.modelindex;
504 // only send this temp entity to a single client
505 te->r.svFlags |= SVF_SINGLECLIENT;
506 te->r.singleClient = other->s.number;
507 }
508 }
509
510 // fire item targets
511 G_UseTargets (ent, other);
512
513 // wait of -1 will not respawn
514 if ( ent->wait == -1 ) {
515 ent->r.svFlags |= SVF_NOCLIENT;
516 ent->s.eFlags |= EF_NODRAW;
517 ent->r.contents = 0;
518 ent->unlinkAfterEvent = qtrue;
519 return;
520 }
521
522 // non zero wait overrides respawn time
523 if ( ent->wait ) {
524 respawn = ent->wait;
525 }
526
527 // random can be used to vary the respawn time
528 if ( ent->random ) {
529 respawn += crandom() * ent->random;
530 if ( respawn < 1 ) {
531 respawn = 1;
532 }
533 }
534
535 // dropped items will not respawn
536 if ( ent->flags & FL_DROPPED_ITEM ) {
537 ent->freeAfterEvent = qtrue;
538 }
539
540 // picked up items still stay around, they just don't
541 // draw anything. This allows respawnable items
542 // to be placed on movers.
543 ent->r.svFlags |= SVF_NOCLIENT;
544 ent->s.eFlags |= EF_NODRAW;
545 ent->r.contents = 0;
546
547 // ZOID
548 // A negative respawn times means to never respawn this item (but don't
549 // delete it). This is used by items that are respawned by third party
550 // events such as ctf flags
551 if ( respawn <= 0 ) {
552 ent->nextthink = 0;
553 ent->think = 0;
554 } else {
555 ent->nextthink = level.time + respawn * 1000;
556 ent->think = RespawnItem;
557 }
558 trap_LinkEntity( ent );
559 }
560
561
562 //======================================================================
563
564 /*
565 ================
566 LaunchItem
567
568 Spawns an item and tosses it forward
569 ================
570 */
571 gentity_t *LaunchItem( gitem_t *item, vec3_t origin, vec3_t velocity ) {
572 gentity_t *dropped;
573
574 dropped = G_Spawn();
575
576 dropped->s.eType = ET_ITEM;
577 dropped->s.modelindex = item - bg_itemlist; // store item number in modelindex
578 dropped->s.modelindex2 = 1; // This is non-zero is it's a dropped item
579
580 dropped->classname = item->classname;
581 dropped->item = item;
582 VectorSet (dropped->r.mins, -ITEM_RADIUS, -ITEM_RADIUS, -ITEM_RADIUS);
583 VectorSet (dropped->r.maxs, ITEM_RADIUS, ITEM_RADIUS, ITEM_RADIUS);
584 dropped->r.contents = CONTENTS_TRIGGER;
585
586 dropped->touch = Touch_Item;
587
588 G_SetOrigin( dropped, origin );
589 dropped->s.pos.trType = TR_GRAVITY;
590 dropped->s.pos.trTime = level.time;
591 VectorCopy( velocity, dropped->s.pos.trDelta );
592
593 dropped->s.eFlags |= EF_BOUNCE_HALF;
594 #ifdef MISSIONPACK
595 if ((g_gametype.integer == GT_CTF || g_gametype.integer == GT_1FCTF) && item->giType == IT_TEAM) { // Special case for CTF flags
596 #else
597 if (g_gametype.integer == GT_CTF && item->giType == IT_TEAM) { // Special case for CTF flags
598 #endif
599 dropped->think = Team_DroppedFlagThink;
600 dropped->nextthink = level.time + 30000;
601 Team_CheckDroppedItem( dropped );
602 } else { // auto-remove after 30 seconds
603 dropped->think = G_FreeEntity;
604 dropped->nextthink = level.time + 30000;
605 }
606
607 dropped->flags = FL_DROPPED_ITEM;
608
609 trap_LinkEntity (dropped);
610
611 return dropped;
612 }
613
614 /*
615 ================
616 Drop_Item
617
618 Spawns an item and tosses it forward
619 ================
620 */
621 gentity_t *Drop_Item( gentity_t *ent, gitem_t *item, float angle ) {
622 vec3_t velocity;
623 vec3_t angles;
624
625 VectorCopy( ent->s.apos.trBase, angles );
626 angles[YAW] += angle;
627 angles[PITCH] = 0; // always forward
628
629 AngleVectors( angles, velocity, NULL, NULL );
630 VectorScale( velocity, 150, velocity );
631 velocity[2] += 200 + crandom() * 50;
632
633 return LaunchItem( item, ent->s.pos.trBase, velocity );
634 }
635
636
637 /*
638 ================
639 Use_Item
640
641 Respawn the item
642 ================
643 */
644 void Use_Item( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
645 RespawnItem( ent );
646 }
647
648 //======================================================================
649
650 /*
651 ================
652 FinishSpawningItem
653
654 Traces down to find where an item should rest, instead of letting them
655 free fall from their spawn points
656 ================
657 */
658 void FinishSpawningItem( gentity_t *ent ) {
659 trace_t tr;
660 vec3_t dest;
661
662 VectorSet( ent->r.mins, -ITEM_RADIUS, -ITEM_RADIUS, -ITEM_RADIUS );
663 VectorSet( ent->r.maxs, ITEM_RADIUS, ITEM_RADIUS, ITEM_RADIUS );
664
665 ent->s.eType = ET_ITEM;
666 ent->s.modelindex = ent->item - bg_itemlist; // store item number in modelindex
667 ent->s.modelindex2 = 0; // zero indicates this isn't a dropped item
668
669 ent->r.contents = CONTENTS_TRIGGER;
670 ent->touch = Touch_Item;
671 // using an item causes it to respawn
672 ent->use = Use_Item;
673
674 if ( ent->spawnflags & 1 ) {
675 // suspended
676 G_SetOrigin( ent, ent->s.origin );
677 } else {
678 // drop to floor
679 VectorSet( dest, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] - 4096 );
680 trap_Trace( &tr, ent->s.origin, ent->r.mins, ent->r.maxs, dest, ent->s.number, MASK_SOLID );
681 if ( tr.startsolid ) {
682 G_Printf ("FinishSpawningItem: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin));
683 G_FreeEntity( ent );
684 return;
685 }
686
687 // allow to ride movers
688 ent->s.groundEntityNum = tr.entityNum;
689
690 G_SetOrigin( ent, tr.endpos );
691 }
692
693 // team members and targeted items aren't present at start
694 if ( ( ent->flags & FL_TEAMMEMBER ) || ent->targetname ) {
695 ent->s.eFlags |= EF_NODRAW;
696 ent->r.contents = 0;
697 return;
698 }
699
700 // powerups don't spawn in for a while
701 if ( ent->item->giType == IT_POWERUP ) {
702 float respawn;
703
704 respawn = 45 + crandom() * 15;
705 ent->s.eFlags |= EF_NODRAW;
706 ent->r.contents = 0;
707 ent->nextthink = level.time + respawn * 1000;
708 ent->think = RespawnItem;
709 return;
710 }
711
712
713 trap_LinkEntity (ent);
714 }
715
716
717 qboolean itemRegistered[MAX_ITEMS];
718
719 /*
720 ==================
721 G_CheckTeamItems
722 ==================
723 */
724 void G_CheckTeamItems( void ) {
725
726 // Set up team stuff
727 Team_InitGame();
728
729 if( g_gametype.integer == GT_CTF ) {
730 gitem_t *item;
731
732 // check for the two flags
733 item = BG_FindItem( "Red Flag" );
734 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
735 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_redflag in map\n" );
736 }
737 item = BG_FindItem( "Blue Flag" );
738 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
739 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_blueflag in map\n" );
740 }
741 }
742 #ifdef MISSIONPACK
743 if( g_gametype.integer == GT_1FCTF ) {
744 gitem_t *item;
745
746 // check for all three flags
747 item = BG_FindItem( "Red Flag" );
748 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
749 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_redflag in map\n" );
750 }
751 item = BG_FindItem( "Blue Flag" );
752 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
753 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_blueflag in map\n" );
754 }
755 item = BG_FindItem( "Neutral Flag" );
756 if ( !item || !itemRegistered[ item - bg_itemlist ] ) {
757 G_Printf( S_COLOR_YELLOW "WARNING: No team_CTF_neutralflag in map\n" );
758 }
759 }
760
761 if( g_gametype.integer == GT_OBELISK ) {
762 gentity_t *ent;
763
764 // check for the two obelisks
765 ent = NULL;
766 ent = G_Find( ent, FOFS(classname), "team_redobelisk" );
767 if( !ent ) {
768 G_Printf( S_COLOR_YELLOW "WARNING: No team_redobelisk in map\n" );
769 }
770
771 ent = NULL;
772 ent = G_Find( ent, FOFS(classname), "team_blueobelisk" );
773 if( !ent ) {
774 G_Printf( S_COLOR_YELLOW "WARNING: No team_blueobelisk in map\n" );
775 }
776 }
777
778 if( g_gametype.integer == GT_HARVESTER ) {
779 gentity_t *ent;
780
781 // check for all three obelisks
782 ent = NULL;
783 ent = G_Find( ent, FOFS(classname), "team_redobelisk" );
784 if( !ent ) {
785 G_Printf( S_COLOR_YELLOW "WARNING: No team_redobelisk in map\n" );
786 }
787
788 ent = NULL;
789 ent = G_Find( ent, FOFS(classname), "team_blueobelisk" );
790 if( !ent ) {
791 G_Printf( S_COLOR_YELLOW "WARNING: No team_blueobelisk in map\n" );
792 }
793
794 ent = NULL;
795 ent = G_Find( ent, FOFS(classname), "team_neutralobelisk" );
796 if( !ent ) {
797 G_Printf( S_COLOR_YELLOW "WARNING: No team_neutralobelisk in map\n" );
798 }
799 }
800 #endif
801 }
802
803 /*
804 ==============
805 ClearRegisteredItems
806 ==============
807 */
808 void ClearRegisteredItems( void ) {
809 memset( itemRegistered, 0, sizeof( itemRegistered ) );
810
811 // players always start with the base weapon
812 RegisterItem( BG_FindItemForWeapon( WP_MACHINEGUN ) );
813 RegisterItem( BG_FindItemForWeapon( WP_GAUNTLET ) );
814 #ifdef MISSIONPACK
815 if( g_gametype.integer == GT_HARVESTER ) {
816 RegisterItem( BG_FindItem( "Red Cube" ) );
817 RegisterItem( BG_FindItem( "Blue Cube" ) );
818 }
819 #endif
820 }
821
822 /*
823 ===============
824 RegisterItem
825
826 The item will be added to the precache list
827 ===============
828 */
829 void RegisterItem( gitem_t *item ) {
830 if ( !item ) {
831 G_Error( "RegisterItem: NULL" );
832 }
833 itemRegistered[ item - bg_itemlist ] = qtrue;
834 }
835
836
837 /*
838 ===============
839 SaveRegisteredItems
840
841 Write the needed items to a config string
842 so the client will know which ones to precache
843 ===============
844 */
845 void SaveRegisteredItems( void ) {
846 char string[MAX_ITEMS+1];
847 int i;
848 int count;
849
850 count = 0;
851 for ( i = 0 ; i < bg_numItems ; i++ ) {
852 if ( itemRegistered[i] ) {
853 count++;
854 string[i] = '1';
855 } else {
856 string[i] = '0';
857 }
858 }
859 string[ bg_numItems ] = 0;
860
861 G_Printf( "%i items registered\n", count );
862 trap_SetConfigstring(CS_ITEMS, string);
863 }
864
865 /*
866 ============
867 G_ItemDisabled
868 ============
869 */
870 int G_ItemDisabled( gitem_t *item ) {
871
872 char name[128];
873
874 Com_sprintf(name, sizeof(name), "disable_%s", item->classname);
875 return trap_Cvar_VariableIntegerValue( name );
876 }
877
878 /*
879 ============
880 G_SpawnItem
881
882 Sets the clipping size and plants the object on the floor.
883
884 Items can't be immediately dropped to floor, because they might
885 be on an entity that hasn't spawned yet.
886 ============
887 */
888 void G_SpawnItem (gentity_t *ent, gitem_t *item) {
889 G_SpawnFloat( "random", "0", &ent->random );
890 G_SpawnFloat( "wait", "0", &ent->wait );
891
892 RegisterItem( item );
893 if ( G_ItemDisabled(item) )
894 return;
895
896 ent->item = item;
897 // some movers spawn on the second frame, so delay item
898 // spawns until the third frame so they can ride trains
899 ent->nextthink = level.time + FRAMETIME * 2;
900 ent->think = FinishSpawningItem;
901
902 ent->physicsBounce = 0.50; // items are bouncy
903
904 if ( item->giType == IT_POWERUP ) {
905 G_SoundIndex( "sound/items/poweruprespawn.wav" );
906 G_SpawnFloat( "noglobalsound", "0", &ent->speed);
907 }
908
909 #ifdef MISSIONPACK
910 if ( item->giType == IT_PERSISTANT_POWERUP ) {
911 ent->s.generic1 = ent->spawnflags;
912 }
913 #endif
914 }
915
916
917 /*
918 ================
919 G_BounceItem
920
921 ================
922 */
923 void G_BounceItem( gentity_t *ent, trace_t *trace ) {
924 vec3_t velocity;
925 float dot;
926 int hitTime;
927
928 // reflect the velocity on the trace plane
929 hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
930 BG_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
931 dot = DotProduct( velocity, trace->plane.normal );
932 VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
933
934 // cut the velocity to keep from bouncing forever
935 VectorScale( ent->s.pos.trDelta, ent->physicsBounce, ent->s.pos.trDelta );
936
937 // check for stop
938 if ( trace->plane.normal[2] > 0 && ent->s.pos.trDelta[2] < 40 ) {
939 trace->endpos[2] += 1.0; // make sure it is off ground
940 SnapVector( trace->endpos );
941 G_SetOrigin( ent, trace->endpos );
942 ent->s.groundEntityNum = trace->entityNum;
943 return;
944 }
945
946 VectorAdd( ent->r.currentOrigin, trace->plane.normal, ent->r.currentOrigin);
947 VectorCopy( ent->r.currentOrigin, ent->s.pos.trBase );
948 ent->s.pos.trTime = level.time;
949 }
950
951
952 /*
953 ================
954 G_RunItem
955
956 ================
957 */
958 void G_RunItem( gentity_t *ent ) {
959 vec3_t origin;
960 trace_t tr;
961 int contents;
962 int mask;
963
964 // if its groundentity has been set to none, it may have been pushed off an edge
965 if ( ent->s.groundEntityNum == ENTITYNUM_NONE ) {
966 if ( ent->s.pos.trType != TR_GRAVITY ) {
967 ent->s.pos.trType = TR_GRAVITY;
968 ent->s.pos.trTime = level.time;
969 }
970 }
971
972 if ( ent->s.pos.trType == TR_STATIONARY ) {
973 // check think function
974 G_RunThink( ent );
975 return;
976 }
977
978 // get current position
979 BG_EvaluateTrajectory( &ent->s.pos, level.time, origin );
980
981 // trace a line from the previous position to the current position
982 if ( ent->clipmask ) {
983 mask = ent->clipmask;
984 } else {
985 mask = MASK_PLAYERSOLID & ~CONTENTS_BODY;//MASK_SOLID;
986 }
987 trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, origin,
988 ent->r.ownerNum, mask );
989
990 VectorCopy( tr.endpos, ent->r.currentOrigin );
991
992 if ( tr.startsolid ) {
993 tr.fraction = 0;
994 }
995
996 trap_LinkEntity( ent ); // FIXME: avoid this for stationary?
997
998 // check think function
999 G_RunThink( ent );
1000
1001 if ( tr.fraction == 1 ) {
1002 return;
1003 }
1004
1005 // if it is in a nodrop volume, remove it
1006 contents = trap_PointContents( ent->r.currentOrigin, -1 );
1007 if ( contents & CONTENTS_NODROP ) {
1008 if (ent->item && ent->item->giType == IT_TEAM) {
1009 Team_FreeEntity(ent);
1010 } else {
1011 G_FreeEntity( ent );
1012 }
1013 return;
1014 }
1015
1016 G_BounceItem( ent, &tr );
1017 }
1018