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")
154 backtrace("PlaceFlag a non-flag");
159 self.t_width = 0.1; // frame animation rate
161 self.t_length = 58; // maximum frame
163 setattachment(self, world, "");
164 self.mdl = self.model;
165 self.flags = FL_ITEM;
166 self.solid = SOLID_TRIGGER;
167 self.movetype = MOVETYPE_NONE;
168 self.velocity = '0 0 0';
169 self.origin_z = self.origin_z + 6;
170 self.think = FlagThink;
171 self.touch = FlagTouch;
172 self.nextthink = time + 0.1;
173 self.cnt = FLAG_BASE;
174 self.mangle = self.angles;
175 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
176 //self.effects = self.effects | EF_DIMLIGHT;
179 self.dropped_origin = self.origin;
184 self.movetype = MOVETYPE_TOSS;
186 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
189 void LogCTF(string mode, float flagteam, entity actor)
192 if(!cvar("sv_eventlog"))
194 s = strcat(":ctf:", mode);
195 s = strcat(s, ":", ftos(flagteam));
197 s = strcat(s, ":", ftos(actor.playerid));
201 void RegenFlag(entity e)
203 if(e.classname != "item_flag_team")
205 backtrace("RegenFlag a non-flag");
209 setattachment(e, world, "");
210 e.damageforcescale = 0;
211 e.movetype = MOVETYPE_NONE;
213 e.movetype = MOVETYPE_TOSS;
214 e.solid = SOLID_TRIGGER;
215 // TODO: play a sound here
216 setorigin(e, e.dropped_origin);
220 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
223 void ReturnFlag(entity e)
225 if(e.classname != "item_flag_team")
227 backtrace("ReturnFlag a non-flag");
232 if (e.owner.flagcarried == e)
234 WaypointSprite_DetachCarrier(e.owner);
235 e.owner.flagcarried = world;
238 FakeTimeLimit(e.owner, -1);
244 void DropFlag(entity e, entity penalty_receiver, entity attacker)
248 if(e.classname != "item_flag_team")
250 backtrace("DropFlag a non-flag");
262 dprint("FLAG: drop - no owner?!?!\n");
266 if (p.flagcarried != e)
268 dprint("FLAG: drop - owner is not carrying this flag??\n");
271 bprint(p.netname, "^7 lost the ", e.netname, "\n");
274 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
276 UpdateFrags(p, -ctf_score_value("penalty_drop"));
277 PlayerScore_Add(p, SP_CTF_DROPS, +1);
278 ctf_captureshield_update(p, 0); // shield only
279 e.playerid = attacker.playerid;
280 e.ctf_droptime = time;
282 if(p.waypointsprite_attachedforcarrier)
284 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
285 WaypointSprite_DetachCarrier(p);
289 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
290 backtrace("Flag carrier had no flag sprite?!?");
292 LogCTF("dropped", p.team, p);
294 setattachment(e, world, "");
295 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
297 if (p.flagcarried == e)
298 p.flagcarried = world;
301 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
302 e.solid = SOLID_TRIGGER;
303 e.movetype = MOVETYPE_TOSS;
304 // setsize(e, '-16 -16 0', '16 16 74');
305 setorigin(e, p.origin - '0 0 24' + '0 0 37');
306 e.cnt = FLAG_DROPPED;
307 e.velocity = '0 0 300';
308 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
310 trace_startsolid = FALSE;
311 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
313 dprint("FLAG FALLTHROUGH will happen SOON\n");
318 if(self.delay > time)
320 self.delay = time + self.t_width;
321 if(self.nextthink > self.delay)
322 self.nextthink = self.delay;
324 self.frame = self.frame + 1;
325 if(self.frame > self.t_length)
333 self.nextthink = time + 0.1;
335 // sorry, we have to reset the flag size if it got squished by something
336 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
338 // if we can grow back, grow back
339 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
340 if(!trace_startsolid)
341 setsize(self, FLAG_MIN, FLAG_MAX);
344 if(self == ctf_worldflaglist) // only for the first flag
347 ctf_captureshield_update(e, 1); // release shield only
352 if(self.speedrunning)
353 if(self.cnt == FLAG_CARRY)
356 if(flagcaptimerecord)
357 if(time >= self.flagpickuptime + flagcaptimerecord)
359 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
361 self.owner.impulse = 77; // returning!
371 if (self.cnt == FLAG_BASE)
374 if (self.cnt == FLAG_DROPPED)
376 // flag fallthrough? FIXME remove this if bug is really fixed now
377 if(self.origin_z < -131072)
379 dprint("FLAG FALLTHROUGH just happened\n");
380 self.pain_finished = 0;
382 setattachment(self, world, "");
383 if (time > self.pain_finished)
385 bprint("The ", self.netname, " has returned to base\n");
386 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
387 LogCTF("returned", self.team, world);
394 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
396 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
397 DropFlag(self, world, world);
401 if(cvar("g_ctf_allow_drop"))
403 DropFlag(self, e, world);
412 local string s, s0, h0, h1;
413 if (other.classname != "player")
415 if (other.health < 1) // ignore dead players
418 if (self.cnt == FLAG_CARRY)
421 if (self.cnt == FLAG_BASE)
422 if (other.team == self.team)
423 if (other.flagcarried) // he's got a flag
424 if (other.flagcarried.team != self.team) // capture
426 if (other.flagcarried == world)
430 if(cvar("g_ctf_captimerecord_allow_assisted") || player_count - currentbots <= 1) // at most one human
432 t = time - other.flagcarried.flagpickuptime;
433 s = ftos_decimals(t, 2);
434 s0 = ftos_decimals(flagcaptimerecord, 2);
435 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
440 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
441 if (flagcaptimerecord == 0)
443 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
444 flagcaptimerecord = t;
445 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
446 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
447 write_recordmarker(other, time - t, t);
449 else if (t < flagcaptimerecord)
451 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
452 flagcaptimerecord = t;
453 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
454 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
455 write_recordmarker(other, time - t, t);
459 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
463 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
465 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
466 LogCTF("capture", other.flagcarried.team, other);
467 // give credit to the individual player
468 UpdateFrags(other, ctf_score_value("score_capture"));
470 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
471 WaypointSprite_DetachCarrier(other);
472 if(self.speedrunning)
473 FakeTimeLimit(other, -1);
474 RegenFlag (other.flagcarried);
475 other.flagcarried = world;
476 other.next_take_time = time + 1;
478 if (self.cnt == FLAG_BASE)
479 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
480 if (other.team != self.team)
481 if (!other.flagcarried)
482 if (!other.ctf_captureshielded)
484 if (other.next_take_time > time)
487 self.flagpickuptime = time; // used for timing runs
488 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
489 if(other.speedrunning)
490 if(flagcaptimerecord)
491 FakeTimeLimit(other, time + flagcaptimerecord);
492 self.solid = SOLID_NOT;
493 setorigin(self, self.origin); // relink
495 other.flagcarried = self;
496 self.cnt = FLAG_CARRY;
497 self.angles = '0 0 0';
498 bprint(other.netname, "^7 got the ", self.netname, "\n");
499 UpdateFrags(other, ctf_score_value("score_pickup_base"));
500 self.dropperid = other.playerid;
501 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
502 LogCTF("steal", self.team, other);
503 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
505 FOR_EACH_PLAYER(player)
506 if(player.team == self.team)
507 centerprint(player, "The enemy got your flag! Retrieve it!");
509 self.movetype = MOVETYPE_NONE;
510 setorigin(self, FLAG_CARRY_POS);
511 setattachment(self, other, "");
512 WaypointSprite_AttachCarrier("flagcarrier", other);
513 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
514 WaypointSprite_Ping(self.sprite);
519 if (self.cnt == FLAG_DROPPED)
521 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
522 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
525 bprint(other.netname, "^7 returned the ", self.netname, "\n");
527 // punish the player who last had it
528 FOR_EACH_PLAYER(player)
529 if(player.playerid == self.dropperid)
531 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
532 ctf_captureshield_update(player, 0); // shield only
535 // punish the team who was last carrying it
536 if(self.team == COLOR_TEAM1)
537 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
539 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
541 // reward the player who returned it
542 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
544 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
545 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
547 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
551 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
552 UpdateFrags(other, ctf_score_value("score_return"));
554 UpdateFrags(other, ctf_score_value("score_return_rogue"));
556 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
557 LogCTF("return", self.team, other);
558 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
561 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
564 self.solid = SOLID_NOT;
565 setorigin(self, self.origin); // relink
567 other.flagcarried = self;
568 self.cnt = FLAG_CARRY;
569 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
572 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
573 //print("factor is ", ftos(f), "\n");
574 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
575 + ctf_score_value("score_pickup_dropped_early") * f;
577 self.dropperid = other.playerid;
578 //print("score is ", ftos(f), "\n");
580 UpdateFrags(other, f);
581 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
582 LogCTF("pickup", self.team, other);
583 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
585 FOR_EACH_PLAYER(player)
586 if(player.team == self.team)
587 centerprint(player, "The enemy got your flag! Retrieve it!");
589 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
590 setorigin(self, FLAG_CARRY_POS);
591 setattachment(self, other, "");
592 self.damageforcescale = 0;
593 WaypointSprite_AttachCarrier("flagcarrier", other);
594 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
599 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
600 CTF Starting point for a player
605 viewing angle when spawning
607 void spawnfunc_info_player_team1()
614 self.team = COLOR_TEAM1; // red
615 spawnfunc_info_player_deathmatch();
617 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
619 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
620 CTF Starting point for a player in
625 viewing angle when spawning
627 void spawnfunc_info_player_team2()
634 self.team = COLOR_TEAM2; // blue
635 spawnfunc_info_player_deathmatch();
637 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
639 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
640 CTF Starting point for a player in
641 team three (Magenta).
645 viewing angle when spawning
647 void spawnfunc_info_player_team3()
654 self.team = COLOR_TEAM3; // purple
655 spawnfunc_info_player_deathmatch();
659 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
660 CTF Starting point for a player in
665 viewing angle when spawning
667 void spawnfunc_info_player_team4()
674 self.team = COLOR_TEAM4; // yellow
675 spawnfunc_info_player_deathmatch();
678 void item_flag_reset()
680 DropFlag(self, world, world);
685 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
686 CTF flag for team one (Red).
687 Multiple are allowed.
691 Angle the flag will point
694 model to use, note this needs red and blue as skins 0 and 1
695 (default models/ctf/flag.md3)
697 sound played when flag is picked up
698 (default ctf/take.wav)
700 sound played when flag is returned by a teammate
701 (default ctf/return.wav)
703 sound played when flag is captured
704 (default ctf/redcapture.wav)
706 sound played when flag is lost in the field and respawns itself
707 (default ctf/respawn.wav)
710 void spawnfunc_item_flag_team1()
718 //if(!cvar("teamplay"))
719 // cvar_set("teamplay", "3");
721 // link flag into ctf_worldflaglist
722 self.ctf_worldflagnext = ctf_worldflaglist;
723 ctf_worldflaglist = self;
725 self.classname = "item_flag_team";
728 self.team = COLOR_TEAM2; // color 13 team (blue)
729 self.items = IT_KEY1; // silver key (bluish enough)
733 self.team = COLOR_TEAM1; // color 4 team (red)
734 self.items = IT_KEY2; // gold key (redish enough)
736 self.netname = "^1RED^7 flag";
737 self.target = "###item###";
738 self.skin = cvar("g_ctf_flag_red_skin");
739 if(self.spawnflags & 1)
742 self.model = cvar_string("g_ctf_flag_red_model");
744 self.noise = "ctf/take.wav";
746 self.noise1 = "ctf/return.wav";
748 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
750 self.noise3 = "ctf/respawn.wav";
751 precache_model (self.model);
752 setmodel (self, self.model); // precision set below
753 precache_sound (self.noise);
754 precache_sound (self.noise1);
755 precache_sound (self.noise2);
756 precache_sound (self.noise3);
757 //setsize(self, '-16 -16 -37', '16 16 37');
758 setsize(self, FLAG_MIN, FLAG_MAX);
759 setorigin(self, self.origin + '0 0 37');
760 self.nextthink = time + 0.2; // start after doors etc
761 self.think = place_flag;
765 //if(!self.glow_size)
766 // self.glow_size = 50;
768 self.effects = self.effects | EF_LOWPRECISION;
769 if(cvar("g_ctf_fullbrightflags"))
770 self.effects |= EF_FULLBRIGHT;
771 if(cvar("g_ctf_dynamiclights"))
772 self.effects |= EF_RED;
774 waypoint_spawnforitem(self);
776 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
777 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
779 precache_model("models/onslaught/generator_shield.md3");
781 self.reset = item_flag_reset;
784 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
785 CTF flag for team two (Blue).
786 Multiple are allowed.
790 Angle the flag will point
793 model to use, note this needs red and blue as skins 0 and 1
794 (default models/ctf/flag.md3)
796 sound played when flag is picked up
797 (default ctf/take.wav)
799 sound played when flag is returned by a teammate
800 (default ctf/return.wav)
802 sound played when flag is captured
803 (default ctf/bluecapture.wav)
805 sound played when flag is lost in the field and respawns itself
806 (default ctf/respawn.wav)
809 void spawnfunc_item_flag_team2()
816 //if(!cvar("teamplay"))
817 // cvar_set("teamplay", "3");
819 // link flag into ctf_worldflaglist
820 self.ctf_worldflagnext = ctf_worldflaglist;
821 ctf_worldflaglist = self;
823 self.classname = "item_flag_team";
826 self.team = COLOR_TEAM1; // color 4 team (red)
827 self.items = IT_KEY2; // gold key (redish enough)
831 self.team = COLOR_TEAM2; // color 13 team (blue)
832 self.items = IT_KEY1; // silver key (bluish enough)
834 self.netname = "^4BLUE^7 flag";
835 self.target = "###item###";
836 self.skin = cvar("g_ctf_flag_blue_skin");
837 if(self.spawnflags & 1)
840 self.model = cvar_string("g_ctf_flag_blue_model");
842 self.noise = "ctf/take.wav";
844 self.noise1 = "ctf/return.wav";
846 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
848 self.noise3 = "ctf/respawn.wav";
849 precache_model (self.model);
850 setmodel (self, self.model); // precision set below
851 precache_sound (self.noise);
852 precache_sound (self.noise1);
853 precache_sound (self.noise2);
854 precache_sound (self.noise3);
855 //setsize(self, '-16 -16 -37', '16 16 37');
856 setsize(self, FLAG_MIN, FLAG_MAX);
857 setorigin(self, self.origin + '0 0 37');
858 self.nextthink = time + 0.2; // start after doors etc
859 self.think = place_flag;
863 //if(!self.glow_size)
864 // self.glow_size = 50;
866 self.effects = self.effects | EF_LOWPRECISION;
867 if(cvar("g_ctf_fullbrightflags"))
868 self.effects |= EF_FULLBRIGHT;
869 if(cvar("g_ctf_dynamiclights"))
870 self.effects |= EF_BLUE;
872 waypoint_spawnforitem(self);
874 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
875 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
877 precache_model("models/onslaught/generator_shield.md3");
879 self.reset = item_flag_reset;
883 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
884 Team declaration for CTF gameplay, this allows you to decide what team
885 names and control point models are used in your map.
887 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
888 domination, you don't need to make a blank one too.
892 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
894 Scoreboard color of the team (for example 4 is red and 13 is blue)
898 void spawnfunc_ctf_team()
905 self.classname = "ctf_team";
906 self.team = self.cnt + 1;
909 // code from here on is just to support maps that don't have control point and team entities
910 void ctf_spawnteam (string teamname, float teamcolor)
912 local entity oldself;
915 self.classname = "ctf_team";
916 self.netname = teamname;
917 self.cnt = teamcolor;
919 spawnfunc_ctf_team();
924 // spawn some default teams if the map is not set up for ctf
925 void ctf_spawnteams()
929 numteams = 2;//cvar("g_ctf_default_teams");
931 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
932 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
935 void ctf_delayedinit()
937 // if no teams are found, spawn defaults
938 if (find(world, classname, "ctf_team") == world)
946 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
947 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
949 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
950 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
951 captureshield_force = cvar("g_ctf_shield_force");
954 void ctf_setstatus2(entity flag, float shift)
956 if (flag.cnt == FLAG_CARRY)
957 if (flag.owner == self)
958 self.items |= shift * 3;
960 self.items |= shift * 1;
961 else if (flag.cnt == FLAG_DROPPED)
962 self.items |= shift * 2;
971 self.items &~= IT_RED_FLAG_TAKEN;
972 self.items &~= IT_RED_FLAG_LOST;
973 self.items &~= IT_BLUE_FLAG_TAKEN;
974 self.items &~= IT_BLUE_FLAG_LOST;
975 self.items &~= IT_CTF_SHIELDED;
979 float redflags, blueflags;
981 if(self.ctf_captureshielded)
982 self.items |= IT_CTF_SHIELDED;
987 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
989 if(flag.items & IT_KEY2) // blue
991 else if(flag.items & IT_KEY1) // red
995 // blinking magic: if there is more than one flag, show one of these in a clever way
997 redflags = mod(floor(time * redflags * 0.75), redflags);
999 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1001 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1003 if(flag.items & IT_KEY2) // blue
1005 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1006 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1008 else if(flag.items & IT_KEY1) // red
1010 if(--blueflags == -1) // happens exactly once
1011 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1017 entity(float cteam) ctf_team_has_commander =
1020 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1023 FOR_EACH_REALPLAYER(pl) {
1024 if(pl.team == cteam && pl.iscommander) {
1031 void(entity e, float st) ctf_setstate =
1037 void(float cteam) ctf_new_commander =
1042 FOR_EACH_REALPLAYER(pl) {
1043 if(pl.team == cteam) {
1044 if(pl.iscommander) { // don't reassign if alreay there
1047 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1051 if(plmax == world) {
1052 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1056 plmax.iscommander = TRUE;
1057 ctf_setstate(plmax, 3);
1058 sprint(plmax, "^3You're the commander now!\n");
1059 centerprint(plmax, "^3You're the commander now!\n");
1062 void() ctf_clientconnect =
1064 self.iscommander = FALSE;
1066 if(!self.team || self.classname != "player") {
1067 ctf_setstate(self, -1);
1069 ctf_setstate(self, 0);
1071 self.team_saved = self.team;
1073 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1074 ctf_new_commander(self.team);
1078 void() ctf_playerchanged =
1080 if(!self.team || self.classname != "player") {
1081 ctf_setstate(self, -1);
1082 } else if(self.ctf_state < 0 && self.classname == "player") {
1083 ctf_setstate(self, 0);
1086 if(self.iscommander &&
1087 (self.classname != "player" || self.team != self.team_saved)
1090 self.iscommander = FALSE;
1091 if(self.classname == "player")
1092 ctf_setstate(self, 0);
1094 ctf_setstate(self, -1);
1095 ctf_new_commander(self.team_saved);
1098 self.team_saved = self.team;
1100 ctf_new_commander(self.team);
1103 void() ctf_clientdisconnect =
1105 if(self.iscommander)
1107 ctf_new_commander(self.team);
1111 entity GetPlayer(string);
1112 float() ctf_clientcommand =
1115 if(argv(0) == "order") {
1117 sprint(self, "This command is not supported in this gamemode.\n");
1120 if(!self.iscommander) {
1121 sprint(self, "^1You are not the commander!\n");
1125 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1128 e = GetPlayer(argv(1));
1130 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1133 if(e.team != self.team) {
1134 sprint(self, "^3You can only give orders to your own team!\n");
1137 if(argv(2) == "attack") {
1138 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1139 sprint(e, "^1Attack!\n");
1140 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1142 } else if(argv(2) == "defend") {
1143 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1144 sprint(e, "^Defend!\n");
1145 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1148 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");