Xonotic
sv_keyhunt.qc
Go to the documentation of this file.
1 #include "sv_keyhunt.qh"
2 
3 #include <server/command/vote.qh>
4 #include <server/gamelog.qh>
5 #include <server/damage.qh>
6 #include <server/items/items.qh>
8 
19 
27 
28 //int autocvar_g_keyhunt_teams;
30 
31 // #define KH_PLAYER_USE_ATTACHMENT
32 // TODO? no model exists for this
33 // #define KH_PLAYER_USE_CARRIEDMODEL
34 
35 #ifdef KH_PLAYER_USE_ATTACHMENT
36 const vector KH_PLAYER_ATTACHMENT_DIST_ROTATED = '0 -4 0';
37 const vector KH_PLAYER_ATTACHMENT_DIST = '4 0 0';
38 const vector KH_PLAYER_ATTACHMENT = '0 0 0';
39 const vector KH_PLAYER_ATTACHMENT_ANGLES = '0 0 0';
40 const string KH_PLAYER_ATTACHMENT_BONE = "";
41 #else
42 const float KH_KEY_ZSHIFT = 22;
43 const float KH_KEY_XYDIST = 24;
44 const float KH_KEY_XYSPEED = 45;
45 #endif
46 const float KH_KEY_WP_ZSHIFT = 20;
47 
48 const vector KH_KEY_MIN = '-10 -10 -46';
49 const vector KH_KEY_MAX = '10 10 3';
50 const float KH_KEY_BRIGHTNESS = 2;
51 
53 
54 // kh_state
55 // bits 0- 4: team of key 1, or 0 for no such key, or 30 for dropped, or 31 for self
56 // bits 5- 9: team of key 2, or 0 for no such key, or 30 for dropped, or 31 for self
57 // bits 10-14: team of key 3, or 0 for no such key, or 30 for dropped, or 31 for self
58 // bits 15-19: team of key 4, or 0 for no such key, or 30 for dropped, or 31 for self
59 .float siren_time; // time delay the siren
60 //.float stuff_time; // time delay to stuffcmd a cvar
61 
62 int kh_Team_ByID(int t)
63 {
64  if(t == 0) return NUM_TEAM_1;
65  if(t == 1) return NUM_TEAM_2;
66  if(t == 2) return NUM_TEAM_3;
67  if(t == 3) return NUM_TEAM_4;
68  return 0;
69 }
70 
72 //bool kh_tracking_enabled;
76 .entity kh_next, kh_prev; // linked list
77 .float kh_droptime;
81 
83 
85 
86 const int ST_KH_CAPS = 1;
88 {
90  field_team(ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
91  field(SP_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
92  field(SP_KH_PUSHES, "pushes", 0);
93  field(SP_KH_DESTROYS, "destroyed", SFL_LOWER_IS_BETTER);
94  field(SP_KH_PICKUPS, "pickups", 0);
95  field(SP_KH_KCKILLS, "kckills", 0);
96  field(SP_KH_LOSSES, "losses", SFL_LOWER_IS_BETTER);
97  });
98 }
99 
100 bool kh_KeyCarrier_waypointsprite_visible_for_player(entity this, entity player, entity view) // runs all the time
101 {
102  if(!IS_PLAYER(view) || DIFF_TEAM(this, view))
104  return false;
105 
106  return true;
107 }
108 
110 {
112  return false;
113  if(!this.owner)
114  return true;
115  if(!this.owner.owner)
116  return true;
117  return false; // draw only when key is not owned
118 }
119 
121 {
122  entity key;
123  int f;
124  int s = 0;
125  FOR_EACH_KH_KEY(key)
126  {
127  if(key.owner)
128  f = key.team;
129  else
130  f = 30;
131  s |= (32 ** key.count) * f;
132  }
133 
134  FOREACH_CLIENT(true, { STAT(OBJECTIVE_STATUS, it) = s; });
135 
136  FOR_EACH_KH_KEY(key)
137  {
138  if(key.owner)
139  STAT(OBJECTIVE_STATUS, key.owner) |= (32 ** key.count) * 31;
140  }
141  //print(ftos((nextent(NULL)).kh_state), "\n");
142 }
143 
144 
145 
146 
148 void kh_Controller_SetThink(float t, kh_Think_t func) // runs occasionaly
149 {
151  kh_controller.cnt = ceil(t);
152  if(t == 0)
153  kh_controller.nextthink = time; // force
154 }
155 void kh_WaitForPlayers();
156 void kh_Controller_Think(entity this) // called a lot
157 {
158  if(game_stopped)
159  return;
160  if(this.cnt > 0)
161  {
162  if(getthink(this) != kh_WaitForPlayers)
163  this.cnt -= 1;
164  }
165  else if(this.cnt == 0)
166  {
167  this.cnt -= 1;
169  }
170  this.nextthink = time + 1;
171 }
172 
173 // frags f: take from cvar * f
174 // frags 0: no frags
175 void kh_Scores_Event(entity player, entity key, string what, float frags_player, float frags_owner) // update the score when a key is captured
176 {
177  string s;
178  if(game_stopped)
179  return;
180 
181  if(frags_player)
182  UpdateFrags(player, frags_player);
183 
184  if(key && key.owner && frags_owner)
185  UpdateFrags(key.owner, frags_owner);
186 
187  if(!autocvar_sv_eventlog) //output extra info to the console or text file
188  return;
189 
190  s = strcat(":keyhunt:", what, ":", ftos(player.playerid), ":", ftos(frags_player));
191 
192  if(key && key.owner)
193  s = strcat(s, ":", ftos(key.owner.playerid));
194  else
195  s = strcat(s, ":0");
196 
197  s = strcat(s, ":", ftos(frags_owner), ":");
198 
199  if(key)
200  s = strcat(s, key.netname);
201 
202  GameLogEcho(s);
203 }
204 
205 vector kh_AttachedOrigin(entity e) // runs when a team captures the flag, it can run 2 or 3 times.
206 {
207  if(e.tag_entity)
208  {
209  makevectors(e.tag_entity.angles);
210  return e.tag_entity.origin + e.origin.x * v_forward - e.origin.y * v_right + e.origin.z * v_up;
211  }
212  else
213  return e.origin;
214 }
215 
216 void kh_Key_Attach(entity key) // runs when a player picks up a key and several times when a key is assigned to a player at the start of a round
217 {
218 #ifdef KH_PLAYER_USE_ATTACHMENT
219  entity first = key.owner.kh_next;
220  if(key == first)
221  {
222  setattachment(key, key.owner, KH_PLAYER_ATTACHMENT_BONE);
223  if(key.kh_next)
224  {
225  setattachment(key.kh_next, key, "");
226  setorigin(key, key.kh_next.origin - 0.5 * KH_PLAYER_ATTACHMENT_DIST);
227  setorigin(key.kh_next, KH_PLAYER_ATTACHMENT_DIST_ROTATED);
228  key.kh_next.angles = '0 0 0';
229  }
230  else
231  setorigin(key, KH_PLAYER_ATTACHMENT);
232  key.angles = KH_PLAYER_ATTACHMENT_ANGLES;
233  }
234  else
235  {
236  setattachment(key, key.kh_prev, "");
237  if(key.kh_next)
238  setattachment(key.kh_next, key, "");
239  setorigin(key, KH_PLAYER_ATTACHMENT_DIST_ROTATED);
240  setorigin(first, first.origin - 0.5 * KH_PLAYER_ATTACHMENT_DIST);
241  key.angles = '0 0 0';
242  }
243 #else
244  setattachment(key, key.owner, "");
245  setorigin(key, '0 0 1' * KH_KEY_ZSHIFT); // fixing x, y in think
246  key.angles_y -= key.owner.angles.y;
247 #endif
248  key.flags = 0;
249  if(IL_CONTAINS(g_items, key))
250  IL_REMOVE(g_items, key);
251  key.solid = SOLID_NOT;
253  key.team = key.owner.team;
254  key.nextthink = time;
255  key.damageforcescale = 0;
256  key.takedamage = DAMAGE_NO;
257  key.modelindex = kh_key_carried;
259 }
260 
261 void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs several times times when all the keys are captured
262 {
263 #ifdef KH_PLAYER_USE_ATTACHMENT
264  entity first = key.owner.kh_next;
265  if(key == first)
266  {
267  if(key.kh_next)
268  {
269  setattachment(key.kh_next, key.owner, KH_PLAYER_ATTACHMENT_BONE);
270  setorigin(key.kh_next, key.origin + 0.5 * KH_PLAYER_ATTACHMENT_DIST);
271  key.kh_next.angles = KH_PLAYER_ATTACHMENT_ANGLES;
272  }
273  }
274  else
275  {
276  if(key.kh_next)
277  setattachment(key.kh_next, key.kh_prev, "");
278  setorigin(first, first.origin + 0.5 * KH_PLAYER_ATTACHMENT_DIST);
279  }
280  // in any case:
281  setattachment(key, NULL, "");
282  setorigin(key, key.owner.origin + '0 0 1' * (STAT(PL_MIN, key.owner).z - KH_KEY_MIN_z));
283  key.angles = key.owner.angles;
284 #else
285  setorigin(key, key.owner.origin + key.origin.z * '0 0 1');
286  setattachment(key, NULL, "");
287  key.angles_y += key.owner.angles.y;
288 #endif
289  key.flags = FL_ITEM;
290  if(!IL_CONTAINS(g_items, key))
291  IL_PUSH(g_items, key);
292  key.solid = SOLID_TRIGGER;
294  key.pain_finished = time + autocvar_g_balance_keyhunt_delay_return;
295  key.damageforcescale = autocvar_g_balance_keyhunt_damageforcescale;
296  key.takedamage = DAMAGE_YES;
297  // let key.team stay
298  key.modelindex = kh_key_dropped;
299  navigation_dynamicgoal_set(key, key.owner);
300  key.kh_previous_owner = key.owner;
301  key.kh_previous_owner_playerid = key.owner.playerid;
302 }
303 
304 void kh_Key_AssignTo(entity key, entity player) // runs every time a key is picked up or assigned. Runs prior to kh_key_attach
305 {
306  if(key.owner == player)
307  return;
308 
309  int ownerteam0 = kh_Key_AllOwnedByWhichTeam();
310 
311  if(key.owner)
312  {
313  kh_Key_Detach(key);
314 
315  // remove from linked list
316  if(key.kh_next)
317  key.kh_next.kh_prev = key.kh_prev;
318  key.kh_prev.kh_next = key.kh_next;
319  key.kh_next = NULL;
320  key.kh_prev = NULL;
321 
322  if(key.owner.kh_next == NULL)
323  {
324  // No longer a key carrier
326  WaypointSprite_Ping(key.owner.waypointsprite_attachedforcarrier);
327  WaypointSprite_DetachCarrier(key.owner);
328  }
329  }
330 
331  key.owner = player;
332 
333  if(player)
334  {
335  // insert into linked list
336  key.kh_next = player.kh_next;
337  key.kh_prev = player;
338  player.kh_next = key;
339  if(key.kh_next)
340  key.kh_next.kh_prev = key;
341 
342  kh_Key_Attach(key);
343 
344  if(key.kh_next == NULL)
345  {
346  // player is now a key carrier
347  entity wp = WaypointSprite_AttachCarrier(WP_Null, player, RADARICON_FLAGCARRIER);
348  wp.colormod = colormapPaletteColor(player.team - 1, 0);
349  player.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_KeyCarrier_waypointsprite_visible_for_player;
350  WaypointSprite_UpdateRule(player.waypointsprite_attachedforcarrier, player.team, SPRITERULE_TEAMPLAY);
351  if(player.team == NUM_TEAM_1)
352  WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, WP_KeyCarrierRed, WP_KeyCarrierFriend, WP_KeyCarrierRed);
353  else if(player.team == NUM_TEAM_2)
354  WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, WP_KeyCarrierBlue, WP_KeyCarrierFriend, WP_KeyCarrierBlue);
355  else if(player.team == NUM_TEAM_3)
356  WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, WP_KeyCarrierYellow, WP_KeyCarrierFriend, WP_KeyCarrierYellow);
357  else if(player.team == NUM_TEAM_4)
358  WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, WP_KeyCarrierPink, WP_KeyCarrierFriend, WP_KeyCarrierPink);
360  WaypointSprite_Ping(player.waypointsprite_attachedforcarrier);
361  }
362  }
363 
364  // moved that here, also update if there's no player
365  kh_update_state();
366 
367  key.pusher = NULL;
368 
369  int ownerteam = kh_Key_AllOwnedByWhichTeam();
370  if(ownerteam != ownerteam0)
371  {
372  entity k;
373  if(ownerteam != -1)
374  {
375  kh_interferemsg_time = time + 0.2;
376  kh_interferemsg_team = player.team;
377 
378  // audit all key carrier sprites, update them to "Run here"
379  FOR_EACH_KH_KEY(k)
380  {
381  if (!k.owner) continue;
382  entity first = WP_Null;
383  FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, { first = it; break; });
384  entity third = WP_Null;
385  FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, { third = it; break; });
386  WaypointSprite_UpdateSprites(k.owner.waypointsprite_attachedforcarrier, first, WP_KeyCarrierFinish, third);
387  }
388  }
389  else
390  {
392 
393  // audit all key carrier sprites, update them to "Key Carrier"
394  FOR_EACH_KH_KEY(k)
395  {
396  if (!k.owner) continue;
397  entity first = WP_Null;
398  FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, { first = it; break; });
399  entity third = WP_Null;
400  FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, { third = it; break; });
401  WaypointSprite_UpdateSprites(k.owner.waypointsprite_attachedforcarrier, first, WP_KeyCarrierFriend, third);
402  }
403  }
404  }
405 }
406 
407 void kh_Key_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
408 {
409  if(this.owner)
410  return;
411  if(ITEM_DAMAGE_NEEDKILL(deathtype))
412  {
414  return;
415  }
416  if(force == '0 0 0')
417  return;
418  if(time > this.pushltime)
419  if(IS_PLAYER(attacker))
420  this.team = attacker.team;
421 }
422 
423 void kh_Key_Collect(entity key, entity player) //a player picks up a dropped key
424 {
425  sound(player, CH_TRIGGER, SND_KH_COLLECT, VOL_BASE, ATTEN_NORM);
426 
427  if(key.kh_dropperteam != player.team)
428  {
429  kh_Scores_Event(player, key, "collect", autocvar_g_balance_keyhunt_score_collect, 0);
430  GameRules_scoring_add(player, KH_PICKUPS, 1);
431  }
432  key.kh_dropperteam = 0;
433  int realteam = kh_Team_ByID(key.count);
434  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_PICKUP), player.netname);
435 
436  kh_Key_AssignTo(key, player); // this also updates .kh_state
437 }
438 
439 void kh_Key_Touch(entity this, entity toucher) // runs many, many times when a key has been dropped and can be picked up
440 {
441  if(game_stopped)
442  return;
443 
444  if(this.owner) // already carried
445  return;
446 
447  if(ITEM_TOUCH_NEEDKILL())
448  {
450  return;
451  }
452 
453  if (!IS_PLAYER(toucher))
454  return;
455  if(IS_DEAD(toucher))
456  return;
457  if(toucher == this.enemy)
459  return; // you just dropped it!
460  kh_Key_Collect(this, toucher);
461 }
462 
463 void kh_Key_Remove(entity key) // runs after when all the keys have been collected or when a key has been dropped for more than X seconds
464 {
465  entity o = key.owner;
466  kh_Key_AssignTo(key, NULL);
467  if(o) // it was attached
468  WaypointSprite_Kill(key.waypointsprite_attachedforcarrier);
469  else // it was dropped
470  WaypointSprite_DetachCarrier(key);
471 
472  // remove key from key list
473  if (kh_worldkeylist == key)
474  kh_worldkeylist = kh_worldkeylist.kh_worldkeynext;
475  else
476  {
477  o = kh_worldkeylist;
478  while (o)
479  {
480  if (o.kh_worldkeynext == key)
481  {
482  o.kh_worldkeynext = o.kh_worldkeynext.kh_worldkeynext;
483  break;
484  }
485  o = o.kh_worldkeynext;
486  }
487  }
488 
489  delete(key);
490 
491  kh_update_state();
492 }
493 
494 void kh_FinishRound() // runs when a team captures the keys
495 {
496  // prepare next round
498  entity key;
499 
500  kh_no_radar_circles = true;
501  FOR_EACH_KH_KEY(key)
502  kh_Key_Remove(key);
503  kh_no_radar_circles = false;
504 
505  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
507 }
508 
509 void nades_GiveBonus(entity player, float score);
510 
511 void kh_WinnerTeam(int winner_team) // runs when a team wins
512 {
513  // all key carriers get some points
514  entity key;
517  // twice the score for 3 team games, three times the score for 4 team games!
518  // note: for a win by destroying the key, this should NOT be applied
519  FOR_EACH_KH_KEY(key)
520  {
521  float f = DistributeEvenly_Get(1);
522  kh_Scores_Event(key.owner, key, "capture", f, 0);
523  GameRules_scoring_add_team(key.owner, KH_CAPS, 1);
524  nades_GiveBonus(key.owner, autocvar_g_nades_bonus_score_high);
525  }
526 
527  bool first = true;
528  string keyowner = "";
529  FOR_EACH_KH_KEY(key)
530  if(key.owner.kh_next == key)
531  {
532  if(!first)
533  keyowner = strcat(keyowner, ", ");
534  keyowner = key.owner.netname;
535  first = false;
536  }
537 
538  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
539  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_KEYHUNT_CAPTURE), keyowner);
540 
541  first = true;
542  vector firstorigin = '0 0 0', lastorigin = '0 0 0', midpoint = '0 0 0';
543  FOR_EACH_KH_KEY(key)
544  {
545  vector thisorigin = kh_AttachedOrigin(key);
546  //dprint("Key origin: ", vtos(thisorigin), "\n");
547  midpoint += thisorigin;
548 
549  if(!first)
550  {
551  // TODO: this effect has been replaced due to a possible crash it causes
552  // see https://gitlab.com/xonotic/darkplaces/issues/123
553  //te_lightning2(NULL, lastorigin, thisorigin);
554  Send_Effect(EFFECT_TR_NEXUIZPLASMA, lastorigin, thisorigin, 1);
555  }
556  lastorigin = thisorigin;
557  if(first)
558  firstorigin = thisorigin;
559  first = false;
560  }
561  if(NumTeams(kh_teams) > 2)
562  {
563  //te_lightning2(NULL, lastorigin, firstorigin); // TODO see above
564  Send_Effect(EFFECT_TR_NEXUIZPLASMA, lastorigin, firstorigin, 1);
565  }
566  midpoint = midpoint * (1 / NumTeams(kh_teams));
567  te_customflash(midpoint, 1000, 1, Team_ColorRGB(winner_team) * 0.5 + '0.5 0.5 0.5'); // make the color >=0.5 in each component
568 
569  play2all(SND(KH_CAPTURE));
570  kh_FinishRound();
571 }
572 
573 void kh_LoserTeam(int loser_team, entity lostkey) // runs when a player pushes a flag carrier off the map
574 {
575  float f;
576  entity attacker = NULL;
577  if(lostkey.pusher)
578  if(lostkey.pusher.team != loser_team)
579  if(IS_PLAYER(lostkey.pusher))
580  attacker = lostkey.pusher;
581 
582  if(attacker)
583  {
584  if(lostkey.kh_previous_owner)
585  kh_Scores_Event(lostkey.kh_previous_owner, NULL, "pushed", 0, -autocvar_g_balance_keyhunt_score_push);
586  // don't actually GIVE him the -nn points, just log
588  GameRules_scoring_add(attacker, KH_PUSHES, 1);
589  //centerprint(attacker, "Your push is the best!"); // does this really need to exist?
590  }
591  else
592  {
593  int players = 0;
595 
596  FOREACH_CLIENT(IS_PLAYER(it) && it.team != loser_team, { ++players; });
597 
598  entity key;
599  int keys = 0;
600  FOR_EACH_KH_KEY(key)
601  if(key.owner && key.team != loser_team)
602  ++keys;
603 
604  if(lostkey.kh_previous_owner)
605  kh_Scores_Event(lostkey.kh_previous_owner, NULL, "destroyed", 0, -autocvar_g_balance_keyhunt_score_destroyed);
606  // don't actually GIVE him the -nn points, just log
607 
608  if(lostkey.kh_previous_owner.playerid == lostkey.kh_previous_owner_playerid)
609  GameRules_scoring_add(lostkey.kh_previous_owner, KH_DESTROYS, 1);
610 
612 
613  FOR_EACH_KH_KEY(key)
614  if(key.owner && key.team != loser_team)
615  {
616  f = DistributeEvenly_Get(of);
617  kh_Scores_Event(key.owner, NULL, "destroyed_holdingkey", f, 0);
618  }
619 
620  int fragsleft = DistributeEvenly_Get(players);
621 
622  // Now distribute these among all other teams...
623  int j = NumTeams(kh_teams) - 1;
624  for(int i = 0; i < NumTeams(kh_teams); ++i)
625  {
626  int thisteam = kh_Team_ByID(i);
627  if(thisteam == loser_team) // bad boy, no cookie - this WILL happen
628  continue;
629 
630  players = 0;
631  FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, { ++players; });
632 
633  DistributeEvenly_Init(fragsleft, j);
634  fragsleft = DistributeEvenly_Get(j - 1);
636 
637  FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, {
638  f = DistributeEvenly_Get(1);
639  kh_Scores_Event(it, NULL, "destroyed", f, 0);
640  });
641 
642  --j;
643  }
644  }
645 
646  int realteam = kh_Team_ByID(lostkey.count);
647  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(loser_team, CENTER_ROUND_TEAM_LOSS));
648  if(attacker)
649  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_PUSHED), attacker.netname, lostkey.kh_previous_owner.netname);
650  else
651  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_DESTROYED), lostkey.kh_previous_owner.netname);
652 
653  play2all(SND(KH_DESTROY));
654  te_tarexplosion(lostkey.origin);
655 
656  kh_FinishRound();
657 }
658 
659 void kh_Key_Think(entity this) // runs all the time
660 {
661  if(game_stopped)
662  return;
663 
664  if(this.owner)
665  {
666 #ifndef KH_PLAYER_USE_ATTACHMENT
667  makevectors('0 1 0' * (this.cnt + (time % 360) * KH_KEY_XYSPEED));
668  setorigin(this, v_forward * KH_KEY_XYDIST + '0 0 1' * this.origin.z);
669 #endif
670  }
671 
672  // if in nodrop or time over, end the round
673  if(!this.owner)
674  if(time > this.pain_finished)
675  kh_LoserTeam(this.team, this);
676 
677  if(this.owner)
678  if(kh_Key_AllOwnedByWhichTeam() != -1)
679  {
680  if(this.siren_time < time)
681  {
682  sound(this.owner, CH_TRIGGER, SND_KH_ALARM, VOL_BASE, ATTEN_NORM); // play a simple alarm
683  this.siren_time = time + 2.5; // repeat every 2.5 seconds
684  }
685 
686  entity key;
687  vector p = this.owner.origin;
688  FOR_EACH_KH_KEY(key)
689  if(vdist(key.owner.origin - p, >, autocvar_g_balance_keyhunt_maxdist))
690  goto not_winning;
691  kh_WinnerTeam(this.team);
692 LABEL(not_winning)
693  }
694 
696  {
699  if(it.team == kh_interferemsg_team)
700  {
701  if(it.kh_next)
702  Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_MEET);
703  else
704  Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_HELP);
705  }
706  else
707  Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(kh_interferemsg_team, CENTER_KEYHUNT_INTERFERE));
708  });
709  }
710 
711  this.nextthink = time + 0.05;
712 }
713 
714 void key_reset(entity this)
715 {
716  kh_Key_AssignTo(this, NULL);
717  kh_Key_Remove(this);
718 }
719 
720 void kh_Key_Spawn(entity initial_owner, float _angle, float i) // runs every time a new flag is created, ie after all the keys have been collected
721 {
722  entity key = new(item_kh_key);
723  key.count = i;
724  settouch(key, kh_Key_Touch);
725  setthink(key, kh_Key_Think);
726  key.nextthink = time;
727  key.cnt = _angle;
728  key.angles = '0 360 0' * random();
729  key.event_damage = kh_Key_Damage;
730  key.takedamage = DAMAGE_YES;
733  key.modelindex = kh_key_dropped;
734  key.model = "key";
735  key.kh_dropperteam = 0;
737  setsize(key, KH_KEY_MIN, KH_KEY_MAX);
738  key.colormod = Team_ColorRGB(initial_owner.team) * KH_KEY_BRIGHTNESS;
739  key.reset = key_reset;
740  navigation_dynamicgoal_init(key, false);
741 
742  switch(initial_owner.team)
743  {
744  case NUM_TEAM_1:
745  key.netname = "^1red key";
746  break;
747  case NUM_TEAM_2:
748  key.netname = "^4blue key";
749  break;
750  case NUM_TEAM_3:
751  key.netname = "^3yellow key";
752  break;
753  case NUM_TEAM_4:
754  key.netname = "^6pink key";
755  break;
756  default:
757  key.netname = "NETGIER key";
758  break;
759  }
760 
761  // link into key list
762  key.kh_worldkeynext = kh_worldkeylist;
763  kh_worldkeylist = key;
764 
765  Send_Notification(NOTIF_ONE, initial_owner, MSG_CENTER, APP_TEAM_NUM(initial_owner.team, CENTER_KEYHUNT_START));
766 
767  WaypointSprite_Spawn(WP_KeyDropped, 0, 0, key, '0 0 1' * KH_KEY_WP_ZSHIFT, NULL, key.team, key, waypointsprite_attachedforcarrier, false, RADARICON_FLAG);
768  key.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_Key_waypointsprite_visible_for_player;
769 
770  kh_Key_AssignTo(key, initial_owner);
771 }
772 
773 // -1 when no team completely owns all keys yet
774 int kh_Key_AllOwnedByWhichTeam() // constantly called. check to see if all the keys are owned by the same team
775 {
776  entity key;
777  int teem = -1;
778  int keys = NumTeams(kh_teams);
779  FOR_EACH_KH_KEY(key)
780  {
781  if(!key.owner)
782  return -1;
783  if(teem == -1)
784  teem = key.team;
785  else if(teem != key.team)
786  return -1;
787  --keys;
788  }
789  if(keys != 0)
790  return -1;
791  return teem;
792 }
793 
795 {
796  // prevent collecting this one for some time
797  entity player = key.owner;
798 
799  key.kh_droptime = time;
800  key.enemy = player;
801 
802  kh_Scores_Event(player, key, "dropkey", 0, 0);
803  GameRules_scoring_add(player, KH_LOSSES, 1);
804  int realteam = kh_Team_ByID(key.count);
805  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_DROP), player.netname);
806 
807  kh_Key_AssignTo(key, NULL);
808  makevectors(player.v_angle);
809  key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, false);
810  key.pusher = NULL;
812  key.kh_dropperteam = key.team;
813 
814  sound(player, CH_TRIGGER, SND_KH_DROP, VOL_BASE, ATTEN_NORM);
815 }
816 
817 void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
818 {
819  if(player.kh_next)
820  {
821  entity mypusher = NULL;
822  if(player.pusher)
823  if(time < player.pushltime)
824  mypusher = player.pusher;
825 
826  entity key;
827  while((key = player.kh_next))
828  {
829  kh_Scores_Event(player, key, "losekey", 0, 0);
830  GameRules_scoring_add(player, KH_LOSSES, 1);
831  int realteam = kh_Team_ByID(key.count);
832  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_LOST), player.netname);
833  kh_Key_AssignTo(key, NULL);
834  makevectors('-1 0 0' * (45 + 45 * random()) + '0 360 0' * random());
835  key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_dropvelocity * v_forward, false);
836  key.pusher = mypusher;
838  if(suicide)
839  key.kh_dropperteam = player.team;
840  }
841  sound(player, CH_TRIGGER, SND_KH_DROP, VOL_BASE, ATTEN_NORM);
842  }
843 }
844 
846 {
847  int missing_teams = 0;
848  for(int i = 0; i < NumTeams(kh_teams); ++i)
849  {
850  int teem = kh_Team_ByID(i);
851  int players = 0;
853  if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem)
854  ++players;
855  });
856  if (!players)
857  missing_teams |= BIT(i);
858  }
859  return missing_teams;
860 }
861 
862 void kh_WaitForPlayers() // delay start of the round until enough players are present
863 {
864  static int prev_missing_teams_mask;
865  if(time < game_starttime)
866  {
867  if (prev_missing_teams_mask > 0)
868  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
869  prev_missing_teams_mask = -1;
870  kh_Controller_SetThink(game_starttime - time + 0.1, kh_WaitForPlayers);
871  return;
872  }
873 
874  int missing_teams_mask = kh_GetMissingTeams();
875  if(!missing_teams_mask)
876  {
877  if(prev_missing_teams_mask > 0)
878  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
879  prev_missing_teams_mask = -1;
880  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
882  }
883  else
884  {
885  if(player_count == 0)
886  {
887  if(prev_missing_teams_mask > 0)
888  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
889  prev_missing_teams_mask = -1;
890  }
891  else
892  {
893  if(prev_missing_teams_mask != missing_teams_mask)
894  {
895  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
896  prev_missing_teams_mask = missing_teams_mask;
897  }
898  }
900  }
901 }
902 
903 void kh_EnableTrackingDevice() // runs after each round
904 {
905  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT);
906  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT_OTHER);
907 
908  kh_tracking_enabled = true;
909 }
910 
911 void kh_StartRound() // runs at the start of each round
912 {
913  if(time < game_starttime)
914  {
915  kh_Controller_SetThink(game_starttime - time + 0.1, kh_WaitForPlayers);
916  return;
917  }
918 
919  if(kh_GetMissingTeams())
920  {
922  return;
923  }
924 
925  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT);
926  Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT_OTHER);
927 
928  for(int i = 0; i < NumTeams(kh_teams); ++i)
929  {
930  int teem = kh_Team_ByID(i);
931  int players = 0;
932  entity my_player = NULL;
934  if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem)
935  {
936  ++players;
937  if(random() * players <= 1)
938  my_player = it;
939  }
940  });
941  kh_Key_Spawn(my_player, 360 * i / NumTeams(kh_teams), i);
942  }
943 
944  kh_tracking_enabled = false;
945  Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_SCAN, autocvar_g_balance_keyhunt_delay_tracking);
947 }
948 
949 float kh_HandleFrags(entity attacker, entity targ, float f) // adds to the player score
950 {
951  if(attacker == targ)
952  return f;
953 
954  if(targ.kh_next)
955  {
956  if(attacker.team == targ.team)
957  {
958  int nk = 0;
959  for(entity k = targ.kh_next; k != NULL; k = k.kh_next)
960  ++nk;
961  kh_Scores_Event(attacker, targ.kh_next, "carrierfrag", -nk * autocvar_g_balance_keyhunt_score_collect, 0);
962  }
963  else
964  {
965  kh_Scores_Event(attacker, targ.kh_next, "carrierfrag", autocvar_g_balance_keyhunt_score_carrierfrag-1, 0);
966  GameRules_scoring_add(attacker, KH_KCKILLS, 1);
967  // the frag gets added later
968  }
969  }
970 
971  return f;
972 }
973 
974 void kh_Initialize() // sets up th KH environment
975 {
976  // setup variables
978  if(kh_teams < 2)
979  kh_teams = cvar("g_keyhunt_teams"); // read the cvar directly as it gets written earlier in the same frame
980  kh_teams = BITS(bound(2, kh_teams, 4));
981 
982  // make a KH entity for controlling the game
986 
987  setmodel(kh_controller, MDL_KH_KEY);
988  kh_key_dropped = kh_controller.modelindex;
989  /*
990  dprint(vtos(kh_controller.mins));
991  dprint(vtos(kh_controller.maxs));
992  dprint("\n");
993  */
994 #ifdef KH_PLAYER_USE_CARRIEDMODEL
995  setmodel(kh_controller, MDL_KH_KEY_CARRIED);
996  kh_key_carried = kh_controller.modelindex;
997 #else
999 #endif
1000 
1001  kh_controller.model = "";
1002  kh_controller.modelindex = 0;
1003 
1005 }
1006 
1008 {
1009  // to be called before intermission
1010  kh_FinishRound();
1011  delete(kh_controller);
1012  kh_controller = NULL;
1013 }
1014 
1015 // legacy bot role
1016 
1021 
1022 
1023 void havocbot_goalrating_kh(entity this, float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
1024 {
1025  entity head;
1026  for (head = kh_worldkeylist; head; head = head.kh_worldkeynext)
1027  {
1028  if(head.owner == this)
1029  continue;
1030  if(!kh_tracking_enabled)
1031  {
1032  // if it's carried by our team we know about it
1033  // otherwise we have to see it to know about it
1034  if(!head.owner || head.team != this.team)
1035  {
1036  traceline(this.origin + this.view_ofs, head.origin, MOVE_NOMONSTERS, this);
1037  if (trace_fraction < 1 && trace_ent != head)
1038  continue; // skip what I can't see
1039  }
1040  }
1041  if(!head.owner)
1042  navigation_routerating(this, head, ratingscale_dropped * 10000, 100000);
1043  else if(head.team == this.team)
1044  navigation_routerating(this, head.owner, ratingscale_team * 10000, 100000);
1045  else
1046  navigation_routerating(this, head.owner, ratingscale_enemy * 10000, 100000);
1047  }
1048 
1049  havocbot_goalrating_items(this, 80000, this.origin, 10000);
1050 }
1051 
1053 {
1054  if(IS_DEAD(this))
1055  return;
1056 
1057  if (!(this.kh_next))
1058  {
1059  LOG_TRACE("changing role to freelancer");
1060  this.havocbot_role = havocbot_role_kh_freelancer;
1061  this.havocbot_role_timeout = 0;
1062  return;
1063  }
1064 
1066  {
1068 
1069  if(kh_Key_AllOwnedByWhichTeam() == this.team)
1070  havocbot_goalrating_kh(this, 10, 0.1, 0.05); // bring home
1071  else
1072  havocbot_goalrating_kh(this, 4, 4, 0.5); // play defensively
1073 
1075 
1077  }
1078 }
1079 
1081 {
1082  if(IS_DEAD(this))
1083  return;
1084 
1085  if (this.kh_next)
1086  {
1087  LOG_TRACE("changing role to carrier");
1088  this.havocbot_role = havocbot_role_kh_carrier;
1089  this.havocbot_role_timeout = 0;
1090  return;
1091  }
1092 
1093  if (!this.havocbot_role_timeout)
1094  this.havocbot_role_timeout = time + random() * 10 + 20;
1095  if (time > this.havocbot_role_timeout)
1096  {
1097  LOG_TRACE("changing role to freelancer");
1098  this.havocbot_role = havocbot_role_kh_freelancer;
1099  this.havocbot_role_timeout = 0;
1100  return;
1101  }
1102 
1104  {
1105  float key_owner_team;
1107 
1108  key_owner_team = kh_Key_AllOwnedByWhichTeam();
1109  if(key_owner_team == this.team)
1110  havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend key carriers
1111  else if(key_owner_team == -1)
1112  havocbot_goalrating_kh(this, 4, 1, 0.05); // play defensively
1113  else
1114  havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK ANYWAY
1115 
1117 
1119  }
1120 }
1121 
1123 {
1124  if(IS_DEAD(this))
1125  return;
1126 
1127  if (this.kh_next)
1128  {
1129  LOG_TRACE("changing role to carrier");
1130  this.havocbot_role = havocbot_role_kh_carrier;
1131  this.havocbot_role_timeout = 0;
1132  return;
1133  }
1134 
1135  if (!this.havocbot_role_timeout)
1136  this.havocbot_role_timeout = time + random() * 10 + 20;
1137  if (time > this.havocbot_role_timeout)
1138  {
1139  LOG_TRACE("changing role to freelancer");
1140  this.havocbot_role = havocbot_role_kh_freelancer;
1141  this.havocbot_role_timeout = 0;
1142  return;
1143  }
1144 
1146  {
1147  float key_owner_team;
1148 
1150 
1151  key_owner_team = kh_Key_AllOwnedByWhichTeam();
1152  if(key_owner_team == this.team)
1153  havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend anyway
1154  else if(key_owner_team == -1)
1155  havocbot_goalrating_kh(this, 0.1, 1, 2); // play offensively
1156  else
1157  havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK! EMERGENCY!
1158 
1160 
1162  }
1163 }
1164 
1166 {
1167  if(IS_DEAD(this))
1168  return;
1169 
1170  if (this.kh_next)
1171  {
1172  LOG_TRACE("changing role to carrier");
1173  this.havocbot_role = havocbot_role_kh_carrier;
1174  this.havocbot_role_timeout = 0;
1175  return;
1176  }
1177 
1178  if (!this.havocbot_role_timeout)
1179  this.havocbot_role_timeout = time + random() * 10 + 10;
1180  if (time > this.havocbot_role_timeout)
1181  {
1182  if (random() < 0.5)
1183  {
1184  LOG_TRACE("changing role to offense");
1185  this.havocbot_role = havocbot_role_kh_offense;
1186  }
1187  else
1188  {
1189  LOG_TRACE("changing role to defense");
1190  this.havocbot_role = havocbot_role_kh_defense;
1191  }
1192  this.havocbot_role_timeout = 0;
1193  return;
1194  }
1195 
1197  {
1199 
1200  int key_owner_team = kh_Key_AllOwnedByWhichTeam();
1201  if(key_owner_team == this.team)
1202  havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend anyway
1203  else if(key_owner_team == -1)
1204  havocbot_goalrating_kh(this, 1, 10, 2); // prefer dropped keys
1205  else
1206  havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK ANYWAY
1207 
1209 
1211  }
1212 }
1213 
1214 
1215 // register this as a mutator
1216 
1218 {
1219  entity player = M_ARGV(0, entity);
1220 
1221  kh_Key_DropAll(player, true);
1222 }
1223 
1224 MUTATOR_HOOKFUNCTION(kh, MakePlayerObserver)
1225 {
1226  entity player = M_ARGV(0, entity);
1227 
1228  kh_Key_DropAll(player, true);
1229 }
1230 
1231 MUTATOR_HOOKFUNCTION(kh, PlayerDies)
1232 {
1233  entity frag_attacker = M_ARGV(1, entity);
1234  entity frag_target = M_ARGV(2, entity);
1235 
1236  if(frag_target == frag_attacker)
1237  kh_Key_DropAll(frag_target, true);
1238  else if(IS_PLAYER(frag_attacker))
1239  kh_Key_DropAll(frag_target, false);
1240  else
1241  kh_Key_DropAll(frag_target, true);
1242 }
1243 
1245 {
1246  entity frag_attacker = M_ARGV(0, entity);
1247  entity frag_target = M_ARGV(1, entity);
1248  float frag_score = M_ARGV(2, float);
1249  M_ARGV(2, float) = kh_HandleFrags(frag_attacker, frag_target, frag_score);
1250 }
1251 
1253 {
1254  kh_finalize();
1255 }
1256 
1258 {
1259  M_ARGV(0, float) = kh_teams;
1260  return true;
1261 }
1262 
1264 {
1265  entity player = M_ARGV(0, entity);
1266 
1267  if(MUTATOR_RETURNVALUE == 0)
1268  {
1269  entity k = player.kh_next;
1270  if(k)
1271  {
1272  kh_Key_DropOne(k);
1273  return true;
1274  }
1275  }
1276 }
1277 
1278 MUTATOR_HOOKFUNCTION(kh, HavocBot_ChooseRole)
1279 {
1280  entity bot = M_ARGV(0, entity);
1281 
1282  if(IS_DEAD(bot))
1283  return true;
1284 
1285  float r = random() * 3;
1286  if (r < 1)
1287  bot.havocbot_role = havocbot_role_kh_offense;
1288  else if (r < 2)
1289  bot.havocbot_role = havocbot_role_kh_defense;
1290  else
1291  bot.havocbot_role = havocbot_role_kh_freelancer;
1292 
1293  return true;
1294 }
1295 
1296 MUTATOR_HOOKFUNCTION(kh, LogDeath_AppendItemCodes)
1297 {
1298  entity player = M_ARGV(0, entity);
1299  if(player.kh_next)
1300  M_ARGV(1, string) = strcat(M_ARGV(1, string), "K"); // item codes
1301 }
1302 
1303 MUTATOR_HOOKFUNCTION(kh, DropSpecialItems)
1304 {
1305  entity frag_target = M_ARGV(0, entity);
1306 
1307  kh_Key_DropAll(frag_target, false);
1308 }
1309 
1310 MUTATOR_HOOKFUNCTION(kh, reset_map_global)
1311 {
1312  kh_WaitForPlayers(); // takes care of killing the "missing teams" message
1313 }
const float SOLID_NOT
Definition: csprogsdefs.qc:244
void havocbot_goalrating_kh(entity this, float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
Definition: sv_keyhunt.qc:1023
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
#define APP_TEAM_NUM(num, prefix)
Definition: all.qh:85
int autocvar_g_keyhunt_teams_override
Definition: sv_keyhunt.qc:29
#define GameRules_scoring(teams, spprio, stprio, fields)
Definition: sv_rules.qh:53
const float KH_KEY_XYDIST
Definition: sv_keyhunt.qc:43
float MOVETYPE_NONE
Definition: progsdefs.qc:246
float havocbot_role_timeout
Definition: api.qh:46
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
void kh_Key_Spawn(entity initial_owner, float _angle, float i)
Definition: sv_keyhunt.qc:720
entity kh_previous_owner
Definition: sv_keyhunt.qc:79
void navigation_goalrating_start(entity this)
Definition: navigation.qc:1830
bool kh_tracking_enabled
Definition: sv_keyhunt.qh:32
const int NUM_TEAM_2
Definition: teams.qh:19
const int CBC_ORDER_EXCLUSIVE
Definition: base.qh:9
void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
Definition: roles.qc:106
void kh_Key_Touch(entity this, entity toucher)
Definition: sv_keyhunt.qc:439
void havocbot_role_kh_carrier(entity this)
Definition: sv_keyhunt.qc:1052
int kh_dropperteam
Definition: sv_keyhunt.qc:78
#define SND(id)
Definition: all.qh:35
float autocvar_g_balance_keyhunt_delay_collect
Definition: sv_keyhunt.qc:10
vector view_ofs
Definition: progsdefs.qc:151
void kh_update_state()
Definition: sv_keyhunt.qc:120
int kh_key_dropped
Definition: sv_keyhunt.qc:82
#define getthink(e)
int NumTeams(int teams)
Definition: scores_rules.qc:17
void kh_Key_Attach(entity key)
Definition: sv_keyhunt.qc:216
void navigation_goalrating_end(entity this)
Definition: navigation.qc:1845
void kh_WinnerTeam(int winner_team)
Definition: sv_keyhunt.qc:511
const vector KH_KEY_MAX
Definition: sv_keyhunt.qc:49
void kh_Controller_Think(entity this)
Definition: sv_keyhunt.qc:156
void kh_Initialize()
Definition: sv_keyhunt.qc:974
int team
Definition: main.qh:157
float MOVETYPE_TOSS
Definition: progsdefs.qc:252
vector Team_ColorRGB(int teamid)
Definition: teams.qh:76
float autocvar_g_balance_keyhunt_delay_round
Definition: sv_keyhunt.qc:13
void kh_Key_DropOne(entity key)
Definition: sv_keyhunt.qc:794
const float KH_KEY_WP_ZSHIFT
Definition: sv_keyhunt.qc:46
const int SFL_SORT_PRIO_SECONDARY
Scoring priority (NOTE: PRIMARY is used for fraglimit)
Definition: scores.qh:126
entity() spawn
int player_count
Definition: api.qh:103
void navigation_dynamicgoal_init(entity this, bool initially_static)
Definition: navigation.qc:76
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
bool kh_no_radar_circles
Definition: sv_keyhunt.qc:52
void() kh_Think_t
Definition: sv_keyhunt.qh:35
#define GameRules_scoring_add(client, fld, value)
Definition: sv_rules.qh:78
int autocvar_g_balance_keyhunt_score_carrierfrag
Definition: sv_keyhunt.qc:21
float kh_droptime
Definition: sv_keyhunt.qc:77
entity kh_controller
Definition: sv_keyhunt.qc:71
float DPCONTENTS_BOTCLIP
const int SFL_SORT_PRIO_PRIMARY
Definition: scores.qh:127
int kh_previous_owner_playerid
Definition: sv_keyhunt.qc:80
float pushltime
Definition: jumppads.qh:10
float autocvar_g_balance_keyhunt_return_when_unreachable
Definition: sv_keyhunt.qc:15
void navigation_dynamicgoal_set(entity this, entity dropper)
Definition: navigation.qc:86
bool kh_KeyCarrier_waypointsprite_visible_for_player(entity this, entity player, entity view)
Definition: sv_keyhunt.qc:100
float DPCONTENTS_PLAYERCLIP
float kh_HandleFrags(entity attacker, entity targ, float f)
Definition: sv_keyhunt.qc:949
void kh_Scores_Event(entity player, entity key, string what, float frags_player, float frags_owner)
Definition: sv_keyhunt.qc:175
void kh_WaitForPlayers()
Definition: sv_keyhunt.qc:862
int autocvar_g_balance_keyhunt_score_capture
Definition: sv_keyhunt.qc:20
origin
Definition: ent_cs.qc:114
const float KH_KEY_ZSHIFT
Definition: sv_keyhunt.qc:42
float autocvar_g_balance_keyhunt_throwvelocity
Definition: sv_keyhunt.qc:26
MUTATOR_HOOKFUNCTION(kh, ClientDisconnect)
Definition: sv_keyhunt.qc:1217
vector kh_AttachedOrigin(entity e)
Definition: sv_keyhunt.qc:205
#define DIFF_TEAM(a, b)
Definition: teams.qh:240
float FL_ITEM
Definition: progsdefs.qc:239
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
const vector KH_KEY_MIN
Definition: sv_keyhunt.qc:48
entity owner
Definition: main.qh:73
ClientDisconnect(this)
const int SFL_LOWER_IS_BETTER
Lower scores are better (e.g.
Definition: scores.qh:98
void navigation_routerating(entity this, entity e, float f, float rangebias)
Definition: navigation.qc:1220
void kh_Controller_SetThink(float t, kh_Think_t func)
Definition: sv_keyhunt.qc:148
entity kh_worldkeylist
Definition: sv_keyhunt.qh:24
entity trace_ent
Definition: csprogsdefs.qc:40
ERASEABLE float DistributeEvenly_Get(float weight)
Definition: random.qc:54
#define setmodel(this, m)
Definition: model.qh:26
entity teams
Definition: main.qh:44
const int SPRITERULE_TEAMPLAY
float autocvar_g_balance_keyhunt_delay_damage_return
Definition: sv_keyhunt.qc:11
float autocvar_g_balance_keyhunt_delay_tracking
Definition: sv_keyhunt.qc:14
int kh_interferemsg_team
Definition: sv_keyhunt.qc:74
void nades_GiveBonus(entity player, float score)
entity kh_prev
Definition: sv_keyhunt.qc:76
float autocvar_g_balance_keyhunt_maxdist
Definition: sv_keyhunt.qc:17
int kh_Team_ByID(int t)
Definition: sv_keyhunt.qc:62
const int ST_KH_CAPS
Definition: sv_keyhunt.qc:86
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
float autocvar_g_balance_keyhunt_dropvelocity
Definition: sv_keyhunt.qc:16
entity enemy
Definition: sv_ctf.qh:143
const float MOVE_NOMONSTERS
Definition: csprogsdefs.qc:253
float cnt
Definition: powerups.qc:24
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
void kh_Key_Think(entity this)
Definition: sv_keyhunt.qc:659
int autocvar_g_balance_keyhunt_score_destroyed
Definition: sv_keyhunt.qc:23
bool navigation_goalrating_timeout(entity this)
Definition: navigation.qc:43
void kh_ScoreRules(int teams)
Definition: sv_keyhunt.qc:87
vector v_up
Definition: csprogsdefs.qc:31
float autocvar_g_balance_keyhunt_protecttime
Definition: sv_keyhunt.qc:18
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int kh_GetMissingTeams()
Definition: sv_keyhunt.qc:845
#define GameRules_scoring_add_team(client, fld, value)
Definition: sv_rules.qh:80
const int CH_TRIGGER
Definition: sound.qh:12
void kh_Key_Collect(entity key, entity player)
Definition: sv_keyhunt.qc:423
void PlayerUseKey(entity this)
Definition: client.qc:2349
void UpdateFrags(entity player, int f)
Definition: damage.qc:44
IntrusiveList g_items
Definition: items.qh:126
bool kh_Key_waypointsprite_visible_for_player(entity this, entity player, entity view)
Definition: sv_keyhunt.qc:109
float autocvar_g_balance_keyhunt_damageforcescale
Definition: sv_keyhunt.qc:9
void key_reset(entity this)
Definition: sv_keyhunt.qc:714
int kh_Key_AllOwnedByWhichTeam()
Definition: sv_keyhunt.qc:774
entity kh_next
Definition: sv_keyhunt.qc:76
const int CBC_ORDER_FIRST
Definition: base.qh:7
void havocbot_role_kh_offense(entity this)
Definition: sv_keyhunt.qc:1122
const float KH_KEY_XYSPEED
Definition: sv_keyhunt.qc:44
const float KH_KEY_BRIGHTNESS
Definition: sv_keyhunt.qc:50
#define NULL
Definition: post.qh:17
float DPCONTENTS_SOLID
void kh_Key_AssignTo(entity key, entity player)
Definition: sv_keyhunt.qc:304
const float VOL_BASE
Definition: sound.qh:36
void GameLogEcho(string s)
Definition: gamelog.qc:12
#define MUTATOR_RETURNVALUE
Definition: base.qh:303
int kh_key_carried
Definition: sv_keyhunt.qc:82
#define M_ARGV(x, type)
Definition: events.qh:17
#define IS_DEAD(s)
Definition: utils.qh:26
const float ATTEN_NORM
Definition: sound.qh:30
float nextthink
Definition: csprogsdefs.qc:121
var kh_Think_t kh_Controller_Thinkfunc
Definition: sv_keyhunt.qc:147
void kh_StartRound()
Definition: sv_keyhunt.qc:911
void navigation_goalrating_timeout_set(entity this)
Definition: navigation.qc:19
void kh_FinishRound()
Definition: sv_keyhunt.qc:494
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition: items.qh:130
const int NUM_TEAM_4
Definition: teams.qh:21
float kh_interferemsg_time
Definition: sv_keyhunt.qc:75
int autocvar_g_balance_keyhunt_score_push
Definition: sv_keyhunt.qc:25
void navigation_dynamicgoal_unset(entity this)
Definition: navigation.qc:95
entity players
Definition: main.qh:43
float autocvar_g_balance_keyhunt_delay_return
Definition: sv_keyhunt.qc:12
int autocvar_g_balance_keyhunt_score_collect
Definition: sv_keyhunt.qc:22
#define ITEM_TOUCH_NEEDKILL()
Definition: items.qh:129
float pain_finished
float DPCONTENTS_BODY
void havocbot_role_kh_defense(entity this)
Definition: sv_keyhunt.qc:1080
void(entity this) havocbot_role_kh_carrier
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
#define LOG_TRACE(...)
Definition: log.qh:81
ERASEABLE void DistributeEvenly_Init(float amount, float totalweight)
Definition: random.qc:42
void kh_Key_DropAll(entity player, float suicide)
Definition: sv_keyhunt.qc:817
float siren_time
Definition: sv_keyhunt.qc:59
void kh_finalize()
Definition: sv_keyhunt.qc:1007
#define FOR_EACH_KH_KEY(v)
Definition: sv_keyhunt.qh:27
const float SOLID_TRIGGER
Definition: csprogsdefs.qc:245
vector v_right
Definition: csprogsdefs.qc:31
#define LABEL(id)
Definition: compiler.qh:36
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
setorigin(ent, v)
#define setthink(e, f)
int kh_teams
Definition: sv_keyhunt.qc:73
void kh_Key_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition: sv_keyhunt.qc:407
const int NUM_TEAM_1
Definition: teams.qh:18
entity TeamBalance_CheckAllowedTeams(entity for_whom)
Checks whether the player can join teams according to global configuration and mutator settings...
Definition: teamplay.qc:487
vector W_CalculateProjectileVelocity(entity actor, vector pvelocity, vector mvelocity, float forceAbsolute)
Definition: tracing.qc:169
#define sound(e, c, s, v, a)
Definition: sound.qh:52
void havocbot_role_kh_freelancer(entity this)
Definition: sv_keyhunt.qc:1165
bool autocvar_sv_eventlog
Definition: gamelog.qh:3
float time
Definition: csprogsdefs.qc:16
void kh_Key_Detach(entity key)
Definition: sv_keyhunt.qc:261
#define makevectors
Definition: post.qh:21
float trace_fraction
Definition: csprogsdefs.qc:36
#define FOREACH(list, cond, body)
Definition: iter.qh:19
float DAMAGE_NO
Definition: progsdefs.qc:282
void kh_Key_Remove(entity key)
Definition: sv_keyhunt.qc:463
void set_movetype(entity this, int mt)
#define IS_PLAYER(v)
Definition: utils.qh:9
#define BITS(n)
Definition: bits.qh:9
#define colormapPaletteColor(c, isPants)
Definition: color.qh:5
void kh_EnableTrackingDevice()
Definition: sv_keyhunt.qc:903
const int NUM_TEAM_3
Definition: teams.qh:20
int autocvar_g_balance_keyhunt_score_destroyed_ownfactor
Definition: sv_keyhunt.qc:24
void kh_LoserTeam(int loser_team, entity lostkey)
Definition: sv_keyhunt.qc:573
vector v_forward
Definition: csprogsdefs.qc:31
float DAMAGE_YES
Definition: progsdefs.qc:283