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);
118 print(etos(e), "\n");
121 float ctf_score_value(string parameter)
123 if(g_ctf_win_mode != 2)
124 return cvar(strcat("g_ctf_personal", parameter));
126 return cvar(strcat("g_ctf_flag", parameter));
129 void FakeTimeLimit(entity e, float t)
132 WriteByte(MSG_ONE, 3); // svc_updatestat
133 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
135 WriteCoord(MSG_ONE, cvar("timelimit"));
137 WriteCoord(MSG_ONE, (t + 1) / 60);
140 float flagcaptimerecord;
141 .float flagpickuptime;
142 //.float iscommander;
151 self.t_width = 0.1; // frame animation rate
153 self.t_length = 119; // maximum frame
155 setattachment(self, world, "");
156 self.mdl = self.model;
157 self.flags = FL_ITEM;
158 self.solid = SOLID_TRIGGER;
159 self.movetype = MOVETYPE_NONE;
160 self.velocity = '0 0 0';
161 self.origin_z = self.origin_z + 6;
162 self.think = FlagThink;
163 self.touch = FlagTouch;
164 self.nextthink = time + 0.1;
165 self.cnt = FLAG_BASE;
166 self.mangle = self.angles;
167 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
168 //self.effects = self.effects | EF_DIMLIGHT;
171 self.dropped_origin = self.origin;
176 self.movetype = MOVETYPE_TOSS;
178 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
181 void LogCTF(string mode, float flagteam, entity actor)
184 if(!cvar("sv_eventlog"))
186 s = strcat(":ctf:", mode);
187 s = strcat(s, ":", ftos(flagteam));
189 s = strcat(s, ":", ftos(actor.playerid));
193 void RegenFlag(entity e)
195 setattachment(e, world, "");
196 e.damageforcescale = 0;
197 e.movetype = MOVETYPE_NONE;
199 e.movetype = MOVETYPE_TOSS;
200 e.solid = SOLID_TRIGGER;
201 // TODO: play a sound here
202 setorigin(e, e.dropped_origin);
206 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
209 void ReturnFlag(entity e)
212 if (e.owner.flagcarried == e)
214 WaypointSprite_DetachCarrier(e.owner);
215 e.owner.flagcarried = world;
218 FakeTimeLimit(e.owner, -1);
224 void DropFlag(entity e, entity penalty_receiver, entity attacker)
236 dprint("FLAG: drop - no owner?!?!\n");
240 if (p.flagcarried != e)
242 dprint("FLAG: drop - owner is not carrying this flag??\n");
245 bprint(p.netname, "^7 lost the ", e.netname, "\n");
248 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
250 UpdateFrags(p, -ctf_score_value("penalty_drop"));
251 PlayerScore_Add(p, SP_CTF_DROPS, +1);
252 ctf_captureshield_update(p, 0); // shield only
253 e.playerid = attacker.playerid;
254 e.ctf_droptime = time;
256 if(p.waypointsprite_attachedforcarrier)
258 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
259 WaypointSprite_DetachCarrier(p);
263 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
264 backtrace("Flag carrier had no flag sprite?!?");
266 LogCTF("dropped", p.team, p);
268 setattachment(e, world, "");
269 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
271 if (p.flagcarried == e)
272 p.flagcarried = world;
275 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
276 e.solid = SOLID_TRIGGER;
277 e.movetype = MOVETYPE_TOSS;
278 // setsize(e, '-16 -16 0', '16 16 74');
279 setorigin(e, p.origin - '0 0 24' + '0 0 37');
280 e.cnt = FLAG_DROPPED;
281 e.velocity = '0 0 300';
282 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
284 trace_startsolid = FALSE;
285 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
287 dprint("FLAG FALLTHROUGH will happen SOON\n");
292 if(self.delay > time)
294 self.delay = time + self.t_width;
295 if(self.nextthink > self.delay)
296 self.nextthink = self.delay;
298 self.frame = self.frame + 1;
299 if(self.frame > self.t_length)
307 self.nextthink = time + 0.1;
309 if(self == ctf_worldflaglist) // only for the first flag
312 ctf_captureshield_update(e, 1); // release shield only
317 if(self.speedrunning)
318 if(self.cnt == FLAG_CARRY)
321 if(flagcaptimerecord)
322 if(time >= self.flagpickuptime + flagcaptimerecord)
324 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
326 self.owner.impulse = 77; // returning!
336 if (self.cnt == FLAG_BASE)
339 if (self.cnt == FLAG_DROPPED)
341 // flag fallthrough? FIXME remove this if bug is really fixed now
342 if(self.origin_z < -131072)
344 dprint("FLAG FALLTHROUGH just happened\n");
345 self.pain_finished = 0;
347 setattachment(self, world, "");
348 if (time > self.pain_finished)
350 bprint("The ", self.netname, " has returned to base\n");
351 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
352 LogCTF("returned", self.team, world);
359 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
361 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
362 DropFlag(self, world, world);
366 if(cvar("g_ctf_allow_drop"))
368 DropFlag(self, e, world);
377 local string s, s0, h0, h1;
378 if (other.classname != "player")
380 if (other.health < 1) // ignore dead players
383 if (self.cnt == FLAG_CARRY)
386 if (self.cnt == FLAG_BASE)
387 if (other.team == self.team)
388 if (other.flagcarried) // he's got a flag
389 if (other.flagcarried.team != self.team) // capture
391 if (other.flagcarried == world)
395 if(player_count - currentbots <= 1) // at most one human
397 t = time - other.flagcarried.flagpickuptime;
398 s = ftos_decimals(t, 2);
399 s0 = ftos_decimals(flagcaptimerecord, 2);
400 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
405 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
406 if (flagcaptimerecord == 0)
408 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
409 flagcaptimerecord = t;
410 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
411 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
412 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
414 else if (t < flagcaptimerecord)
416 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
417 flagcaptimerecord = t;
418 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
419 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
420 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
424 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
428 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
430 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
431 LogCTF("capture", other.flagcarried.team, other);
432 // give credit to the individual player
433 UpdateFrags(other, ctf_score_value("score_capture"));
435 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
436 WaypointSprite_DetachCarrier(other);
437 if(self.speedrunning)
438 FakeTimeLimit(other, -1);
439 RegenFlag (other.flagcarried);
440 other.flagcarried = world;
441 other.next_take_time = time + 1;
443 if (self.cnt == FLAG_BASE)
444 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
445 if (other.team != self.team)
446 if (!other.flagcarried)
447 if (!other.ctf_captureshielded)
449 if (other.next_take_time > time)
452 self.flagpickuptime = time; // used for timing runs
453 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
454 if(other.speedrunning)
455 if(flagcaptimerecord)
456 FakeTimeLimit(other, time + flagcaptimerecord);
457 self.solid = SOLID_NOT;
458 setorigin(self, self.origin); // relink
460 other.flagcarried = self;
461 self.cnt = FLAG_CARRY;
462 self.angles = '0 0 0';
463 bprint(other.netname, "^7 got the ", self.netname, "\n");
464 UpdateFrags(other, ctf_score_value("score_pickup_base"));
465 self.dropperid = other.playerid;
466 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
467 LogCTF("steal", self.team, other);
468 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
470 FOR_EACH_PLAYER(player)
471 if(player.team == self.team)
472 centerprint(player, "The enemy got your flag! Retrieve it!");
474 self.movetype = MOVETYPE_NONE;
475 setorigin(self, FLAG_CARRY_POS);
476 setattachment(self, other, "");
477 WaypointSprite_AttachCarrier("flagcarrier", other);
478 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
479 WaypointSprite_Ping(self.sprite);
484 if (self.cnt == FLAG_DROPPED)
486 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
487 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
490 bprint(other.netname, "^7 returned the ", self.netname, "\n");
492 // punish the player who last had it
493 FOR_EACH_PLAYER(player)
494 if(player.playerid == self.dropperid)
496 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
497 ctf_captureshield_update(player, 0); // shield only
500 // punish the team who was last carrying it
501 if(self.team == COLOR_TEAM1)
502 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
504 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
506 // reward the player who returned it
507 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
509 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
510 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
512 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
516 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
517 UpdateFrags(other, ctf_score_value("score_return"));
519 UpdateFrags(other, ctf_score_value("score_return_rogue"));
521 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
522 LogCTF("return", self.team, other);
523 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
526 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
529 self.solid = SOLID_NOT;
530 setorigin(self, self.origin); // relink
532 other.flagcarried = self;
533 self.cnt = FLAG_CARRY;
534 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
537 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
538 //print("factor is ", ftos(f), "\n");
539 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
540 + ctf_score_value("score_pickup_dropped_early") * f;
542 self.dropperid = other.playerid;
543 //print("score is ", ftos(f), "\n");
545 UpdateFrags(other, f);
546 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
547 LogCTF("pickup", self.team, other);
548 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
550 FOR_EACH_PLAYER(player)
551 if(player.team == self.team)
552 centerprint(player, "The enemy got your flag! Retrieve it!");
554 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
555 setorigin(self, FLAG_CARRY_POS);
556 setattachment(self, other, "");
557 self.damageforcescale = 0;
558 WaypointSprite_AttachCarrier("flagcarrier", other);
559 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
564 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
565 CTF Starting point for a player
570 viewing angle when spawning
572 void spawnfunc_info_player_team1()
579 self.team = COLOR_TEAM1; // red
580 spawnfunc_info_player_deathmatch();
582 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
584 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
585 CTF Starting point for a player in
590 viewing angle when spawning
592 void spawnfunc_info_player_team2()
599 self.team = COLOR_TEAM2; // blue
600 spawnfunc_info_player_deathmatch();
602 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
604 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
605 CTF Starting point for a player in
606 team three (Magenta).
610 viewing angle when spawning
612 void spawnfunc_info_player_team3()
619 self.team = COLOR_TEAM3; // purple
620 spawnfunc_info_player_deathmatch();
624 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
625 CTF Starting point for a player in
630 viewing angle when spawning
632 void spawnfunc_info_player_team4()
639 self.team = COLOR_TEAM4; // yellow
640 spawnfunc_info_player_deathmatch();
646 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
647 CTF flag for team one (Red).
648 Multiple are allowed.
652 Angle the flag will point
655 model to use, note this needs red and blue as skins 0 and 1
656 (default models/ctf/flag.md3)
658 sound played when flag is picked up
659 (default ctf/take.wav)
661 sound played when flag is returned by a teammate
662 (default ctf/return.wav)
664 sound played when flag is captured
665 (default ctf/redcapture.wav)
667 sound played when flag is lost in the field and respawns itself
668 (default ctf/respawn.wav)
671 void spawnfunc_item_flag_team1()
679 //if(!cvar("teamplay"))
680 // cvar_set("teamplay", "3");
682 // link flag into ctf_worldflaglist
683 self.ctf_worldflagnext = ctf_worldflaglist;
684 ctf_worldflaglist = self;
686 self.classname = "item_flag_team";
689 self.team = COLOR_TEAM2; // color 13 team (blue)
690 self.items = IT_KEY1; // silver key (bluish enough)
694 self.team = COLOR_TEAM1; // color 4 team (red)
695 self.items = IT_KEY2; // gold key (redish enough)
697 self.netname = "^1RED^7 flag";
698 self.target = "###item###";
700 if(self.spawnflags & 1)
703 self.model = "models/ctf/flag_red.md3";
705 self.noise = "ctf/take.wav";
707 self.noise1 = "ctf/return.wav";
709 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
711 self.noise3 = "ctf/respawn.wav";
712 precache_model (self.model);
713 setmodel (self, self.model); // precision set below
714 precache_sound (self.noise);
715 precache_sound (self.noise1);
716 precache_sound (self.noise2);
717 precache_sound (self.noise3);
718 //setsize(self, '-16 -16 -37', '16 16 37');
719 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
720 setorigin(self, self.origin + '0 0 37');
721 self.nextthink = time + 0.2; // start after doors etc
722 self.think = place_flag;
726 //if(!self.glow_size)
727 // self.glow_size = 50;
729 self.effects = self.effects | EF_LOWPRECISION;
730 if(cvar("g_ctf_fullbrightflags"))
731 self.effects |= EF_FULLBRIGHT;
733 waypoint_spawnforitem(self);
735 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
736 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
738 precache_model("models/onslaught/generator_shield.md3");
741 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
742 CTF flag for team two (Blue).
743 Multiple are allowed.
747 Angle the flag will point
750 model to use, note this needs red and blue as skins 0 and 1
751 (default models/ctf/flag.md3)
753 sound played when flag is picked up
754 (default ctf/take.wav)
756 sound played when flag is returned by a teammate
757 (default ctf/return.wav)
759 sound played when flag is captured
760 (default ctf/bluecapture.wav)
762 sound played when flag is lost in the field and respawns itself
763 (default ctf/respawn.wav)
766 void spawnfunc_item_flag_team2()
773 //if(!cvar("teamplay"))
774 // cvar_set("teamplay", "3");
776 // link flag into ctf_worldflaglist
777 self.ctf_worldflagnext = ctf_worldflaglist;
778 ctf_worldflaglist = self;
780 self.classname = "item_flag_team";
783 self.team = COLOR_TEAM1; // color 4 team (red)
784 self.items = IT_KEY2; // gold key (redish enough)
788 self.team = COLOR_TEAM2; // color 13 team (blue)
789 self.items = IT_KEY1; // silver key (bluish enough)
791 self.netname = "^4BLUE^7 flag";
792 self.target = "###item###";
794 if(self.spawnflags & 1)
797 self.model = "models/ctf/flag_blue.md3";
799 self.noise = "ctf/take.wav";
801 self.noise1 = "ctf/return.wav";
803 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
805 self.noise3 = "ctf/respawn.wav";
806 precache_model (self.model);
807 setmodel (self, self.model); // precision set below
808 precache_sound (self.noise);
809 precache_sound (self.noise1);
810 precache_sound (self.noise2);
811 precache_sound (self.noise3);
812 //setsize(self, '-16 -16 -37', '16 16 37');
813 setsize(self, PL_MIN + '0 0 -13', PL_MAX + '0 0 -13');
814 setorigin(self, self.origin + '0 0 37');
815 self.nextthink = time + 0.2; // start after doors etc
816 self.think = place_flag;
820 //if(!self.glow_size)
821 // self.glow_size = 50;
823 self.effects = self.effects | EF_LOWPRECISION;
824 if(cvar("g_ctf_fullbrightflags"))
825 self.effects |= EF_FULLBRIGHT;
827 waypoint_spawnforitem(self);
829 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
830 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
832 precache_model("models/onslaught/generator_shield.md3");
836 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
837 Team declaration for CTF gameplay, this allows you to decide what team
838 names and control point models are used in your map.
840 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
841 domination, you don't need to make a blank one too.
845 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
847 Scoreboard color of the team (for example 4 is red and 13 is blue)
851 void spawnfunc_ctf_team()
858 self.classname = "ctf_team";
859 self.team = self.cnt + 1;
862 // code from here on is just to support maps that don't have control point and team entities
863 void ctf_spawnteam (string teamname, float teamcolor)
865 local entity oldself;
868 self.classname = "ctf_team";
869 self.netname = teamname;
870 self.cnt = teamcolor;
872 spawnfunc_ctf_team();
877 // spawn some default teams if the map is not set up for ctf
878 void ctf_spawnteams()
882 numteams = 2;//cvar("g_ctf_default_teams");
884 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
885 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
888 void ctf_delayedinit()
890 // if no teams are found, spawn defaults
891 if (find(world, classname, "ctf_team") == world)
899 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
900 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
902 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
903 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
904 captureshield_force = cvar("g_ctf_shield_force");
907 void ctf_setstatus2(entity flag, float shift)
909 if (flag.cnt == FLAG_CARRY)
910 if (flag.owner == self)
911 self.items |= shift * 3;
913 self.items |= shift * 1;
914 else if (flag.cnt == FLAG_DROPPED)
915 self.items |= shift * 2;
924 self.items &~= IT_RED_FLAG_TAKEN;
925 self.items &~= IT_RED_FLAG_LOST;
926 self.items &~= IT_BLUE_FLAG_TAKEN;
927 self.items &~= IT_BLUE_FLAG_LOST;
928 self.items &~= IT_CTF_SHIELDED;
932 float redflags, blueflags;
934 if(self.ctf_captureshielded)
935 self.items |= IT_CTF_SHIELDED;
940 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
942 if(flag.items & IT_KEY2) // blue
944 else if(flag.items & IT_KEY1) // red
948 // blinking magic: if there is more than one flag, show one of these in a clever way
950 redflags = mod(floor(time * redflags * 0.75), redflags);
952 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
954 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
956 if(flag.items & IT_KEY2) // blue
958 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
959 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
961 else if(flag.items & IT_KEY1) // red
963 if(--blueflags == -1) // happens exactly once
964 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
970 entity(float cteam) ctf_team_has_commander =
973 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
976 FOR_EACH_REALPLAYER(pl) {
977 if(pl.team == cteam && pl.iscommander) {
984 void(entity e, float st) ctf_setstate =
990 void(float cteam) ctf_new_commander =
995 FOR_EACH_REALPLAYER(pl) {
996 if(pl.team == cteam) {
997 if(pl.iscommander) { // don't reassign if alreay there
1000 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1004 if(plmax == world) {
1005 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1009 plmax.iscommander = TRUE;
1010 ctf_setstate(plmax, 3);
1011 sprint(plmax, "^3You're the commander now!\n");
1012 centerprint(plmax, "^3You're the commander now!\n");
1015 void() ctf_clientconnect =
1017 self.iscommander = FALSE;
1019 if(!self.team || self.classname != "player") {
1020 ctf_setstate(self, -1);
1022 ctf_setstate(self, 0);
1024 self.team_saved = self.team;
1026 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1027 ctf_new_commander(self.team);
1031 void() ctf_playerchanged =
1033 if(!self.team || self.classname != "player") {
1034 ctf_setstate(self, -1);
1035 } else if(self.ctf_state < 0 && self.classname == "player") {
1036 ctf_setstate(self, 0);
1039 if(self.iscommander &&
1040 (self.classname != "player" || self.team != self.team_saved)
1043 self.iscommander = FALSE;
1044 if(self.classname == "player")
1045 ctf_setstate(self, 0);
1047 ctf_setstate(self, -1);
1048 ctf_new_commander(self.team_saved);
1051 self.team_saved = self.team;
1053 ctf_new_commander(self.team);
1056 void() ctf_clientdisconnect =
1058 if(self.iscommander)
1060 ctf_new_commander(self.team);
1064 entity GetPlayer(string);
1065 float() ctf_clientcommand =
1068 if(argv(0) == "order") {
1070 sprint(self, "This command is not supported in this gamemode.\n");
1073 if(!self.iscommander) {
1074 sprint(self, "^1You are not the commander!\n");
1078 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1081 e = GetPlayer(argv(1));
1083 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1086 if(e.team != self.team) {
1087 sprint(self, "^3You can only give orders to your own team!\n");
1090 if(argv(2) == "attack") {
1091 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1092 sprint(e, "^1Attack!\n");
1093 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1095 } else if(argv(2) == "defend") {
1096 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1097 sprint(e, "^Defend!\n");
1098 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1101 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");