2 entity ctf_worldflaglist; // CTF flags in the map
3 .entity ctf_worldflagnext;
7 .float next_take_time; // the next time a player can pick up a flag (time + blah)
8 /// I used this, in part, to fix the looping score bug. - avirox
9 //float FLAGSCORE_PICKUP = 1;
10 //float FLAGSCORE_RETURN = 5; // returned by owner team
11 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
12 //float FLAGSCORE_CAPTURE = 5;
14 #define FLAG_CARRY_POS '-15 0 7'
16 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
18 float captureshield_min_negscore; // punish at -20 points
19 float captureshield_max_ratio; // punish at most 30% of each team
20 float captureshield_force; // push force of the shield
22 float ctf_captureshield_shielded(entity p)
26 float players_worseeq, players_total;
28 if(captureshield_max_ratio <= 0)
31 s = PlayerScore_Add(p, SP_SCORE, 0);
32 if(s >= -captureshield_min_negscore)
35 players_total = players_worseeq = 0;
40 se = PlayerScore_Add(e, SP_SCORE, 0);
46 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
49 if(players_worseeq >= players_total * captureshield_max_ratio)
55 void ctf_captureshield_update(entity p, float dir)
58 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
60 should = ctf_captureshield_shielded(p);
65 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.");
66 // TODO csqc notifier for this
70 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.");
71 // TODO csqc notifier for this
73 p.ctf_captureshielded = should;
78 float ctf_captureshield_customize()
80 if not(other.ctf_captureshielded)
82 if(self.team == other.team)
87 void ctf_captureshield_touch()
89 if not(other.ctf_captureshielded)
91 if(self.team == other.team)
95 mymid = (self.absmin + self.absmax) * 0.5;
96 othermid = (other.absmin + other.absmax) * 0.5;
97 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
98 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.");
101 void ctf_captureshield_spawn()
107 e.touch = ctf_captureshield_touch;
108 e.customizeentityforclient = ctf_captureshield_customize;
109 e.classname = "ctf_captureshield";
110 e.effects = EF_ADDITIVE;
111 e.movetype = MOVETYPE_NOCLIP;
112 e.solid = SOLID_TRIGGER;
113 e.avelocity = '7 0 11';
114 setorigin(e, self.origin);
115 setmodel(e, "models/onslaught/generator_shield.md3");
117 setsize(e, e.scale * e.mins, e.scale * e.maxs);
120 float ctf_score_value(string parameter)
122 if(g_ctf_win_mode != 2)
123 return cvar(strcat("g_ctf_personal", parameter));
125 return cvar(strcat("g_ctf_flag", parameter));
128 void FakeTimeLimit(entity e, float t)
131 WriteByte(MSG_ONE, 3); // svc_updatestat
132 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
134 WriteCoord(MSG_ONE, cvar("timelimit"));
136 WriteCoord(MSG_ONE, (t + 1) / 60);
139 float flagcaptimerecord;
140 .float flagpickuptime;
141 //.float iscommander;
150 self.t_width = 0.1; // frame animation rate
152 self.t_length = 58; // maximum frame
154 setattachment(self, world, "");
155 self.mdl = self.model;
156 self.flags = FL_ITEM;
157 self.solid = SOLID_TRIGGER;
158 self.movetype = MOVETYPE_NONE;
159 self.velocity = '0 0 0';
160 self.origin_z = self.origin_z + 6;
161 self.think = FlagThink;
162 self.touch = FlagTouch;
163 self.nextthink = time + 0.1;
164 self.cnt = FLAG_BASE;
165 self.mangle = self.angles;
166 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
167 //self.effects = self.effects | EF_DIMLIGHT;
170 self.dropped_origin = self.origin;
175 self.movetype = MOVETYPE_TOSS;
177 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
180 void LogCTF(string mode, float flagteam, entity actor)
183 if(!cvar("sv_eventlog"))
185 s = strcat(":ctf:", mode);
186 s = strcat(s, ":", ftos(flagteam));
188 s = strcat(s, ":", ftos(actor.playerid));
192 void RegenFlag(entity e)
194 setattachment(e, world, "");
195 e.damageforcescale = 0;
196 e.movetype = MOVETYPE_NONE;
198 e.movetype = MOVETYPE_TOSS;
199 e.solid = SOLID_TRIGGER;
200 // TODO: play a sound here
201 setorigin(e, e.dropped_origin);
205 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
208 void ReturnFlag(entity e)
211 if (e.owner.flagcarried == e)
213 WaypointSprite_DetachCarrier(e.owner);
214 e.owner.flagcarried = world;
217 FakeTimeLimit(e.owner, -1);
223 void DropFlag(entity e, entity penalty_receiver, entity attacker)
235 dprint("FLAG: drop - no owner?!?!\n");
239 if (p.flagcarried != e)
241 dprint("FLAG: drop - owner is not carrying this flag??\n");
244 bprint(p.netname, "^7 lost the ", e.netname, "\n");
247 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
249 UpdateFrags(p, -ctf_score_value("penalty_drop"));
250 PlayerScore_Add(p, SP_CTF_DROPS, +1);
251 ctf_captureshield_update(p, 0); // shield only
252 e.playerid = attacker.playerid;
253 e.ctf_droptime = time;
255 if(p.waypointsprite_attachedforcarrier)
257 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
258 WaypointSprite_DetachCarrier(p);
262 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
263 backtrace("Flag carrier had no flag sprite?!?");
265 LogCTF("dropped", p.team, p);
267 setattachment(e, world, "");
268 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
270 if (p.flagcarried == e)
271 p.flagcarried = world;
274 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
275 e.solid = SOLID_TRIGGER;
276 e.movetype = MOVETYPE_TOSS;
277 // setsize(e, '-16 -16 0', '16 16 74');
278 setorigin(e, p.origin - '0 0 24' + '0 0 37');
279 e.cnt = FLAG_DROPPED;
280 e.velocity = '0 0 300';
281 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
283 trace_startsolid = FALSE;
284 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
286 dprint("FLAG FALLTHROUGH will happen SOON\n");
291 if(self.delay > time)
293 self.delay = time + self.t_width;
294 if(self.nextthink > self.delay)
295 self.nextthink = self.delay;
297 self.frame = self.frame + 1;
298 if(self.frame > self.t_length)
306 self.nextthink = time + 0.1;
308 if(self == ctf_worldflaglist) // only for the first flag
311 ctf_captureshield_update(e, 1); // release shield only
316 if(self.speedrunning)
317 if(self.cnt == FLAG_CARRY)
320 if(flagcaptimerecord)
321 if(time >= self.flagpickuptime + flagcaptimerecord)
323 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
325 self.owner.impulse = 77; // returning!
335 if (self.cnt == FLAG_BASE)
338 if (self.cnt == FLAG_DROPPED)
340 // flag fallthrough? FIXME remove this if bug is really fixed now
341 if(self.origin_z < -131072)
343 dprint("FLAG FALLTHROUGH just happened\n");
344 self.pain_finished = 0;
346 setattachment(self, world, "");
347 if (time > self.pain_finished)
349 bprint("The ", self.netname, " has returned to base\n");
350 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
351 LogCTF("returned", self.team, world);
358 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
360 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
361 DropFlag(self, world, world);
365 if(cvar("g_ctf_allow_drop"))
367 DropFlag(self, e, world);
376 local string s, s0, h0, h1;
377 if (other.classname != "player")
379 if (other.health < 1) // ignore dead players
382 if (self.cnt == FLAG_CARRY)
385 if (self.cnt == FLAG_BASE)
386 if (other.team == self.team)
387 if (other.flagcarried) // he's got a flag
388 if (other.flagcarried.team != self.team) // capture
390 if (other.flagcarried == world)
394 if(player_count - currentbots <= 1) // at most one human
396 t = time - other.flagcarried.flagpickuptime;
397 s = ftos_decimals(t, 2);
398 s0 = ftos_decimals(flagcaptimerecord, 2);
399 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
404 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
405 if (flagcaptimerecord == 0)
407 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
408 flagcaptimerecord = t;
409 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
410 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
411 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
413 else if (t < flagcaptimerecord)
415 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
416 flagcaptimerecord = t;
417 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
418 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
419 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
423 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
427 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
429 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
430 LogCTF("capture", other.flagcarried.team, other);
431 // give credit to the individual player
432 UpdateFrags(other, ctf_score_value("score_capture"));
434 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
435 WaypointSprite_DetachCarrier(other);
436 if(self.speedrunning)
437 FakeTimeLimit(other, -1);
438 RegenFlag (other.flagcarried);
439 other.flagcarried = world;
440 other.next_take_time = time + 1;
442 if (self.cnt == FLAG_BASE)
443 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
444 if (other.team != self.team)
445 if (!other.flagcarried)
446 if (!other.ctf_captureshielded)
448 if (other.next_take_time > time)
451 self.flagpickuptime = time; // used for timing runs
452 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
453 if(other.speedrunning)
454 if(flagcaptimerecord)
455 FakeTimeLimit(other, time + flagcaptimerecord);
456 self.solid = SOLID_NOT;
457 setorigin(self, self.origin); // relink
459 other.flagcarried = self;
460 self.cnt = FLAG_CARRY;
461 self.angles = '0 0 0';
462 bprint(other.netname, "^7 got the ", self.netname, "\n");
463 UpdateFrags(other, ctf_score_value("score_pickup_base"));
464 self.dropperid = other.playerid;
465 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
466 LogCTF("steal", self.team, other);
467 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
469 FOR_EACH_PLAYER(player)
470 if(player.team == self.team)
471 centerprint(player, "The enemy got your flag! Retrieve it!");
473 self.movetype = MOVETYPE_NONE;
474 setorigin(self, FLAG_CARRY_POS);
475 setattachment(self, other, "");
476 WaypointSprite_AttachCarrier("flagcarrier", other);
477 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
478 WaypointSprite_Ping(self.sprite);
483 if (self.cnt == FLAG_DROPPED)
485 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
486 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
489 bprint(other.netname, "^7 returned the ", self.netname, "\n");
491 // punish the player who last had it
492 FOR_EACH_PLAYER(player)
493 if(player.playerid == self.dropperid)
495 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
496 ctf_captureshield_update(player, 0); // shield only
499 // punish the team who was last carrying it
500 if(self.team == COLOR_TEAM1)
501 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
503 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
505 // reward the player who returned it
506 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
508 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
509 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
511 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
515 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
516 UpdateFrags(other, ctf_score_value("score_return"));
518 UpdateFrags(other, ctf_score_value("score_return_rogue"));
520 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
521 LogCTF("return", self.team, other);
522 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
525 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
528 self.solid = SOLID_NOT;
529 setorigin(self, self.origin); // relink
531 other.flagcarried = self;
532 self.cnt = FLAG_CARRY;
533 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
536 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
537 //print("factor is ", ftos(f), "\n");
538 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
539 + ctf_score_value("score_pickup_dropped_early") * f;
541 self.dropperid = other.playerid;
542 //print("score is ", ftos(f), "\n");
544 UpdateFrags(other, f);
545 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
546 LogCTF("pickup", self.team, other);
547 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
549 FOR_EACH_PLAYER(player)
550 if(player.team == self.team)
551 centerprint(player, "The enemy got your flag! Retrieve it!");
553 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
554 setorigin(self, FLAG_CARRY_POS);
555 setattachment(self, other, "");
556 self.damageforcescale = 0;
557 WaypointSprite_AttachCarrier("flagcarrier", other);
558 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
563 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
564 CTF Starting point for a player
569 viewing angle when spawning
571 void spawnfunc_info_player_team1()
578 self.team = COLOR_TEAM1; // red
579 spawnfunc_info_player_deathmatch();
581 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
583 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
584 CTF Starting point for a player in
589 viewing angle when spawning
591 void spawnfunc_info_player_team2()
598 self.team = COLOR_TEAM2; // blue
599 spawnfunc_info_player_deathmatch();
601 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
603 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
604 CTF Starting point for a player in
605 team three (Magenta).
609 viewing angle when spawning
611 void spawnfunc_info_player_team3()
618 self.team = COLOR_TEAM3; // purple
619 spawnfunc_info_player_deathmatch();
623 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
624 CTF Starting point for a player in
629 viewing angle when spawning
631 void spawnfunc_info_player_team4()
638 self.team = COLOR_TEAM4; // yellow
639 spawnfunc_info_player_deathmatch();
642 void item_flag_reset()
644 DropFlag(self, world, world);
649 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
650 CTF flag for team one (Red).
651 Multiple are allowed.
655 Angle the flag will point
658 model to use, note this needs red and blue as skins 0 and 1
659 (default models/ctf/flag.md3)
661 sound played when flag is picked up
662 (default ctf/take.wav)
664 sound played when flag is returned by a teammate
665 (default ctf/return.wav)
667 sound played when flag is captured
668 (default ctf/redcapture.wav)
670 sound played when flag is lost in the field and respawns itself
671 (default ctf/respawn.wav)
674 void spawnfunc_item_flag_team1()
682 //if(!cvar("teamplay"))
683 // cvar_set("teamplay", "3");
685 // link flag into ctf_worldflaglist
686 self.ctf_worldflagnext = ctf_worldflaglist;
687 ctf_worldflaglist = self;
689 self.classname = "item_flag_team";
692 self.team = COLOR_TEAM2; // color 13 team (blue)
693 self.items = IT_KEY1; // silver key (bluish enough)
697 self.team = COLOR_TEAM1; // color 4 team (red)
698 self.items = IT_KEY2; // gold key (redish enough)
700 self.netname = "^1RED^7 flag";
701 self.target = "###item###";
703 if(self.spawnflags & 1)
706 self.model = "models/ctf/flags.md3";
708 self.noise = "ctf/take.wav";
710 self.noise1 = "ctf/return.wav";
712 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
714 self.noise3 = "ctf/respawn.wav";
715 precache_model (self.model);
716 setmodel (self, self.model); // precision set below
717 precache_sound (self.noise);
718 precache_sound (self.noise1);
719 precache_sound (self.noise2);
720 precache_sound (self.noise3);
721 //setsize(self, '-16 -16 -37', '16 16 37');
722 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
723 setorigin(self, self.origin + '0 0 37');
724 self.nextthink = time + 0.2; // start after doors etc
725 self.think = place_flag;
729 //if(!self.glow_size)
730 // self.glow_size = 50;
732 self.effects = self.effects | EF_LOWPRECISION;
733 if(cvar("g_ctf_fullbrightflags"))
734 self.effects |= EF_FULLBRIGHT;
735 if(cvar("g_ctf_dynamiclights"))
736 self.effects |= EF_RED;
738 waypoint_spawnforitem(self);
740 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
741 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
743 precache_model("models/onslaught/generator_shield.md3");
745 self.reset = item_flag_reset;
748 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
749 CTF flag for team two (Blue).
750 Multiple are allowed.
754 Angle the flag will point
757 model to use, note this needs red and blue as skins 0 and 1
758 (default models/ctf/flag.md3)
760 sound played when flag is picked up
761 (default ctf/take.wav)
763 sound played when flag is returned by a teammate
764 (default ctf/return.wav)
766 sound played when flag is captured
767 (default ctf/bluecapture.wav)
769 sound played when flag is lost in the field and respawns itself
770 (default ctf/respawn.wav)
773 void spawnfunc_item_flag_team2()
780 //if(!cvar("teamplay"))
781 // cvar_set("teamplay", "3");
783 // link flag into ctf_worldflaglist
784 self.ctf_worldflagnext = ctf_worldflaglist;
785 ctf_worldflaglist = self;
787 self.classname = "item_flag_team";
790 self.team = COLOR_TEAM1; // color 4 team (red)
791 self.items = IT_KEY2; // gold key (redish enough)
795 self.team = COLOR_TEAM2; // color 13 team (blue)
796 self.items = IT_KEY1; // silver key (bluish enough)
798 self.netname = "^4BLUE^7 flag";
799 self.target = "###item###";
801 if(self.spawnflags & 1)
804 self.model = "models/ctf/flags.md3";
806 self.noise = "ctf/take.wav";
808 self.noise1 = "ctf/return.wav";
810 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
812 self.noise3 = "ctf/respawn.wav";
813 precache_model (self.model);
814 setmodel (self, self.model); // precision set below
815 precache_sound (self.noise);
816 precache_sound (self.noise1);
817 precache_sound (self.noise2);
818 precache_sound (self.noise3);
819 //setsize(self, '-16 -16 -37', '16 16 37');
820 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
821 setorigin(self, self.origin + '0 0 37');
822 self.nextthink = time + 0.2; // start after doors etc
823 self.think = place_flag;
827 //if(!self.glow_size)
828 // self.glow_size = 50;
830 self.effects = self.effects | EF_LOWPRECISION;
831 if(cvar("g_ctf_fullbrightflags"))
832 self.effects |= EF_FULLBRIGHT;
833 if(cvar("g_ctf_dynamiclights"))
834 self.effects |= EF_BLUE;
836 waypoint_spawnforitem(self);
838 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
839 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
841 precache_model("models/onslaught/generator_shield.md3");
843 self.reset = item_flag_reset;
847 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
848 Team declaration for CTF gameplay, this allows you to decide what team
849 names and control point models are used in your map.
851 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
852 domination, you don't need to make a blank one too.
856 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
858 Scoreboard color of the team (for example 4 is red and 13 is blue)
862 void spawnfunc_ctf_team()
869 self.classname = "ctf_team";
870 self.team = self.cnt + 1;
873 // code from here on is just to support maps that don't have control point and team entities
874 void ctf_spawnteam (string teamname, float teamcolor)
876 local entity oldself;
879 self.classname = "ctf_team";
880 self.netname = teamname;
881 self.cnt = teamcolor;
883 spawnfunc_ctf_team();
888 // spawn some default teams if the map is not set up for ctf
889 void ctf_spawnteams()
893 numteams = 2;//cvar("g_ctf_default_teams");
895 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
896 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
899 void ctf_delayedinit()
901 // if no teams are found, spawn defaults
902 if (find(world, classname, "ctf_team") == world)
910 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
911 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
913 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
914 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
915 captureshield_force = cvar("g_ctf_shield_force");
918 void ctf_setstatus2(entity flag, float shift)
920 if (flag.cnt == FLAG_CARRY)
921 if (flag.owner == self)
922 self.items |= shift * 3;
924 self.items |= shift * 1;
925 else if (flag.cnt == FLAG_DROPPED)
926 self.items |= shift * 2;
935 self.items &~= IT_RED_FLAG_TAKEN;
936 self.items &~= IT_RED_FLAG_LOST;
937 self.items &~= IT_BLUE_FLAG_TAKEN;
938 self.items &~= IT_BLUE_FLAG_LOST;
939 self.items &~= IT_CTF_SHIELDED;
943 float redflags, blueflags;
945 if(self.ctf_captureshielded)
946 self.items |= IT_CTF_SHIELDED;
951 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
953 if(flag.items & IT_KEY2) // blue
955 else if(flag.items & IT_KEY1) // red
959 // blinking magic: if there is more than one flag, show one of these in a clever way
961 redflags = mod(floor(time * redflags * 0.75), redflags);
963 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
965 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
967 if(flag.items & IT_KEY2) // blue
969 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
970 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
972 else if(flag.items & IT_KEY1) // red
974 if(--blueflags == -1) // happens exactly once
975 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
981 entity(float cteam) ctf_team_has_commander =
984 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
987 FOR_EACH_REALPLAYER(pl) {
988 if(pl.team == cteam && pl.iscommander) {
995 void(entity e, float st) ctf_setstate =
1001 void(float cteam) ctf_new_commander =
1006 FOR_EACH_REALPLAYER(pl) {
1007 if(pl.team == cteam) {
1008 if(pl.iscommander) { // don't reassign if alreay there
1011 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1015 if(plmax == world) {
1016 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1020 plmax.iscommander = TRUE;
1021 ctf_setstate(plmax, 3);
1022 sprint(plmax, "^3You're the commander now!\n");
1023 centerprint(plmax, "^3You're the commander now!\n");
1026 void() ctf_clientconnect =
1028 self.iscommander = FALSE;
1030 if(!self.team || self.classname != "player") {
1031 ctf_setstate(self, -1);
1033 ctf_setstate(self, 0);
1035 self.team_saved = self.team;
1037 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1038 ctf_new_commander(self.team);
1042 void() ctf_playerchanged =
1044 if(!self.team || self.classname != "player") {
1045 ctf_setstate(self, -1);
1046 } else if(self.ctf_state < 0 && self.classname == "player") {
1047 ctf_setstate(self, 0);
1050 if(self.iscommander &&
1051 (self.classname != "player" || self.team != self.team_saved)
1054 self.iscommander = FALSE;
1055 if(self.classname == "player")
1056 ctf_setstate(self, 0);
1058 ctf_setstate(self, -1);
1059 ctf_new_commander(self.team_saved);
1062 self.team_saved = self.team;
1064 ctf_new_commander(self.team);
1067 void() ctf_clientdisconnect =
1069 if(self.iscommander)
1071 ctf_new_commander(self.team);
1075 entity GetPlayer(string);
1076 float() ctf_clientcommand =
1079 if(argv(0) == "order") {
1081 sprint(self, "This command is not supported in this gamemode.\n");
1084 if(!self.iscommander) {
1085 sprint(self, "^1You are not the commander!\n");
1089 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1092 e = GetPlayer(argv(1));
1094 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1097 if(e.team != self.team) {
1098 sprint(self, "^3You can only give orders to your own team!\n");
1101 if(argv(2) == "attack") {
1102 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1103 sprint(e, "^1Attack!\n");
1104 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1106 } else if(argv(2) == "defend") {
1107 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1108 sprint(e, "^Defend!\n");
1109 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1112 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");