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, RADARICON_FLAG, '0 1 1');
300 WaypointSprite_Ping(e.waypointsprite_attachedforcarrier);
302 if(p.waypointsprite_attachedforcarrier)
304 WaypointSprite_DetachCarrier(p);
308 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
309 backtrace("Flag carrier had no flag sprite?!?");
311 LogCTF("dropped", p.team, p);
312 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
314 setattachment(e, world, "");
315 e.damageforcescale = autocvar_g_balance_ctf_damageforcescale;
316 e.takedamage = DAMAGE_YES;
318 if (p.flagcarried == e)
319 p.flagcarried = world;
322 e.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
323 e.solid = SOLID_TRIGGER;
324 e.movetype = MOVETYPE_TOSS;
325 // setsize(e, '-16 -16 0', '16 16 74');
326 setorigin(e, p.origin - '0 0 24' + '0 0 37');
327 e.cnt = FLAG_DROPPED;
328 e.velocity = '0 0 300';
329 e.pain_finished = time + autocvar_g_ctf_flag_returntime;//30;
331 trace_startsolid = FALSE;
332 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
334 dprint("FLAG FALLTHROUGH will happen SOON\n");
341 self.nextthink = time + 0.1;
343 // sorry, we have to reset the flag size if it got squished by something
344 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
346 // if we can grow back, grow back
347 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
348 if(!trace_startsolid)
349 setsize(self, FLAG_MIN, FLAG_MAX);
352 if(self == ctf_worldflaglist) // only for the first flag
355 ctf_captureshield_update(e, 1); // release shield only
358 if(self.speedrunning)
359 if(self.cnt == FLAG_CARRY)
362 if(flagcaptimerecord)
363 if(time >= self.flagpickuptime + flagcaptimerecord)
365 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
367 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
368 self.owner.impulse = 141; // returning!
379 if (self.cnt == FLAG_BASE)
382 if (self.cnt == FLAG_DROPPED)
384 // flag fallthrough? FIXME remove this if bug is really fixed now
385 if(self.origin_z < -131072)
387 dprint("FLAG FALLTHROUGH just happened\n");
388 self.pain_finished = 0;
390 setattachment(self, world, "");
391 if (time > self.pain_finished)
393 bprint("The ", self.netname, " has returned to base\n");
394 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
395 LogCTF("returned", self.team, world);
402 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
404 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
405 DropFlag(self, world, world);
414 DropFlag(self.flagcarried, self, world);
420 void flag_cap_ring_spawn(vector org)
422 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
431 local string s, s0, h0, h1;
432 if (other.classname != "player")
434 if (other.health < 1) // ignore dead players
437 if (self.cnt == FLAG_CARRY)
440 if (self.cnt == FLAG_BASE)
441 if (other.team == self.team)
442 if (other.flagcarried) // he's got a flag
443 if (other.flagcarried.team != self.team) // capture
445 if (other.flagcarried == world)
449 if(autocvar_g_ctf_captimerecord_always || player_count - currentbots <= 1) // at most one human
451 t = time - other.flagcarried.flagpickuptime;
452 s = ftos_decimals(t, 2);
453 s0 = ftos_decimals(flagcaptimerecord, 2);
454 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
459 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
460 if (flagcaptimerecord == 0)
462 s = strcat(" in ", s, " seconds");
463 flagcaptimerecord = t;
464 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
465 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
466 write_recordmarker(other, time - t, t);
468 else if (t < flagcaptimerecord)
470 s = strcat(" in ", s, " seconds, breaking ", h0, " previous record of ", s0, " seconds");
471 flagcaptimerecord = t;
472 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
473 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
474 write_recordmarker(other, time - t, t);
478 s = strcat(" in ", s, " seconds, failing to break ", h0, " record of ", s0, " seconds");
484 Send_KillNotification (other.netname, other.flagcarried.netname, s, INFO_CAPTUREFLAG, MSG_INFO);
486 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
487 LogCTF("capture", other.flagcarried.team, other);
488 // give credit to the individual player
489 UpdateFrags(other, ctf_score_value("score_capture"));
491 if (autocvar_g_ctf_flag_capture_effects) {
492 if (other.team == COLOR_TEAM1) { // red team scores effect
493 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
494 flag_cap_ring_spawn(self.origin);
496 if (other.team == COLOR_TEAM2) { // blue team scores effect
497 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
498 flag_cap_ring_spawn(self.origin);
502 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
503 WaypointSprite_DetachCarrier(other);
504 if(self.speedrunning)
505 FakeTimeLimit(other, -1);
506 RegenFlag (other.flagcarried);
507 other.flagcarried = world;
508 other.next_take_time = time + 1;
510 if (self.cnt == FLAG_BASE)
511 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
512 if (other.team != self.team)
513 if (!other.flagcarried)
514 if (!other.ctf_captureshielded)
516 if (other.next_take_time > time)
519 if (autocvar_g_ctf_flag_pickup_effects) // pickup effect
520 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
523 self.flagpickuptime = time; // used for timing runs
524 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
525 if(other.speedrunning)
526 if(flagcaptimerecord)
527 FakeTimeLimit(other, time + flagcaptimerecord);
528 self.solid = SOLID_NOT;
529 setorigin(self, self.origin); // relink
531 other.flagcarried = self;
532 self.cnt = FLAG_CARRY;
533 self.angles = '0 0 0';
534 //bprint(other.netname, "^7 got the ", self.netname, "\n");
535 Send_KillNotification (other.netname, self.netname, "", INFO_GOTFLAG, MSG_INFO);
536 UpdateFrags(other, ctf_score_value("score_pickup_base"));
537 self.dropperid = other.playerid;
538 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
539 LogCTF("steal", self.team, other);
540 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
542 FOR_EACH_PLAYER(player)
543 if(player.team == self.team)
544 centerprint(player, "The enemy got your flag! Retrieve it!");
546 self.movetype = MOVETYPE_NONE;
547 setorigin(self, FLAG_CARRY_POS);
548 setattachment(self, other, "");
549 WaypointSprite_AttachCarrier("flagcarrier", other);
550 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
551 WaypointSprite_Ping(self.sprite);
556 if (self.cnt == FLAG_DROPPED)
558 self.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
559 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
562 Send_KillNotification (other.netname, self.netname, "", INFO_RETURNFLAG, MSG_INFO);
563 //bprint(other.netname, "^7 returned the ", self.netname, "\n");
565 // punish the player who last had it
566 FOR_EACH_PLAYER(player)
567 if(player.playerid == self.dropperid)
569 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
570 ctf_captureshield_update(player, 0); // shield only
573 // punish the team who was last carrying it
574 if(self.team == COLOR_TEAM1)
575 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
577 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
579 // reward the player who returned it
580 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
582 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
583 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
585 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
589 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
590 UpdateFrags(other, ctf_score_value("score_return"));
592 UpdateFrags(other, ctf_score_value("score_return_rogue"));
594 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
595 LogCTF("return", self.team, other);
596 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
599 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_balance_ctf_delay_collect))
601 if(self.waypointsprite_attachedforcarrier)
602 WaypointSprite_DetachCarrier(self);
604 if (autocvar_g_ctf_flag_pickup_effects) // field pickup effect
605 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
608 self.solid = SOLID_NOT;
609 setorigin(self, self.origin); // relink
611 other.flagcarried = self;
612 self.cnt = FLAG_CARRY;
613 Send_KillNotification (other.netname, self.netname, "", INFO_PICKUPFLAG, MSG_INFO);
614 //bprint(other.netname, "^7 picked up the ", self.netname, "\n");
617 f = bound(0, (self.pain_finished - time) / autocvar_g_ctf_flag_returntime, 1);
618 //print("factor is ", ftos(f), "\n");
619 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
620 + ctf_score_value("score_pickup_dropped_early") * f;
622 self.dropperid = other.playerid;
623 //print("score is ", ftos(f), "\n");
625 UpdateFrags(other, f);
626 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
627 LogCTF("pickup", self.team, other);
628 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
630 FOR_EACH_PLAYER(player)
631 if(player.team == self.team)
632 centerprint(player, "The enemy got your flag! Retrieve it!");
634 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
635 setorigin(self, FLAG_CARRY_POS);
636 setattachment(self, other, "");
637 self.damageforcescale = 0;
638 self.takedamage = DAMAGE_NO;
639 WaypointSprite_AttachCarrier("flagcarrier", other);
640 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
645 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
646 CTF Starting point for a player
651 viewing angle when spawning
653 void spawnfunc_info_player_team1()
660 self.team = COLOR_TEAM1; // red
661 spawnfunc_info_player_deathmatch();
663 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
665 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
666 CTF Starting point for a player in
671 viewing angle when spawning
673 void spawnfunc_info_player_team2()
680 self.team = COLOR_TEAM2; // blue
681 spawnfunc_info_player_deathmatch();
683 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
685 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
686 CTF Starting point for a player in
691 viewing angle when spawning
693 void spawnfunc_info_player_team3()
700 self.team = COLOR_TEAM3; // yellow
701 spawnfunc_info_player_deathmatch();
705 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
706 CTF Starting point for a player in
711 viewing angle when spawning
713 void spawnfunc_info_player_team4()
720 self.team = COLOR_TEAM4; // purple
721 spawnfunc_info_player_deathmatch();
724 void item_flag_reset()
726 DropFlag(self, world, world);
727 if(self.waypointsprite_attachedforcarrier)
728 WaypointSprite_DetachCarrier(self);
732 void item_flag_postspawn()
733 { // Check CTF Item Flag Post Spawn
735 // Flag Glow Trail Support
736 if(autocvar_g_ctf_flag_glowtrails)
737 { // Provide Flag Glow Trail
738 if(self.team == COLOR_TEAM1)
740 self.glow_color = 251;
742 if(self.team == COLOR_TEAM2)
744 self.glow_color = 210;
751 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
752 CTF flag for team one (Red).
753 Multiple are allowed.
757 Angle the flag will point
760 model to use, note this needs red and blue as skins 0 and 1
761 (default models/ctf/flag.md3)
763 sound played when flag is picked up
764 (default ctf/take.wav)
766 sound played when flag is returned by a teammate
767 (default ctf/return.wav)
769 sound played when flag is captured
770 (default ctf/redcapture.wav)
772 sound played when flag is lost in the field and respawns itself
773 (default ctf/respawn.wav)
776 void spawnfunc_item_flag_team1()
784 // link flag into ctf_worldflaglist
785 self.ctf_worldflagnext = ctf_worldflaglist;
786 ctf_worldflaglist = self;
788 self.classname = "item_flag_team";
791 self.team = COLOR_TEAM2; // color 13 team (blue)
792 self.items = IT_KEY1; // silver key (bluish enough)
796 self.team = COLOR_TEAM1; // color 4 team (red)
797 self.items = IT_KEY2; // gold key (redish enough)
799 self.netname = "^1RED^7 flag";
800 self.target = "###item###";
801 self.skin = autocvar_g_ctf_flag_red_skin;
802 if(self.spawnflags & 1)
805 self.model = autocvar_g_ctf_flag_red_model;
807 self.noise = "ctf/red_taken.wav";
809 self.noise1 = "ctf/red_returned.wav";
811 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
813 self.noise3 = "ctf/flag_respawn.wav";
815 self.noise4 = "ctf/red_dropped.wav";
816 precache_model (self.model);
817 setmodel (self, self.model); // precision set below
818 precache_sound (self.noise);
819 precache_sound (self.noise1);
820 precache_sound (self.noise2);
821 precache_sound (self.noise3);
822 precache_sound (self.noise4);
823 //setsize(self, '-16 -16 -37', '16 16 37');
824 setsize(self, FLAG_MIN, FLAG_MAX);
825 setorigin(self, self.origin + '0 0 37');
826 self.nextthink = time + 0.2; // start after doors etc
827 self.think = place_flag;
831 //if(!self.glow_size)
832 // self.glow_size = 50;
834 self.effects = self.effects | EF_LOWPRECISION;
835 if(autocvar_g_ctf_fullbrightflags)
836 self.effects |= EF_FULLBRIGHT;
837 if(autocvar_g_ctf_dynamiclights)
838 self.effects |= EF_RED;
841 item_flag_postspawn();
843 precache_model("models/ctf/shield.md3");
844 precache_model("models/ctf/shockwavetransring.md3");
846 self.reset = item_flag_reset;
849 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
850 CTF flag for team two (Blue).
851 Multiple are allowed.
855 Angle the flag will point
858 model to use, note this needs red and blue as skins 0 and 1
859 (default models/ctf/flag.md3)
861 sound played when flag is picked up
862 (default ctf/take.wav)
864 sound played when flag is returned by a teammate
865 (default ctf/return.wav)
867 sound played when flag is captured
868 (default ctf/bluecapture.wav)
870 sound played when flag is lost in the field and respawns itself
871 (default ctf/respawn.wav)
874 void spawnfunc_item_flag_team2()
882 // link flag into ctf_worldflaglist
883 self.ctf_worldflagnext = ctf_worldflaglist;
884 ctf_worldflaglist = self;
886 self.classname = "item_flag_team";
889 self.team = COLOR_TEAM1; // color 4 team (red)
890 self.items = IT_KEY2; // gold key (redish enough)
894 self.team = COLOR_TEAM2; // color 13 team (blue)
895 self.items = IT_KEY1; // silver key (bluish enough)
897 self.netname = "^4BLUE^7 flag";
898 self.target = "###item###";
899 self.skin = autocvar_g_ctf_flag_blue_skin;
900 if(self.spawnflags & 1)
903 self.model = autocvar_g_ctf_flag_blue_model;
905 self.noise = "ctf/blue_taken.wav";
907 self.noise1 = "ctf/blue_returned.wav";
909 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
911 self.noise3 = "ctf/flag_respawn.wav";
913 self.noise4 = "ctf/blue_dropped.wav";
914 precache_model (self.model);
915 setmodel (self, self.model); // precision set below
916 precache_sound (self.noise);
917 precache_sound (self.noise1);
918 precache_sound (self.noise2);
919 precache_sound (self.noise3);
920 precache_sound (self.noise4);
921 //setsize(self, '-16 -16 -37', '16 16 37');
922 setsize(self, FLAG_MIN, FLAG_MAX);
923 setorigin(self, self.origin + '0 0 37');
924 self.nextthink = time + 0.2; // start after doors etc
925 self.think = place_flag;
929 //if(!self.glow_size)
930 // self.glow_size = 50;
932 self.effects = self.effects | EF_LOWPRECISION;
933 if(autocvar_g_ctf_fullbrightflags)
934 self.effects |= EF_FULLBRIGHT;
935 if(autocvar_g_ctf_dynamiclights)
936 self.effects |= EF_BLUE;
939 item_flag_postspawn();
941 precache_model("models/ctf/shield.md3");
942 precache_model("models/ctf/shockwavetransring.md3");
944 self.reset = item_flag_reset;
948 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
949 Team declaration for CTF gameplay, this allows you to decide what team
950 names and control point models are used in your map.
952 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
953 domination, you don't need to make a blank one too.
957 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
959 Scoreboard color of the team (for example 4 is red and 13 is blue)
963 void spawnfunc_ctf_team()
970 self.classname = "ctf_team";
971 self.team = self.cnt + 1;
974 // code from here on is just to support maps that don't have control point and team entities
975 void ctf_spawnteam (string teamname, float teamcolor)
977 local entity oldself;
980 self.classname = "ctf_team";
981 self.netname = teamname;
982 self.cnt = teamcolor;
984 spawnfunc_ctf_team();
989 // spawn some default teams if the map is not set up for ctf
990 void ctf_spawnteams()
994 numteams = 2;//cvar("g_ctf_default_teams");
996 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
997 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
1000 void ctf_delayedinit()
1002 // if no teams are found, spawn defaults
1003 if (find(world, classname, "ctf_team") == world)
1011 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1012 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1014 captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
1015 captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio;
1016 captureshield_force = autocvar_g_ctf_shield_force;
1019 //#NO AUTOCVARS START
1020 g_ctf_win_mode = cvar("g_ctf_win_mode");
1024 void ctf_setstatus2(entity flag, float shift)
1026 if (flag.cnt == FLAG_CARRY)
1027 if (flag.owner == self)
1028 self.items |= shift * 3;
1030 self.items |= shift * 1;
1031 else if (flag.cnt == FLAG_DROPPED)
1032 self.items |= shift * 2;
1039 void ctf_setstatus()
1041 self.items &~= IT_RED_FLAG_TAKEN;
1042 self.items &~= IT_RED_FLAG_LOST;
1043 self.items &~= IT_BLUE_FLAG_TAKEN;
1044 self.items &~= IT_BLUE_FLAG_LOST;
1045 self.items &~= IT_CTF_SHIELDED;
1048 float redflags, blueflags;
1050 if(self.ctf_captureshielded)
1051 self.items |= IT_CTF_SHIELDED;
1056 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1058 if(flag.items & IT_KEY2) // blue
1060 else if(flag.items & IT_KEY1) // red
1064 // blinking magic: if there is more than one flag, show one of these in a clever way
1066 redflags = mod(floor(time * redflags * 0.75), redflags);
1068 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1070 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1072 if(flag.items & IT_KEY2) // blue
1074 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1075 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1077 else if(flag.items & IT_KEY1) // red
1079 if(--blueflags == -1) // happens exactly once
1080 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1085 entity(float cteam) ctf_team_has_commander =
1088 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1091 FOR_EACH_REALPLAYER(pl) {
1092 if(pl.team == cteam && pl.iscommander) {
1099 void(entity e, float st) ctf_setstate =
1105 void(float cteam) ctf_new_commander =
1110 FOR_EACH_REALPLAYER(pl) {
1111 if(pl.team == cteam) {
1112 if(pl.iscommander) { // don't reassign if alreay there
1115 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1119 if(plmax == world) {
1120 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1124 plmax.iscommander = TRUE;
1125 ctf_setstate(plmax, 3);
1126 sprint(plmax, "^3You're the commander now!\n");
1127 centerprint(plmax, "^3You're the commander now!\n");
1130 void() ctf_clientconnect =
1132 self.iscommander = FALSE;
1134 if(!self.team || self.classname != "player") {
1135 ctf_setstate(self, -1);
1137 ctf_setstate(self, 0);
1139 self.team_saved = self.team;
1141 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1142 ctf_new_commander(self.team);
1146 void() ctf_playerchanged =
1148 if(!self.team || self.classname != "player") {
1149 ctf_setstate(self, -1);
1150 } else if(self.ctf_state < 0 && self.classname == "player") {
1151 ctf_setstate(self, 0);
1154 if(self.iscommander &&
1155 (self.classname != "player" || self.team != self.team_saved)
1158 self.iscommander = FALSE;
1159 if(self.classname == "player")
1160 ctf_setstate(self, 0);
1162 ctf_setstate(self, -1);
1163 ctf_new_commander(self.team_saved);
1166 self.team_saved = self.team;
1168 ctf_new_commander(self.team);
1171 void() ctf_clientdisconnect =
1173 if(self.iscommander)
1175 ctf_new_commander(self.team);
1179 entity GetPlayer(string);
1180 float() ctf_clientcommand =
1183 if(argv(0) == "order") {
1185 sprint(self, "This command is not supported in this gamemode.\n");
1188 if(!self.iscommander) {
1189 sprint(self, "^1You are not the commander!\n");
1193 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1196 e = GetPlayer(argv(1));
1198 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1201 if(e.team != self.team) {
1202 sprint(self, "^3You can only give orders to your own team!\n");
1205 if(argv(2) == "attack") {
1206 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1207 sprint(e, "^1Attack!\n");
1208 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1210 } else if(argv(2) == "defend") {
1211 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1212 sprint(e, "^Defend!\n");
1213 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1216 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");