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;
153 self.t_width = 0.1; // frame animation rate
155 self.t_length = 58; // maximum frame
157 setattachment(self, world, "");
158 self.mdl = self.model;
159 self.flags = FL_ITEM;
160 self.solid = SOLID_TRIGGER;
161 self.movetype = MOVETYPE_NONE;
162 self.velocity = '0 0 0';
163 self.origin_z = self.origin_z + 6;
164 self.think = FlagThink;
165 self.touch = FlagTouch;
166 self.nextthink = time + 0.1;
167 self.cnt = FLAG_BASE;
168 self.mangle = self.angles;
169 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
170 //self.effects = self.effects | EF_DIMLIGHT;
173 self.dropped_origin = self.origin;
178 self.movetype = MOVETYPE_TOSS;
180 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
183 void LogCTF(string mode, float flagteam, entity actor)
186 if(!cvar("sv_eventlog"))
188 s = strcat(":ctf:", mode);
189 s = strcat(s, ":", ftos(flagteam));
191 s = strcat(s, ":", ftos(actor.playerid));
195 void RegenFlag(entity e)
197 setattachment(e, world, "");
198 e.damageforcescale = 0;
199 e.movetype = MOVETYPE_NONE;
201 e.movetype = MOVETYPE_TOSS;
202 e.solid = SOLID_TRIGGER;
203 // TODO: play a sound here
204 setorigin(e, e.dropped_origin);
208 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
211 void ReturnFlag(entity e)
214 if (e.owner.flagcarried == e)
216 WaypointSprite_DetachCarrier(e.owner);
217 e.owner.flagcarried = world;
220 FakeTimeLimit(e.owner, -1);
226 void DropFlag(entity e, entity penalty_receiver, entity attacker)
238 dprint("FLAG: drop - no owner?!?!\n");
242 if (p.flagcarried != e)
244 dprint("FLAG: drop - owner is not carrying this flag??\n");
247 bprint(p.netname, "^7 lost the ", e.netname, "\n");
250 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
252 UpdateFrags(p, -ctf_score_value("penalty_drop"));
253 PlayerScore_Add(p, SP_CTF_DROPS, +1);
254 ctf_captureshield_update(p, 0); // shield only
255 e.playerid = attacker.playerid;
256 e.ctf_droptime = time;
258 if(p.waypointsprite_attachedforcarrier)
260 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
261 WaypointSprite_DetachCarrier(p);
265 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
266 backtrace("Flag carrier had no flag sprite?!?");
268 LogCTF("dropped", p.team, p);
270 setattachment(e, world, "");
271 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
273 if (p.flagcarried == e)
274 p.flagcarried = world;
277 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
278 e.solid = SOLID_TRIGGER;
279 e.movetype = MOVETYPE_TOSS;
280 // setsize(e, '-16 -16 0', '16 16 74');
281 setorigin(e, p.origin - '0 0 24' + '0 0 37');
282 e.cnt = FLAG_DROPPED;
283 e.velocity = '0 0 300';
284 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
286 trace_startsolid = FALSE;
287 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
289 dprint("FLAG FALLTHROUGH will happen SOON\n");
294 if(self.delay > time)
296 self.delay = time + self.t_width;
297 if(self.nextthink > self.delay)
298 self.nextthink = self.delay;
300 self.frame = self.frame + 1;
301 if(self.frame > self.t_length)
309 self.nextthink = time + 0.1;
311 // sorry, we have to reset the flag size if it got squished by something
312 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
314 // if we can grow back, grow back
315 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
316 if(!trace_startsolid)
317 setsize(self, FLAG_MIN, FLAG_MAX);
320 if(self == ctf_worldflaglist) // only for the first flag
323 ctf_captureshield_update(e, 1); // release shield only
328 if(self.speedrunning)
329 if(self.cnt == FLAG_CARRY)
332 if(flagcaptimerecord)
333 if(time >= self.flagpickuptime + flagcaptimerecord)
335 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
337 self.owner.impulse = 77; // returning!
347 if (self.cnt == FLAG_BASE)
350 if (self.cnt == FLAG_DROPPED)
352 // flag fallthrough? FIXME remove this if bug is really fixed now
353 if(self.origin_z < -131072)
355 dprint("FLAG FALLTHROUGH just happened\n");
356 self.pain_finished = 0;
358 setattachment(self, world, "");
359 if (time > self.pain_finished)
361 bprint("The ", self.netname, " has returned to base\n");
362 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
363 LogCTF("returned", self.team, world);
370 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
372 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
373 DropFlag(self, world, world);
377 if(cvar("g_ctf_allow_drop"))
379 DropFlag(self, e, world);
388 local string s, s0, h0, h1;
389 if (other.classname != "player")
391 if (other.health < 1) // ignore dead players
394 if (self.cnt == FLAG_CARRY)
397 if (self.cnt == FLAG_BASE)
398 if (other.team == self.team)
399 if (other.flagcarried) // he's got a flag
400 if (other.flagcarried.team != self.team) // capture
402 if (other.flagcarried == world)
406 if(player_count - currentbots <= 1) // at most one human
408 t = time - other.flagcarried.flagpickuptime;
409 s = ftos_decimals(t, 2);
410 s0 = ftos_decimals(flagcaptimerecord, 2);
411 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
416 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
417 if (flagcaptimerecord == 0)
419 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
420 flagcaptimerecord = t;
421 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
422 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
423 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
425 else if (t < flagcaptimerecord)
427 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
428 flagcaptimerecord = t;
429 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
430 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
431 GameLogEcho(strcat(":recordset:", ftos(other.playerid), ":", ftos(t)));
435 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
439 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
441 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
442 LogCTF("capture", other.flagcarried.team, other);
443 // give credit to the individual player
444 UpdateFrags(other, ctf_score_value("score_capture"));
446 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
447 WaypointSprite_DetachCarrier(other);
448 if(self.speedrunning)
449 FakeTimeLimit(other, -1);
450 RegenFlag (other.flagcarried);
451 other.flagcarried = world;
452 other.next_take_time = time + 1;
454 if (self.cnt == FLAG_BASE)
455 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
456 if (other.team != self.team)
457 if (!other.flagcarried)
458 if (!other.ctf_captureshielded)
460 if (other.next_take_time > time)
463 self.flagpickuptime = time; // used for timing runs
464 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
465 if(other.speedrunning)
466 if(flagcaptimerecord)
467 FakeTimeLimit(other, time + flagcaptimerecord);
468 self.solid = SOLID_NOT;
469 setorigin(self, self.origin); // relink
471 other.flagcarried = self;
472 self.cnt = FLAG_CARRY;
473 self.angles = '0 0 0';
474 bprint(other.netname, "^7 got the ", self.netname, "\n");
475 UpdateFrags(other, ctf_score_value("score_pickup_base"));
476 self.dropperid = other.playerid;
477 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
478 LogCTF("steal", self.team, other);
479 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
481 FOR_EACH_PLAYER(player)
482 if(player.team == self.team)
483 centerprint(player, "The enemy got your flag! Retrieve it!");
485 self.movetype = MOVETYPE_NONE;
486 setorigin(self, FLAG_CARRY_POS);
487 setattachment(self, other, "");
488 WaypointSprite_AttachCarrier("flagcarrier", other);
489 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
490 WaypointSprite_Ping(self.sprite);
495 if (self.cnt == FLAG_DROPPED)
497 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
498 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
501 bprint(other.netname, "^7 returned the ", self.netname, "\n");
503 // punish the player who last had it
504 FOR_EACH_PLAYER(player)
505 if(player.playerid == self.dropperid)
507 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
508 ctf_captureshield_update(player, 0); // shield only
511 // punish the team who was last carrying it
512 if(self.team == COLOR_TEAM1)
513 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
515 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
517 // reward the player who returned it
518 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
520 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
521 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
523 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
527 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
528 UpdateFrags(other, ctf_score_value("score_return"));
530 UpdateFrags(other, ctf_score_value("score_return_rogue"));
532 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
533 LogCTF("return", self.team, other);
534 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
537 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
540 self.solid = SOLID_NOT;
541 setorigin(self, self.origin); // relink
543 other.flagcarried = self;
544 self.cnt = FLAG_CARRY;
545 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
548 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
549 //print("factor is ", ftos(f), "\n");
550 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
551 + ctf_score_value("score_pickup_dropped_early") * f;
553 self.dropperid = other.playerid;
554 //print("score is ", ftos(f), "\n");
556 UpdateFrags(other, f);
557 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
558 LogCTF("pickup", self.team, other);
559 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
561 FOR_EACH_PLAYER(player)
562 if(player.team == self.team)
563 centerprint(player, "The enemy got your flag! Retrieve it!");
565 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
566 setorigin(self, FLAG_CARRY_POS);
567 setattachment(self, other, "");
568 self.damageforcescale = 0;
569 WaypointSprite_AttachCarrier("flagcarrier", other);
570 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
575 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
576 CTF Starting point for a player
581 viewing angle when spawning
583 void spawnfunc_info_player_team1()
590 self.team = COLOR_TEAM1; // red
591 spawnfunc_info_player_deathmatch();
593 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
595 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
596 CTF Starting point for a player in
601 viewing angle when spawning
603 void spawnfunc_info_player_team2()
610 self.team = COLOR_TEAM2; // blue
611 spawnfunc_info_player_deathmatch();
613 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
615 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
616 CTF Starting point for a player in
617 team three (Magenta).
621 viewing angle when spawning
623 void spawnfunc_info_player_team3()
630 self.team = COLOR_TEAM3; // purple
631 spawnfunc_info_player_deathmatch();
635 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
636 CTF Starting point for a player in
641 viewing angle when spawning
643 void spawnfunc_info_player_team4()
650 self.team = COLOR_TEAM4; // yellow
651 spawnfunc_info_player_deathmatch();
654 void item_flag_reset()
656 DropFlag(self, world, world);
661 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
662 CTF flag for team one (Red).
663 Multiple are allowed.
667 Angle the flag will point
670 model to use, note this needs red and blue as skins 0 and 1
671 (default models/ctf/flag.md3)
673 sound played when flag is picked up
674 (default ctf/take.wav)
676 sound played when flag is returned by a teammate
677 (default ctf/return.wav)
679 sound played when flag is captured
680 (default ctf/redcapture.wav)
682 sound played when flag is lost in the field and respawns itself
683 (default ctf/respawn.wav)
686 void spawnfunc_item_flag_team1()
694 //if(!cvar("teamplay"))
695 // cvar_set("teamplay", "3");
697 // link flag into ctf_worldflaglist
698 self.ctf_worldflagnext = ctf_worldflaglist;
699 ctf_worldflaglist = self;
701 self.classname = "item_flag_team";
704 self.team = COLOR_TEAM2; // color 13 team (blue)
705 self.items = IT_KEY1; // silver key (bluish enough)
709 self.team = COLOR_TEAM1; // color 4 team (red)
710 self.items = IT_KEY2; // gold key (redish enough)
712 self.netname = "^1RED^7 flag";
713 self.target = "###item###";
715 if(self.spawnflags & 1)
718 self.model = "models/ctf/flags.md3";
720 self.noise = "ctf/take.wav";
722 self.noise1 = "ctf/return.wav";
724 self.noise2 = "ctf/redcapture.wav"; // blue team scores by capturing the red flag
726 self.noise3 = "ctf/respawn.wav";
727 precache_model (self.model);
728 setmodel (self, self.model); // precision set below
729 precache_sound (self.noise);
730 precache_sound (self.noise1);
731 precache_sound (self.noise2);
732 precache_sound (self.noise3);
733 //setsize(self, '-16 -16 -37', '16 16 37');
734 setsize(self, FLAG_MIN, FLAG_MAX);
735 setorigin(self, self.origin + '0 0 37');
736 self.nextthink = time + 0.2; // start after doors etc
737 self.think = place_flag;
741 //if(!self.glow_size)
742 // self.glow_size = 50;
744 self.effects = self.effects | EF_LOWPRECISION;
745 if(cvar("g_ctf_fullbrightflags"))
746 self.effects |= EF_FULLBRIGHT;
747 if(cvar("g_ctf_dynamiclights"))
748 self.effects |= EF_RED;
750 waypoint_spawnforitem(self);
752 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
753 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
755 precache_model("models/onslaught/generator_shield.md3");
757 self.reset = item_flag_reset;
760 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
761 CTF flag for team two (Blue).
762 Multiple are allowed.
766 Angle the flag will point
769 model to use, note this needs red and blue as skins 0 and 1
770 (default models/ctf/flag.md3)
772 sound played when flag is picked up
773 (default ctf/take.wav)
775 sound played when flag is returned by a teammate
776 (default ctf/return.wav)
778 sound played when flag is captured
779 (default ctf/bluecapture.wav)
781 sound played when flag is lost in the field and respawns itself
782 (default ctf/respawn.wav)
785 void spawnfunc_item_flag_team2()
792 //if(!cvar("teamplay"))
793 // cvar_set("teamplay", "3");
795 // link flag into ctf_worldflaglist
796 self.ctf_worldflagnext = ctf_worldflaglist;
797 ctf_worldflaglist = self;
799 self.classname = "item_flag_team";
802 self.team = COLOR_TEAM1; // color 4 team (red)
803 self.items = IT_KEY2; // gold key (redish enough)
807 self.team = COLOR_TEAM2; // color 13 team (blue)
808 self.items = IT_KEY1; // silver key (bluish enough)
810 self.netname = "^4BLUE^7 flag";
811 self.target = "###item###";
813 if(self.spawnflags & 1)
816 self.model = "models/ctf/flags.md3";
818 self.noise = "ctf/take.wav";
820 self.noise1 = "ctf/return.wav";
822 self.noise2 = "ctf/bluecapture.wav"; // red team scores by capturing the blue flag
824 self.noise3 = "ctf/respawn.wav";
825 precache_model (self.model);
826 setmodel (self, self.model); // precision set below
827 precache_sound (self.noise);
828 precache_sound (self.noise1);
829 precache_sound (self.noise2);
830 precache_sound (self.noise3);
831 //setsize(self, '-16 -16 -37', '16 16 37');
832 setsize(self, FLAG_MIN, FLAG_MAX);
833 setorigin(self, self.origin + '0 0 37');
834 self.nextthink = time + 0.2; // start after doors etc
835 self.think = place_flag;
839 //if(!self.glow_size)
840 // self.glow_size = 50;
842 self.effects = self.effects | EF_LOWPRECISION;
843 if(cvar("g_ctf_fullbrightflags"))
844 self.effects |= EF_FULLBRIGHT;
845 if(cvar("g_ctf_dynamiclights"))
846 self.effects |= EF_BLUE;
848 waypoint_spawnforitem(self);
850 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
851 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
853 precache_model("models/onslaught/generator_shield.md3");
855 self.reset = item_flag_reset;
859 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
860 Team declaration for CTF gameplay, this allows you to decide what team
861 names and control point models are used in your map.
863 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
864 domination, you don't need to make a blank one too.
868 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
870 Scoreboard color of the team (for example 4 is red and 13 is blue)
874 void spawnfunc_ctf_team()
881 self.classname = "ctf_team";
882 self.team = self.cnt + 1;
885 // code from here on is just to support maps that don't have control point and team entities
886 void ctf_spawnteam (string teamname, float teamcolor)
888 local entity oldself;
891 self.classname = "ctf_team";
892 self.netname = teamname;
893 self.cnt = teamcolor;
895 spawnfunc_ctf_team();
900 // spawn some default teams if the map is not set up for ctf
901 void ctf_spawnteams()
905 numteams = 2;//cvar("g_ctf_default_teams");
907 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
908 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
911 void ctf_delayedinit()
913 // if no teams are found, spawn defaults
914 if (find(world, classname, "ctf_team") == world)
922 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
923 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
925 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
926 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
927 captureshield_force = cvar("g_ctf_shield_force");
930 void ctf_setstatus2(entity flag, float shift)
932 if (flag.cnt == FLAG_CARRY)
933 if (flag.owner == self)
934 self.items |= shift * 3;
936 self.items |= shift * 1;
937 else if (flag.cnt == FLAG_DROPPED)
938 self.items |= shift * 2;
947 self.items &~= IT_RED_FLAG_TAKEN;
948 self.items &~= IT_RED_FLAG_LOST;
949 self.items &~= IT_BLUE_FLAG_TAKEN;
950 self.items &~= IT_BLUE_FLAG_LOST;
951 self.items &~= IT_CTF_SHIELDED;
955 float redflags, blueflags;
957 if(self.ctf_captureshielded)
958 self.items |= IT_CTF_SHIELDED;
963 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
965 if(flag.items & IT_KEY2) // blue
967 else if(flag.items & IT_KEY1) // red
971 // blinking magic: if there is more than one flag, show one of these in a clever way
973 redflags = mod(floor(time * redflags * 0.75), redflags);
975 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
977 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
979 if(flag.items & IT_KEY2) // blue
981 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
982 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
984 else if(flag.items & IT_KEY1) // red
986 if(--blueflags == -1) // happens exactly once
987 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
993 entity(float cteam) ctf_team_has_commander =
996 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
999 FOR_EACH_REALPLAYER(pl) {
1000 if(pl.team == cteam && pl.iscommander) {
1007 void(entity e, float st) ctf_setstate =
1013 void(float cteam) ctf_new_commander =
1018 FOR_EACH_REALPLAYER(pl) {
1019 if(pl.team == cteam) {
1020 if(pl.iscommander) { // don't reassign if alreay there
1023 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1027 if(plmax == world) {
1028 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1032 plmax.iscommander = TRUE;
1033 ctf_setstate(plmax, 3);
1034 sprint(plmax, "^3You're the commander now!\n");
1035 centerprint(plmax, "^3You're the commander now!\n");
1038 void() ctf_clientconnect =
1040 self.iscommander = FALSE;
1042 if(!self.team || self.classname != "player") {
1043 ctf_setstate(self, -1);
1045 ctf_setstate(self, 0);
1047 self.team_saved = self.team;
1049 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1050 ctf_new_commander(self.team);
1054 void() ctf_playerchanged =
1056 if(!self.team || self.classname != "player") {
1057 ctf_setstate(self, -1);
1058 } else if(self.ctf_state < 0 && self.classname == "player") {
1059 ctf_setstate(self, 0);
1062 if(self.iscommander &&
1063 (self.classname != "player" || self.team != self.team_saved)
1066 self.iscommander = FALSE;
1067 if(self.classname == "player")
1068 ctf_setstate(self, 0);
1070 ctf_setstate(self, -1);
1071 ctf_new_commander(self.team_saved);
1074 self.team_saved = self.team;
1076 ctf_new_commander(self.team);
1079 void() ctf_clientdisconnect =
1081 if(self.iscommander)
1083 ctf_new_commander(self.team);
1087 entity GetPlayer(string);
1088 float() ctf_clientcommand =
1091 if(argv(0) == "order") {
1093 sprint(self, "This command is not supported in this gamemode.\n");
1096 if(!self.iscommander) {
1097 sprint(self, "^1You are not the commander!\n");
1101 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1104 e = GetPlayer(argv(1));
1106 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1109 if(e.team != self.team) {
1110 sprint(self, "^3You can only give orders to your own team!\n");
1113 if(argv(2) == "attack") {
1114 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1115 sprint(e, "^1Attack!\n");
1116 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1118 } else if(argv(2) == "defend") {
1119 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1120 sprint(e, "^Defend!\n");
1121 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1124 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");