2 entity ctf_worldflaglist; // CTF flags in the map
3 .entity ctf_worldflagnext;
5 .float next_take_time; // the next time a player can pick up a flag (time + blah)
6 /// I used this, in part, to fix the looping score bug. - avirox
8 //float FLAGSCORE_PICKUP = 1;
9 //float FLAGSCORE_RETURN = 5; // returned by owner team
10 //float FLAGSCORE_RETURNROGUE = 10; // returned by rogue team
11 //float FLAGSCORE_CAPTURE = 5;
12 //float FLAGSCORE_CAPTURE_TEAM = 20;
14 #define FLAG_CARRY_POS '-15 0 7'
16 void FakeTimeLimit(entity e, float t)
19 WriteByte(MSG_ONE, 3); // svc_updatestat
20 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
22 WriteCoord(MSG_ONE, cvar("timelimit"));
24 WriteCoord(MSG_ONE, (t + 1) / 60);
27 float flagcaptimerecord;
28 .float flagpickuptime;
36 self.t_width = 0.1; // frame animation rate
38 self.t_length = 119; // maximum frame
40 setattachment(self, world, "");
41 self.mdl = self.model;
43 self.solid = SOLID_TRIGGER;
44 self.movetype = MOVETYPE_NONE;
45 self.velocity = '0 0 0';
46 self.origin_z = self.origin_z + 6;
47 self.think = FlagThink;
48 self.touch = FlagTouch;
49 self.nextthink = time + 0.1;
51 self.mangle = self.angles;
52 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
53 //self.effects = self.effects | EF_DIMLIGHT;
56 self.movetype = MOVETYPE_TOSS;
59 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
64 self.oldorigin = self.origin;
67 void LogCTF(string mode, float flagteam, entity actor)
70 if(!cvar("sv_eventlog"))
72 s = strcat(":ctf:", mode);
73 s = strcat(s, ":", ftos(flagteam));
75 s = strcat(s, ":", ftos(actor.playerid));
76 GameLogEcho(s, FALSE);
79 void(entity e) RegenFlag =
81 setattachment(e, world, "");
82 e.movetype = MOVETYPE_NONE;
84 e.movetype = MOVETYPE_TOSS;
85 e.solid = SOLID_TRIGGER;
86 // TODO: play a sound here
87 setorigin(e, e.oldorigin);
91 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
94 void(entity e) ReturnFlag =
97 if (e.owner.flagcarried == e)
99 WaypointSprite_DetachCarrier(e.owner);
100 e.owner.flagcarried = world;
103 FakeTimeLimit(e.owner, -1);
109 void(entity e) DropFlag =
121 dprint("FLAG: drop - no owner?!?!\n");
125 if (p.flagcarried != e)
127 dprint("FLAG: drop - owner is not carrying this flag??\n");
130 bprint(p.netname, "^7 lost the ", e.netname, "\n");
131 WaypointSprite_DetachCarrier(p);
132 LogCTF("dropped", p.team, p.flagcarried);
134 setattachment(e, world, "");
136 if (p.flagcarried == e)
137 p.flagcarried = world;
140 e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
141 e.solid = SOLID_TRIGGER;
142 e.movetype = MOVETYPE_TOSS;
143 // setsize(e, '-16 -16 0', '16 16 74');
144 setorigin(e, p.origin - '0 0 24' + '0 0 37');
145 e.cnt = FLAG_DROPPED;
146 e.velocity = '0 0 300';
147 e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
149 trace_startsolid = FALSE;
150 tracebox(e.origin, e.mins, e.maxs, e.origin, TRUE, e);
152 dprint("FLAG FALLTHROUGH will happen SOON\n");
157 if(self.delay > time)
159 self.delay = time + self.t_width;
160 if(self.nextthink > self.delay)
161 self.nextthink = self.delay;
163 self.frame = self.frame + 1;
164 if(self.frame > self.t_length)
172 self.nextthink = time + 0.1;
176 if(self.speedrunning)
177 if(self.cnt == FLAG_CARRY)
180 if(flagcaptimerecord)
181 if(time >= self.flagpickuptime + flagcaptimerecord)
183 bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
185 self.owner.impulse = 77; // returning!
195 if (self.cnt == FLAG_BASE)
198 if (self.cnt == FLAG_DROPPED)
200 // flag fallthrough? FIXME remove this if bug is really fixed now
201 if(self.origin_z < -131072)
203 dprint("FLAG FALLTHROUGH just happened\n");
204 self.pain_finished = 0;
206 setattachment(self, world, "");
207 if (time > self.pain_finished)
209 bprint("The ", self.netname, " has returned to base\n");
210 sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
211 LogCTF("returned", self.team, world);
218 if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
220 dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
233 local string s, s0, h0, h1;
234 if (other.classname != "player")
236 if (other.health < 1) // ignore dead players
239 if (self.cnt == FLAG_CARRY)
242 if (self.cnt == FLAG_BASE)
243 if (other.team == self.team)
244 if (other.flagcarried) // he's got a flag
245 if (other.flagcarried.team != self.team) // capture
247 if (other.flagcarried == world)
251 t = time - other.flagcarried.flagpickuptime;
252 s = ftos_decimals(t, 2);
253 s0 = ftos_decimals(flagcaptimerecord, 2);
254 h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
259 h0 = strcat(h0, "^7's"); // h0: display text for previous netname
260 if (flagcaptimerecord == 0)
262 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, " seconds\n");
263 flagcaptimerecord = t;
264 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
265 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
267 else if (t < flagcaptimerecord)
269 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", breaking ", strcat(h0, " previous record of ", s0, " seconds\n"));
270 flagcaptimerecord = t;
271 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
272 db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
276 bprint(other.netname, "^7 captured the ", other.flagcarried.netname, " in ", s, ", failing to break ", strcat(h0, " record of ", s0, " seconds\n"));
279 LogCTF("capture", other.flagcarried.team, other);
280 // give credit to the individual player
281 UpdateFrags(other, cvar("g_ctf_flagscore_capture"));
283 // give credit to all players of the team (rewards large teams)
284 // NOTE: this defaults to 0
285 FOR_EACH_PLAYER(head)
286 if (head.team == self.team)
287 UpdateFrags(head, cvar("g_ctf_flagscore_capture_team"));
289 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
290 WaypointSprite_DetachCarrier(other);
291 if(self.speedrunning)
292 FakeTimeLimit(other, -1);
293 RegenFlag (other.flagcarried);
294 other.flagcarried = world;
295 other.next_take_time = time + 1;
297 if (self.cnt == FLAG_BASE)
298 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags
299 if (other.team != self.team)
300 if (!other.flagcarried)
302 if (other.next_take_time > time)
305 self.flagpickuptime = time; // used for timing runs
306 self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
307 if(other.speedrunning)
308 if(flagcaptimerecord)
309 FakeTimeLimit(other, time + flagcaptimerecord);
310 self.solid = SOLID_NOT;
311 setorigin(self, self.origin); // relink
313 other.flagcarried = self;
314 self.cnt = FLAG_CARRY;
315 self.angles = '0 0 0';
316 bprint(other.netname, "^7 got the ", self.netname, "\n");
317 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
318 LogCTF("steal", self.team, other);
319 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
321 FOR_EACH_PLAYER(player)
322 if(player.team == self.team)
323 centerprint(player, "The enemy got your flag! Retrieve it!");
325 self.movetype = MOVETYPE_NONE;
326 setorigin(self, FLAG_CARRY_POS);
327 setattachment(self, other, "");
328 WaypointSprite_AttachCarrier("flagcarrier", other);
333 if (self.cnt == FLAG_DROPPED)
335 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
336 if (other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
339 bprint(other.netname, "^7 returned the ", self.netname, "\n");
340 if (other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
341 UpdateFrags(other, cvar("g_ctf_flagscore_return"));
343 UpdateFrags(other, cvar("g_ctf_flagscore_return_rogue"));
344 LogCTF("return", self.team, other);
345 sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
348 else if (!other.flagcarried)
351 self.solid = SOLID_NOT;
352 setorigin(self, self.origin); // relink
354 other.flagcarried = self;
355 self.cnt = FLAG_CARRY;
356 bprint(other.netname, "^7 picked up the ", self.netname, "\n");
357 UpdateFrags(other, cvar("g_ctf_flagscore_pickup"));
358 LogCTF("pickup", self.team, other);
359 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
361 FOR_EACH_PLAYER(player)
362 if(player.team == self.team)
363 centerprint(player, "The enemy got your flag! Retrieve it!");
365 self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
366 setorigin(self, FLAG_CARRY_POS);
367 setattachment(self, other, "");
368 WaypointSprite_AttachCarrier("flagcarrier", other);
373 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
374 CTF Starting point for a player
379 viewing angle when spawning
381 void() info_player_team1 =
383 self.team = COLOR_TEAM1; // red
384 info_player_deathmatch();
386 //self.team = 4;self.classname = "info_player_start";info_player_start();};
388 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
389 CTF Starting point for a player in
394 viewing angle when spawning
396 void() info_player_team2 =
398 self.team = COLOR_TEAM2; // blue
399 info_player_deathmatch();
401 //self.team = 13;self.classname = "info_player_start";info_player_start();};
403 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
404 CTF Starting point for a player in
405 team three (Magenta).
409 viewing angle when spawning
411 void() info_player_team3 =
413 self.team = COLOR_TEAM3; // purple
414 info_player_deathmatch();
418 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
419 CTF Starting point for a player in
424 viewing angle when spawning
426 void() info_player_team4 =
428 self.team = COLOR_TEAM4; // yellow
429 info_player_deathmatch();
435 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
436 CTF flag for team one (Red).
437 Multiple are allowed.
441 Angle the flag will point
444 model to use, note this needs red and blue as skins 0 and 1
445 (default models/ctf/flag.md3)
447 sound played when flag is picked up
448 (default ctf/take.wav)
450 sound played when flag is returned by a teammate
451 (default ctf/return.wav)
453 sound played when flag is captured
454 (default ctf/capture.wav)
456 sound played when flag is lost in the field and respawns itself
457 (default ctf/respawn.wav)
460 void() item_flag_team1 =
465 //if(!cvar("teamplay"))
466 // cvar_set("teamplay", "3");
468 // link flag into ctf_worldflaglist
469 self.ctf_worldflagnext = ctf_worldflaglist;
470 ctf_worldflaglist = self;
472 self.classname = "item_flag_team";
473 self.team = COLOR_TEAM1; // color 4 team (red)
474 self.items = IT_KEY2; // gold key (redish enough)
475 self.netname = "^1RED^7 flag";
476 self.target = "###item###";
478 if(self.spawnflags & 1)
481 self.model = "models/ctf/flag_red.md3";
483 self.noise = "ctf/take.wav";
485 self.noise1 = "ctf/return.wav";
487 self.noise2 = "ctf/capture.wav";
489 self.noise3 = "ctf/respawn.wav";
490 precache_model (self.model);
491 setmodel (self, self.model); // precision set below
492 precache_sound (self.noise);
493 precache_sound (self.noise1);
494 precache_sound (self.noise2);
495 precache_sound (self.noise3);
496 setsize(self, '-16 -16 -37', '16 16 37');
497 setorigin(self, self.origin + '0 0 37');
498 self.nextthink = time + 0.2; // start after doors etc
499 self.think = place_flag;
503 //if(!self.glow_size)
504 // self.glow_size = 50;
506 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
510 waypoint_spawnforitem(self);
512 WaypointSprite_SpawnFixed("redbase", self.origin + '0 0 37', self, sprite);
515 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
516 CTF flag for team two (Blue).
517 Multiple are allowed.
521 Angle the flag will point
526 void() item_flag_team2 =
530 //if(!cvar("teamplay"))
531 // cvar_set("teamplay", "3");
533 // link flag into ctf_worldflaglist
534 self.ctf_worldflagnext = ctf_worldflaglist;
535 ctf_worldflaglist = self;
537 self.classname = "item_flag_team";
538 self.team = COLOR_TEAM2; // color 13 team (blue)
539 self.items = IT_KEY1; // silver key (bluish enough)
540 self.netname = "^4BLUE^7 flag";
541 self.target = "###item###";
543 if(self.spawnflags & 1)
546 self.model = "models/ctf/flag_blue.md3";
548 self.noise = "ctf/take.wav";
550 self.noise1 = "ctf/return.wav";
552 self.noise2 = "ctf/capture.wav";
554 self.noise3 = "ctf/respawn.wav";
555 precache_model (self.model);
556 setmodel (self, self.model); // precision set below
557 precache_sound (self.noise);
558 precache_sound (self.noise1);
559 precache_sound (self.noise2);
560 precache_sound (self.noise3);
561 setsize(self, '-16 -16 -37', '16 16 37');
562 setorigin(self, self.origin + '0 0 37');
563 self.nextthink = time + 0.2; // start after doors etc
564 self.think = place_flag;
568 //if(!self.glow_size)
569 // self.glow_size = 50;
571 self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
575 waypoint_spawnforitem(self);
577 WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 37', self, sprite);
581 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
582 Team declaration for CTF gameplay, this allows you to decide what team
583 names and control point models are used in your map.
585 Note: If you use ctf_team entities you must define at least 2! However, unlike
586 domination, you don't need to make a blank one too.
590 Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
592 Scoreboard color of the team (for example 4 is red and 13 is blue)
598 self.classname = "ctf_team";
599 self.team = self.cnt + 1;
602 // code from here on is just to support maps that don't have control point and team entities
603 void ctf_spawnteam (string teamname, float teamcolor)
605 local entity oldself;
608 self.classname = "ctf_team";
609 self.netname = teamname;
610 self.cnt = teamcolor;
617 // spawn some default teams if the map is not set up for ctf
618 void() ctf_spawnteams =
622 numteams = 2;//cvar("g_ctf_default_teams");
624 ctf_spawnteam("Red", COLOR_TEAM1 - 1);
625 ctf_spawnteam("Blue", COLOR_TEAM2 - 1);
628 void() ctf_delayedinit =
630 self.think = SUB_Remove;
631 self.nextthink = time;
632 // if no teams are found, spawn defaults
633 if (find(world, classname, "ctf_team") == world)
641 e.think = ctf_delayedinit;
642 e.nextthink = time + 0.1;
643 flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
646 void(entity flag) ctf_setstatus2 =
650 if (flag.team == COLOR_TEAM1) shift = IT_RED_FLAG_TAKEN;
651 else if (flag.team == COLOR_TEAM2) shift = IT_BLUE_FLAG_TAKEN;
655 if (flag.cnt == FLAG_CARRY)
656 if (flag.owner == self) status = 3;
658 else if (flag.cnt == FLAG_DROPPED) status = 2;
661 self.items = self.items | (shift * status);
665 void() ctf_setstatus =
667 self.items = self.items - (self.items & IT_RED_FLAG_TAKEN);
668 self.items = self.items - (self.items & IT_RED_FLAG_LOST);
669 self.items = self.items - (self.items & IT_BLUE_FLAG_TAKEN);
670 self.items = self.items - (self.items & IT_BLUE_FLAG_LOST);
674 flag = ctf_worldflaglist;
677 ctf_setstatus2(flag);
678 flag = flag.ctf_worldflagnext;