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_captureshield_spawn()
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);
124 float ctf_score_value(string parameter)
126 if(g_ctf_win_mode != 2)
127 return cvar(strcat("g_ctf_personal", parameter));
129 return cvar(strcat("g_ctf_flag", parameter));
132 void FakeTimeLimit(entity e, float t)
135 WriteByte(MSG_ONE, 3); // svc_updatestat
136 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
138 WriteCoord(MSG_ONE, cvar("timelimit"));
140 WriteCoord(MSG_ONE, (t + 1) / 60);
143 float flagcaptimerecord;
144 .float flagpickuptime;
145 //.float iscommander;
153 if(self.classname != "item_flag_team")
155 backtrace("PlaceFlag a non-flag");
160 self.t_width = 0.1; // frame animation rate
162 self.t_length = 58; // maximum frame
164 setattachment(self, world, "");
165 self.mdl = self.model;
166 self.flags = FL_ITEM;
167 self.solid = SOLID_TRIGGER;
168 self.movetype = MOVETYPE_NONE;
169 self.velocity = '0 0 0';
170 self.origin_z = self.origin_z + 6;
171 self.think = FlagThink;
172 self.touch = FlagTouch;
173 self.nextthink = time + 0.1;
174 self.cnt = FLAG_BASE;
175 self.mangle = self.angles;
176 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
177 //self.effects = self.effects | EF_DIMLIGHT;
180 self.dropped_origin = self.origin;
185 self.movetype = MOVETYPE_TOSS;
187 InitializeEntity(self, ctf_captureshield_spawn, INITPRIO_SETLOCATION);
190 void LogCTF(string mode, float flagteam, entity actor)
193 if(!cvar("sv_eventlog"))
195 s = strcat(":ctf:", mode);
196 s = strcat(s, ":", ftos(flagteam));
198 s = strcat(s, ":", ftos(actor.playerid));
202 void RegenFlag(entity e)
204 if(e.classname != "item_flag_team")
206 backtrace("RegenFlag a non-flag");
210 setattachment(e, world, "");
211 e.damageforcescale = 0;
212 e.takedamage = DAMAGE_NO;
213 e.movetype = MOVETYPE_NONE;
215 e.movetype = MOVETYPE_TOSS;
216 e.velocity = '0 0 0';
217 e.solid = SOLID_TRIGGER;
218 // TODO: play a sound here
219 setorigin(e, e.dropped_origin);
223 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
226 void ReturnFlag(entity e)
228 if(e.classname != "item_flag_team")
230 backtrace("ReturnFlag a non-flag");
235 if (e.owner.flagcarried == e)
237 WaypointSprite_DetachCarrier(e.owner);
238 e.owner.flagcarried = world;
241 FakeTimeLimit(e.owner, -1);
247 void DropFlag(entity e, entity penalty_receiver, entity attacker)
251 if(e.classname != "item_flag_team")
253 backtrace("DropFlag a non-flag");
265 dprint("FLAG: drop - no owner?!?!\n");
269 if (p.flagcarried != e)
271 dprint("FLAG: drop - owner is not carrying this flag??\n");
274 bprint(p.netname, "^7 lost the ", e.netname, "\n");
277 UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
279 UpdateFrags(p, -ctf_score_value("penalty_drop"));
280 PlayerScore_Add(p, SP_CTF_DROPS, +1);
281 ctf_captureshield_update(p, 0); // shield only
282 e.playerid = attacker.playerid;
283 e.ctf_droptime = time;
285 if(p.waypointsprite_attachedforcarrier)
287 WaypointSprite_Ping(p.waypointsprite_attachedforcarrier);
288 WaypointSprite_DetachCarrier(p);
292 bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
293 backtrace("Flag carrier had no flag sprite?!?");
295 LogCTF("dropped", p.team, p);
296 sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
298 setattachment(e, world, "");
299 e.damageforcescale = cvar("g_balance_ctf_damageforcescale");
300 e.takedamage = DAMAGE_YES;
302 if (p.flagcarried == e)
303 p.flagcarried = world;
306 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
307 e.solid = SOLID_TRIGGER;
308 e.movetype = MOVETYPE_TOSS;
309 // setsize(e, '-16 -16 0', '16 16 74');
310 setorigin(e, p.origin - '0 0 24' + '0 0 37');
311 e.cnt = FLAG_DROPPED;
312 e.velocity = '0 0 300';
313 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
315 trace_startsolid = FALSE;
316 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
318 dprint("FLAG FALLTHROUGH will happen SOON\n");
323 if(self.delay > time)
325 self.delay = time + self.t_width;
326 if(self.nextthink > self.delay)
327 self.nextthink = self.delay;
329 self.frame = self.frame + 1;
330 if(self.frame > self.t_length)
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
357 if(self.speedrunning)
358 if(self.cnt == FLAG_CARRY)
361 if(flagcaptimerecord)
362 if(time >= self.flagpickuptime + flagcaptimerecord)
364 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
366 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
367 self.owner.impulse = 141; // returning!
378 if (self.cnt == FLAG_BASE)
381 if (self.cnt == FLAG_DROPPED)
383 // flag fallthrough? FIXME remove this if bug is really fixed now
384 if(self.origin_z < -131072)
386 dprint("FLAG FALLTHROUGH just happened\n");
387 self.pain_finished = 0;
389 setattachment(self, world, "");
390 if (time > self.pain_finished)
392 bprint("The ", self.netname, " has returned to base\n");
393 sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
394 LogCTF("returned", self.team, world);
401 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
403 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
404 DropFlag(self, world, world);
408 if(cvar("g_ctf_allow_drop"))
410 DropFlag(self, e, world);
413 void flag_cap_ring_spawn(vector org)
415 shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
424 local string s, s0, h0, h1;
425 if (other.classname != "player")
427 if (other.health < 1) // ignore dead players
430 if (self.cnt == FLAG_CARRY)
433 if (self.cnt == FLAG_BASE)
434 if (other.team == self.team)
435 if (other.flagcarried) // he's got a flag
436 if (other.flagcarried.team != self.team) // capture
438 if (other.flagcarried == world)
442 if(cvar("g_ctf_captimerecord_always") || player_count - currentbots <= 1) // at most one human
444 t = time - other.flagcarried.flagpickuptime;
445 s = ftos_decimals(t, 2);
446 s0 = ftos_decimals(flagcaptimerecord, 2);
447 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
452 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
453 if (flagcaptimerecord == 0)
455 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
456 flagcaptimerecord = t;
457 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
458 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
459 write_recordmarker(other, time - t, t);
461 else if (t < flagcaptimerecord)
463 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
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);
471 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
475 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, "\n");
477 PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
478 LogCTF("capture", other.flagcarried.team, other);
479 // give credit to the individual player
480 UpdateFrags(other, ctf_score_value("score_capture"));
482 if (cvar("g_ctf_flag_capture_effects")) {
483 if (other.team == COLOR_TEAM1) { // red team scores effect
484 pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
485 flag_cap_ring_spawn(self.origin);
487 if (other.team == COLOR_TEAM2) { // blue team scores effect
488 pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
489 flag_cap_ring_spawn(self.origin);
493 sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
494 WaypointSprite_DetachCarrier(other);
495 if(self.speedrunning)
496 FakeTimeLimit(other, -1);
497 RegenFlag (other.flagcarried);
498 other.flagcarried = world;
499 other.next_take_time = time + 1;
501 if (self.cnt == FLAG_BASE)
502 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
503 if (other.team != self.team)
504 if (!other.flagcarried)
505 if (!other.ctf_captureshielded)
507 if (other.next_take_time > time)
510 if (cvar("g_ctf_flag_pickup_effects")) // pickup effect
511 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
514 self.flagpickuptime = time; // used for timing runs
515 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
516 if(other.speedrunning)
517 if(flagcaptimerecord)
518 FakeTimeLimit(other, time + flagcaptimerecord);
519 self.solid = SOLID_NOT;
520 setorigin(self, self.origin); // relink
522 other.flagcarried = self;
523 self.cnt = FLAG_CARRY;
524 self.angles = '0 0 0';
525 bprint(other.netname, "^7 got the ", self.netname, "\n");
526 UpdateFrags(other, ctf_score_value("score_pickup_base"));
527 self.dropperid = other.playerid;
528 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
529 LogCTF("steal", self.team, other);
530 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
532 FOR_EACH_PLAYER(player)
533 if(player.team == self.team)
534 centerprint(player, "The enemy got your flag! Retrieve it!");
536 self.movetype = MOVETYPE_NONE;
537 setorigin(self, FLAG_CARRY_POS);
538 setattachment(self, other, "");
539 WaypointSprite_AttachCarrier("flagcarrier", other);
540 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
541 WaypointSprite_Ping(self.sprite);
546 if (self.cnt == FLAG_DROPPED)
548 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
549 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
552 bprint(other.netname, "^7 returned the ", self.netname, "\n");
554 // punish the player who last had it
555 FOR_EACH_PLAYER(player)
556 if(player.playerid == self.dropperid)
558 PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
559 ctf_captureshield_update(player, 0); // shield only
562 // punish the team who was last carrying it
563 if(self.team == COLOR_TEAM1)
564 TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
566 TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
568 // reward the player who returned it
569 if(other.playerid == self.playerid) // is this the guy who killed the FC last?
571 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
572 UpdateFrags(other, ctf_score_value("score_return_by_killer"));
574 UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
578 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
579 UpdateFrags(other, ctf_score_value("score_return"));
581 UpdateFrags(other, ctf_score_value("score_return_rogue"));
583 PlayerScore_Add(other, SP_CTF_RETURNS, 1);
584 LogCTF("return", self.team, other);
585 sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
588 else if (!other.flagcarried && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_balance_ctf_delay_collect")))
590 if (cvar("g_ctf_flag_pickup_effects")) // field pickup effect
591 pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
594 self.solid = SOLID_NOT;
595 setorigin(self, self.origin); // relink
597 other.flagcarried = self;
598 self.cnt = FLAG_CARRY;
599 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
602 f = bound(0, (self.pain_finished - time) / cvar("g_ctf_flag_returntime"), 1);
603 //print("factor is ", ftos(f), "\n");
604 f = ctf_score_value("score_pickup_dropped_late") * (1-f)
605 + ctf_score_value("score_pickup_dropped_early") * f;
607 self.dropperid = other.playerid;
608 //print("score is ", ftos(f), "\n");
610 UpdateFrags(other, f);
611 PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
612 LogCTF("pickup", self.team, other);
613 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
615 FOR_EACH_PLAYER(player)
616 if(player.team == self.team)
617 centerprint(player, "The enemy got your flag! Retrieve it!");
619 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
620 setorigin(self, FLAG_CARRY_POS);
621 setattachment(self, other, "");
622 self.damageforcescale = 0;
623 self.takedamage = DAMAGE_NO;
624 WaypointSprite_AttachCarrier("flagcarrier", other);
625 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
630 /*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
631 CTF Starting point for a player
636 viewing angle when spawning
638 void spawnfunc_info_player_team1()
645 self.team = COLOR_TEAM1; // red
646 spawnfunc_info_player_deathmatch();
648 //self.team = 4;self.classname = "info_player_start";spawnfunc_info_player_start();};
650 /*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
651 CTF Starting point for a player in
656 viewing angle when spawning
658 void spawnfunc_info_player_team2()
665 self.team = COLOR_TEAM2; // blue
666 spawnfunc_info_player_deathmatch();
668 //self.team = 13;self.classname = "info_player_start";spawnfunc_info_player_start();};
670 /*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
671 CTF Starting point for a player in
676 viewing angle when spawning
678 void spawnfunc_info_player_team3()
685 self.team = COLOR_TEAM3; // yellow
686 spawnfunc_info_player_deathmatch();
690 /*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
691 CTF Starting point for a player in
696 viewing angle when spawning
698 void spawnfunc_info_player_team4()
705 self.team = COLOR_TEAM4; // purple
706 spawnfunc_info_player_deathmatch();
709 void item_flag_reset()
711 DropFlag(self, world, world);
715 void item_flag_postspawn()
716 { // Check CTF Item Flag Post Spawn
718 // Flag Glow Trail Support
719 if(cvar("g_ctf_flag_glowtrails"))
720 { // Provide Flag Glow Trail
721 if(self.team == COLOR_TEAM1)
723 self.glow_color = 251;
725 if(self.team == COLOR_TEAM2)
727 self.glow_color = 210;
734 /*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
735 CTF flag for team one (Red).
736 Multiple are allowed.
740 Angle the flag will point
743 model to use, note this needs red and blue as skins 0 and 1
744 (default models/ctf/flag.md3)
746 sound played when flag is picked up
747 (default ctf/take.wav)
749 sound played when flag is returned by a teammate
750 (default ctf/return.wav)
752 sound played when flag is captured
753 (default ctf/redcapture.wav)
755 sound played when flag is lost in the field and respawns itself
756 (default ctf/respawn.wav)
759 void spawnfunc_item_flag_team1()
767 //if(!cvar("teamplay"))
768 // cvar_set("teamplay", "3");
770 // link flag into ctf_worldflaglist
771 self.ctf_worldflagnext = ctf_worldflaglist;
772 ctf_worldflaglist = self;
774 self.classname = "item_flag_team";
777 self.team = COLOR_TEAM2; // color 13 team (blue)
778 self.items = IT_KEY1; // silver key (bluish enough)
782 self.team = COLOR_TEAM1; // color 4 team (red)
783 self.items = IT_KEY2; // gold key (redish enough)
785 self.netname = "^1RED^7 flag";
786 self.target = "###item###";
787 self.skin = cvar("g_ctf_flag_red_skin");
788 if(self.spawnflags & 1)
791 self.model = cvar_string("g_ctf_flag_red_model");
793 self.noise = "ctf/red_taken.wav";
795 self.noise1 = "ctf/red_returned.wav";
797 self.noise2 = "ctf/red_capture.wav"; // blue team scores by capturing the red flag
799 self.noise3 = "ctf/flag_respawn.wav";
801 self.noise4 = "ctf/red_dropped.wav";
802 precache_model (self.model);
803 setmodel (self, self.model); // precision set below
804 precache_sound (self.noise);
805 precache_sound (self.noise1);
806 precache_sound (self.noise2);
807 precache_sound (self.noise3);
808 precache_sound (self.noise4);
809 //setsize(self, '-16 -16 -37', '16 16 37');
810 setsize(self, FLAG_MIN, FLAG_MAX);
811 setorigin(self, self.origin + '0 0 37');
812 self.nextthink = time + 0.2; // start after doors etc
813 self.think = place_flag;
817 //if(!self.glow_size)
818 // self.glow_size = 50;
820 self.effects = self.effects | EF_LOWPRECISION;
821 if(cvar("g_ctf_fullbrightflags"))
822 self.effects |= EF_FULLBRIGHT;
823 if(cvar("g_ctf_dynamiclights"))
824 self.effects |= EF_RED;
827 item_flag_postspawn();
829 waypoint_spawnforitem_force(self, self.origin);
830 self.nearestwaypointtimeout = 0; // activate waypointing again
831 self.basewaypoint = self.nearestwaypoint;
833 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
834 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
836 precache_model("models/ctf/shield.md3");
837 precache_model("models/ctf/shockwavetransring.md3");
839 self.reset = item_flag_reset;
842 /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
843 CTF flag for team two (Blue).
844 Multiple are allowed.
848 Angle the flag will point
851 model to use, note this needs red and blue as skins 0 and 1
852 (default models/ctf/flag.md3)
854 sound played when flag is picked up
855 (default ctf/take.wav)
857 sound played when flag is returned by a teammate
858 (default ctf/return.wav)
860 sound played when flag is captured
861 (default ctf/bluecapture.wav)
863 sound played when flag is lost in the field and respawns itself
864 (default ctf/respawn.wav)
867 void spawnfunc_item_flag_team2()
874 //if(!cvar("teamplay"))
875 // cvar_set("teamplay", "3");
877 // link flag into ctf_worldflaglist
878 self.ctf_worldflagnext = ctf_worldflaglist;
879 ctf_worldflaglist = self;
881 self.classname = "item_flag_team";
884 self.team = COLOR_TEAM1; // color 4 team (red)
885 self.items = IT_KEY2; // gold key (redish enough)
889 self.team = COLOR_TEAM2; // color 13 team (blue)
890 self.items = IT_KEY1; // silver key (bluish enough)
892 self.netname = "^4BLUE^7 flag";
893 self.target = "###item###";
894 self.skin = cvar("g_ctf_flag_blue_skin");
895 if(self.spawnflags & 1)
898 self.model = cvar_string("g_ctf_flag_blue_model");
900 self.noise = "ctf/blue_taken.wav";
902 self.noise1 = "ctf/blue_returned.wav";
904 self.noise2 = "ctf/blue_capture.wav"; // blue team scores by capturing the red flag
906 self.noise3 = "ctf/flag_respawn.wav";
908 self.noise4 = "ctf/blue_dropped.wav";
909 precache_model (self.model);
910 setmodel (self, self.model); // precision set below
911 precache_sound (self.noise);
912 precache_sound (self.noise1);
913 precache_sound (self.noise2);
914 precache_sound (self.noise3);
915 precache_sound (self.noise4);
916 //setsize(self, '-16 -16 -37', '16 16 37');
917 setsize(self, FLAG_MIN, FLAG_MAX);
918 setorigin(self, self.origin + '0 0 37');
919 self.nextthink = time + 0.2; // start after doors etc
920 self.think = place_flag;
924 //if(!self.glow_size)
925 // self.glow_size = 50;
927 self.effects = self.effects | EF_LOWPRECISION;
928 if(cvar("g_ctf_fullbrightflags"))
929 self.effects |= EF_FULLBRIGHT;
930 if(cvar("g_ctf_dynamiclights"))
931 self.effects |= EF_BLUE;
934 item_flag_postspawn();
936 waypoint_spawnforitem_force(self, self.origin);
937 self.nearestwaypointtimeout = 0; // activate waypointing again
938 self.basewaypoint = self.nearestwaypoint;
940 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
941 WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
943 precache_model("models/ctf/shield.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 = cvar("g_ctf_shield_min_negscore");
1016 captureshield_max_ratio = cvar("g_ctf_shield_max_ratio");
1017 captureshield_force = cvar("g_ctf_shield_force");
1020 void ctf_setstatus2(entity flag, float shift)
1022 if (flag.cnt == FLAG_CARRY)
1023 if (flag.owner == self)
1024 self.items |= shift * 3;
1026 self.items |= shift * 1;
1027 else if (flag.cnt == FLAG_DROPPED)
1028 self.items |= shift * 2;
1035 void ctf_setstatus()
1037 self.items &~= IT_RED_FLAG_TAKEN;
1038 self.items &~= IT_RED_FLAG_LOST;
1039 self.items &~= IT_BLUE_FLAG_TAKEN;
1040 self.items &~= IT_BLUE_FLAG_LOST;
1041 self.items &~= IT_CTF_SHIELDED;
1045 float redflags, blueflags;
1047 if(self.ctf_captureshielded)
1048 self.items |= IT_CTF_SHIELDED;
1053 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1055 if(flag.items & IT_KEY2) // blue
1057 else if(flag.items & IT_KEY1) // red
1061 // blinking magic: if there is more than one flag, show one of these in a clever way
1063 redflags = mod(floor(time * redflags * 0.75), redflags);
1065 blueflags = mod(floor(time * blueflags * 0.75), blueflags);
1067 for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
1069 if(flag.items & IT_KEY2) // blue
1071 if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times)
1072 ctf_setstatus2(flag, IT_RED_FLAG_TAKEN);
1074 else if(flag.items & IT_KEY1) // red
1076 if(--blueflags == -1) // happens exactly once
1077 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");