1 #define FLAG_MIN (PL_MIN + '0 0 -13')
2 #define FLAG_MAX (PL_MAX + '0 0 -13')
5 entity ctf_worldflaglist; // CTF flags in the map
6 .entity ctf_worldflagnext;
10 .float next_take_time; // the next time a player can pick up a flag (time + blah)
11 /// I used this, in part, to fix the looping score bug. - avirox
12 //float FLAGSCORE_PICKUP = 1;
13 //float FLAGSCORE_RETURN = 5; // returned by owner team
14 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
15 //float FLAGSCORE_CAPTURE = 5;
17 #define FLAG_CARRY_POS '-15 0 7'
19 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
21 float captureshield_min_negscore; // punish at -20 points
22 float captureshield_max_ratio; // punish at most 30% of each team
23 float captureshield_force; // push force of the shield
25 float ctf_captureshield_shielded(entity p)
29 float players_worseeq, players_total;
31 if(captureshield_max_ratio <= 0)
34 s = PlayerScore_Add(p, SP_SCORE, 0);
35 if(s >= -captureshield_min_negscore)
38 players_total = players_worseeq = 0;
43 se = PlayerScore_Add(e, SP_SCORE, 0);
49 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
52 if(players_worseeq >= players_total * captureshield_max_ratio)
58 void ctf_captureshield_update(entity p, float dir)
61 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
63 should = ctf_captureshield_shielded(p);
68 centerprint_atprio(p, CENTERPRIO_SHIELDING, "^3You are now ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Make some defensive scores before trying again.");
69 // TODO csqc notifier for this
73 centerprint_atprio(p, CENTERPRIO_SHIELDING, "^3You are now free.\n\n^3Feel free to ^1try to capture^3 the flag again\n^3if you think you will succeed.");
74 // TODO csqc notifier for this
76 p.ctf_captureshielded = should;
81 float ctf_captureshield_customize()
83 if not(other.ctf_captureshielded)
85 if(self.team == other.team)
90 void ctf_captureshield_touch()
92 if not(other.ctf_captureshielded)
94 if(self.team == other.team)
98 mymid = (self.absmin + self.absmax) * 0.5;
99 othermid = (other.absmin + other.absmax) * 0.5;
100 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
101 centerprint_atprio(other, CENTERPRIO_SHIELDING, "^3You are ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Get some defensive scores before trying again.");
104 void ctf_captureshield_spawn()
110 e.touch = ctf_captureshield_touch;
111 e.customizeentityforclient = ctf_captureshield_customize;
112 e.classname = "ctf_captureshield";
113 e.effects = EF_ADDITIVE;
114 e.movetype = MOVETYPE_NOCLIP;
115 e.solid = SOLID_TRIGGER;
116 e.avelocity = '7 0 11';
117 setorigin(e, self.origin);
118 setmodel(e, "models/onslaught/generator_shield.md3");
120 setsize(e, e.scale * e.mins, e.scale * e.maxs);
123 float ctf_score_value(string parameter)
125 if(g_ctf_win_mode != 2)
126 return cvar(strcat("g_ctf_personal", parameter));
128 return cvar(strcat("g_ctf_flag", parameter));
131 void FakeTimeLimit(entity e, float t)
134 WriteByte(MSG_ONE, 3); // svc_updatestat
135 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
137 WriteCoord(MSG_ONE, cvar("timelimit"));
139 WriteCoord(MSG_ONE, (t + 1) / 60);
142 float flagcaptimerecord;
143 .float flagpickuptime;
144 //.float iscommander;
152 if(self.classname != "item_flag_team")
153 error("PlaceFlag a non-flag");
156 self.t_width = 0.1; // frame animation rate
158 self.t_length = 58; // maximum frame
160 setattachment(self, world, "");
161 self.mdl = self.model;
162 self.flags = FL_ITEM;
163 self.solid = SOLID_TRIGGER;
164 self.movetype = MOVETYPE_NONE;
165 self.velocity = '0 0 0';
166 self.origin_z = self.origin_z + 6;
167 self.think = FlagThink;
168 self.touch = FlagTouch;
169 self.nextthink = time + 0.1;
170 self.cnt = FLAG_BASE;
171 self.mangle = self.angles;
172 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
173 //self.effects = self.effects | EF_DIMLIGHT;
176 self.dropped_origin = self.origin;
181 self.movetype = MOVETYPE_TOSS;
183 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
186 void LogCTF(string mode, float flagteam, entity actor)
189 if(!cvar("sv_eventlog"))
191 s = strcat(":ctf:", mode);
192 s = strcat(s, ":", ftos(flagteam));
194 s = strcat(s, ":", ftos(actor.playerid));
198 void RegenFlag(entity e)
200 if(e.classname != "item_flag_team")
201 error("RegenFlag a non-flag");
203 setattachment(e, world, "");
204 e.damageforcescale = 0;
205 e.movetype = MOVETYPE_NONE;
207 e.movetype = MOVETYPE_TOSS;
208 e.solid = SOLID_TRIGGER;
209 // TODO: play a sound here
210 setorigin(e, e.dropped_origin);
214 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
217 void ReturnFlag(entity e)
219 if(e.classname != "item_flag_team")
220 error("ReturnFlag a non-flag");
223 if (e.owner.flagcarried == e)
225 WaypointSprite_DetachCarrier(e.owner);
226 e.owner.flagcarried = world;
229 FakeTimeLimit(e.owner, -1);
235 void DropFlag(entity e, entity penalty_receiver, entity attacker)
239 if(e.classname != "item_flag_team")
240 error("DropFlag a non-flag");
250 dprint("FLAG: drop - no owner?!?!\n");
254 if (p.flagcarried != e)
256 dprint("FLAG: drop - owner is not carrying this flag??\n");
259 bprint(p.netname, "^7 lost the ", e.netname, "\n");
262 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
264 UpdateFrags(p, -ctf_score_value("penalty_drop"));
265 PlayerScore_Add(p, SP_CTF_DROPS, +1);
266 ctf_captureshield_update(p, 0); // shield only
267 e.playerid = attacker.playerid;
268 e.ctf_droptime = time;
270 if(p.waypointsprite_attachedforcarrier)
272 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
273 WaypointSprite_DetachCarrier(p);
277 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
278 backtrace("Flag carrier had no flag sprite?!?");
280 LogCTF("dropped", p.team, p);
282 setattachment(e, world, "");
283 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
285 if (p.flagcarried == e)
286 p.flagcarried = world;
289 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
290 e.solid = SOLID_TRIGGER;
291 e.movetype = MOVETYPE_TOSS;
292 // setsize(e, '-16 -16 0', '16 16 74');
293 setorigin(e, p.origin - '0 0 24' + '0 0 37');
294 e.cnt = FLAG_DROPPED;
295 e.velocity = '0 0 300';
296 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
298 trace_startsolid = FALSE;
299 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
301 dprint("FLAG FALLTHROUGH will happen SOON\n");
306 if(self.delay > time)
308 self.delay = time + self.t_width;
309 if(self.nextthink > self.delay)
310 self.nextthink = self.delay;
312 self.frame = self.frame + 1;
313 if(self.frame > self.t_length)
321 self.nextthink = time + 0.1;
323 // sorry, we have to reset the flag size if it got squished by something
324 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
326 // if we can grow back, grow back
327 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
328 if(!trace_startsolid)
329 setsize(self, FLAG_MIN, FLAG_MAX);
332 if(self == ctf_worldflaglist) // only for the first flag
335 ctf_captureshield_update(e, 1); // release shield only
340 if(self.speedrunning)
341 if(self.cnt == FLAG_CARRY)
344 if(flagcaptimerecord)
345 if(time >= self.flagpickuptime + flagcaptimerecord)
347 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
349 self.owner.impulse = 77; // returning!
359 if (self.cnt == FLAG_BASE)
362 if (self.cnt == FLAG_DROPPED)
364 // flag fallthrough? FIXME remove this if bug is really fixed now
365 if(self.origin_z < -131072)
367 dprint("FLAG FALLTHROUGH just happened\n");
368 self.pain_finished = 0;
370 setattachment(self, world, "");
371 if (time > self.pain_finished)
373 bprint("The ", self.netname, " has returned to base\n");
374 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
375 LogCTF("returned", self.team, world);
382 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
384 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
385 DropFlag(self, world, world);
389 if(cvar("g_ctf_allow_drop"))
391 DropFlag(self, e, world);
400 local string s, s0, h0, h1;
401 if (other.classname != "player")
403 if (other.health < 1) // ignore dead players
406 if (self.cnt == FLAG_CARRY)
409 if (self.cnt == FLAG_BASE)
410 if (other.team == self.team)
411 if (other.flagcarried) // he's got a flag
412 if (other.flagcarried.team != self.team) // capture
414 if (other.flagcarried == world)
418 if(player_count - currentbots <= 1) // at most one human
420 t = time - other.flagcarried.flagpickuptime;
421 s = ftos_decimals(t, 2);
422 s0 = ftos_decimals(flagcaptimerecord, 2);
423 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
428 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
429 if (flagcaptimerecord == 0)
431 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
432 flagcaptimerecord = t;
433 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
434 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
435 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
437 else if (t < flagcaptimerecord)
439 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
440 flagcaptimerecord = t;
441 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
442 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
443 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
447 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
451 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
453 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
454 LogCTF("capture", other.flagcarried.team, other);
455 // give credit to the individual player
456 UpdateFrags(other, ctf_score_value("score_capture"));
458 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
459 WaypointSprite_DetachCarrier(other);
460 if(self.speedrunning)
461 FakeTimeLimit(other, -1);
462 RegenFlag (other.flagcarried);
463 other.flagcarried = world;
464 other.next_take_time = time + 1;
466 if (self.cnt == FLAG_BASE)
467 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
468 if (other.team != self.team)
469 if (!other.flagcarried)
470 if (!other.ctf_captureshielded)
472 if (other.next_take_time > time)
475 self.flagpickuptime = time; // used for timing runs
476 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
477 if(other.speedrunning)
478 if(flagcaptimerecord)
479 FakeTimeLimit(other, time + flagcaptimerecord);
480 self.solid = SOLID_NOT;
481 setorigin(self, self.origin); // relink
483 other.flagcarried = self;
484 self.cnt = FLAG_CARRY;
485 self.angles = '0 0 0';
486 bprint(other.netname, "^7 got the ", self.netname, "\n");
487 UpdateFrags(other, ctf_score_value("score_pickup_base"));
488 self.dropperid = other.playerid;
489 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
490 LogCTF("steal", self.team, other);
491 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
493 FOR_EACH_PLAYER(player)
494 if(player.team == self.team)
495 centerprint(player, "The enemy got your flag! Retrieve it!");
497 self.movetype = MOVETYPE_NONE;
498 setorigin(self, FLAG_CARRY_POS);
499 setattachment(self, other, "");
500 WaypointSprite_AttachCarrier("flagcarrier", other);
501 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
502 WaypointSprite_Ping(self.sprite);
507 if (self.cnt == FLAG_DROPPED)
509 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
510 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
513 bprint(other.netname, "^7 returned the ", self.netname, "\n");
515 // punish the player who last had it
516 FOR_EACH_PLAYER(player)
517 if(player.playerid == self.dropperid)
519 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
520 ctf_captureshield_update(player, 0); // shield only
523 // punish the team who was last carrying it
524 if(self.team == COLOR_TEAM1)
525 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
527 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
529 // reward the player who returned it
530 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
532 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
533 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
535 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
539 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
540 UpdateFrags(other, ctf_score_value("score_return"));
542 UpdateFrags(other, ctf_score_value("score_return_rogue"));
544 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
545 LogCTF("return", self.team, other);
546 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
549 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
552 self.solid = SOLID_NOT;
553 setorigin(self, self.origin); // relink
555 other.flagcarried = self;
556 self.cnt = FLAG_CARRY;
557 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
560 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
561 //print("factor is ", ftos(f), "\n");
562 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
563 + ctf_score_value("score_pickup_dropped_early") * f;
565 self.dropperid = other.playerid;
566 //print("score is ", ftos(f), "\n");
568 UpdateFrags(other, f);
569 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
570 LogCTF("pickup", self.team, other);
571 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
573 FOR_EACH_PLAYER(player)
574 if(player.team == self.team)
575 centerprint(player, "The enemy got your flag! Retrieve it!");
577 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
578 setorigin(self, FLAG_CARRY_POS);
579 setattachment(self, other, "");
580 self.damageforcescale = 0;
581 WaypointSprite_AttachCarrier("flagcarrier", other);
582 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
587 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
588 CTF Starting point for a player
593 viewing angle when spawning
595 void spawnfunc_info_player_team1()
602 self.team = COLOR_TEAM1; // red
603 spawnfunc_info_player_deathmatch();
605 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
607 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
608 CTF Starting point for a player in
613 viewing angle when spawning
615 void spawnfunc_info_player_team2()
622 self.team = COLOR_TEAM2; // blue
623 spawnfunc_info_player_deathmatch();
625 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
627 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
628 CTF Starting point for a player in
629 team three (Magenta).
633 viewing angle when spawning
635 void spawnfunc_info_player_team3()
642 self.team = COLOR_TEAM3; // purple
643 spawnfunc_info_player_deathmatch();
647 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
648 CTF Starting point for a player in
653 viewing angle when spawning
655 void spawnfunc_info_player_team4()
662 self.team = COLOR_TEAM4; // yellow
663 spawnfunc_info_player_deathmatch();
666 void item_flag_reset()
668 DropFlag(self, world, world);
673 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
674 CTF flag for team one (Red).
675 Multiple are allowed.
679 Angle the flag will point
682 model to use, note this needs red and blue as skins 0 and 1
683 (default models/ctf/flag.md3)
685 sound played when flag is picked up
686 (default ctf/take.wav)
688 sound played when flag is returned by a teammate
689 (default ctf/return.wav)
691 sound played when flag is captured
692 (default ctf/redcapture.wav)
694 sound played when flag is lost in the field and respawns itself
695 (default ctf/respawn.wav)
698 void spawnfunc_item_flag_team1()
706 //if(!cvar("teamplay"))
707 // cvar_set("teamplay", "3");
709 // link flag into ctf_worldflaglist
710 self.ctf_worldflagnext = ctf_worldflaglist;
711 ctf_worldflaglist = self;
713 self.classname = "item_flag_team";
716 self.team = COLOR_TEAM2; // color 13 team (blue)
717 self.items = IT_KEY1; // silver key (bluish enough)
721 self.team = COLOR_TEAM1; // color 4 team (red)
722 self.items = IT_KEY2; // gold key (redish enough)
724 self.netname = "^1RED^7 flag";
725 self.target = "###item###";
727 if(self.spawnflags & 1)
730 self.model = "models/ctf/flags.md3";
732 self.noise = "ctf/take.wav";
734 self.noise1 = "ctf/return.wav";
736 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
738 self.noise3 = "ctf/respawn.wav";
739 precache_model (self.model);
740 setmodel (self, self.model); // precision set below
741 precache_sound (self.noise);
742 precache_sound (self.noise1);
743 precache_sound (self.noise2);
744 precache_sound (self.noise3);
745 //setsize(self, '-16 -16 -37', '16 16 37');
746 setsize(self, FLAG_MIN, FLAG_MAX);
747 setorigin(self, self.origin + '0 0 37');
748 self.nextthink = time + 0.2; // start after doors etc
749 self.think = place_flag;
753 //if(!self.glow_size)
754 // self.glow_size = 50;
756 self.effects = self.effects | EF_LOWPRECISION;
757 if(cvar("g_ctf_fullbrightflags"))
758 self.effects |= EF_FULLBRIGHT;
759 if(cvar("g_ctf_dynamiclights"))
760 self.effects |= EF_RED;
762 waypoint_spawnforitem(self);
764 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
765 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
767 precache_model("models/onslaught/generator_shield.md3");
769 self.reset = item_flag_reset;
772 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
773 CTF flag for team two (Blue).
774 Multiple are allowed.
778 Angle the flag will point
781 model to use, note this needs red and blue as skins 0 and 1
782 (default models/ctf/flag.md3)
784 sound played when flag is picked up
785 (default ctf/take.wav)
787 sound played when flag is returned by a teammate
788 (default ctf/return.wav)
790 sound played when flag is captured
791 (default ctf/bluecapture.wav)
793 sound played when flag is lost in the field and respawns itself
794 (default ctf/respawn.wav)
797 void spawnfunc_item_flag_team2()
804 //if(!cvar("teamplay"))
805 // cvar_set("teamplay", "3");
807 // link flag into ctf_worldflaglist
808 self.ctf_worldflagnext = ctf_worldflaglist;
809 ctf_worldflaglist = self;
811 self.classname = "item_flag_team";
814 self.team = COLOR_TEAM1; // color 4 team (red)
815 self.items = IT_KEY2; // gold key (redish enough)
819 self.team = COLOR_TEAM2; // color 13 team (blue)
820 self.items = IT_KEY1; // silver key (bluish enough)
822 self.netname = "^4BLUE^7 flag";
823 self.target = "###item###";
825 if(self.spawnflags & 1)
828 self.model = "models/ctf/flags.md3";
830 self.noise = "ctf/take.wav";
832 self.noise1 = "ctf/return.wav";
834 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
836 self.noise3 = "ctf/respawn.wav";
837 precache_model (self.model);
838 setmodel (self, self.model); // precision set below
839 precache_sound (self.noise);
840 precache_sound (self.noise1);
841 precache_sound (self.noise2);
842 precache_sound (self.noise3);
843 //setsize(self, '-16 -16 -37', '16 16 37');
844 setsize(self, FLAG_MIN, FLAG_MAX);
845 setorigin(self, self.origin + '0 0 37');
846 self.nextthink = time + 0.2; // start after doors etc
847 self.think = place_flag;
851 //if(!self.glow_size)
852 // self.glow_size = 50;
854 self.effects = self.effects | EF_LOWPRECISION;
855 if(cvar("g_ctf_fullbrightflags"))
856 self.effects |= EF_FULLBRIGHT;
857 if(cvar("g_ctf_dynamiclights"))
858 self.effects |= EF_BLUE;
860 waypoint_spawnforitem(self);
862 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
863 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
865 precache_model("models/onslaught/generator_shield.md3");
867 self.reset = item_flag_reset;
871 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
872 Team declaration for CTF gameplay, this allows you to decide what team
873 names and control point models are used in your map.
875 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
876 domination, you don't need to make a blank one too.
880 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
882 Scoreboard color of the team (for example 4 is red and 13 is blue)
886 void spawnfunc_ctf_team()
893 self.classname = "ctf_team";
894 self.team = self.cnt + 1;
897 // code from here on is just to support maps that don't have control point and team entities
898 void ctf_spawnteam (string teamname, float teamcolor)
900 local entity oldself;
903 self.classname = "ctf_team";
904 self.netname = teamname;
905 self.cnt = teamcolor;
907 spawnfunc_ctf_team();
912 // spawn some default teams if the map is not set up for ctf
913 void ctf_spawnteams()
917 numteams = 2;//cvar("g_ctf_default_teams");
919 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
920 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
923 void ctf_delayedinit()
925 // if no teams are found, spawn defaults
926 if (find(world, classname, "ctf_team") == world)
934 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
935 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
937 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
938 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
939 captureshield_force = cvar("g_ctf_shield_force");
942 void ctf_setstatus2(entity flag, float shift)
944 if (flag.cnt == FLAG_CARRY)
945 if (flag.owner == self)
946 self.items |= shift * 3;
948 self.items |= shift * 1;
949 else if (flag.cnt == FLAG_DROPPED)
950 self.items |= shift * 2;
959 self.items &~= IT_RED_FLAG_TAKEN;
960 self.items &~= IT_RED_FLAG_LOST;
961 self.items &~= IT_BLUE_FLAG_TAKEN;
962 self.items &~= IT_BLUE_FLAG_LOST;
963 self.items &~= IT_CTF_SHIELDED;
967 float redflags, blueflags;
969 if(self.ctf_captureshielded)
970 self.items |= IT_CTF_SHIELDED;
975 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
977 if(flag.items & IT_KEY2) // blue
979 else if(flag.items & IT_KEY1) // red
983 // blinking magic: if there is more than one flag, show one of these in a clever way
985 redflags = mod(floor(time * redflags * 0.75), redflags);
987 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
989 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
991 if(flag.items & IT_KEY2) // blue
993 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
994 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
996 else if(flag.items & IT_KEY1) // red
998 if(--blueflags == -1) // happens exactly once
999 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1005 entity(float cteam) ctf_team_has_commander =
1008 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1011 FOR_EACH_REALPLAYER(pl) {
1012 if(pl.team == cteam && pl.iscommander) {
1019 void(entity e, float st) ctf_setstate =
1025 void(float cteam) ctf_new_commander =
1030 FOR_EACH_REALPLAYER(pl) {
1031 if(pl.team == cteam) {
1032 if(pl.iscommander) { // don't reassign if alreay there
1035 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1039 if(plmax == world) {
1040 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1044 plmax.iscommander = TRUE;
1045 ctf_setstate(plmax, 3);
1046 sprint(plmax, "^3You're the commander now!\n");
1047 centerprint(plmax, "^3You're the commander now!\n");
1050 void() ctf_clientconnect =
1052 self.iscommander = FALSE;
1054 if(!self.team || self.classname != "player") {
1055 ctf_setstate(self, -1);
1057 ctf_setstate(self, 0);
1059 self.team_saved = self.team;
1061 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1062 ctf_new_commander(self.team);
1066 void() ctf_playerchanged =
1068 if(!self.team || self.classname != "player") {
1069 ctf_setstate(self, -1);
1070 } else if(self.ctf_state < 0 && self.classname == "player") {
1071 ctf_setstate(self, 0);
1074 if(self.iscommander &&
1075 (self.classname != "player" || self.team != self.team_saved)
1078 self.iscommander = FALSE;
1079 if(self.classname == "player")
1080 ctf_setstate(self, 0);
1082 ctf_setstate(self, -1);
1083 ctf_new_commander(self.team_saved);
1086 self.team_saved = self.team;
1088 ctf_new_commander(self.team);
1091 void() ctf_clientdisconnect =
1093 if(self.iscommander)
1095 ctf_new_commander(self.team);
1099 entity GetPlayer(string);
1100 float() ctf_clientcommand =
1103 if(argv(0) == "order") {
1105 sprint(self, "This command is not supported in this gamemode.\n");
1108 if(!self.iscommander) {
1109 sprint(self, "^1You are not the commander!\n");
1113 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1116 e = GetPlayer(argv(1));
1118 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1121 if(e.team != self.team) {
1122 sprint(self, "^3You can only give orders to your own team!\n");
1125 if(argv(2) == "attack") {
1126 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1127 sprint(e, "^1Attack!\n");
1128 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1130 } else if(argv(2) == "defend") {
1131 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1132 sprint(e, "^Defend!\n");
1133 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1136 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");