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