/
g_teamplay.c
689 lines (517 loc) · 16.1 KB
/
g_teamplay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
// g_teamplay.c - teamplay oriented code
#include "g_local.h"
#define CASH_ROLL 10
#define CASH_BAG 25
#define MAX_CASH_ITEMS 10 // never spawn more than this many cash items at once
int num_cash_items;
char *team_names[] = {
"(spectator)",
"Dragons",
"Nikki's Boyz",
NULL
};
int team_cash[3]; // cash per team, 0 is neutral so just ignore
float last_safe_withdrawal[3];
float last_safe_deposit[3];
//=====================================================================
// Entity spawn functions
// ....................................................................
// Cash Spawning during GRAB DA LOOT
void cash_touch( edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
float speed;
if (surf && plane && plane->normal[2] > 0.5)
{ // let it rest here
if ((speed = VectorLength( self->velocity )) > 10)
{
self->s.angles[ROLL] = 0;
self->s.angles[PITCH] = 0;
self->avelocity[PITCH] = 0;
self->avelocity[ROLL] = 0;
self->avelocity[YAW] *= 0.5;
// randomize bounce
VectorAdd( self->velocity, tv( crandom()*speed*0.3, crandom()*speed*0.3, random()*speed*0.15 ), self->velocity );
}
else
{
VectorClear( self->velocity );
VectorClear( self->avelocity );
self->s.angles[PITCH] = 0;
self->s.angles[ROLL] = 0;
self->movetype = MOVETYPE_NONE;
}
return;
}
if (other->client)
{
if (other->client->pers.currentcash < MAX_CASH_PLAYER)
{ // they can hold the cash
if ((self->currentcash == CASH_BAG) || (self->movetype != MOVETYPE_NONE) || (other->client->ps.pmove.pm_flags & PMF_DUCKED))
{ // they can pick it up
Touch_Item( self, other, plane, surf );
num_cash_items--;
G_FreeEdict( self );
return;
}
}
}
}
void cash_kill( edict_t *self )
{
num_cash_items--;
G_FreeEdict( self );
}
void cashroll_animate( edict_t *self )
{
// reduce XY velocity (air friction)
self->velocity[0] *= 0.9;
self->velocity[1] *= 0.9;
if (level.time > (self->timestamp))
{
cash_kill( self );
return;
}
if (self->movetype != MOVETYPE_NONE)
{
if (VectorDistance( self->s.origin, self->pos1 ) < 1)
self->count++;
else
self->count = 0;
VectorCopy( self->s.origin, self->pos1 );
if (self->count > 2) // rested for 2 frames
{
VectorClear( self->velocity );
VectorClear( self->avelocity );
self->s.angles[PITCH] = 0;
self->s.angles[ROLL] = 0;
self->movetype = MOVETYPE_NONE;
}
}
self->nextthink = level.time + 0.1;
}
void cashspawn_think( edict_t *self )
{
edict_t *cash;
if ((num_cash_items > MAX_CASH_ITEMS) || (level.modeset == MATCHSETUP) || (level.modeset == MATCHCOUNT) || (level.modeset == PREGAME))
{
self->nextthink = level.time + self->delay;
return;
}
// spawn some money
cash = G_Spawn();
VectorCopy( self->s.origin, cash->s.origin );
cash->movetype = MOVETYPE_BOUNCE;
cash->solid = SOLID_TRIGGER;
AngleVectors( self->s.angles, cash->velocity, NULL, NULL );
VectorScale( cash->velocity, self->speed, cash->velocity );
// randomize the velocity a bit
VectorAdd( cash->velocity, tv( crandom()*self->speed*0.3, crandom()*self->speed*0.3, crandom()*self->speed*0.15 ), cash->velocity );
cash->s.renderfx2 |= RF2_NOSHADOW;
// FIXME: doh this doesn't work, need to spawn actual item's, so the HUD is updated automatically when picking up
if (!strcmp(self->type, "cashroll"))
{ // small dollar notes
cash->s.modelindex = gi.modelindex( "models/pu_icon/cash/tris.md2" );
cash->gravity = 0.1 + random()*0.5;
cash->think = cashroll_animate;
cash->nextthink = level.time + 0.1;
cash->s.angles[PITCH] = 10;
VectorSet( cash->avelocity, 0, 10000 * cash->gravity, 0 );
VectorSet( cash->mins, -4, -4, -15 );
VectorSet( cash->maxs, 4, 4, -13 );
cash->item = FindItem("Cash");
cash->currentcash = CASH_ROLL;
cash->touch = cash_touch;
cash->timestamp = level.time + 60;
cash->think = cashroll_animate;
cash->nextthink = level.time + 0.1;
}
else
{
cash->s.modelindex = gi.modelindex( "models/pu_icon/money/money_sm.md2" );
cash->gravity = 1.0;
VectorSet( cash->mins, -12, -12, -15 );
VectorSet( cash->maxs, 12, 12, 10 );
cash->item = FindItem("Small Cash Bag");
cash->currentcash = CASH_BAG;
cash->touch = cash_touch;
cash->think = cash_kill;
cash->nextthink = level.time + 60;
}
num_cash_items++;
self->nextthink = level.time + self->delay;
}
/*QUAKED dm_cashspawn (0.5 0 1) (-16 -16 -16) (16 16 16)
Spawn location for cash during "Grab da Loot" games
angle - direction to project cash upon spawning
speed - speed of projection
type - "cashroll" or "cashbag" (more money, longer delay)
*/
void SP_dm_cashspawn( edict_t *self )
{
if ((int)teamplay->value != 1)
return;
num_cash_items = 0;
if (!strcmp(self->type, "cashroll"))
{
self->delay = (float)g_cashspawndelay->value;
}
else // bag, so longer delay
{
self->delay = (float)g_cashspawndelay->value * (CASH_BAG / CASH_ROLL);
}
if (!self->speed)
self->speed = 10;
self->think = cashspawn_think;
self->nextthink = level.time + self->delay;
}
// ....................................................................
// Safe Bag, used for Grab Da Loot and teamplay Cash-Match
void safebag_touch( edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
static float last_touch_time;
static edict_t *last_touch_ent;
static int last_touch_count = 0;
if (!other->client)
return;
if ((level.time < last_touch_time) || (last_touch_time && (last_touch_time < (level.time - 2.0))) || (last_touch_ent && (last_touch_ent != other)))
{ // reset
last_touch_time = 0;
last_touch_ent = NULL;
last_touch_count = 0;
}
else if (last_touch_time > (level.time - 0.1))
{
return;
}
else
{
last_touch_count++;
last_touch_time = level.time;
if (last_touch_count > (int)(50.0 * (1.0 + (0.5*(other->client->pers.team == self->style)))))
{
// let them go away on their own terms
T_Damage( other, other, other, vec3_origin, other->s.origin, vec3_origin, 9999, 0, 0, MOD_SAFECAMPER );
last_touch_count = 0;
}
}
last_touch_ent = other;
if (other->client->pers.team == self->style)
{
if (self->timestamp > (level.time - 0.5))
return;
}
else if (self->timestamp > (level.time - 1.0))
return;
self->timestamp = level.time;
// depositing, or withdrawing?
if (other->client->pers.team == self->style)
{ // deposit
if (other->client->pers.currentcash > 0 || other->client->pers.bagcash > 0)
{
int precash, amount;
precash = team_cash[self->style];
team_cash[self->style] += other->client->pers.currentcash;
team_cash[self->style] += other->client->pers.bagcash;
UpdateScore();
other->client->resp.deposited += other->client->pers.currentcash;
other->client->resp.deposited += other->client->pers.bagcash;
other->client->pers.currentcash = 0;
other->client->pers.bagcash = 0;
gi.sound(other, CHAN_ITEM, gi.soundindex("world/pickups/cash.wav"), 1, 3, 0);
// make a droping sound
gi.positioned_sound(self->s.origin, self, CHAN_ITEM, gi.soundindex("world/doors/dr1_end.wav"), 1, 1, 0);
// let everyone know how much was deposited
amount = team_cash[self->style] - precash;
gi.bprintf( PRINT_MEDIUM, "%s deposited $%i\n", other->client->pers.netname, amount );
other->client->fakeThief = 0;
last_safe_deposit[self->style] = level.time;
}
}
else if (team_cash[self->style] > 0)
{ // withdrawal
if (other->client->pers.bagcash < MAX_BAGCASH_PLAYER)
{
int precash, amount;
precash = team_cash[self->style];
team_cash[self->style] -= (MAX_BAGCASH_PLAYER - other->client->pers.bagcash);
other->client->pers.bagcash += (MAX_BAGCASH_PLAYER - other->client->pers.bagcash);
if (team_cash[self->style] < 0)
{ // don't take more than they have
other->client->pers.bagcash += team_cash[self->style];
team_cash[self->style] = 0;
}
UpdateScore();
gi.sound(other, CHAN_ITEM, gi.soundindex("world/pickups/cash.wav"), 1, 3, 0);
// alarm!
gi.positioned_sound(self->s.origin, self, CHAN_ITEM, gi.soundindex("misc/cashmatch_alarm.wav"), 1, 1, 0);
// let everyone know how much was stolen
other->client->fakeThief = amount = precash - team_cash[self->style];
gi.bprintf( PRINT_MEDIUM, "%s stole $%i from %s's safe!\n", other->client->pers.netname, amount, team_names[self->style] );
last_safe_withdrawal[self->style] = level.time;
other->client->resp.stole += amount;
}
}
}
// Safebag think, if a friendly guy has been standing near us for more than a few seconds, make them vulnerable to friendly fire
void safebag_think(edict_t *self)
{
int i;
edict_t *trav;
qboolean noenemies = true;
#define SAFE_CLOSE_DIST 128
#define MAX_TIMEATSAFE 8.0
// first, check if we have any unwanted enemies around, if so, don't count
for (i=0; i<maxclients->value; i++)
{
trav = &g_edicts[i+1];
if (!trav->inuse || !trav->client)
continue;
if (trav->health <= 0)
continue;
if (!trav->client->pers.team || (trav->client->pers.team == self->style))
continue;
if (VectorDistance( self->s.origin, trav->s.origin ) > 512)
continue;
if (!gi.inPVS( self->s.origin, trav->s.origin ))
continue;
noenemies = false;
break;
}
for (i=0; i<maxclients->value; i++)
{
trav = &g_edicts[i+1];
if (!trav->inuse || !trav->client)
continue;
if (trav->health <= 0)
continue;
if (!trav->client->pers.team || (trav->client->pers.team != self->style))
continue;
if (noenemies)
{
if (VectorDistance( self->s.origin, trav->s.origin ) > SAFE_CLOSE_DIST)
{
trav->client->pers.timeatsafe -= 0.2;
if (trav->client->pers.timeatsafe < 0)
trav->client->pers.timeatsafe = 0;
}
else
{
trav->client->pers.timeatsafe += 0.2;
if (trav->client->pers.timeatsafe > MAX_TIMEATSAFE)
trav->client->pers.timeatsafe = MAX_TIMEATSAFE;
}
if (trav->client->pers.timeatsafe >= MAX_TIMEATSAFE)
trav->client->pers.friendly_vulnerable = true;
else
trav->client->pers.friendly_vulnerable = false;
}
else // turn off vulnerability, there is an enemy in range
{
trav->client->pers.friendly_vulnerable = false;
}
}
self->nextthink = level.time + 0.2;
}
/*QUAKED dm_safebag (0.5 0 1) (-12 -12 -16) (12 12 12)
Bag that holds the money in the safe.
style - team that this bag belongs to (1 or 2)
*/
void SP_dm_safebag( edict_t *self )
{
if (!teamplay->value)
{
G_FreeEdict( self );
return;
}
if (self->style < 1 || self->style > 2)
{
gi.dprintf( "dm_safebag has invalid \"style\" at %s, should be 1 or 2.\n", vtos(self->s.origin));
G_FreeEdict( self );
return;
}
self->s.modelindex = gi.modelindex("models/pu_icon/money/money_lg.md2");
VectorSet( self->mins, -12, -12, -16 );
VectorSet( self->maxs, 12, 12, 12 );
self->movetype = MOVETYPE_NONE;
self->solid = SOLID_TRIGGER;
gi.linkentity( self );
self->touch = safebag_touch;
self->currentcash = 0; // start with no cash
self->think = safebag_think;
self->nextthink = level.time + 2;
}
/*QUAKED dm_props_banner (.5 0 1) (-4 -4 -4) (4 4 4)
Temp banner for teamplay
style = team (1 / 2)
scale = scale the size up/down (2 = double size)
model="models\props\temp\triangle\small.md2"
*/
void SP_dm_props_banner (edict_t *self)
{
// vec3_t end, bestnorm, bestend;
// float bestdist;
// int x,y;
// trace_t tr;
if (!deathmatch_value || !teamplay->value)
{ // remove
G_FreeEdict (self);
return;
}
if (!self->style)
{
gi.dprintf( "%s has invalid style (should be 1 or 2) at %s\n", self->classname, vtos(self->s.origin) );
G_FreeEdict (self);
return;
}
/*
// trace a line back, to get the wall, then go out
{
bestdist = 9999;
for (x=-256; x<300; x+= 256)
{
VectorCopy( self->s.origin, end );
end[0] = self->s.origin[0] + x;
tr = gi.trace( self->s.origin, NULL, NULL, end, NULL, MASK_SOLID );
if (tr.fraction < bestdist)
{
VectorCopy( tr.plane.normal, bestnorm );
VectorCopy( tr.endpos, bestend );
bestdist = tr.fraction;
}
}
for (y=-256; y<300; y+= 256)
{
VectorCopy( self->s.origin, end );
end[1] = self->s.origin[1] + y;
tr = gi.trace( self->s.origin, NULL, NULL, end, NULL, MASK_SOLID );
if (tr.fraction < bestdist)
{
VectorCopy( tr.plane.normal, bestnorm );
VectorCopy( tr.endpos, bestend );
bestdist = tr.fraction;
}
}
vectoangles( bestnorm, self->s.angles );
VectorMA( bestend, 40 * self->cast_info.scale, bestnorm, self->s.origin );
}
*/
// Ridah, 1-jun-99, use flag models for now
#if 1
{
void think_flag (edict_t *self);
// self->solid = SOLID_BBOX;
self->movetype = MOVETYPE_NONE;
if (self->style == 2)
{
self->model = "models/props/flag/flag1.md2";
}
else
{
self->model = "models/props/flag/flag3.md2";
}
self->s.modelindex = gi.modelindex (self->model);
self->s.renderfx2 |= RF2_NOSHADOW;
self->s.renderfx |= RF_MINLIGHT;
if (!self->cast_info.scale)
self->cast_info.scale = 1;
self->s.scale = (self->cast_info.scale - 1);
// VectorMA( bestend, 40 * self->cast_info.scale, bestnorm, self->s.origin );
self->cast_info.scale *= 0.3;
gi.linkentity (self);
self->s.effects |= EF_ANIM_ALLFAST_NEW;
self->s.renderfx2 |= RF2_MODULUS_FRAME;
self->s.renderfx2 |= RDF_NOLERP;
// Disabled, doesn't animate much, and uses bandwidth
// self->nextthink = level.time + FRAMETIME *2;
// self->think = think_flag;
}
#else // TRIANGULAR ROTATING ICONS
self->solid = SOLID_NOT;
self->movetype = MOVETYPE_NONE;
self->s.skinnum = self->style - 1;
self->s.renderfx2 |= RF2_NOSHADOW;
self->s.renderfx |= RF_MINLIGHT;
if (!self->cast_info.scale)
self->cast_info.scale = 1;
self->s.scale = self->cast_info.scale - 1;
self->s.modelindex = gi.modelindex ("models/props/temp/triangle/small.md2");
gi.linkentity (self);
{
edict_t *arm;
arm = G_Spawn();
arm->solid = self->solid;
arm->movetype = self->movetype;
arm->s.renderfx2 |= RF2_NOSHADOW;
arm->s.scale = self->s.scale;
VectorCopy( self->s.origin, arm->s.origin );
VectorCopy( self->s.angles, arm->s.angles );
arm->s.modelindex = gi.modelindex ("models/props/temp/triangle/arm.md2");
gi.linkentity (arm);
}
VectorCopy( self->s.angles, self->last_step_pos );
VectorClear( self->move_angles );
#endif
}
// ....................................................................
void Teamplay_ValidateSkin( edict_t *self )
{
// TODO: we need color coded skins, for now, just use any skin
}
extern void ClientUserinfoChanged (edict_t *ent, char *userinfo);
// Papa - made some changes to this function
qboolean Teamplay_ValidateJoinTeam( edict_t *self, int teamindex )
{
// NOTE: this is called by each player on level change, as well as when a player issues a "join XXX" command
// TODO: player limit per team? cvar?
Teamplay_ValidateSkin( self );
// InitClientPersistant (self->client);
self->client->pers.team = teamindex;
self->client->pers.spectator = PLAYING;
if ((level.modeset != MATCHSPAWN) && (level.modeset != PUBLICSPAWN))
{
gi.bprintf( PRINT_HIGH, "%s joined %s\n", self->client->pers.netname, team_names[teamindex] );
}
if ((level.modeset == PUBLIC) || (level.modeset == MATCH) || (level.modeset == MATCHSPAWN) || (level.modeset == PUBLICSPAWN))
{
/*
// Validate skins
{
char *str[256];
strcpy( str, self->client->pers.userinfo );
ClientUserinfoChanged ( self, str );
}
*/
if (self->client->resp.enterframe!=level.framenum)
PutClientInServer( self ); // find a new spawn point
}
return true;
}
void Teamplay_AutoJoinTeam( edict_t *self )
{
int team_count[2];
int i;
// count number of players on each team, assign the team with least players
team_count[0] = 0;
team_count[1] = 0;
for (i=1; i<maxclients->value; i++)
{
if (g_edicts[i].client && g_edicts[i].client->pers.team)
team_count[g_edicts[i].client->pers.team - 1]++;
}
if (team_count[0] > team_count[1])
self->client->pers.team = 2;
else
self->client->pers.team = 1;
self->client->pers.spectator = PLAYING;
Teamplay_ValidateJoinTeam( self, self->client->pers.team );
}
void Teamplay_InitTeamplay (void)
{
num_cash_items = 0;
memset( team_cash, 0, sizeof(int) * 3 );
memset( last_safe_withdrawal, 0, sizeof(float) * 3 );
memset( last_safe_deposit, 0, sizeof(float) * 3 );
last_safe_deposit[0] = last_safe_deposit[1] = 0;
last_safe_withdrawal[0] = last_safe_withdrawal[1] = 0;
if (teamplay->value) UpdateScore();
}