]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc
Add Team Keepaway, a teamplay variant of Keepaway where points are awarded for each...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / tka / sv_tka.qc
1 #include "sv_tka.qh"
2
3 #include <common/effects/all.qh>
4
5 .entity ballcarried;
6
7 int autocvar_g_tka_ballcarrier_effects;
8 float autocvar_g_tka_ballcarrier_damage;
9 float autocvar_g_tka_ballcarrier_force;
10 float autocvar_g_tka_ballcarrier_highspeed;
11 float autocvar_g_tka_ballcarrier_selfdamage;
12 float autocvar_g_tka_ballcarrier_selfforce;
13 float autocvar_g_tka_noncarrier_damage;
14 float autocvar_g_tka_noncarrier_force;
15 float autocvar_g_tka_noncarrier_selfdamage;
16 float autocvar_g_tka_noncarrier_selfforce;
17 bool autocvar_g_tka_noncarrier_warn;
18 int autocvar_g_tka_score_bckill;
19 int autocvar_g_tka_score_killac;
20 bool autocvar_g_tka_score_team;
21 int autocvar_g_tka_score_timepoints;
22 float autocvar_g_tka_score_timeinterval;
23 float autocvar_g_tkaball_damageforcescale;
24 int autocvar_g_tkaball_effects;
25 float autocvar_g_tkaball_respawntime;
26 int autocvar_g_tkaball_trail_color;
27
28 bool tka_ballcarrier_waypointsprite_visible_for_player(entity this, entity player, entity view) // runs on waypoints which are attached to ballcarriers, updates once per frame
29 {
30         if(view.ballcarried)
31                 if(IS_SPEC(player))
32                         return false; // we don't want spectators of the ballcarrier to see the attached waypoint on the top of their screen
33
34         // TODO: Make the ballcarrier lack a waypointsprite whenever they have the invisibility powerup
35
36         return true;
37 }
38
39 void tka_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
40 {
41         if(autocvar_sv_eventlog)
42                 GameLogEcho(strcat(":tka:", mode, ((actor != NULL) ? (strcat(":", ftos(actor.team), ":", ftos(actor.playerid))) : "")));
43 }
44
45 void tka_TouchEvent(entity this, entity toucher);
46 void tka_RespawnBall(entity this) // runs whenever the ball needs to be relocated
47 {
48         if(game_stopped) return;
49         vector oldballorigin = this.origin;
50
51         if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
52         {
53                 entity spot = SelectSpawnPoint(this, true);
54                 setorigin(this, spot.origin);
55                 this.angles = spot.angles;
56         }
57
58         makevectors(this.angles);
59         set_movetype(this, MOVETYPE_BOUNCE);
60         this.velocity = '0 0 200';
61         this.angles = '0 0 0';
62         this.effects = autocvar_g_tkaball_effects;
63         settouch(this, tka_TouchEvent);
64         setthink(this, tka_RespawnBall);
65         this.nextthink = time + autocvar_g_tkaball_respawntime;
66         navigation_dynamicgoal_set(this, NULL);
67
68         Send_Effect(EFFECT_ELECTRO_COMBO, oldballorigin, '0 0 0', 1);
69         Send_Effect(EFFECT_ELECTRO_COMBO, this.origin, '0 0 0', 1);
70
71         WaypointSprite_Spawn(WP_KaBall, 0, 0, this, '0 0 64', NULL, this.team, this, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
72         WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
73
74         sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
75 }
76
77 void tka_TimeScoring(entity this)
78 {
79         if(this.owner.ballcarried)
80         { // add points for holding the ball after a certain amount of time
81                 if(autocvar_g_tka_score_timepoints)
82                         GameRules_scoring_add_team(this.owner, SCORE, autocvar_g_tka_score_timepoints);
83
84                 GameRules_scoring_add(this.owner, TKA_BCTIME, (autocvar_g_tka_score_timeinterval / 1)); // interval is divided by 1 so that time always shows "seconds"
85                 this.nextthink = time + autocvar_g_tka_score_timeinterval;
86         }
87 }
88
89 void tka_TouchEvent(entity this, entity toucher) // runs any time that the ball comes in contact with something
90 {
91         if (!this || game_stopped)
92                 return;
93
94         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
95         { // The ball fell off the map, respawn it since players can't get to it
96                 tka_RespawnBall(this);
97                 return;
98         }
99         if(toucher.ballcarried) { return; }
100         if(IS_DEAD(toucher)) { return; }
101         if(STAT(FROZEN, toucher)) { return; }
102         if (!IS_PLAYER(toucher))
103         {  // The ball just touched an object, most likely the world
104                 Send_Effect(EFFECT_BALL_SPARKS, this.origin, '0 0 0', 1);
105                 sound(this, CH_TRIGGER, SND_KA_TOUCH, VOL_BASE, ATTEN_NORM);
106                 return;
107         }
108         else if(this.wait > time) { return; }
109
110         // attach the ball to the player
111         this.owner = toucher;
112         toucher.ballcarried = this;
113         GameRules_scoring_vip(toucher, true);
114         setattachment(this, toucher, "");
115         setorigin(this, '0 0 0');
116
117         // make the ball invisible/unable to do anything/set up time scoring
118         this.velocity = '0 0 0';
119         set_movetype(this, MOVETYPE_NONE);
120         this.effects |= EF_NODRAW;
121         settouch(this, func_null);
122         setthink(this, tka_TimeScoring);
123         this.nextthink = time + autocvar_g_tka_score_timeinterval;
124         this.takedamage = DAMAGE_NO;
125         navigation_dynamicgoal_unset(this);
126
127         // apply effects to player
128         toucher.glow_color = autocvar_g_tkaball_trail_color;
129         toucher.glow_trail = true;
130         toucher.effects |= autocvar_g_tka_ballcarrier_effects;
131
132         // messages and sounds
133         tka_EventLog("pickup", toucher);
134         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_KEEPAWAY_PICKUP, toucher.netname);
135         Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_CENTER, CENTER_KEEPAWAY_PICKUP, toucher.netname);
136         Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_KEEPAWAY_PICKUP_SELF);
137         sound(this.owner, CH_TRIGGER, SND_KA_PICKEDUP, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
138
139         // scoring
140         GameRules_scoring_add(toucher, TKA_PICKUPS, 1);
141
142         // waypoints
143         WaypointSprite_AttachCarrier(WP_Null, toucher, RADARICON_FLAGCARRIER);
144         toucher.waypointsprite_attachedforcarrier.colormod = colormapPaletteColor(toucher.team - 1, 0);
145         toucher.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = tka_ballcarrier_waypointsprite_visible_for_player;
146         WaypointSprite_UpdateRule(toucher.waypointsprite_attachedforcarrier, toucher.team, SPRITERULE_TEAMPLAY);
147         if(toucher.team == NUM_TEAM_1)
148                 WaypointSprite_UpdateSprites(toucher.waypointsprite_attachedforcarrier, WP_TkaBallCarrierRed, WP_KaBallCarrier, WP_TkaBallCarrierRed);
149         else if(toucher.team == NUM_TEAM_2)
150                 WaypointSprite_UpdateSprites(toucher.waypointsprite_attachedforcarrier, WP_TkaBallCarrierBlue, WP_KaBallCarrier, WP_TkaBallCarrierBlue);
151         else if(toucher.team == NUM_TEAM_3)
152                 WaypointSprite_UpdateSprites(toucher.waypointsprite_attachedforcarrier, WP_TkaBallCarrierYellow, WP_KaBallCarrier, WP_TkaBallCarrierYellow);
153         else if(toucher.team == NUM_TEAM_4)
154                 WaypointSprite_UpdateSprites(toucher.waypointsprite_attachedforcarrier, WP_TkaBallCarrierPink, WP_KaBallCarrier, WP_TkaBallCarrierPink);
155         WaypointSprite_Ping(toucher.waypointsprite_attachedforcarrier);
156         WaypointSprite_Kill(this.waypointsprite_attachedforcarrier);
157 }
158
159 void tka_PlayerReset(entity player)
160 {
161         player.ballcarried = NULL;
162         GameRules_scoring_vip(player, false);
163         WaypointSprite_Kill(player.waypointsprite_attachedforcarrier);
164
165         // reset the player effects
166         player.glow_trail = false;
167         player.effects &= ~autocvar_g_tka_ballcarrier_effects;
168 }
169
170 void tka_DropEvent(entity player) // runs any time that a player is supposed to lose the ball
171 {
172         entity ball;
173         ball = player.ballcarried;
174
175         if(!ball) { return; }
176
177         // reset the ball
178         setattachment(ball, NULL, "");
179         set_movetype(ball, MOVETYPE_BOUNCE);
180         ball.wait = time + 1;
181         settouch(ball, tka_TouchEvent);
182         setthink(ball, tka_RespawnBall);
183         ball.nextthink = time + autocvar_g_tkaball_respawntime;
184         ball.takedamage = DAMAGE_YES;
185         ball.effects &= ~EF_NODRAW;
186         setorigin(ball, player.origin + '0 0 10');
187         ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
188         ball.owner = NULL;
189         navigation_dynamicgoal_set(ball, player);
190
191         // messages and sounds
192         tka_EventLog("dropped", player);
193         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_KEEPAWAY_DROPPED, player.netname);
194         Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEEPAWAY_DROPPED, player.netname);
195         sound(NULL, CH_TRIGGER, SND_KA_DROPPED, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
196
197         // waypoints
198         WaypointSprite_Spawn(WP_KaBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
199         WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
200         WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
201
202         tka_PlayerReset(player);
203 }
204
205 .bool pushable;
206
207 MODEL(TKA_BALL, "models/orbs/orbblue.md3");
208
209 void tka_RemoveBall(entity ball)
210 {
211         entity player = ball.owner;
212         if (player) // it was attached
213                 tka_PlayerReset(player);
214         else
215                 WaypointSprite_DetachCarrier(ball);
216         delete(ball);
217 }
218
219 void tka_RemoveBalls()
220 {
221         IL_EACH(g_tkaballs, true,
222         {
223                 tka_RemoveBall(it);
224         });
225 }
226
227 void tka_SpawnBall()
228 {
229         entity e = new(keepawayball);
230         setmodel(e, MDL_TKA_BALL);
231         setsize(e, '-16 -16 -20', '16 16 20'); // 20 20 20 was too big, player is only 16 16 24... gotta cheat with the Z (20) axis so that the particle isn't cut off
232         e.damageforcescale = autocvar_g_tkaball_damageforcescale;
233         e.takedamage = DAMAGE_YES;
234         e.solid = SOLID_TRIGGER;
235         set_movetype(e, MOVETYPE_BOUNCE);
236         e.glow_color = autocvar_g_tkaball_trail_color;
237         e.glow_trail = true;
238         e.flags = FL_ITEM;
239         IL_PUSH(g_items, e);
240         e.pushable = true;
241         settouch(e, tka_TouchEvent);
242         e.owner = NULL;
243         IL_PUSH(g_tkaballs, e);
244         navigation_dynamicgoal_init(e, false);
245
246         InitializeEntity(e, tka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So.
247 }
248
249 void tka_SpawnBalls(int ballcount)
250 {
251         int realballcount = max(1, ballcount); // never allow less than 1 ball to spawn
252         for(int j = 0; j < realballcount; ++j)
253         {
254                 tka_SpawnBall();
255         }
256 }
257
258 void tka_Handler_CheckBall(entity this)
259 {
260         if(time < game_starttime)
261         {
262                 if (!IL_EMPTY(g_tkaballs))
263                         tka_RemoveBalls();
264         }
265         else
266         {
267                 if (IL_EMPTY(g_tkaballs))
268                         tka_SpawnBalls(TKA_BALL_COUNT);
269         }
270
271         this.nextthink = time;
272 }
273
274 void tka_DelayedInit(entity this) // run at the start of a match, initiates game mode
275 {
276         g_tkaballs = IL_NEW();
277         tka_Handler = new(tka_Handler);
278         setthink(tka_Handler, tka_Handler_CheckBall);
279         tka_Handler.nextthink = time;
280 }
281
282
283 // ================
284 // Bot player logic
285 // ================
286
287 void havocbot_goalrating_tkaball(entity this, float ratingscale, vector org)
288 {
289         entity ball = NULL, ball_carried = NULL;
290
291         // stops at last ball, prefers ball without carrier
292         IL_EACH(g_tkaballs, it.owner != this && DIFF_TEAM(ball.owner, this),
293         {
294                 if(it.owner)
295                         ball_carried = it.owner;
296                 else
297                         ball = it;
298         });
299
300         if (ball)
301                 navigation_routerating(this, ball, ratingscale, 2000);
302         else if(ball_carried)
303                 navigation_routerating(this, ball_carried, ratingscale, 2000);
304 }
305
306 void havocbot_role_tka_carrier(entity this)
307 {
308         if (IS_DEAD(this))
309                 return;
310
311         if (navigation_goalrating_timeout(this))
312         {
313                 navigation_goalrating_start(this);
314                 havocbot_goalrating_items(this, 10000, this.origin, 10000);
315                 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
316                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
317                 navigation_goalrating_end(this);
318
319                 navigation_goalrating_timeout_set(this);
320         }
321
322         if (!this.ballcarried)
323         {
324                 this.havocbot_role = havocbot_role_tka_collector;
325                 navigation_goalrating_timeout_expire(this, 2);
326         }
327 }
328
329 void havocbot_role_tka_collector(entity this)
330 {
331         if (IS_DEAD(this))
332                 return;
333
334         if (navigation_goalrating_timeout(this))
335         {
336                 navigation_goalrating_start(this);
337                 havocbot_goalrating_items(this, 10000, this.origin, 10000);
338                 havocbot_goalrating_enemyplayers(this, 500, this.origin, 10000);
339                 havocbot_goalrating_tkaball(this, 8000, this.origin);
340                 navigation_goalrating_end(this);
341
342                 navigation_goalrating_timeout_set(this);
343         }
344
345         if (this.ballcarried)
346         {
347                 this.havocbot_role = havocbot_role_tka_carrier;
348                 navigation_goalrating_timeout_expire(this, 2);
349         }
350 }
351
352
353 // ==============
354 // Hook Functions
355 // ==============
356
357 MUTATOR_HOOKFUNCTION(tka, PlayerDies)
358 {
359         entity frag_attacker = M_ARGV(1, entity);
360         entity frag_target = M_ARGV(2, entity);
361
362         if(frag_attacker != frag_target && IS_PLAYER(frag_attacker) && DIFF_TEAM(frag_attacker, frag_target))
363         {
364                 bool team_has_ball = false;
365                 IL_EACH(g_tkaballs, it.owner != frag_attacker && SAME_TEAM(it.owner, frag_attacker),
366                 {
367                         team_has_ball = true;
368                         break;
369                 });
370                 if(frag_target.ballcarried) { // add to amount of times killing carrier
371                         GameRules_scoring_add(frag_attacker, TKA_CARRIERKILLS, 1);
372                         if(autocvar_g_tka_score_bckill) // add bckills to the score
373                                 GameRules_scoring_add_team(frag_attacker, SCORE, autocvar_g_tka_score_bckill);
374                 }
375                 else if(!frag_attacker.ballcarried && !(autocvar_g_tka_score_team && team_has_ball))
376                 {
377                         if(autocvar_g_tka_noncarrier_warn)
378                                 Send_Notification(NOTIF_ONE_ONLY, frag_attacker, MSG_CENTER, CENTER_KEEPAWAY_WARN);
379                 }
380
381                 if(frag_attacker.ballcarried || (autocvar_g_tka_score_team && team_has_ball)) // add to amount of kills while ballcarrier (or if team scoring is enabled)
382                         GameRules_scoring_add_team(frag_attacker, SCORE, autocvar_g_tka_score_killac);
383         }
384
385         if(frag_target.ballcarried) { tka_DropEvent(frag_target); } // a player with the ball has died, drop it
386 }
387
388 MUTATOR_HOOKFUNCTION(tka, GiveFragsForKill)
389 {
390         M_ARGV(2, float) = 0; // no frags counted in keepaway
391         return true; // you deceptive little bugger ;3 This needs to be true in order for this function to even count.
392 }
393
394 MUTATOR_HOOKFUNCTION(tka, Scores_CountFragsRemaining)
395 {
396         // announce remaining frags, but only when timed scoring is off
397         return !autocvar_g_tka_score_timepoints;
398 }
399
400 MUTATOR_HOOKFUNCTION(tka, PlayerPreThink)
401 {
402         entity player = M_ARGV(0, entity);
403
404         // clear the item used for the ball in keepaway
405         STAT(TKA_BALLSTATUS, player) = 0;
406
407         // if the player has the ball, make sure they have the item for it (Used for HUD primarily)
408         if(player.ballcarried)
409                 STAT(TKA_BALLSTATUS, player) |= TKA_BALL_CARRYING;
410
411         IL_EACH(g_tkaballs, true,
412         {
413                 if(!it.owner)
414                         STAT(TKA_BALLSTATUS, player) |= TKA_BALL_DROPPED;
415                 else
416                 {
417                         // TODO: teamless carrier?
418                         switch(it.owner.team)
419                         {
420                                 case NUM_TEAM_1: STAT(TKA_BALLSTATUS, player) |= TKA_BALL_TAKEN_RED; break;
421                                 case NUM_TEAM_2: STAT(TKA_BALLSTATUS, player) |= TKA_BALL_TAKEN_BLUE; break;
422                                 case NUM_TEAM_3: STAT(TKA_BALLSTATUS, player) |= TKA_BALL_TAKEN_YELLOW; break;
423                                 case NUM_TEAM_4: STAT(TKA_BALLSTATUS, player) |= TKA_BALL_TAKEN_PINK; break;
424                         }
425                 }
426         });
427 }
428
429 MUTATOR_HOOKFUNCTION(tka, PlayerUseKey)
430 {
431         entity player = M_ARGV(0, entity);
432
433         if(MUTATOR_RETURNVALUE == 0)
434         if(player.ballcarried)
435         {
436                 tka_DropEvent(player);
437                 return true;
438         }
439 }
440
441 MUTATOR_HOOKFUNCTION(tka, Damage_Calculate) // for changing damage and force values that are applied to players
442 {
443         entity frag_attacker = M_ARGV(1, entity);
444         entity frag_target = M_ARGV(2, entity);
445         float frag_damage = M_ARGV(4, float);
446         vector frag_force = M_ARGV(6, vector);
447
448         // as a gamemode rule, only apply scaling to player versus player combat
449         if(!IS_PLAYER(frag_attacker) || !IS_PLAYER(frag_target))
450                 return;
451
452         if(frag_attacker.ballcarried) // if the attacker is a ballcarrier
453         {
454                 if(frag_target == frag_attacker) // damage done to yourself
455                 {
456                         frag_damage *= autocvar_g_tka_ballcarrier_selfdamage;
457                         frag_force *= autocvar_g_tka_ballcarrier_selfforce;
458                 }
459                 else // damage done to other ballcarriers
460                 {
461                         frag_damage *= autocvar_g_tka_ballcarrier_damage;
462                         frag_force *= autocvar_g_tka_ballcarrier_force;
463                 }
464         }
465         else // if the attacker is a noncarrier
466         {
467                 if(frag_target == frag_attacker) // damage done to yourself
468                 {
469                         frag_damage *= autocvar_g_tka_noncarrier_selfdamage;
470                         frag_force *= autocvar_g_tka_noncarrier_selfforce;
471                 }
472                 else // damage done to other noncarriers
473                 {
474                         frag_damage *= autocvar_g_tka_noncarrier_damage;
475                         frag_force *= autocvar_g_tka_noncarrier_force;
476                 }
477         }
478
479         M_ARGV(4, float) = frag_damage;
480         M_ARGV(6, vector) = frag_force;
481 }
482
483 MUTATOR_HOOKFUNCTION(tka, ClientDisconnect)
484 {
485         entity player = M_ARGV(0, entity);
486
487         if(player.ballcarried) { tka_DropEvent(player); } // a player with the ball has left the match, drop it
488 }
489
490 MUTATOR_HOOKFUNCTION(tka, MakePlayerObserver)
491 {
492         entity player = M_ARGV(0, entity);
493
494         if(player.ballcarried) { tka_DropEvent(player); } // a player with the ball has left the match, drop it
495 }
496
497 MUTATOR_HOOKFUNCTION(tka, PlayerPowerups)
498 {
499         entity player = M_ARGV(0, entity);
500
501         // In the future this hook is supposed to allow me to do some extra stuff with waypointsprites and invisibility powerup
502         // So bare with me until I can fix a certain bug with tka_ballcarrier_waypointsprite_visible_for_player()
503
504         player.effects &= ~autocvar_g_tka_ballcarrier_effects;
505
506         if(player.ballcarried)
507                 player.effects |= autocvar_g_tka_ballcarrier_effects;
508 }
509
510
511 MUTATOR_HOOKFUNCTION(tka, PlayerPhysics_UpdateStats)
512 {
513         entity player = M_ARGV(0, entity);
514         // these automatically reset, no need to worry
515
516         if(player.ballcarried)
517                 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_tka_ballcarrier_highspeed;
518 }
519
520 MUTATOR_HOOKFUNCTION(tka, BotShouldAttack)
521 {
522         entity bot = M_ARGV(0, entity);
523         entity targ = M_ARGV(1, entity);
524
525         // if neither player has ball then don't attack unless the ball is on the ground
526         bool have_held_ball = false, team_has_ball = false;
527         IL_EACH(g_tkaballs, it.owner,
528         {
529                 have_held_ball = true;
530                 if(SAME_TEAM(bot, it.owner))
531                         team_has_ball = true;
532         });
533
534         if(!targ.ballcarried && !bot.ballcarried && have_held_ball && !(autocvar_g_tka_score_team && team_has_ball))
535                 return true;
536 }
537
538 MUTATOR_HOOKFUNCTION(tka, HavocBot_ChooseRole)
539 {
540         entity bot = M_ARGV(0, entity);
541
542         if (bot.ballcarried)
543                 bot.havocbot_role = havocbot_role_tka_carrier;
544         else
545                 bot.havocbot_role = havocbot_role_tka_collector;
546         return true;
547 }
548
549 MUTATOR_HOOKFUNCTION(tka, DropSpecialItems)
550 {
551         entity frag_target = M_ARGV(0, entity);
552
553         if(frag_target.ballcarried)
554                 tka_DropEvent(frag_target);
555 }
556
557 MUTATOR_HOOKFUNCTION(tka, SpectateCopy)
558 {
559         entity spectatee = M_ARGV(0, entity);
560         entity client = M_ARGV(1, entity);
561
562         STAT(TKA_BALLSTATUS, client) = STAT(TKA_BALLSTATUS, spectatee);
563 }
564
565 MUTATOR_HOOKFUNCTION(tka, TeamBalance_CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
566 {
567         M_ARGV(0, float) = tka_teams;
568         return true;
569 }
570
571 void tka_Initialize()
572 {
573         tka_teams = autocvar_g_tka_teams_override;
574         if(tka_teams < 2)
575                 tka_teams = cvar("g_tka_teams"); // read the cvar directly as it gets written earlier in the same frame
576         tka_teams = BITS(bound(2, tka_teams, 4));
577         GameRules_scoring(tka_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
578                 field(SP_TKA_PICKUPS, "pickups", 0);
579                 field(SP_TKA_CARRIERKILLS, "bckills", 0);
580                 field(SP_TKA_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY);
581         });
582
583         InitializeEntity(NULL, tka_DelayedInit, INITPRIO_GAMETYPE);
584 }