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;
152 if(self.classname != "item_flag_team")
154 backtrace("PlaceFlag a non-flag");
159 self.t_width = 0.1; // frame animation rate
161 self.t_length = 58; // maximum frame
163 setattachment(self, world, "");
164 self.mdl = self.model;
165 self.flags = FL_ITEM;
166 self.solid = SOLID_TRIGGER;
167 self.movetype = MOVETYPE_NONE;
168 self.velocity = '0 0 0';
169 self.origin_z = self.origin_z + 6;
170 self.think = FlagThink;
171 self.touch = FlagTouch;
172 self.nextthink = time + 0.1;
173 self.cnt = FLAG_BASE;
174 self.mangle = self.angles;
175 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
176 //self.effects = self.effects | EF_DIMLIGHT;
179 self.dropped_origin = self.origin;
184 self.movetype = MOVETYPE_TOSS;
186 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
189 void LogCTF(string mode, float flagteam, entity actor)
192 if(!cvar("sv_eventlog"))
194 s = strcat(":ctf:", mode);
195 s = strcat(s, ":", ftos(flagteam));
197 s = strcat(s, ":", ftos(actor.playerid));
201 void RegenFlag(entity e)
203 if(e.classname != "item_flag_team")
205 backtrace("RegenFlag a non-flag");
209 setattachment(e, world, "");
210 e.damageforcescale = 0;
211 e.movetype = MOVETYPE_NONE;
213 e.movetype = MOVETYPE_TOSS;
214 e.solid = SOLID_TRIGGER;
215 // TODO: play a sound here
216 setorigin(e, e.dropped_origin);
220 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
223 void ReturnFlag(entity e)
225 if(e.classname != "item_flag_team")
227 backtrace("ReturnFlag a non-flag");
232 if (e.owner.flagcarried == e)
234 WaypointSprite_DetachCarrier(e.owner);
235 e.owner.flagcarried = world;
238 FakeTimeLimit(e.owner, -1);
244 void DropFlag(entity e, entity penalty_receiver, entity attacker)
248 if(e.classname != "item_flag_team")
250 backtrace("DropFlag a non-flag");
262 dprint("FLAG: drop - no owner?!?!\n");
266 if (p.flagcarried != e)
268 dprint("FLAG: drop - owner is not carrying this flag??\n");
271 bprint(p.netname, "^7 lost the ", e.netname, "\n");
274 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
276 UpdateFrags(p, -ctf_score_value("penalty_drop"));
277 PlayerScore_Add(p, SP_CTF_DROPS, +1);
278 ctf_captureshield_update(p, 0); // shield only
279 e.playerid = attacker.playerid;
280 e.ctf_droptime = time;
282 if(p.waypointsprite_attachedforcarrier)
284 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
285 WaypointSprite_DetachCarrier(p);
289 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
290 backtrace("Flag carrier had no flag sprite?!?");
292 LogCTF("dropped", p.team, p);
293 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
295 setattachment(e, world, "");
296 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
298 if (p.flagcarried == e)
299 p.flagcarried = world;
302 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
303 e.solid = SOLID_TRIGGER;
304 e.movetype = MOVETYPE_TOSS;
305 // setsize(e, '-16 -16 0', '16 16 74');
306 setorigin(e, p.origin - '0 0 24' + '0 0 37');
307 e.cnt = FLAG_DROPPED;
308 e.velocity = '0 0 300';
309 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
311 trace_startsolid = FALSE;
312 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
314 dprint("FLAG FALLTHROUGH will happen SOON\n");
319 if(self.delay > time)
321 self.delay = time + self.t_width;
322 if(self.nextthink > self.delay)
323 self.nextthink = self.delay;
325 self.frame = self.frame + 1;
326 if(self.frame > self.t_length)
334 self.nextthink = time + 0.1;
336 // sorry, we have to reset the flag size if it got squished by something
337 if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
339 // if we can grow back, grow back
340 tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
341 if(!trace_startsolid)
342 setsize(self, FLAG_MIN, FLAG_MAX);
345 if(self == ctf_worldflaglist) // only for the first flag
348 ctf_captureshield_update(e, 1); // release shield only
353 if(self.speedrunning)
354 if(self.cnt == FLAG_CARRY)
357 if(flagcaptimerecord)
358 if(time >= self.flagpickuptime + flagcaptimerecord)
360 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
362 self.owner.impulse = 77; // returning!
372 if (self.cnt == FLAG_BASE)
375 if (self.cnt == FLAG_DROPPED)
377 // flag fallthrough? FIXME remove this if bug is really fixed now
378 if(self.origin_z < -131072)
380 dprint("FLAG FALLTHROUGH just happened\n");
381 self.pain_finished = 0;
383 setattachment(self, world, "");
384 if (time > self.pain_finished)
386 bprint("The ", self.netname, " has returned to base\n");
387 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
388 LogCTF("returned", self.team, world);
395 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
397 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
398 DropFlag(self, world, world);
402 if(cvar("g_ctf_allow_drop"))
404 DropFlag(self, e, world);
413 local string s, s0, h0, h1;
414 if (other.classname != "player")
416 if (other.health < 1) // ignore dead players
419 if (self.cnt == FLAG_CARRY)
422 if (self.cnt == FLAG_BASE)
423 if (other.team == self.team)
424 if (other.flagcarried) // he's got a flag
425 if (other.flagcarried.team != self.team) // capture
427 if (other.flagcarried == world)
431 if(cvar("g_ctf_captimerecord_allow_assisted") || player_count - currentbots <= 1) // at most one human
433 t = time - other.flagcarried.flagpickuptime;
434 s = ftos_decimals(t, 2);
435 s0 = ftos_decimals(flagcaptimerecord, 2);
436 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
441 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
442 if (flagcaptimerecord == 0)
444 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
445 flagcaptimerecord = t;
446 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
447 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
448 write_recordmarker(other, time - t, t);
450 else if (t < flagcaptimerecord)
452 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
453 flagcaptimerecord = t;
454 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
455 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
456 write_recordmarker(other, time - t, t);
460 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
464 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
466 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
467 LogCTF("capture", other.flagcarried.team, other);
468 // give credit to the individual player
469 UpdateFrags(other, ctf_score_value("score_capture"));
471 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
472 WaypointSprite_DetachCarrier(other);
473 if(self.speedrunning)
474 FakeTimeLimit(other, -1);
475 RegenFlag (other.flagcarried);
476 other.flagcarried = world;
477 other.next_take_time = time + 1;
479 if (self.cnt == FLAG_BASE)
480 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
481 if (other.team != self.team)
482 if (!other.flagcarried)
483 if (!other.ctf_captureshielded)
485 if (other.next_take_time > time)
488 self.flagpickuptime = time; // used for timing runs
489 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
490 if(other.speedrunning)
491 if(flagcaptimerecord)
492 FakeTimeLimit(other, time + flagcaptimerecord);
493 self.solid = SOLID_NOT;
494 setorigin(self, self.origin); // relink
496 other.flagcarried = self;
497 self.cnt = FLAG_CARRY;
498 self.angles = '0 0 0';
499 bprint(other.netname, "^7 got the ", self.netname, "\n");
500 UpdateFrags(other, ctf_score_value("score_pickup_base"));
501 self.dropperid = other.playerid;
502 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
503 LogCTF("steal", self.team, other);
504 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
506 FOR_EACH_PLAYER(player)
507 if(player.team == self.team)
508 centerprint(player, "The enemy got your flag! Retrieve it!");
510 self.movetype = MOVETYPE_NONE;
511 setorigin(self, FLAG_CARRY_POS);
512 setattachment(self, other, "");
513 WaypointSprite_AttachCarrier("flagcarrier", other);
514 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
515 WaypointSprite_Ping(self.sprite);
520 if (self.cnt == FLAG_DROPPED)
522 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
523 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
526 bprint(other.netname, "^7 returned the ", self.netname, "\n");
528 // punish the player who last had it
529 FOR_EACH_PLAYER(player)
530 if(player.playerid == self.dropperid)
532 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
533 ctf_captureshield_update(player, 0); // shield only
536 // punish the team who was last carrying it
537 if(self.team == COLOR_TEAM1)
538 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
540 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
542 // reward the player who returned it
543 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
545 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
546 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
548 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
552 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
553 UpdateFrags(other, ctf_score_value("score_return"));
555 UpdateFrags(other, ctf_score_value("score_return_rogue"));
557 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
558 LogCTF("return", self.team, other);
559 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
562 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
565 self.solid = SOLID_NOT;
566 setorigin(self, self.origin); // relink
568 other.flagcarried = self;
569 self.cnt = FLAG_CARRY;
570 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
573 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
574 //print("factor is ", ftos(f), "\n");
575 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
576 + ctf_score_value("score_pickup_dropped_early") * f;
578 self.dropperid = other.playerid;
579 //print("score is ", ftos(f), "\n");
581 UpdateFrags(other, f);
582 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
583 LogCTF("pickup", self.team, other);
584 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
586 FOR_EACH_PLAYER(player)
587 if(player.team == self.team)
588 centerprint(player, "The enemy got your flag! Retrieve it!");
590 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
591 setorigin(self, FLAG_CARRY_POS);
592 setattachment(self, other, "");
593 self.damageforcescale = 0;
594 WaypointSprite_AttachCarrier("flagcarrier", other);
595 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
600 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
601 CTF Starting point for a player
606 viewing angle when spawning
608 void spawnfunc_info_player_team1()
615 self.team = COLOR_TEAM1; // red
616 spawnfunc_info_player_deathmatch();
618 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
620 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
621 CTF Starting point for a player in
626 viewing angle when spawning
628 void spawnfunc_info_player_team2()
635 self.team = COLOR_TEAM2; // blue
636 spawnfunc_info_player_deathmatch();
638 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
640 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
641 CTF Starting point for a player in
642 team three (Magenta).
646 viewing angle when spawning
648 void spawnfunc_info_player_team3()
655 self.team = COLOR_TEAM3; // purple
656 spawnfunc_info_player_deathmatch();
660 /*QUAKED spawnfunc_info_player_team4 (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_team4()
675 self.team = COLOR_TEAM4; // yellow
676 spawnfunc_info_player_deathmatch();
679 void item_flag_reset()
681 DropFlag(self, world, world);
685 void item_flag_postspawn()
686 { // Check CTF Item Flag Post Spawn
688 // Flag Glow Trail Support
689 if(cvar("g_ctf_flag_glowtrails"))
690 { // Provide Flag Glow Trail
691 if(self.team == COLOR_TEAM1)
693 self.glow_color = 251;
695 if(self.team == COLOR_TEAM2)
697 self.glow_color = 210;
704 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
705 CTF flag for team one (Red).
706 Multiple are allowed.
710 Angle the flag will point
713 model to use, note this needs red and blue as skins 0 and 1
714 (default models/ctf/flag.md3)
716 sound played when flag is picked up
717 (default ctf/take.wav)
719 sound played when flag is returned by a teammate
720 (default ctf/return.wav)
722 sound played when flag is captured
723 (default ctf/redcapture.wav)
725 sound played when flag is lost in the field and respawns itself
726 (default ctf/respawn.wav)
729 void spawnfunc_item_flag_team1()
737 //if(!cvar("teamplay"))
738 // cvar_set("teamplay", "3");
740 // link flag into ctf_worldflaglist
741 self.ctf_worldflagnext = ctf_worldflaglist;
742 ctf_worldflaglist = self;
744 self.classname = "item_flag_team";
747 self.team = COLOR_TEAM2; // color 13 team (blue)
748 self.items = IT_KEY1; // silver key (bluish enough)
752 self.team = COLOR_TEAM1; // color 4 team (red)
753 self.items = IT_KEY2; // gold key (redish enough)
755 self.netname = "^1RED^7 flag";
756 self.target = "###item###";
757 self.skin = cvar("g_ctf_flag_red_skin");
758 if(self.spawnflags & 1)
761 self.model = cvar_string("g_ctf_flag_red_model");
763 self.noise = "ctf/red_taken.wav";
765 self.noise1 = "ctf/red_returned.wav";
767 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
769 self.noise3 = "ctf/flag_respawn.wav";
771 self.noise4 = "ctf/red_dropped.wav";
772 precache_model (self.model);
773 setmodel (self, self.model); // precision set below
774 precache_sound (self.noise);
775 precache_sound (self.noise1);
776 precache_sound (self.noise2);
777 precache_sound (self.noise3);
778 precache_sound (self.noise4);
779 //setsize(self, '-16 -16 -37', '16 16 37');
780 setsize(self, FLAG_MIN, FLAG_MAX);
781 setorigin(self, self.origin + '0 0 37');
782 self.nextthink = time + 0.2; // start after doors etc
783 self.think = place_flag;
787 //if(!self.glow_size)
788 // self.glow_size = 50;
790 self.effects = self.effects | EF_LOWPRECISION;
791 if(cvar("g_ctf_fullbrightflags"))
792 self.effects |= EF_FULLBRIGHT;
793 if(cvar("g_ctf_dynamiclights"))
794 self.effects |= EF_RED;
797 item_flag_postspawn();
799 waypoint_spawnforitem(self);
801 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
802 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '1 0 0');
804 precache_model("models/onslaught/generator_shield.md3");
806 self.reset = item_flag_reset;
809 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
810 CTF flag for team two (Blue).
811 Multiple are allowed.
815 Angle the flag will point
818 model to use, note this needs red and blue as skins 0 and 1
819 (default models/ctf/flag.md3)
821 sound played when flag is picked up
822 (default ctf/take.wav)
824 sound played when flag is returned by a teammate
825 (default ctf/return.wav)
827 sound played when flag is captured
828 (default ctf/bluecapture.wav)
830 sound played when flag is lost in the field and respawns itself
831 (default ctf/respawn.wav)
834 void spawnfunc_item_flag_team2()
841 //if(!cvar("teamplay"))
842 // cvar_set("teamplay", "3");
844 // link flag into ctf_worldflaglist
845 self.ctf_worldflagnext = ctf_worldflaglist;
846 ctf_worldflaglist = self;
848 self.classname = "item_flag_team";
851 self.team = COLOR_TEAM1; // color 4 team (red)
852 self.items = IT_KEY2; // gold key (redish enough)
856 self.team = COLOR_TEAM2; // color 13 team (blue)
857 self.items = IT_KEY1; // silver key (bluish enough)
859 self.netname = "^4BLUE^7 flag";
860 self.target = "###item###";
861 self.skin = cvar("g_ctf_flag_blue_skin");
862 if(self.spawnflags & 1)
865 self.model = cvar_string("g_ctf_flag_blue_model");
867 self.noise = "ctf/blue_taken.wav";
869 self.noise1 = "ctf/blue_returned.wav";
871 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
873 self.noise3 = "ctf/flag_respawn.wav";
875 self.noise4 = "ctf/blue_dropped.wav";
876 precache_model (self.model);
877 setmodel (self, self.model); // precision set below
878 precache_sound (self.noise);
879 precache_sound (self.noise1);
880 precache_sound (self.noise2);
881 precache_sound (self.noise3);
882 precache_sound (self.noise4);
883 //setsize(self, '-16 -16 -37', '16 16 37');
884 setsize(self, FLAG_MIN, FLAG_MAX);
885 setorigin(self, self.origin + '0 0 37');
886 self.nextthink = time + 0.2; // start after doors etc
887 self.think = place_flag;
891 //if(!self.glow_size)
892 // self.glow_size = 50;
894 self.effects = self.effects | EF_LOWPRECISION;
895 if(cvar("g_ctf_fullbrightflags"))
896 self.effects |= EF_FULLBRIGHT;
897 if(cvar("g_ctf_dynamiclights"))
898 self.effects |= EF_BLUE;
901 item_flag_postspawn();
903 waypoint_spawnforitem(self);
905 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
906 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, '0 0 1');
908 precache_model("models/onslaught/generator_shield.md3");
910 self.reset = item_flag_reset;
914 /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
915 Team declaration for CTF gameplay, this allows you to decide what team
916 names and control point models are used in your map.
918 Note: If you use spawnfunc_ctf_team entities you must define at least 2! However, unlike
919 domination, you don't need to make a blank one too.
923 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
925 Scoreboard color of the team (for example 4 is red and 13 is blue)
929 void spawnfunc_ctf_team()
936 self.classname = "ctf_team";
937 self.team = self.cnt + 1;
940 // code from here on is just to support maps that don't have control point and team entities
941 void ctf_spawnteam (string teamname, float teamcolor)
943 local entity oldself;
946 self.classname = "ctf_team";
947 self.netname = teamname;
948 self.cnt = teamcolor;
950 spawnfunc_ctf_team();
955 // spawn some default teams if the map is not set up for ctf
956 void ctf_spawnteams()
960 numteams = 2;//cvar("g_ctf_default_teams");
962 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
963 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
966 void ctf_delayedinit()
968 // if no teams are found, spawn defaults
969 if (find(world, classname, "ctf_team") == world)
977 InitializeEntity(world, ctf_delayedinit, INITPRIO_GAMETYPE);
978 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
980 captureshield_min_negscore = cvar("g_ctf_shield_min_negscore");
981 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
982 captureshield_force = cvar("g_ctf_shield_force");
985 void ctf_setstatus2(entity flag, float shift)
987 if (flag.cnt == FLAG_CARRY)
988 if (flag.owner == self)
989 self.items |= shift * 3;
991 self.items |= shift * 1;
992 else if (flag.cnt == FLAG_DROPPED)
993 self.items |= shift * 2;
1000 void ctf_setstatus()
1002 self.items &~= IT_RED_FLAG_TAKEN;
1003 self.items &~= IT_RED_FLAG_LOST;
1004 self.items &~= IT_BLUE_FLAG_TAKEN;
1005 self.items &~= IT_BLUE_FLAG_LOST;
1006 self.items &~= IT_CTF_SHIELDED;
1010 float redflags, blueflags;
1012 if(self.ctf_captureshielded)
1013 self.items |= IT_CTF_SHIELDED;
1018 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1020 if(flag.items & IT_KEY2) // blue
1022 else if(flag.items & IT_KEY1) // red
1026 // blinking magic: if there is more than one flag, show one of these in a clever way
1028 redflags = mod(floor(time * redflags * 0.75), redflags);
1030 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1032 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1034 if(flag.items & IT_KEY2) // blue
1036 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1037 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1039 else if(flag.items & IT_KEY1) // red
1041 if(--blueflags == -1) // happens exactly once
1042 ctf_setstatus2(flag, IT_BLUE_FLAG_TAKEN);
1048 entity(float cteam) ctf_team_has_commander =
1051 if(cteam != COLOR_TEAM1 || cteam != COLOR_TEAM2)
1054 FOR_EACH_REALPLAYER(pl) {
1055 if(pl.team == cteam && pl.iscommander) {
1062 void(entity e, float st) ctf_setstate =
1068 void(float cteam) ctf_new_commander =
1073 FOR_EACH_REALPLAYER(pl) {
1074 if(pl.team == cteam) {
1075 if(pl.iscommander) { // don't reassign if alreay there
1078 if(plmax == world || plmax.frags < pl.frags) <<<<<<<<<<<<<<<<< BROKEN in new scoring system
1082 if(plmax == world) {
1083 bprint(strcat(ColoredTeamName(cteam), " Team has no Commander!\n"));
1087 plmax.iscommander = TRUE;
1088 ctf_setstate(plmax, 3);
1089 sprint(plmax, "^3You're the commander now!\n");
1090 centerprint(plmax, "^3You're the commander now!\n");
1093 void() ctf_clientconnect =
1095 self.iscommander = FALSE;
1097 if(!self.team || self.classname != "player") {
1098 ctf_setstate(self, -1);
1100 ctf_setstate(self, 0);
1102 self.team_saved = self.team;
1104 if(self.team != 0 && self.classname == "player" && !ctf_team_has_commander(self.team)) {
1105 ctf_new_commander(self.team);
1109 void() ctf_playerchanged =
1111 if(!self.team || self.classname != "player") {
1112 ctf_setstate(self, -1);
1113 } else if(self.ctf_state < 0 && self.classname == "player") {
1114 ctf_setstate(self, 0);
1117 if(self.iscommander &&
1118 (self.classname != "player" || self.team != self.team_saved)
1121 self.iscommander = FALSE;
1122 if(self.classname == "player")
1123 ctf_setstate(self, 0);
1125 ctf_setstate(self, -1);
1126 ctf_new_commander(self.team_saved);
1129 self.team_saved = self.team;
1131 ctf_new_commander(self.team);
1134 void() ctf_clientdisconnect =
1136 if(self.iscommander)
1138 ctf_new_commander(self.team);
1142 entity GetPlayer(string);
1143 float() ctf_clientcommand =
1146 if(argv(0) == "order") {
1148 sprint(self, "This command is not supported in this gamemode.\n");
1151 if(!self.iscommander) {
1152 sprint(self, "^1You are not the commander!\n");
1156 sprint(self, "Usage: order #player status - (playernumber as in status)\n");
1159 e = GetPlayer(argv(1));
1161 sprint(self, "Invalid player.\nUsage: order #player status - (playernumber as in status)\n");
1164 if(e.team != self.team) {
1165 sprint(self, "^3You can only give orders to your own team!\n");
1168 if(argv(2) == "attack") {
1169 sprint(self, strcat("Ordering ", e.netname, " to attack!\n"));
1170 sprint(e, "^1Attack!\n");
1171 centerprint(e, "^7You've been ordered to^9\n^1Attack!\n");
1173 } else if(argv(2) == "defend") {
1174 sprint(self, strcat("Ordering ", e.netname, " to defend!\n"));
1175 sprint(e, "^Defend!\n");
1176 centerprint(e, "^7You've been ordered to^9\n^2Defend!\n");
1179 sprint(self, "^7Invalid command, use ^3attack^7, or ^3defend^7.\n");