change all function declarations (except builtins and data types) to ANSI C-like...
[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 RegenFlag(entity e)
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 ReturnFlag(entity e)
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 DropFlag(entity e)
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 spawnfunc_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 spawnfunc_info_player_team1()
382 {
383         self.team = COLOR_TEAM1; // red
384         spawnfunc_info_player_deathmatch();
385 };
386 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
387
388 /*QUAKED spawnfunc_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 spawnfunc_info_player_team2()
397 {
398         self.team = COLOR_TEAM2; // blue
399         spawnfunc_info_player_deathmatch();
400 };
401 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
402
403 /*QUAKED spawnfunc_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 spawnfunc_info_player_team3()
412 {
413         self.team = COLOR_TEAM3; // purple
414         spawnfunc_info_player_deathmatch();
415 };
416
417
418 /*QUAKED spawnfunc_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 spawnfunc_info_player_team4()
427 {
428         self.team = COLOR_TEAM4; // yellow
429         spawnfunc_info_player_deathmatch();
430 };
431
432
433
434
435 /*QUAKED spawnfunc_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/redcapture.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 spawnfunc_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/redcapture.wav"; // blue team scores by capturing the red flag
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 spawnfunc_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 "model"
527  model to use, note this needs red and blue as skins 0 and 1
528  (default models/ctf/flag.md3)
529 "noise"
530  sound played when flag is picked up
531  (default ctf/take.wav)
532 "noise1"
533  sound played when flag is returned by a teammate
534  (default ctf/return.wav)
535 "noise2"
536  sound played when flag is captured
537  (default ctf/bluecapture.wav)
538 "noise3"
539  sound played when flag is lost in the field and respawns itself
540  (default ctf/respawn.wav)
541 */
542
543 void spawnfunc_item_flag_team2()
544 {
545         if (!g_ctf)
546         {
547                 remove(self);
548                 return;
549         }
550         //if(!cvar("teamplay"))
551         //      cvar_set("teamplay", "3");
552
553         // link flag into ctf_worldflaglist
554         self.ctf_worldflagnext = ctf_worldflaglist;
555         ctf_worldflaglist = self;
556
557         self.classname = "item_flag_team";
558         self.team = COLOR_TEAM2; // color 13 team (blue)
559         self.items = IT_KEY1; // silver key (bluish enough)
560         self.netname = "^4BLUE^7 flag";
561         self.target = "###item###";
562         self.skin = 0;
563         if(self.spawnflags & 1)
564                 self.noalign = 1;
565         if (!self.model)
566                 self.model = "models/ctf/flag_blue.md3";
567         if (!self.noise)
568                 self.noise = "ctf/take.wav";
569         if (!self.noise1)
570                 self.noise1 = "ctf/return.wav";
571         if (!self.noise2)
572                 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
573         if (!self.noise3)
574                 self.noise3 = "ctf/respawn.wav";
575         precache_model (self.model);
576         setmodel (self, self.model); // precision set below
577         precache_sound (self.noise);
578         precache_sound (self.noise1);
579         precache_sound (self.noise2);
580         precache_sound (self.noise3);
581         setsize(self, '-16 -16 -37', '16 16 37');
582         setorigin(self, self.origin + '0 0 37');
583         self.nextthink = time + 0.2; // start after doors etc
584         self.think = place_flag;
585
586         if(!self.scale)
587                 self.scale = 0.6;
588         //if(!self.glow_size)
589         //      self.glow_size = 50;
590
591         self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
592         if(!self.noalign)
593                 droptofloor();
594
595         waypoint_spawnforitem(self);
596
597         WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
598 };
599
600
601 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
602 Team declaration for CTF gameplay, this allows you to decide what team
603 names and control point models are used in your map.
604
605 Note: If you use spawnfunc_ctf_team entities you must define at least 2!  However, unlike
606 domination, you don't need to make a blank one too.
607
608 Keys:
609 "netname"
610  Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
611 "cnt"
612  Scoreboard color of the team (for example 4 is red and 13 is blue)
613
614 */
615
616 void spawnfunc_ctf_team()
617 {
618         if (!g_ctf)
619         {
620                 remove(self);
621                 return;
622         }
623         self.classname = "ctf_team";
624         self.team = self.cnt + 1;
625 };
626
627 // code from here on is just to support maps that don't have control point and team entities
628 void ctf_spawnteam (string teamname, float teamcolor)
629 {
630         local entity oldself;
631         oldself = self;
632         self = spawn();
633         self.classname = "ctf_team";
634         self.netname = teamname;
635         self.cnt = teamcolor;
636
637         spawnfunc_ctf_team();
638
639         self = oldself;
640 };
641
642 // spawn some default teams if the map is not set up for ctf
643 void ctf_spawnteams()
644 {
645         float numteams;
646
647         numteams = 2;//cvar("g_ctf_default_teams");
648
649         ctf_spawnteam("Red", COLOR_TEAM1 - 1);
650         ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
651 };
652
653 void ctf_delayedinit()
654 {
655         self.think = SUB_Remove;
656         self.nextthink = time;
657         // if no teams are found, spawn defaults
658         if (find(world, classname, "ctf_team") == world)
659                 ctf_spawnteams();
660 };
661
662 void ctf_init()
663 {
664         local entity e;
665         e = spawn();
666         e.think = ctf_delayedinit;
667         e.nextthink = time + 0.1;
668         flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
669 };
670
671 void ctf_setstatus2(entity flag, float shift)
672 {
673         if (flag.cnt == FLAG_CARRY)
674                 if (flag.owner == self)
675                         self.items |= shift * 3;
676                 else
677                         self.items |= shift * 1;
678         else if (flag.cnt == FLAG_DROPPED)
679                 self.items |= shift * 2;
680         else
681         {
682                 // no status bits
683         }
684 };
685
686 void ctf_setstatus()
687 {
688         self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
689         self.items = self.items - (self.items & IT_RED_FLAG_LOST);
690         self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
691         self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
692
693         if (g_ctf) {
694                 local entity flag;
695                 float redflags, blueflags;
696
697                 redflags = 0;
698                 blueflags = 0;
699
700                 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
701                 {
702                         if(flag.team == COLOR_TEAM1)
703                                 ++redflags;
704                         else if(flag.team == COLOR_TEAM2)
705                                 ++blueflags;
706                 }
707
708                 // blinking magic: if there is more than one flag, show one of these in a clever way
709                 if(redflags)
710                         redflags = mod(floor(time * redflags * 0.75), redflags);
711                 if(blueflags)
712                         blueflags = mod(floor(time * blueflags * 0.75), blueflags);
713
714                 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
715                 {
716                         if(flag.team == COLOR_TEAM1)
717                         {
718                                 if(redflags-- == 0) // happens exactly once
719                                         ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
720                         }
721                         else if(flag.team == COLOR_TEAM2)
722                         {
723                                 if(blueflags-- == 0) // happens exactly once
724                                         ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
725                         }
726                 }
727         }
728 };