1 #define FLAG_MIN (PL_MIN + '0 0 -13')
2 #define FLAG_MAX (PL_MAX + '0 0 -13')
6 entity ctf_worldflaglist; // CTF flags in the map
7 .entity ctf_worldflagnext;
11 .float next_take_time; // the next time a player can pick up a flag (time + blah)
12 /// I used this, in part, to fix the looping score bug. - avirox
13 //float FLAGSCORE_PICKUP = 1;
14 //float FLAGSCORE_RETURN = 5; // returned by owner team
15 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
16 //float FLAGSCORE_CAPTURE = 5;
18 #define FLAG_CARRY_POS '-15 0 7'
20 .float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
22 float captureshield_min_negscore; // punish at -20 points
23 float captureshield_max_ratio; // punish at most 30% of each team
24 float captureshield_force; // push force of the shield
26 float ctf_captureshield_shielded(entity p)
30 float players_worseeq, players_total;
32 if(captureshield_max_ratio <= 0)
35 s = PlayerScore_Add(p, SP_SCORE, 0);
36 if(s >= -captureshield_min_negscore)
39 players_total = players_worseeq = 0;
44 se = PlayerScore_Add(e, SP_SCORE, 0);
50 // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
53 if(players_worseeq >= players_total * captureshield_max_ratio)
59 void ctf_captureshield_update(entity p, float dir)
62 if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
64 should = ctf_captureshield_shielded(p);
69 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.");
70 // TODO csqc notifier for this
74 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.");
75 // TODO csqc notifier for this
77 p.ctf_captureshielded = should;
82 float ctf_captureshield_customize()
84 if not(other.ctf_captureshielded)
86 if(self.team == other.team)
91 void ctf_captureshield_touch()
93 if not(other.ctf_captureshielded)
95 if(self.team == other.team)
99 mymid = (self.absmin + self.absmax) * 0.5;
100 othermid = (other.absmin + other.absmax) * 0.5;
101 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
102 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.");
105 void ctf_flag_spawnstuff()
111 e.touch = ctf_captureshield_touch;
112 e.customizeentityforclient = ctf_captureshield_customize;
113 e.classname = "ctf_captureshield";
114 e.effects = EF_ADDITIVE;
115 e.movetype = MOVETYPE_NOCLIP;
116 e.solid = SOLID_TRIGGER;
117 e.avelocity = '7 0 11';
118 setorigin(e, self.origin);
119 setmodel(e, "models/ctf/shield.md3");
121 setsize(e, e.scale * e.mins, e.scale * e.maxs);
123 waypoint_spawnforitem_force(self, self.origin);
124 self.nearestwaypointtimeout = 0; // activate waypointing again
125 self.basewaypoint = self.nearestwaypoint;
127 if(self.team == COLOR_TEAM1)
129 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 61', self, sprite);
130 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
134 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 61', self, sprite);
135 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
139 float ctf_score_value(string parameter)
141 if(g_ctf_win_mode != 2)
142 return cvar(strcat("g_ctf_personal", parameter));
144 return cvar(strcat("g_ctf_flag", parameter));
147 void FakeTimeLimit(entity e, float t)
150 WriteByte(MSG_ONE, 3); // svc_updatestat
151 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
153 WriteCoord(MSG_ONE, autocvar_timelimit);
155 WriteCoord(MSG_ONE, (t + 1) / 60);
158 float flagcaptimerecord;
159 .float flagpickuptime;
160 //.float iscommander;
168 if(self.classname != "item_flag_team")
170 backtrace("PlaceFlag a non-flag");
174 setattachment(self, world, "");
175 self.mdl = self.model;
176 self.flags = FL_ITEM | FL_NOTARGET;
177 self.solid = SOLID_TRIGGER;
178 self.movetype = MOVETYPE_NONE;
179 self.velocity = '0 0 0';
180 self.origin_z = self.origin_z + 6;
181 self.think = FlagThink;
182 self.touch = FlagTouch;
183 self.nextthink = time + 0.1;
184 self.cnt = FLAG_BASE;
185 self.mangle = self.angles;
186 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
187 //self.effects = self.effects | EF_DIMLIGHT;
190 self.dropped_origin = self.origin;
195 self.movetype = MOVETYPE_TOSS;
198 InitializeEntity(self, ctf_flag_spawnstuff, INITPRIO_SETLOCATION);
201 void LogCTF(string mode, float flagteam, entity actor)
204 if(!autocvar_sv_eventlog)
206 s = strcat(":ctf:", mode);
207 s = strcat(s, ":", ftos(flagteam));
209 s = strcat(s, ":", ftos(actor.playerid));
213 void RegenFlag(entity e)
215 if(e.classname != "item_flag_team")
217 backtrace("RegenFlag a non-flag");
221 if(e.waypointsprite_attachedforcarrier)
222 WaypointSprite_DetachCarrier(e);
224 setattachment(e, world, "");
225 e.damageforcescale = 0;
226 e.takedamage = DAMAGE_NO;
227 e.movetype = MOVETYPE_NONE;
229 e.movetype = MOVETYPE_TOSS;
230 e.velocity = '0 0 0';
231 e.solid = SOLID_TRIGGER;
232 // TODO: play a sound here
233 setorigin(e, e.dropped_origin);
237 e.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
240 void ReturnFlag(entity e)
242 if(e.classname != "item_flag_team")
244 backtrace("ReturnFlag a non-flag");
249 if (e.owner.flagcarried == e)
251 WaypointSprite_DetachCarrier(e.owner);
252 e.owner.flagcarried = world;
255 FakeTimeLimit(e.owner, -1);
261 void DropFlag(entity e, entity penalty_receiver, entity attacker)
265 if(e.classname != "item_flag_team")
267 backtrace("DropFlag a non-flag");
279 dprint("FLAG: drop - no owner?!?!\n");
283 if (p.flagcarried != e)
285 dprint("FLAG: drop - owner is not carrying this flag??\n");
288 //bprint(p.netname, "^7 lost the ", e.netname, "\n");
289 Send_KillNotification (p.netname, e.netname, "", INFO_LOSTFLAG, MSG_INFO);
292 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
294 UpdateFrags(p, -ctf_score_value("penalty_drop"));
295 PlayerScore_Add(p, SP_CTF_DROPS, +1);
296 ctf_captureshield_update(p, 0); // shield only
297 e.playerid = attacker.playerid;
298 e.ctf_droptime = time;
299 WaypointSprite_Spawn("flagdropped", 0, 0, e, '0 0 1' * 61, world, COLOR_TEAM1 + COLOR_TEAM2 - e.team, e, waypointsprite_attachedforcarrier, FALSE);
300 WaypointSprite_UpdateTeamRadar(e.waypointsprite_attachedforcarrier, RADARICON_FLAG, '0 1 1');
301 WaypointSprite_Ping(e.waypointsprite_attachedforcarrier);
303 if(p.waypointsprite_attachedforcarrier)
305 WaypointSprite_DetachCarrier(p);
309 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
310 backtrace("Flag carrier had no flag sprite?!?");
312 LogCTF("dropped", p.team, p);
313 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
315 setattachment(e, world, "");
316 e.damageforcescale = autocvar_g_balance_ctf_damageforcescale;
317 e.takedamage = DAMAGE_YES;
319 if (p.flagcarried == e)
320 p.flagcarried = world;
323 e.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
324 e.solid = SOLID_TRIGGER;
325 e.movetype = MOVETYPE_TOSS;
326 // setsize(e, '-16 -16 0', '16 16 74');
327 setorigin(e, p.origin - '0 0 24' + '0 0 37');
328 e.cnt = FLAG_DROPPED;
329 e.velocity = '0 0 300';
330 e.pain_finished = time + autocvar_g_ctf_flag_returntime;//30;
332 trace_startsolid = FALSE;
333 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
335 dprint("FLAG FALLTHROUGH will happen SOON\n");
342 self.nextthink = time + 0.1;
344 // sorry, we have to reset the flag size if it got squished by something
345 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
347 // if we can grow back, grow back
348 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
349 if(!trace_startsolid)
350 setsize(self, FLAG_MIN, FLAG_MAX);
353 if(self == ctf_worldflaglist) // only for the first flag
356 ctf_captureshield_update(e, 1); // release shield only
359 if(self.speedrunning)
360 if(self.cnt == FLAG_CARRY)
363 if(flagcaptimerecord)
364 if(time >= self.flagpickuptime + flagcaptimerecord)
366 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
368 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
369 self.owner.impulse = 141; // returning!
380 if (self.cnt == FLAG_BASE)
383 if (self.cnt == FLAG_DROPPED)
385 // flag fallthrough? FIXME remove this if bug is really fixed now
386 if(self.origin_z < -131072)
388 dprint("FLAG FALLTHROUGH just happened\n");
389 self.pain_finished = 0;
391 setattachment(self, world, "");
392 if (time > self.pain_finished)
394 bprint("The ", self.netname, " has returned to base\n");
395 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
396 LogCTF("returned", self.team, world);
403 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
405 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
406 DropFlag(self, world, world);
415 DropFlag(self.flagcarried, self, world);
421 void flag_cap_ring_spawn(vector org)
423 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
432 local string s, s0, h0, h1;
433 if (other.classname != "player")
435 if (other.health < 1) // ignore dead players
438 if (self.cnt == FLAG_CARRY)
441 if (self.cnt == FLAG_BASE)
442 if (other.team == self.team)
443 if (other.flagcarried) // he's got a flag
444 if (other.flagcarried.team != self.team) // capture
446 if (other.flagcarried == world)
450 if(autocvar_g_ctf_captimerecord_always || player_count - currentbots <= 1) // at most one human
452 t = time - other.flagcarried.flagpickuptime;
453 s = ftos_decimals(t, 2);
454 s0 = ftos_decimals(flagcaptimerecord, 2);
455 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
460 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
461 if (flagcaptimerecord == 0)
463 s = strcat(" in ", s, " seconds");
464 flagcaptimerecord = t;
465 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
466 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
467 write_recordmarker(other, time - t, t);
469 else if (t < flagcaptimerecord)
471 s = strcat(" in ", s, " seconds, breaking ", h0, " previous record of ", s0, " seconds");
472 flagcaptimerecord = t;
473 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
474 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
475 write_recordmarker(other, time - t, t);
479 s = strcat(" in ", s, " seconds, failing to break ", h0, " record of ", s0, " seconds");
485 Send_KillNotification (other.netname, other.flagcarried.netname, s, INFO_CAPTUREFLAG, MSG_INFO);
487 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
488 LogCTF("capture", other.flagcarried.team, other);
489 // give credit to the individual player
490 UpdateFrags(other, ctf_score_value("score_capture"));
492 if (autocvar_g_ctf_flag_capture_effects) {
493 if (other.team == COLOR_TEAM1) { // red team scores effect
494 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
495 flag_cap_ring_spawn(self.origin);
497 if (other.team == COLOR_TEAM2) { // blue team scores effect
498 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
499 flag_cap_ring_spawn(self.origin);
503 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
504 WaypointSprite_DetachCarrier(other);
505 if(self.speedrunning)
506 FakeTimeLimit(other, -1);
507 RegenFlag (other.flagcarried);
508 other.flagcarried = world;
509 other.next_take_time = time + 1;
511 if (self.cnt == FLAG_BASE)
512 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
513 if (other.team != self.team)
514 if (!other.flagcarried)
515 if (!other.ctf_captureshielded)
517 if (other.next_take_time > time)
520 if (autocvar_g_ctf_flag_pickup_effects) // pickup effect
521 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
524 self.flagpickuptime = time; // used for timing runs
525 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
526 if(other.speedrunning)
527 if(flagcaptimerecord)
528 FakeTimeLimit(other, time + flagcaptimerecord);
529 self.solid = SOLID_NOT;
530 setorigin(self, self.origin); // relink
532 other.flagcarried = self;
533 self.cnt = FLAG_CARRY;
534 self.angles = '0 0 0';
535 //bprint(other.netname, "^7 got the ", self.netname, "\n");
536 Send_KillNotification (other.netname, self.netname, "", INFO_GOTFLAG, MSG_INFO);
537 UpdateFrags(other, ctf_score_value("score_pickup_base"));
538 self.dropperid = other.playerid;
539 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
540 LogCTF("steal", self.team, other);
541 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
543 FOR_EACH_PLAYER(player)
544 if(player.team == self.team)
545 centerprint(player, "The enemy got your flag! Retrieve it!");
547 self.movetype = MOVETYPE_NONE;
548 setorigin(self, FLAG_CARRY_POS);
549 setattachment(self, other, "");
550 WaypointSprite_AttachCarrier("flagcarrier", other);
551 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
552 WaypointSprite_Ping(self.sprite);
557 if (self.cnt == FLAG_DROPPED)
559 self.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
560 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
563 Send_KillNotification (other.netname, self.netname, "", INFO_RETURNFLAG, MSG_INFO);
564 //bprint(other.netname, "^7 returned the ", self.netname, "\n");
566 // punish the player who last had it
567 FOR_EACH_PLAYER(player)
568 if(player.playerid == self.dropperid)
570 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
571 ctf_captureshield_update(player, 0); // shield only
574 // punish the team who was last carrying it
575 if(self.team == COLOR_TEAM1)
576 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
578 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
580 // reward the player who returned it
581 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
583 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
584 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
586 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
590 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
591 UpdateFrags(other, ctf_score_value("score_return"));
593 UpdateFrags(other, ctf_score_value("score_return_rogue"));
595 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
596 LogCTF("return", self.team, other);
597 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
600 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_balance_ctf_delay_collect))
602 if(self.waypointsprite_attachedforcarrier)
603 WaypointSprite_DetachCarrier(self);
605 if (autocvar_g_ctf_flag_pickup_effects) // field pickup effect
606 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
609 self.solid = SOLID_NOT;
610 setorigin(self, self.origin); // relink
612 other.flagcarried = self;
613 self.cnt = FLAG_CARRY;
614 Send_KillNotification (other.netname, self.netname, "", INFO_PICKUPFLAG, MSG_INFO);
615 //bprint(other.netname, "^7 picked up the ", self.netname, "\n");
618 f = bound(0, (self.pain_finished - time) / autocvar_g_ctf_flag_returntime, 1);
619 //print("factor is ", ftos(f), "\n");
620 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
621 + ctf_score_value("score_pickup_dropped_early") * f;
623 self.dropperid = other.playerid;
624 //print("score is ", ftos(f), "\n");
626 UpdateFrags(other, f);
627 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
628 LogCTF("pickup", self.team, other);
629 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
631 FOR_EACH_PLAYER(player)
632 if(player.team == self.team)
633 centerprint(player, "The enemy got your flag! Retrieve it!");
635 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
636 setorigin(self, FLAG_CARRY_POS);
637 setattachment(self, other, "");
638 self.damageforcescale = 0;
639 self.takedamage = DAMAGE_NO;
640 WaypointSprite_AttachCarrier("flagcarrier", other);
641 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
646 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
647 CTF Starting point for a player
652 viewing angle when spawning
654 void spawnfunc_info_player_team1()
661 self.team = COLOR_TEAM1; // red
662 spawnfunc_info_player_deathmatch();
664 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
666 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
667 CTF Starting point for a player in
672 viewing angle when spawning
674 void spawnfunc_info_player_team2()
681 self.team = COLOR_TEAM2; // blue
682 spawnfunc_info_player_deathmatch();
684 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
686 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
687 CTF Starting point for a player in
692 viewing angle when spawning
694 void spawnfunc_info_player_team3()
701 self.team = COLOR_TEAM3; // yellow
702 spawnfunc_info_player_deathmatch();
706 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
707 CTF Starting point for a player in
712 viewing angle when spawning
714 void spawnfunc_info_player_team4()
721 self.team = COLOR_TEAM4; // purple
722 spawnfunc_info_player_deathmatch();
725 void item_flag_reset()
727 DropFlag(self, world, world);
728 if(self.waypointsprite_attachedforcarrier)
729 WaypointSprite_DetachCarrier(self);
733 void item_flag_postspawn()
734 { // Check CTF Item Flag Post Spawn
736 // Flag Glow Trail Support
737 if(autocvar_g_ctf_flag_glowtrails)
738 { // Provide Flag Glow Trail
739 if(self.team == COLOR_TEAM1)
741 self.glow_color = 251;
743 if(self.team == COLOR_TEAM2)
745 self.glow_color = 210;
752 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
753 CTF flag for team one (Red).
754 Multiple are allowed.
758 Angle the flag will point
761 model to use, note this needs red and blue as skins 0 and 1
762 (default models/ctf/flag.md3)
764 sound played when flag is picked up
765 (default ctf/take.wav)
767 sound played when flag is returned by a teammate
768 (default ctf/return.wav)
770 sound played when flag is captured
771 (default ctf/redcapture.wav)
773 sound played when flag is lost in the field and respawns itself
774 (default ctf/respawn.wav)
777 void spawnfunc_item_flag_team1()
785 // link flag into ctf_worldflaglist
786 self.ctf_worldflagnext = ctf_worldflaglist;
787 ctf_worldflaglist = self;
789 self.classname = "item_flag_team";
792 self.team = COLOR_TEAM2; // color 13 team (blue)
793 self.items = IT_KEY1; // silver key (bluish enough)
797 self.team = COLOR_TEAM1; // color 4 team (red)
798 self.items = IT_KEY2; // gold key (redish enough)
800 self.netname = "^1RED^7 flag";
801 self.target = "###item###";
802 self.skin = autocvar_g_ctf_flag_red_skin;
803 if(self.spawnflags & 1)
806 self.model = autocvar_g_ctf_flag_red_model;
808 self.noise = "ctf/red_taken.wav";
810 self.noise1 = "ctf/red_returned.wav";
812 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
814 self.noise3 = "ctf/flag_respawn.wav";
816 self.noise4 = "ctf/red_dropped.wav";
817 precache_model (self.model);
818 setmodel (self, self.model); // precision set below
819 precache_sound (self.noise);
820 precache_sound (self.noise1);
821 precache_sound (self.noise2);
822 precache_sound (self.noise3);
823 precache_sound (self.noise4);
824 //setsize(self, '-16 -16 -37', '16 16 37');
825 setsize(self, FLAG_MIN, FLAG_MAX);
826 setorigin(self, self.origin + '0 0 37');
827 self.nextthink = time + 0.2; // start after doors etc
828 self.think = place_flag;
832 //if(!self.glow_size)
833 // self.glow_size = 50;
835 self.effects = self.effects | EF_LOWPRECISION;
836 if(autocvar_g_ctf_fullbrightflags)
837 self.effects |= EF_FULLBRIGHT;
838 if(autocvar_g_ctf_dynamiclights)
839 self.effects |= EF_RED;
842 item_flag_postspawn();
844 precache_model("models/ctf/shield.md3");
845 precache_model("models/ctf/shockwavetransring.md3");
847 self.reset = item_flag_reset;
850 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
851 CTF flag for team two (Blue).
852 Multiple are allowed.
856 Angle the flag will point
859 model to use, note this needs red and blue as skins 0 and 1
860 (default models/ctf/flag.md3)
862 sound played when flag is picked up
863 (default ctf/take.wav)
865 sound played when flag is returned by a teammate
866 (default ctf/return.wav)
868 sound played when flag is captured
869 (default ctf/bluecapture.wav)
871 sound played when flag is lost in the field and respawns itself
872 (default ctf/respawn.wav)
875 void spawnfunc_item_flag_team2()
883 // link flag into ctf_worldflaglist
884 self.ctf_worldflagnext = ctf_worldflaglist;
885 ctf_worldflaglist = self;
887 self.classname = "item_flag_team";
890 self.team = COLOR_TEAM1; // color 4 team (red)
891 self.items = IT_KEY2; // gold key (redish enough)
895 self.team = COLOR_TEAM2; // color 13 team (blue)
896 self.items = IT_KEY1; // silver key (bluish enough)
898 self.netname = "^4BLUE^7 flag";
899 self.target = "###item###";
900 self.skin = autocvar_g_ctf_flag_blue_skin;
901 if(self.spawnflags & 1)
904 self.model = autocvar_g_ctf_flag_blue_model;
906 self.noise = "ctf/blue_taken.wav";
908 self.noise1 = "ctf/blue_returned.wav";
910 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
912 self.noise3 = "ctf/flag_respawn.wav";
914 self.noise4 = "ctf/blue_dropped.wav";
915 precache_model (self.model);
916 setmodel (self, self.model); // precision set below
917 precache_sound (self.noise);
918 precache_sound (self.noise1);
919 precache_sound (self.noise2);
920 precache_sound (self.noise3);
921 precache_sound (self.noise4);
922 //setsize(self, '-16 -16 -37', '16 16 37');
923 setsize(self, FLAG_MIN, FLAG_MAX);
924 setorigin(self, self.origin + '0 0 37');
925 self.nextthink = time + 0.2; // start after doors etc
926 self.think = place_flag;
930 //if(!self.glow_size)
931 // self.glow_size = 50;
933 self.effects = self.effects | EF_LOWPRECISION;
934 if(autocvar_g_ctf_fullbrightflags)
935 self.effects |= EF_FULLBRIGHT;
936 if(autocvar_g_ctf_dynamiclights)
937 self.effects |= EF_BLUE;
940 item_flag_postspawn();
942 precache_model("models/ctf/shield.md3");
943 precache_model("models/ctf/shockwavetransring.md3");
945 self.reset = item_flag_reset;
949 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
950 Team declaration for CTF gameplay, this allows you to decide what team
951 names and control point models are used in your map.
953 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
954 domination, you don't need to make a blank one too.
958 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
960 Scoreboard color of the team (for example 4 is red and 13 is blue)
964 void spawnfunc_ctf_team()
971 self.classname = "ctf_team";
972 self.team = self.cnt + 1;
975 // code from here on is just to support maps that don't have control point and team entities
976 void ctf_spawnteam (string teamname, float teamcolor)
978 local entity oldself;
981 self.classname = "ctf_team";
982 self.netname = teamname;
983 self.cnt = teamcolor;
985 spawnfunc_ctf_team();
990 // spawn some default teams if the map is not set up for ctf
991 void ctf_spawnteams()
995 numteams = 2;//cvar("g_ctf_default_teams");
997 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
998 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
1001 void ctf_delayedinit()
1003 // if no teams are found, spawn defaults
1004 if (find(world, classname, "ctf_team") == world)
1012 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1013 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1015 captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
1016 captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio;
1017 captureshield_force = autocvar_g_ctf_shield_force;
1020 //#NO AUTOCVARS START
1021 g_ctf_win_mode = cvar("g_ctf_win_mode");
1025 void ctf_setstatus2(entity flag, float shift)
1027 if (flag.cnt == FLAG_CARRY)
1028 if (flag.owner == self)
1029 self.items |= shift * 3;
1031 self.items |= shift * 1;
1032 else if (flag.cnt == FLAG_DROPPED)
1033 self.items |= shift * 2;
1040 void ctf_setstatus()
1042 self.items &~= IT_RED_FLAG_TAKEN;
1043 self.items &~= IT_RED_FLAG_LOST;
1044 self.items &~= IT_BLUE_FLAG_TAKEN;
1045 self.items &~= IT_BLUE_FLAG_LOST;
1046 self.items &~= IT_CTF_SHIELDED;
1049 float redflags, blueflags;
1051 if(self.ctf_captureshielded)
1052 self.items |= IT_CTF_SHIELDED;
1057 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1059 if(flag.items & IT_KEY2) // blue
1061 else if(flag.items & IT_KEY1) // red
1065 // blinking magic: if there is more than one flag, show one of these in a clever way
1067 redflags = mod(floor(time * redflags * 0.75), redflags);
1069 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1071 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1073 if(flag.items & IT_KEY2) // blue
1075 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1076 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1078 else if(flag.items & IT_KEY1) // red
1080 if(--blueflags == -1) // happens exactly once
1081 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1086 entity(float cteam) ctf_team_has_commander =
1089 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1092 FOR_EACH_REALPLAYER(pl) {
1093 if(pl.team == cteam && pl.iscommander) {
1100 void(entity e, float st) ctf_setstate =
1106 void(float cteam) ctf_new_commander =
1111 FOR_EACH_REALPLAYER(pl) {
1112 if(pl.team == cteam) {
1113 if(pl.iscommander) { // don't reassign if alreay there
1116 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1120 if(plmax == world) {
1121 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1125 plmax.iscommander = TRUE;
1126 ctf_setstate(plmax, 3);
1127 sprint(plmax, "^3You're the commander now!\n");
1128 centerprint(plmax, "^3You're the commander now!\n");
1131 void() ctf_clientconnect =
1133 self.iscommander = FALSE;
1135 if(!self.team || self.classname != "player") {
1136 ctf_setstate(self, -1);
1138 ctf_setstate(self, 0);
1140 self.team_saved = self.team;
1142 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1143 ctf_new_commander(self.team);
1147 void() ctf_playerchanged =
1149 if(!self.team || self.classname != "player") {
1150 ctf_setstate(self, -1);
1151 } else if(self.ctf_state < 0 && self.classname == "player") {
1152 ctf_setstate(self, 0);
1155 if(self.iscommander &&
1156 (self.classname != "player" || self.team != self.team_saved)
1159 self.iscommander = FALSE;
1160 if(self.classname == "player")
1161 ctf_setstate(self, 0);
1163 ctf_setstate(self, -1);
1164 ctf_new_commander(self.team_saved);
1167 self.team_saved = self.team;
1169 ctf_new_commander(self.team);
1172 void() ctf_clientdisconnect =
1174 if(self.iscommander)
1176 ctf_new_commander(self.team);
1180 entity GetPlayer(string);
1181 float() ctf_clientcommand =
1184 if(argv(0) == "order") {
1186 sprint(self, "This command is not supported in this gamemode.\n");
1189 if(!self.iscommander) {
1190 sprint(self, "^1You are not the commander!\n");
1194 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1197 e = GetPlayer(argv(1));
1199 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1202 if(e.team != self.team) {
1203 sprint(self, "^3You can only give orders to your own team!\n");
1206 if(argv(2) == "attack") {
1207 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1208 sprint(e, "^1Attack!\n");
1209 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1211 } else if(argv(2) == "defend") {
1212 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1213 sprint(e, "^Defend!\n");
1214 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1217 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");