-
- // if in nodrop or time over, end the round
- if(!self.owner)
- if(time > self.pain_finished)
- kh_LoserTeam(self.team, self);
-
- if(self.owner)
- if(kh_Key_AllOwnedByWhichTeam() != -1)
- {
- if(self.siren_time < time)
- {
- sound(self.owner, CHAN_AUTO, kh_sound_alarm, VOL_BASE, ATTN_NORM); // play a simple alarm
- self.siren_time = time + 2.5; // repeat every 2.5 seconds
- }
-
- entity key;
- vector p;
- p = self.owner.origin;
- FOR_EACH_KH_KEY(key)
- if(vlen(key.owner.origin - p) > cvar("g_balance_keyhunt_maxdist"))
- goto not_winning;
- kh_WinnerTeam(self.team);
-:not_winning
- }
-
- if(kh_interferemsg_time && time > kh_interferemsg_time)
- {
- kh_interferemsg_time = 0;
- FOR_EACH_PLAYER(head)
- {
- if(head.team == kh_interferemsg_team)
- if(head.kh_next)
- centerprint(head, "All keys are in your team's hands!\n\nMeet the other key carriers ^1NOW^7!");
- else
- centerprint(head, "All keys are in your team's hands!\n\nHelp the key carriers to meet!");
- else
- centerprint(head, strcat("All keys are in the ", ColoredTeamName(kh_interferemsg_team), "^7's hands!\n\nInterfere ^1NOW^7!"));
- }
- }
-
- self.nextthink = time + 0.05;
-}
-
-void kh_WinnerTeam(float teem) // runs when a team wins
-{
- // all key carriers get some points
- vector firstorigin, lastorigin, midpoint;
- float first;
- entity key;
- float score;
- score = (kh_teams - 1) * cvar("g_balance_keyhunt_score_capture");
- DistributeEvenly_Init(score, kh_teams);
- // twice the score for 3 team games, three times the score for 4 team games!
- // note: for a win by destroying the key, this should NOT be applied
- FOR_EACH_KH_KEY(key)
- {
- float f;
- f = DistributeEvenly_Get(1);
- kh_Scores_Event(key.owner, key, "capture", f, 0);
- PlayerTeamScore_Add(key.owner, SP_KH_CAPS, ST_KH_CAPS, 1);
- }
-
- first = TRUE;
- FOR_EACH_KH_KEY(key)
- if(key.owner.kh_next == key)
- {
- if(!first)
- bprint("^7, ");
- bprint(key.owner.netname);
- first = FALSE;
- }
- bprint("^7 captured the keys for the ", ColoredTeamName(teem), "\n");
-
- first = TRUE;
- midpoint = '0 0 0';
- FOR_EACH_KH_KEY(key)
- {
- vector thisorigin;
-
- thisorigin = kh_AttachedOrigin(key);
- //dprint("Key origin: ", vtos(thisorigin), "\n");
- midpoint += thisorigin;
-
- if(!first)
- te_lightning2(world, lastorigin, thisorigin);
- lastorigin = thisorigin;
- if(first)
- firstorigin = thisorigin;
- first = FALSE;
- }
- if(kh_teams > 2)
- {
- te_lightning2(world, lastorigin, firstorigin);
- }
- midpoint = midpoint * (1 / kh_teams);
- te_customflash(midpoint, 1000, 1, TeamColor(teem) * 0.5 + '0.5 0.5 0.5'); // make the color >=0.5 in each component