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 Send_CSQC_Centerprint_Generic(other, CPID_CTF_CAPTURESHIELD, "^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.", 5, 0);
70 // TODO csqc notifier for this
74 Send_CSQC_Centerprint_Generic(p, CPID_CTF_CAPTURESHIELD, "^3You are now free.\n\n^3Feel free to ^1try to capture^3 the flag again\n^3if you think you will succeed.", 5, 0);
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 .float ctf_captureshield_touch_msgtime;
92 void ctf_captureshield_touch()
94 if not(other.ctf_captureshielded)
96 if(self.team == other.team)
100 mymid = (self.absmin + self.absmax) * 0.5;
101 othermid = (other.absmin + other.absmax) * 0.5;
102 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
103 if (time - other.ctf_captureshield_touch_msgtime > 2)
104 Send_CSQC_Centerprint_Generic(other, CPID_CTF_CAPTURESHIELD, "^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.", 5, 0);
105 other.ctf_captureshield_touch_msgtime = time;
108 void ctf_flag_spawnstuff()
114 e.touch = ctf_captureshield_touch;
115 e.customizeentityforclient = ctf_captureshield_customize;
116 e.classname = "ctf_captureshield";
117 e.effects = EF_ADDITIVE;
118 e.movetype = MOVETYPE_NOCLIP;
119 e.solid = SOLID_TRIGGER;
120 e.avelocity = '7 0 11';
121 setorigin(e, self.origin);
122 setmodel(e, "models/ctf/shield.md3");
124 setsize(e, e.scale * e.mins, e.scale * e.maxs);
126 waypoint_spawnforitem_force(self, self.origin);
127 self.nearestwaypointtimeout = 0; // activate waypointing again
128 self.basewaypoint = self.nearestwaypoint;
130 if(self.team == COLOR_TEAM1)
131 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 61', self, sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
133 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 61', self, sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
136 float ctf_score_value(string parameter)
138 if(g_ctf_win_mode != 2)
139 return cvar(strcat("g_ctf_personal", parameter));
141 return cvar(strcat("g_ctf_flag", parameter));
144 void FakeTimeLimit(entity e, float t)
147 WriteByte(MSG_ONE, 3); // svc_updatestat
148 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
150 WriteCoord(MSG_ONE, autocvar_timelimit);
152 WriteCoord(MSG_ONE, (t + 1) / 60);
155 float flagcaptimerecord;
156 .float flagpickuptime;
157 //.float iscommander;
165 if(self.classname != "item_flag_team")
167 backtrace("PlaceFlag a non-flag");
171 setattachment(self, world, "");
172 self.mdl = self.model;
173 self.flags = FL_ITEM | FL_NOTARGET;
174 self.solid = SOLID_TRIGGER;
175 self.movetype = MOVETYPE_NONE;
176 self.velocity = '0 0 0';
177 self.origin_z = self.origin_z + 6;
178 self.think = FlagThink;
179 self.touch = FlagTouch;
180 self.nextthink = time + 0.1;
181 self.cnt = FLAG_BASE;
182 self.mangle = self.angles;
183 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
184 //self.effects = self.effects | EF_DIMLIGHT;
187 self.dropped_origin = self.origin;
192 self.movetype = MOVETYPE_TOSS;
195 InitializeEntity(self, ctf_flag_spawnstuff, INITPRIO_SETLOCATION);
198 void LogCTF(string mode, float flagteam, entity actor)
201 if(!autocvar_sv_eventlog)
203 s = strcat(":ctf:", mode);
204 s = strcat(s, ":", ftos(flagteam));
206 s = strcat(s, ":", ftos(actor.playerid));
210 void RegenFlag(entity e)
212 if(e.classname != "item_flag_team")
214 backtrace("RegenFlag a non-flag");
218 if(e.waypointsprite_attachedforcarrier)
219 WaypointSprite_DetachCarrier(e);
221 setattachment(e, world, "");
222 e.damageforcescale = 0;
223 e.takedamage = DAMAGE_NO;
224 e.movetype = MOVETYPE_NONE;
226 e.movetype = MOVETYPE_TOSS;
227 e.velocity = '0 0 0';
228 e.solid = SOLID_TRIGGER;
229 // TODO: play a sound here
230 setorigin(e, e.dropped_origin);
234 e.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
237 void ReturnFlag(entity e)
239 if(e.classname != "item_flag_team")
241 backtrace("ReturnFlag a non-flag");
246 if (e.owner.flagcarried == e)
248 WaypointSprite_DetachCarrier(e.owner);
249 e.owner.flagcarried = world;
252 FakeTimeLimit(e.owner, -1);
258 void DropFlag(entity e, entity penalty_receiver, entity attacker)
262 if(e.classname != "item_flag_team")
264 backtrace("DropFlag a non-flag");
276 dprint("FLAG: drop - no owner?!?!\n");
280 if (p.flagcarried != e)
282 dprint("FLAG: drop - owner is not carrying this flag??\n");
285 //bprint(p.netname, "^7 lost the ", e.netname, "\n");
286 Send_KillNotification (p.netname, e.netname, "", INFO_LOSTFLAG, MSG_INFO);
289 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
291 UpdateFrags(p, -ctf_score_value("penalty_drop"));
292 PlayerScore_Add(p, SP_CTF_DROPS, +1);
293 ctf_captureshield_update(p, 0); // shield only
294 e.playerid = attacker.playerid;
295 e.ctf_droptime = time;
296 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');
297 WaypointSprite_Ping(e.waypointsprite_attachedforcarrier);
299 if(p.waypointsprite_attachedforcarrier)
301 WaypointSprite_DetachCarrier(p);
305 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
306 backtrace("Flag carrier had no flag sprite?!?");
308 LogCTF("dropped", p.team, p);
309 sound (p, CH_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
311 setattachment(e, world, "");
312 e.damageforcescale = autocvar_g_balance_ctf_damageforcescale;
313 e.takedamage = DAMAGE_YES;
315 if (p.flagcarried == e)
316 p.flagcarried = world;
319 e.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
320 e.solid = SOLID_TRIGGER;
321 e.movetype = MOVETYPE_TOSS;
322 // setsize(e, '-16 -16 0', '16 16 74');
323 setorigin(e, p.origin - '0 0 24' + '0 0 37');
324 e.cnt = FLAG_DROPPED;
325 e.velocity = '0 0 300';
326 e.pain_finished = time + autocvar_g_ctf_flag_returntime;//30;
328 trace_startsolid = FALSE;
329 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
331 dprint("FLAG FALLTHROUGH will happen SOON\n");
338 self.nextthink = time + 0.1;
340 // sorry, we have to reset the flag size if it got squished by something
341 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
343 // if we can grow back, grow back
344 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
345 if(!trace_startsolid)
346 setsize(self, FLAG_MIN, FLAG_MAX);
349 if(self == ctf_worldflaglist) // only for the first flag
352 ctf_captureshield_update(e, 1); // release shield only
355 if(self.speedrunning)
356 if(self.cnt == FLAG_CARRY)
359 if(flagcaptimerecord)
360 if(time >= self.flagpickuptime + flagcaptimerecord)
362 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
364 sound (self, CH_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
365 self.owner.impulse = 141; // returning!
376 if (self.cnt == FLAG_BASE)
379 if (self.cnt == FLAG_DROPPED)
381 // flag fallthrough? FIXME remove this if bug is really fixed now
382 if(self.origin_z < -131072)
384 dprint("FLAG FALLTHROUGH just happened\n");
385 self.pain_finished = 0;
387 setattachment(self, world, "");
388 if (time > self.pain_finished)
390 bprint("The ", self.netname, " has returned to base\n");
391 sound (self, CH_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
392 LogCTF("returned", self.team, world);
399 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
401 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
402 DropFlag(self, world, world);
411 DropFlag(self.flagcarried, self, world);
417 void flag_cap_ring_spawn(vector org)
419 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
428 local string s, s0, h0, h1;
429 if (other.classname != "player")
431 if (other.health < 1) // ignore dead players
434 if (self.cnt == FLAG_CARRY)
437 if (self.cnt == FLAG_BASE)
438 if (other.team == self.team)
439 if (other.flagcarried) // he's got a flag
440 if (other.flagcarried.team != self.team) // capture
442 if (other.flagcarried == world)
446 if(autocvar_g_ctf_captimerecord_always || player_count - currentbots <= 1) // at most one human
448 t = time - other.flagcarried.flagpickuptime;
449 s = ftos_decimals(t, 2);
450 s0 = ftos_decimals(flagcaptimerecord, 2);
451 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
456 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
457 if (flagcaptimerecord == 0)
459 s = strcat(" in ", s, " seconds");
460 flagcaptimerecord = t;
461 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
462 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
463 write_recordmarker(other, time - t, t);
465 else if (t < flagcaptimerecord)
467 s = strcat(" in ", s, " seconds, breaking ", h0, " previous record of ", s0, " seconds");
468 flagcaptimerecord = t;
469 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
470 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
471 write_recordmarker(other, time - t, t);
475 s = strcat(" in ", s, " seconds, failing to break ", h0, " record of ", s0, " seconds");
481 Send_KillNotification (other.netname, other.flagcarried.netname, s, INFO_CAPTUREFLAG, MSG_INFO);
483 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
484 LogCTF("capture", other.flagcarried.team, other);
485 // give credit to the individual player
486 UpdateFrags(other, ctf_score_value("score_capture"));
488 if (autocvar_g_ctf_flag_capture_effects) {
489 if (other.team == COLOR_TEAM1) { // red team scores effect
490 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
491 flag_cap_ring_spawn(self.origin);
493 if (other.team == COLOR_TEAM2) { // blue team scores effect
494 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
495 flag_cap_ring_spawn(self.origin);
499 sound (other, CH_TRIGGER, self.noise2, VOL_BASE, ATTN_NONE);
500 WaypointSprite_DetachCarrier(other);
501 if(self.speedrunning)
502 FakeTimeLimit(other, -1);
503 RegenFlag (other.flagcarried);
504 other.flagcarried = world;
505 other.next_take_time = time + 1;
507 if (self.cnt == FLAG_BASE)
508 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
509 if (other.team != self.team)
510 if (!other.flagcarried)
511 if (!other.ctf_captureshielded)
513 if (other.next_take_time > time)
516 if (autocvar_g_ctf_flag_pickup_effects) // pickup effect
517 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
520 self.flagpickuptime = time; // used for timing runs
521 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
522 if(other.speedrunning)
523 if(flagcaptimerecord)
524 FakeTimeLimit(other, time + flagcaptimerecord);
525 self.solid = SOLID_NOT;
526 setorigin(self, self.origin); // relink
528 other.flagcarried = self;
529 self.cnt = FLAG_CARRY;
530 self.angles = '0 0 0';
531 //bprint(other.netname, "^7 got the ", self.netname, "\n");
532 Send_KillNotification (other.netname, self.netname, "", INFO_GOTFLAG, MSG_INFO);
533 UpdateFrags(other, ctf_score_value("score_pickup_base"));
534 self.dropperid = other.playerid;
535 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
536 LogCTF("steal", self.team, other);
537 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NONE);
539 FOR_EACH_PLAYER(player)
540 if(player.team == self.team)
541 centerprint(player, "The enemy got your flag! Retrieve it!");
543 self.movetype = MOVETYPE_NONE;
544 setorigin(self, FLAG_CARRY_POS);
545 setattachment(self, other, "");
546 WaypointSprite_AttachCarrier("flagcarrier", other, RADARICON_FLAGCARRIER, '1 1 0');
547 WaypointSprite_Ping(self.sprite);
552 if (self.cnt == FLAG_DROPPED)
554 self.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND and any other junk
555 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
558 Send_KillNotification (other.netname, self.netname, "", INFO_RETURNFLAG, MSG_INFO);
559 //bprint(other.netname, "^7 returned the ", self.netname, "\n");
561 // punish the player who last had it
562 FOR_EACH_PLAYER(player)
563 if(player.playerid == self.dropperid)
565 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
566 ctf_captureshield_update(player, 0); // shield only
569 // punish the team who was last carrying it
570 if(self.team == COLOR_TEAM1)
571 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
573 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
575 // reward the player who returned it
576 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
578 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
579 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
581 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
585 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
586 UpdateFrags(other, ctf_score_value("score_return"));
588 UpdateFrags(other, ctf_score_value("score_return_rogue"));
590 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
591 LogCTF("return", self.team, other);
592 sound (other, CH_TRIGGER, self.noise1, VOL_BASE, ATTN_NONE);
595 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_balance_ctf_delay_collect))
597 if(self.waypointsprite_attachedforcarrier)
598 WaypointSprite_DetachCarrier(self);
600 if (autocvar_g_ctf_flag_pickup_effects) // field pickup effect
601 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
604 self.solid = SOLID_NOT;
605 setorigin(self, self.origin); // relink
607 other.flagcarried = self;
608 self.cnt = FLAG_CARRY;
609 Send_KillNotification (other.netname, self.netname, "", INFO_PICKUPFLAG, MSG_INFO);
610 //bprint(other.netname, "^7 picked up the ", self.netname, "\n");
613 f = bound(0, (self.pain_finished - time) / autocvar_g_ctf_flag_returntime, 1);
614 //print("factor is ", ftos(f), "\n");
615 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
616 + ctf_score_value("score_pickup_dropped_early") * f;
618 self.dropperid = other.playerid;
619 //print("score is ", ftos(f), "\n");
621 UpdateFrags(other, f);
622 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
623 LogCTF("pickup", self.team, other);
624 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NONE);
626 FOR_EACH_PLAYER(player)
627 if(player.team == self.team)
628 centerprint(player, "The enemy got your flag! Retrieve it!");
630 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
631 setorigin(self, FLAG_CARRY_POS);
632 setattachment(self, other, "");
633 self.damageforcescale = 0;
634 self.takedamage = DAMAGE_NO;
635 WaypointSprite_AttachCarrier("flagcarrier", other, RADARICON_FLAGCARRIER, '1 1 0');
640 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
641 CTF Starting point for a player
646 viewing angle when spawning
648 void spawnfunc_info_player_team1()
655 self.team = COLOR_TEAM1; // red
656 spawnfunc_info_player_deathmatch();
658 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
660 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
661 CTF Starting point for a player in
666 viewing angle when spawning
668 void spawnfunc_info_player_team2()
675 self.team = COLOR_TEAM2; // blue
676 spawnfunc_info_player_deathmatch();
678 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
680 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
681 CTF Starting point for a player in
686 viewing angle when spawning
688 void spawnfunc_info_player_team3()
695 self.team = COLOR_TEAM3; // yellow
696 spawnfunc_info_player_deathmatch();
700 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
701 CTF Starting point for a player in
706 viewing angle when spawning
708 void spawnfunc_info_player_team4()
715 self.team = COLOR_TEAM4; // purple
716 spawnfunc_info_player_deathmatch();
719 void item_flag_reset()
721 DropFlag(self, world, world);
722 if(self.waypointsprite_attachedforcarrier)
723 WaypointSprite_DetachCarrier(self);
727 void item_flag_postspawn()
728 { // Check CTF Item Flag Post Spawn
730 // Flag Glow Trail Support
731 if(autocvar_g_ctf_flag_glowtrails)
732 { // Provide Flag Glow Trail
733 if(self.team == COLOR_TEAM1)
735 self.glow_color = 251;
737 if(self.team == COLOR_TEAM2)
739 self.glow_color = 210;
746 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
747 CTF flag for team one (Red).
748 Multiple are allowed.
752 Angle the flag will point
755 model to use, note this needs red and blue as skins 0 and 1
756 (default models/ctf/flag.md3)
758 sound played when flag is picked up
759 (default ctf/take.wav)
761 sound played when flag is returned by a teammate
762 (default ctf/return.wav)
764 sound played when flag is captured
765 (default ctf/redcapture.wav)
767 sound played when flag is lost in the field and respawns itself
768 (default ctf/respawn.wav)
771 void spawnfunc_item_flag_team2();
772 void spawnfunc_item_flag_team1()
782 float old_g_ctf_reverse = g_ctf_reverse;
783 g_ctf_reverse = 0; // avoid an endless loop
784 spawnfunc_item_flag_team2();
785 g_ctf_reverse = old_g_ctf_reverse;
789 // link flag into ctf_worldflaglist
790 self.ctf_worldflagnext = ctf_worldflaglist;
791 ctf_worldflaglist = self;
793 self.classname = "item_flag_team";
794 self.team = COLOR_TEAM1; // color 4 team (red)
795 self.items = IT_KEY2; // gold key (redish enough)
796 self.netname = "^1RED^7 flag";
797 self.target = "###item###";
798 self.skin = autocvar_g_ctf_flag_red_skin;
799 if(self.spawnflags & 1)
802 self.model = autocvar_g_ctf_flag_red_model;
804 self.noise = "ctf/red_taken.wav";
806 self.noise1 = "ctf/red_returned.wav";
808 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
810 self.noise3 = "ctf/flag_respawn.wav";
812 self.noise4 = "ctf/red_dropped.wav";
813 precache_model (self.model);
814 setmodel (self, self.model); // precision set below
815 precache_sound (self.noise);
816 precache_sound (self.noise1);
817 precache_sound (self.noise2);
818 precache_sound (self.noise3);
819 precache_sound (self.noise4);
820 //setsize(self, '-16 -16 -37', '16 16 37');
821 setsize(self, FLAG_MIN, FLAG_MAX);
822 setorigin(self, self.origin + '0 0 37');
823 self.nextthink = time + 0.2; // start after doors etc
824 self.think = place_flag;
828 //if(!self.glow_size)
829 // self.glow_size = 50;
831 self.effects = self.effects | EF_LOWPRECISION;
832 if(autocvar_g_ctf_fullbrightflags)
833 self.effects |= EF_FULLBRIGHT;
834 if(autocvar_g_ctf_dynamiclights)
835 self.effects |= EF_RED;
838 item_flag_postspawn();
840 precache_model("models/ctf/shield.md3");
841 precache_model("models/ctf/shockwavetransring.md3");
843 self.reset = item_flag_reset;
846 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
847 CTF flag for team two (Blue).
848 Multiple are allowed.
852 Angle the flag will point
855 model to use, note this needs red and blue as skins 0 and 1
856 (default models/ctf/flag.md3)
858 sound played when flag is picked up
859 (default ctf/take.wav)
861 sound played when flag is returned by a teammate
862 (default ctf/return.wav)
864 sound played when flag is captured
865 (default ctf/bluecapture.wav)
867 sound played when flag is lost in the field and respawns itself
868 (default ctf/respawn.wav)
871 void spawnfunc_item_flag_team2()
881 float old_g_ctf_reverse = g_ctf_reverse;
882 g_ctf_reverse = 0; // avoid an endless loop
883 spawnfunc_item_flag_team1();
884 g_ctf_reverse = old_g_ctf_reverse;
888 // link flag into ctf_worldflaglist
889 self.ctf_worldflagnext = ctf_worldflaglist;
890 ctf_worldflaglist = self;
892 self.classname = "item_flag_team";
893 self.team = COLOR_TEAM2; // color 13 team (blue)
894 self.items = IT_KEY1; // silver key (bluish enough)
895 self.netname = "^4BLUE^7 flag";
896 self.target = "###item###";
897 self.skin = autocvar_g_ctf_flag_blue_skin;
898 if(self.spawnflags & 1)
901 self.model = autocvar_g_ctf_flag_blue_model;
903 self.noise = "ctf/blue_taken.wav";
905 self.noise1 = "ctf/blue_returned.wav";
907 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
909 self.noise3 = "ctf/flag_respawn.wav";
911 self.noise4 = "ctf/blue_dropped.wav";
912 precache_model (self.model);
913 setmodel (self, self.model); // precision set below
914 precache_sound (self.noise);
915 precache_sound (self.noise1);
916 precache_sound (self.noise2);
917 precache_sound (self.noise3);
918 precache_sound (self.noise4);
919 //setsize(self, '-16 -16 -37', '16 16 37');
920 setsize(self, FLAG_MIN, FLAG_MAX);
921 setorigin(self, self.origin + '0 0 37');
922 self.nextthink = time + 0.2; // start after doors etc
923 self.think = place_flag;
927 //if(!self.glow_size)
928 // self.glow_size = 50;
930 self.effects = self.effects | EF_LOWPRECISION;
931 if(autocvar_g_ctf_fullbrightflags)
932 self.effects |= EF_FULLBRIGHT;
933 if(autocvar_g_ctf_dynamiclights)
934 self.effects |= EF_BLUE;
937 item_flag_postspawn();
939 precache_model("models/ctf/shield.md3");
940 precache_model("models/ctf/shockwavetransring.md3");
942 self.reset = item_flag_reset;
946 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
947 Team declaration for CTF gameplay, this allows you to decide what team
948 names and control point models are used in your map.
950 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
951 domination, you don't need to make a blank one too.
955 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
957 Scoreboard color of the team (for example 4 is red and 13 is blue)
961 void spawnfunc_ctf_team()
968 self.classname = "ctf_team";
969 self.team = self.cnt + 1;
972 // code from here on is just to support maps that don't have control point and team entities
973 void ctf_spawnteam (string teamname, float teamcolor)
975 local entity oldself;
978 self.classname = "ctf_team";
979 self.netname = teamname;
980 self.cnt = teamcolor;
982 spawnfunc_ctf_team();
987 // spawn some default teams if the map is not set up for ctf
988 void ctf_spawnteams()
992 numteams = 2;//cvar("g_ctf_default_teams");
994 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
995 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
998 void ctf_delayedinit()
1000 // if no teams are found, spawn defaults
1001 if (find(world, classname, "ctf_team") == world)
1009 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
1010 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
1012 captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
1013 captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio;
1014 captureshield_force = autocvar_g_ctf_shield_force;
1017 //#NO AUTOCVARS START
1018 g_ctf_win_mode = cvar("g_ctf_win_mode");
1022 void ctf_setstatus2(entity flag, float shift)
1024 if (flag.cnt == FLAG_CARRY)
1025 if (flag.owner == self)
1026 self.items |= shift * 3;
1028 self.items |= shift * 1;
1029 else if (flag.cnt == FLAG_DROPPED)
1030 self.items |= shift * 2;
1037 void ctf_setstatus()
1039 self.items &~= IT_RED_FLAG_TAKEN;
1040 self.items &~= IT_RED_FLAG_LOST;
1041 self.items &~= IT_BLUE_FLAG_TAKEN;
1042 self.items &~= IT_BLUE_FLAG_LOST;
1043 self.items &~= IT_CTF_SHIELDED;
1046 float redflags, blueflags;
1048 if(self.ctf_captureshielded)
1049 self.items |= IT_CTF_SHIELDED;
1054 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1056 if(flag.items & IT_KEY2) // blue
1058 else if(flag.items & IT_KEY1) // red
1062 // blinking magic: if there is more than one flag, show one of these in a clever way
1064 redflags = mod(floor(time * redflags * 0.75), redflags);
1066 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1068 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1070 if(flag.items & IT_KEY2) // blue
1072 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1073 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1075 else if(flag.items & IT_KEY1) // red
1077 if(--blueflags == -1) // happens exactly once
1078 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1083 entity(float cteam) ctf_team_has_commander =
1086 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1089 FOR_EACH_REALPLAYER(pl) {
1090 if(pl.team == cteam && pl.iscommander) {
1097 void(entity e, float st) ctf_setstate =
1103 void(float cteam) ctf_new_commander =
1108 FOR_EACH_REALPLAYER(pl) {
1109 if(pl.team == cteam) {
1110 if(pl.iscommander) { // don't reassign if alreay there
1113 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1117 if(plmax == world) {
1118 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1122 plmax.iscommander = TRUE;
1123 ctf_setstate(plmax, 3);
1124 sprint(plmax, "^3You're the commander now!\n");
1125 centerprint(plmax, "^3You're the commander now!\n");
1128 void() ctf_clientconnect =
1130 self.iscommander = FALSE;
1132 if(!self.team || self.classname != "player") {
1133 ctf_setstate(self, -1);
1135 ctf_setstate(self, 0);
1137 self.team_saved = self.team;
1139 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1140 ctf_new_commander(self.team);
1144 void() ctf_playerchanged =
1146 if(!self.team || self.classname != "player") {
1147 ctf_setstate(self, -1);
1148 } else if(self.ctf_state < 0 && self.classname == "player") {
1149 ctf_setstate(self, 0);
1152 if(self.iscommander &&
1153 (self.classname != "player" || self.team != self.team_saved)
1156 self.iscommander = FALSE;
1157 if(self.classname == "player")
1158 ctf_setstate(self, 0);
1160 ctf_setstate(self, -1);
1161 ctf_new_commander(self.team_saved);
1164 self.team_saved = self.team;
1166 ctf_new_commander(self.team);
1169 void() ctf_clientdisconnect =
1171 if(self.iscommander)
1173 ctf_new_commander(self.team);
1177 entity GetPlayer(string);
1178 float() ctf_clientcommand =
1181 if(argv(0) == "order") {
1183 sprint(self, "This command is not supported in this gamemode.\n");
1186 if(!self.iscommander) {
1187 sprint(self, "^1You are not the commander!\n");
1191 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1194 e = GetPlayer(argv(1));
1196 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1199 if(e.team != self.team) {
1200 sprint(self, "^3You can only give orders to your own team!\n");
1203 if(argv(2) == "attack") {
1204 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1205 sprint(e, "^1Attack!\n");
1206 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1208 } else if(argv(2) == "defend") {
1209 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1210 sprint(e, "^Defend!\n");
1211 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1214 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");