]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/ctf.qc
blinking magic: if there is more than one flag, show one of these in a clever way
[divverent/nexuiz.git] / data / qcsrc / server / ctf.qc
1 .entity sprite;
2 entity ctf_worldflaglist; // CTF flags in the map
3 .entity ctf_worldflagnext;
4
5 .float next_take_time;                  // the next time a player can pick up a flag (time + blah)
6                                                                 /// I used this, in part, to fix the looping score bug. - avirox
7
8 //float FLAGSCORE_PICKUP        =  1;
9 //float FLAGSCORE_RETURN        =  5; // returned by owner team
10 //float FLAGSCORE_RETURNROGUE   = 10; // returned by rogue team
11 //float FLAGSCORE_CAPTURE       =  5;
12 //float FLAGSCORE_CAPTURE_TEAM  = 20;
13
14 #define FLAG_CARRY_POS '-15 0 7'
15
16 void FakeTimeLimit(entity e, float t)
17 {
18         msg_entity = e;
19         WriteByte(MSG_ONE, 3); // svc_updatestat
20         WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
21         if(t < 0)
22                 WriteCoord(MSG_ONE, cvar("timelimit"));
23         else
24                 WriteCoord(MSG_ONE, (t + 1) / 60);
25 }
26
27 float   flagcaptimerecord;
28 .float  flagpickuptime;
29
30 void() FlagThink;
31 void() FlagTouch;
32
33 void() place_flag =
34 {
35         if(!self.t_width)
36                 self.t_width = 0.1; // frame animation rate
37         if(!self.t_length)
38                 self.t_length = 119; // maximum frame
39
40         setattachment(self, world, "");
41         self.mdl = self.model;
42         self.flags = FL_ITEM;
43         self.solid = SOLID_TRIGGER;
44         self.movetype = MOVETYPE_NONE;
45         self.velocity = '0 0 0';
46         self.origin_z = self.origin_z + 6;
47         self.think = FlagThink;
48         self.touch = FlagTouch;
49         self.nextthink = time + 0.1;
50         self.cnt = FLAG_BASE;
51         self.mangle = self.angles;
52         self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
53         //self.effects = self.effects | EF_DIMLIGHT;
54         if(!self.noalign)
55         {
56                 self.movetype = MOVETYPE_TOSS;
57                 if (!droptofloor())
58                 {
59                         dprint("Flag fell out of level at ", vtos(self.origin), "\n");
60                         remove(self);
61                         return;
62                 }
63         }
64         self.oldorigin = self.origin;
65 };
66
67 void LogCTF(string mode, float flagteam, entity actor)
68 {
69         string s;
70         if(!cvar("sv_eventlog"))
71                 return;
72         s = strcat(":ctf:", mode);
73         s = strcat(s, ":", ftos(flagteam));
74         if(actor != world)
75                 s = strcat(s, ":", ftos(actor.playerid));
76         GameLogEcho(s, FALSE);
77 }
78
79 void(entity e) RegenFlag =
80 {
81         setattachment(e, world, "");
82         e.movetype = MOVETYPE_NONE;
83         if(!self.noalign)
84                 e.movetype = MOVETYPE_TOSS;
85         e.solid = SOLID_TRIGGER;
86         // TODO: play a sound here
87         setorigin(e, e.oldorigin);
88         e.angles = e.mangle;
89         e.cnt = FLAG_BASE;
90         e.owner = world;
91         e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
92 };
93
94 void(entity e) ReturnFlag =
95 {
96         if (e.owner)
97         if (e.owner.flagcarried == e)
98         {
99                 WaypointSprite_DetachCarrier(e.owner);
100                 e.owner.flagcarried = world;
101
102                 if(e.speedrunning)
103                         FakeTimeLimit(e.owner, -1);
104         }
105         e.owner = world;
106         RegenFlag(e);
107 };
108
109 void(entity e) DropFlag =
110 {
111         local entity p;
112
113         if(e.speedrunning)
114         {
115                 ReturnFlag(e);
116                 return;
117         }
118
119         if (!e.owner)
120         {
121                 dprint("FLAG: drop - no owner?!?!\n");
122                 return;
123         }
124         p = e.owner;
125         if (p.flagcarried != e)
126         {
127                 dprint("FLAG: drop - owner is not carrying this flag??\n");
128                 return;
129         }
130         bprint(p.netname, "^7 lost the ", e.netname, "\n");
131         WaypointSprite_DetachCarrier(p);
132         LogCTF("dropped", p.team, p.flagcarried);
133
134         setattachment(e, world, "");
135
136         if (p.flagcarried == e)
137                 p.flagcarried = world;
138         e.owner = world;
139
140         e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
141         e.solid = SOLID_TRIGGER;
142         e.movetype = MOVETYPE_TOSS;
143         // setsize(e, '-16 -16 0', '16 16 74');
144         setorigin(e, p.origin - '0 0 24' + '0 0 37');
145         e.cnt = FLAG_DROPPED;
146         e.velocity = '0 0 300';
147         e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
148
149         trace_startsolid = FALSE;
150         tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
151         if(trace_startsolid)
152                 dprint("FLAG FALLTHROUGH will happen SOON\n");
153 };
154
155 void AnimateFlag()
156 {
157         if(self.delay > time)
158                 return;
159         self.delay = time + self.t_width;
160         if(self.nextthink > self.delay)
161                 self.nextthink = self.delay;
162
163         self.frame = self.frame + 1;
164         if(self.frame > self.t_length)
165                 self.frame = 0;
166 }
167
168 void() FlagThink =
169 {
170         local entity e;
171
172         self.nextthink = time + 0.1;
173
174         AnimateFlag();
175
176         if(self.speedrunning)
177         if(self.cnt == FLAG_CARRY)
178         {
179                 if(self.owner)
180                 if(flagcaptimerecord)
181                 if(time >= self.flagpickuptime + flagcaptimerecord)
182                 {
183                         bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
184
185                         self.owner.impulse = 77; // returning!
186                         e = self;
187                         self = self.owner;
188                         ReturnFlag(e);
189                         ImpulseCommands();
190                         self = e;
191                         return;
192                 }
193         }
194
195         if (self.cnt == FLAG_BASE)
196                 return;
197
198         if (self.cnt == FLAG_DROPPED)
199         {
200                 // flag fallthrough? FIXME remove this if bug is really fixed now
201                 if(self.origin_z < -131072)
202                 {
203                         dprint("FLAG FALLTHROUGH just happened\n");
204                         self.pain_finished = 0;
205                 }
206                 setattachment(self, world, "");
207                 if (time > self.pain_finished)
208                 {
209                         bprint("The ", self.netname, " has returned to base\n");
210                         sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
211                         LogCTF("returned", self.team, world);
212                         ReturnFlag(self);
213                 }
214                 return;
215         }
216
217         e = self.owner;
218         if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
219         {
220                 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
221                 DropFlag(self);
222                 return;
223         }
224 };
225
226 void() FlagTouch =
227 {
228         if(gameover) return;
229
230         local float t;
231         local entity head;
232         local entity player;
233         local string s, s0, h0, h1;
234         if (other.classname != "player")
235                 return;
236         if (other.health < 1) // ignore dead players
237                 return;
238
239         if (self.cnt == FLAG_CARRY)
240                 return;
241
242         if (self.cnt == FLAG_BASE)
243         if (other.team == self.team)
244         if (other.flagcarried) // he's got a flag
245         if (other.flagcarried.team != self.team) // capture
246         {
247                 if (other.flagcarried == world)
248                 {
249                         return;
250                 }
251                 t = time - other.flagcarried.flagpickuptime;
252                 s = ftos_decimals(t, 2);
253                 s0 = ftos_decimals(flagcaptimerecord, 2);
254                 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
255                 h1 = other.netname;
256                 if(h0 == h1)
257                         h0 = "his";
258                 else
259                         h0 = strcat(h0, "^7's"); // h0: display text for previous netname
260                 if (flagcaptimerecord == 0)
261                 {
262                         bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
263                         flagcaptimerecord = t;
264                         db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
265                         db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
266                 }
267                 else if (t < flagcaptimerecord)
268                 {
269                         bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
270                         flagcaptimerecord = t;
271                         db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
272                         db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
273                 }
274                 else
275                 {
276                         bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
277                 }
278
279                 LogCTF("capture", other.flagcarried.team, other);
280                 // give credit to the individual player
281                 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
282
283                 // give credit to all players of the team (rewards large teams)
284                 // NOTE: this defaults to 0
285                 FOR_EACH_PLAYER(head)
286                         if (head.team == self.team)
287                                 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
288
289                 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
290                 WaypointSprite_DetachCarrier(other);
291                 if(self.speedrunning)
292                         FakeTimeLimit(other, -1);
293                 RegenFlag (other.flagcarried);
294                 other.flagcarried = world;
295                 other.next_take_time = time + 1;
296         }
297         if (self.cnt == FLAG_BASE)
298         if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
299         if (other.team != self.team)
300         if (!other.flagcarried)
301         {
302                 if (other.next_take_time > time)
303                         return;
304                 // pick up
305                 self.flagpickuptime = time; // used for timing runs
306                 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
307                 if(other.speedrunning)
308                 if(flagcaptimerecord)
309                         FakeTimeLimit(other, time + flagcaptimerecord);
310                 self.solid = SOLID_NOT;
311                 setorigin(self, self.origin); // relink
312                 self.owner = other;
313                 other.flagcarried = self;
314                 self.cnt = FLAG_CARRY;
315                 self.angles = '0 0 0';
316                 bprint(other.netname, "^7 got the ", self.netname, "\n");
317                 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
318                 LogCTF("steal", self.team, other);
319                 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
320
321                 FOR_EACH_PLAYER(player)
322                         if(player.team == self.team)
323                                 centerprint(player, "The enemy got your flag! Retrieve it!");
324
325                 self.movetype = MOVETYPE_NONE;
326                 setorigin(self, FLAG_CARRY_POS);
327                 setattachment(self, other, "");
328                 WaypointSprite_AttachCarrier("flagcarrier", other);
329
330                 return;
331         }
332
333         if (self.cnt == FLAG_DROPPED)
334         {
335                 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
336                 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
337                 {
338                         // return flag
339                         bprint(other.netname, "^7 returned the ", self.netname, "\n");
340                         if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
341                                 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
342                         else
343                                 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
344                         LogCTF("return", self.team, other);
345                         sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
346                         ReturnFlag(self);
347                 }
348                 else if (!other.flagcarried)
349                 {
350                         // pick up
351                         self.solid = SOLID_NOT;
352                         setorigin(self, self.origin); // relink
353                         self.owner = other;
354                         other.flagcarried = self;
355                         self.cnt = FLAG_CARRY;
356                         bprint(other.netname, "^7 picked up the ", self.netname, "\n");
357                         UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
358                         LogCTF("pickup", self.team, other);
359                         sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
360
361                         FOR_EACH_PLAYER(player)
362                                 if(player.team == self.team)
363                                         centerprint(player, "The enemy got your flag! Retrieve it!");
364
365                         self.movetype = MOVETYPE_NONE;  // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
366                         setorigin(self, FLAG_CARRY_POS);
367                         setattachment(self, other, "");
368                         WaypointSprite_AttachCarrier("flagcarrier", other);
369                 }
370         }
371 };
372
373 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
374 CTF Starting point for a player
375 in team one (Red).
376
377 Keys:
378 "angle"
379  viewing angle when spawning
380 */
381 void() info_player_team1 =
382 {
383         self.team = COLOR_TEAM1; // red
384         info_player_deathmatch();
385 };
386 //self.team = 4;self.classname = "info_player_start";info_player_start();};
387
388 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
389 CTF Starting point for a player in
390 team two (Blue).
391
392 Keys:
393 "angle"
394  viewing angle when spawning
395 */
396 void() info_player_team2 =
397 {
398         self.team = COLOR_TEAM2; // blue
399         info_player_deathmatch();
400 };
401 //self.team = 13;self.classname = "info_player_start";info_player_start();};
402
403 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
404 CTF Starting point for a player in
405 team three (Magenta).
406
407 Keys:
408 "angle"
409  viewing angle when spawning
410 */
411 void() info_player_team3 =
412 {
413         self.team = COLOR_TEAM3; // purple
414         info_player_deathmatch();
415 };
416
417
418 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
419 CTF Starting point for a player in
420 team four (Yellow).
421
422 Keys:
423 "angle"
424  viewing angle when spawning
425 */
426 void() info_player_team4 =
427 {
428         self.team = COLOR_TEAM4; // yellow
429         info_player_deathmatch();
430 };
431
432
433
434
435 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
436 CTF flag for team one (Red).
437 Multiple are allowed.
438
439 Keys:
440 "angle"
441  Angle the flag will point
442 (minus 90 degrees)
443 "model"
444  model to use, note this needs red and blue as skins 0 and 1
445  (default models/ctf/flag.md3)
446 "noise"
447  sound played when flag is picked up
448  (default ctf/take.wav)
449 "noise1"
450  sound played when flag is returned by a teammate
451  (default ctf/return.wav)
452 "noise2"
453  sound played when flag is captured
454  (default ctf/capture.wav)
455 "noise3"
456  sound played when flag is lost in the field and respawns itself
457  (default ctf/respawn.wav)
458 */
459
460 void() item_flag_team1 =
461 {
462         if (!g_ctf)
463         {
464                 remove(self);
465                 return;
466         }
467
468         //if(!cvar("teamplay"))
469         //      cvar_set("teamplay", "3");
470
471         // link flag into ctf_worldflaglist
472         self.ctf_worldflagnext = ctf_worldflaglist;
473         ctf_worldflaglist = self;
474
475         self.classname = "item_flag_team";
476         self.team = COLOR_TEAM1; // color 4 team (red)
477         self.items = IT_KEY2; // gold key (redish enough)
478         self.netname = "^1RED^7 flag";
479         self.target = "###item###";
480         self.skin = 0;
481         if(self.spawnflags & 1)
482                 self.noalign = 1;
483         if (!self.model)
484                 self.model = "models/ctf/flag_red.md3";
485         if (!self.noise)
486                 self.noise = "ctf/take.wav";
487         if (!self.noise1)
488                 self.noise1 = "ctf/return.wav";
489         if (!self.noise2)
490                 self.noise2 = "ctf/capture.wav";
491         if (!self.noise3)
492                 self.noise3 = "ctf/respawn.wav";
493         precache_model (self.model);
494         setmodel (self, self.model); // precision set below
495         precache_sound (self.noise);
496         precache_sound (self.noise1);
497         precache_sound (self.noise2);
498         precache_sound (self.noise3);
499         setsize(self, '-16 -16 -37', '16 16 37');
500         setorigin(self, self.origin + '0 0 37');
501         self.nextthink = time + 0.2; // start after doors etc
502         self.think = place_flag;
503
504         if(!self.scale)
505                 self.scale = 0.6;
506         //if(!self.glow_size)
507         //      self.glow_size = 50;
508
509         self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
510         if(!self.noalign)
511                 droptofloor();
512
513         waypoint_spawnforitem(self);
514
515         WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
516 };
517
518 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
519 CTF flag for team two (Blue).
520 Multiple are allowed.
521
522 Keys:
523 "angle"
524  Angle the flag will point
525 (minus 90 degrees)
526
527 */
528
529 void() item_flag_team2 =
530 {
531         if (!g_ctf)
532         {
533                 remove(self);
534                 return;
535         }
536         //if(!cvar("teamplay"))
537         //      cvar_set("teamplay", "3");
538
539         // link flag into ctf_worldflaglist
540         self.ctf_worldflagnext = ctf_worldflaglist;
541         ctf_worldflaglist = self;
542
543         self.classname = "item_flag_team";
544         self.team = COLOR_TEAM2; // color 13 team (blue)
545         self.items = IT_KEY1; // silver key (bluish enough)
546         self.netname = "^4BLUE^7 flag";
547         self.target = "###item###";
548         self.skin = 0;
549         if(self.spawnflags & 1)
550                 self.noalign = 1;
551         if (!self.model)
552                 self.model = "models/ctf/flag_blue.md3";
553         if (!self.noise)
554                 self.noise = "ctf/take.wav";
555         if (!self.noise1)
556                 self.noise1 = "ctf/return.wav";
557         if (!self.noise2)
558                 self.noise2 = "ctf/capture.wav";
559         if (!self.noise3)
560                 self.noise3 = "ctf/respawn.wav";
561         precache_model (self.model);
562         setmodel (self, self.model); // precision set below
563         precache_sound (self.noise);
564         precache_sound (self.noise1);
565         precache_sound (self.noise2);
566         precache_sound (self.noise3);
567         setsize(self, '-16 -16 -37', '16 16 37');
568         setorigin(self, self.origin + '0 0 37');
569         self.nextthink = time + 0.2; // start after doors etc
570         self.think = place_flag;
571
572         if(!self.scale)
573                 self.scale = 0.6;
574         //if(!self.glow_size)
575         //      self.glow_size = 50;
576
577         self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
578         if(!self.noalign)
579                 droptofloor();
580
581         waypoint_spawnforitem(self);
582
583         WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
584 };
585
586
587 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
588 Team declaration for CTF gameplay, this allows you to decide what team
589 names and control point models are used in your map.
590
591 Note: If you use ctf_team entities you must define at least 2!  However, unlike
592 domination, you don't need to make a blank one too.
593
594 Keys:
595 "netname"
596  Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
597 "cnt"
598  Scoreboard color of the team (for example 4 is red and 13 is blue)
599
600 */
601
602 void() ctf_team =
603 {
604         if (!g_ctf)
605         {
606                 remove(self);
607                 return;
608         }
609         self.classname = "ctf_team";
610         self.team = self.cnt + 1;
611 };
612
613 // code from here on is just to support maps that don't have control point and team entities
614 void ctf_spawnteam (string teamname, float teamcolor)
615 {
616         local entity oldself;
617         oldself = self;
618         self = spawn();
619         self.classname = "ctf_team";
620         self.netname = teamname;
621         self.cnt = teamcolor;
622
623         ctf_team();
624
625         self = oldself;
626 };
627
628 // spawn some default teams if the map is not set up for ctf
629 void() ctf_spawnteams =
630 {
631         float numteams;
632
633         numteams = 2;//cvar("g_ctf_default_teams");
634
635         ctf_spawnteam("Red", COLOR_TEAM1 - 1);
636         ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
637 };
638
639 void() ctf_delayedinit =
640 {
641         self.think = SUB_Remove;
642         self.nextthink = time;
643         // if no teams are found, spawn defaults
644         if (find(world, classname, "ctf_team") == world)
645                 ctf_spawnteams();
646 };
647
648 void() ctf_init =
649 {
650         local entity e;
651         e = spawn();
652         e.think = ctf_delayedinit;
653         e.nextthink = time + 0.1;
654         flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
655 };
656
657 void(entity flag, float shift) ctf_setstatus2 =
658 {
659         if (flag.cnt == FLAG_CARRY)
660                 if (flag.owner == self)
661                         self.items |= shift * 3;
662                 else
663                         self.items |= shift * 1;
664         else if (flag.cnt == FLAG_DROPPED)
665                 self.items |= shift * 2;
666         else
667         {
668                 // no status bits
669         }
670 };
671
672 void() ctf_setstatus =
673 {
674         self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
675         self.items = self.items - (self.items & IT_RED_FLAG_LOST);
676         self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
677         self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
678
679         if (g_ctf) {
680                 local entity flag;
681                 float redflags, blueflags;
682
683                 redflags = 0;
684                 blueflags = 0;
685
686                 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
687                 {
688                         if(flag.team == COLOR_TEAM1)
689                                 ++redflags;
690                         else if(flag.team == COLOR_TEAM2)
691                                 ++blueflags;
692                 }
693
694                 // blinking magic: if there is more than one flag, show one of these in a clever way
695                 if(redflags)
696                         redflags = mod(floor(time * redflags * 0.75), redflags);
697                 if(blueflags)
698                         blueflags = mod(floor(time * blueflags * 0.75), blueflags);
699
700                 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
701                 {
702                         if(flag.team == COLOR_TEAM1)
703                         {
704                                 if(redflags-- == 0) // happens exactly once
705                                         ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
706                         }
707                         else if(flag.team == COLOR_TEAM2)
708                         {
709                                 if(blueflags-- == 0) // happens exactly once
710                                         ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
711                         }
712                 }
713         }
714 };