]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/gamec/ctf.c
added minstagib mutator, killmessages and a first bunch of announcer messages (soundf...
[divverent/nexuiz.git] / data / qcsrc / gamec / ctf.c
1
2 .entity flagcarried;
3
4 //float FLAGSCORE_PICKUP        =  1;
5 //float FLAGSCORE_RETURN        =  5; // returned by owner team
6 //float FLAGSCORE_RETURNROGUE   = 10; // returned by rogue team
7 //float FLAGSCORE_CAPTURE       =  5;
8 //float FLAGSCORE_CAPTURE_TEAM  = 20;
9
10 float FLAG_BASE = 1;
11 float FLAG_CARRY = 2;
12 float FLAG_DROPPED = 3;
13
14 void() FlagThink;
15 void() FlagTouch;
16
17 void() place_flag =
18 {
19         if(!self.t_width)
20                 self.t_width = 0.1; // frame animation rate
21         if(!self.t_length)
22                 self.t_length = 119; // maximum frame
23                 
24         self.mdl = self.model;
25         self.flags = FL_ITEM;
26         self.solid = SOLID_TRIGGER;
27         self.movetype = MOVETYPE_TOSS;
28         self.velocity = '0 0 0';
29         self.origin_z = self.origin_z + 6;
30         self.think = FlagThink;
31         self.touch = FlagTouch;
32         self.nextthink = time + 0.1;
33         self.cnt = FLAG_BASE;
34         self.mangle = self.angles;
35         //self.effects = self.effects | EF_DIMLIGHT;
36         if (!droptofloor(0, 0))
37         {
38                 dprint("Flag fell out of level at ", vtos(self.origin), "\n");
39                 remove(self);
40                 return;
41         }
42         self.oldorigin = self.origin;
43 };
44
45 void(entity e) RegenFlag =
46 {
47         e.movetype = MOVETYPE_TOSS;
48         e.solid = SOLID_TRIGGER;
49         // TODO: play a sound here
50         sound (e, CHAN_AUTO, self.noise3, 1, ATTN_NONE);
51         setorigin(e, e.oldorigin);
52         e.angles = e.mangle;
53         e.cnt = FLAG_BASE;
54         e.owner = world;
55         e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
56 };
57
58 void(entity e) ReturnFlag =
59 {
60         if (e.owner)
61         if (e.owner.flagcarried == e)
62                 e.owner.flagcarried = world;
63         e.owner = world;
64         RegenFlag(e);
65 };
66
67 void(entity e) DropFlag =
68 {
69         local entity p;
70
71         if (!e.owner)
72         {
73                 dprint("FLAG: drop - no owner?!?!\n");
74                 return;
75         }
76         p = e.owner;
77         if (p.flagcarried != e)
78         {
79                 dprint("FLAG: drop - owner is not carrying this flag??\n");
80                 return;
81         }
82         bprint(p.netname);
83         if (e.team == 5)
84                 bprint("^7 lost the RED flag\n");
85         else
86                 bprint("^7 lost the BLUE flag\n");
87         if (p.flagcarried == e)
88                 p.flagcarried = world;
89         e.owner = world;
90
91         e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
92         e.solid = SOLID_TRIGGER;
93         e.movetype = MOVETYPE_TOSS;
94         // setsize(e, '-16 -16 0', '16 16 74');
95         setorigin(e, p.origin - '0 0 24');
96         e.cnt = FLAG_DROPPED;
97         e.velocity = '0 0 300';
98         e.pain_finished = time + cvar("g_ctf_flag_returntime");//30;
99 };
100
101 void AnimateFlag()
102 {
103         if(self.delay > time)
104                 return;
105         self.delay = time + self.t_width;
106         if(self.nextthink > self.delay)
107                 self.nextthink = self.delay;
108
109         self.frame = self.frame + 1;
110         if(self.frame > self.t_length)
111                 self.frame = 0;
112 }
113
114 void() FlagThink =
115 {
116         local entity e;
117         local vector v;
118         local float f;
119
120         self.nextthink = time + 0.1;
121         
122         AnimateFlag();
123
124         if (self.cnt == FLAG_BASE)
125                 return;
126
127         if (self.cnt == FLAG_DROPPED)
128         {
129                 if (time > self.pain_finished)
130                 {
131                         if (self.team == 5)
132                                 bprint("The RED flag has returned to base\n");
133                         else
134                                 bprint("The BLUE flag has returned to base\n");
135                         ReturnFlag(self);
136                 }
137                 return;
138         }
139
140         e = self.owner;
141         if (e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
142         {
143                 DropFlag(self);
144                 return;
145         }
146
147         // borrowed from threewave CTF, because it would be way too much work
148
149         makevectors (e.angles);
150         v = v_forward;
151         v_z = 0 - v_z; // reverse z
152
153         f = 14;
154         /*
155         if (e.frame >= 29 && e.frame <= 40)
156         {
157                 if (e.frame >= 29 && e.frame <= 34)
158                 {
159                         //axpain
160                         if      (e.frame == 29) f = f + 2;
161                         else if (e.frame == 30) f = f + 8;
162                         else if (e.frame == 31) f = f + 12;
163                         else if (e.frame == 32) f = f + 11;
164                         else if (e.frame == 33) f = f + 10;
165                         else if (e.frame == 34) f = f + 4;
166                 }
167                 else if (e.frame >= 35 && e.frame <= 40)
168                 {
169                         // pain
170                         if      (e.frame == 35) f = f + 2;
171                         else if (e.frame == 36) f = f + 10;
172                         else if (e.frame == 37) f = f + 10;
173                         else if (e.frame == 38) f = f + 8;
174                         else if (e.frame == 39) f = f + 4;
175                         else if (e.frame == 40) f = f + 2;
176                 }
177         }
178         else if (e.frame >= 103 && e.frame <= 118)
179         {
180                 if      (e.frame >= 103 && e.frame <= 104) f = f + 6;  //nailattack
181                 else if (e.frame >= 105 && e.frame <= 106) f = f + 6;  //light
182                 else if (e.frame >= 107 && e.frame <= 112) f = f + 7;  //rocketattack
183                 else if (e.frame >= 112 && e.frame <= 118) f = f + 7;  //shotattack
184         }
185         */
186         self.angles = e.angles + '0 0 -45';
187         setorigin (self, e.origin + '0 0 0' - f*v + v_right * 22);
188         self.nextthink = time + 0.01;
189 };
190
191 float   flagcaptimerecord;
192 .float  flagpickuptime;
193
194 void() FlagTouch =
195 {
196         local float t;
197         local entity head;
198         local entity player;
199         if (other.classname != "player")
200                 return;
201         if (other.health < 1) // ignore dead players
202                 return;
203
204         if (self.cnt == FLAG_CARRY)
205                 return;
206
207         if (self.cnt == FLAG_BASE)
208         if (other.team == self.team)
209         if (other.flagcarried) // he's got a flag
210         if (other.flagcarried.team != self.team) // capture
211         {
212                 t = time - other.flagpickuptime;
213                 if (flagcaptimerecord == 0)
214                 {
215                         if (other.flagcarried.team == 5)
216                                 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), " seconds\n");
217                         else
218                                 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), " seconds\n");
219                         flagcaptimerecord = t;
220                 }
221                 else if (t < flagcaptimerecord)
222                 {
223                         if (other.flagcarried.team == 5)
224                                 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
225                         else
226                                 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", breaking the previous record of", ftos(flagcaptimerecord), " seconds\n");
227                         flagcaptimerecord = t;
228                 }
229                 else
230                 {
231                         if (other.flagcarried.team == 5)
232                                 bprint(other.netname, "^7 captured the RED flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
233                         else
234                                 bprint(other.netname, "^7 captured the BLUE flag in ", ftos(t), ", failing to break the previous record of", ftos(flagcaptimerecord), " seconds\n");
235                 }
236                 other.frags = other.frags + cvar("g_ctf_flagscore_capture");//FLAGSCORE_CAPTURE;
237                 head = find(head, classname, "player");
238                 while (head)
239                 {
240                         if (head.team == self.team)
241                                 head.frags = head.frags + cvar("g_ctf_flagscore_capture_team");//FLAGSCORE_CAPTURE_TEAM;
242                         head = find(head, classname, "player");
243                 }
244                 sound (self, CHAN_AUTO, self.noise2, 1, ATTN_NONE);
245                 ReturnFlag(other.flagcarried);
246         }
247         if (self.cnt == FLAG_BASE)
248         if (other.team == 5 || other.team == 14) // only red and blue team can steal flags
249         if (other.team != self.team)
250         if (!other.flagcarried)
251         {
252                 // pick up
253                 other.flagpickuptime = time; // used for timing runs
254                 self.solid = SOLID_NOT;
255                 setorigin(self, self.origin); // relink
256                 self.owner = other;
257                 other.flagcarried = self;
258                 self.cnt = FLAG_CARRY;
259                 if (other.flagcarried.team == 5)
260                         bprint(other.netname, "^7 got the RED flag\n");
261                 else
262                         bprint(other.netname, "^7 got the BLUE flag\n");
263                 other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
264                 sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
265                 
266                 player = find(world, classname, "player");
267                 while(player) {
268                         if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
269                         player = find(player, classname, "player");
270                 }
271                 
272                 return;
273         }
274
275         if (self.cnt == FLAG_DROPPED)
276         {
277                 self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
278                 if (other.team == self.team || (other.team != 5 && other.team != 14))
279                 {
280                         // return flag
281                         if (self.team == 5)
282                                 bprint(other.netname, "^7 returned the RED flag\n");
283                         else
284                                 bprint(other.netname, "^7 returned the BLUE flag\n");
285                         if (other.team == 5 || other.team == 14)
286                                 other.frags = other.frags + cvar("g_ctf_flagscore_return");//FLAGSCORE_RETURN;
287                         else
288                                 other.frags = other.frags + cvar("g_ctf_flagscore_return_rogue");//FLAGSCORE_RETURNROGUE;
289                         sound (self, CHAN_AUTO, self.noise1, 1, ATTN_NONE);
290                         ReturnFlag(self);
291                 }
292                 else if (!other.flagcarried)
293                 {
294                         // pick up
295                         other.flagpickuptime = time; // used for timing runs
296                         self.solid = SOLID_NOT;
297                         setorigin(self, self.origin); // relink
298                         self.owner = other;
299                         other.flagcarried = self;
300                         self.cnt = FLAG_CARRY;
301                         if (self.team == 5)
302                                 bprint(other.netname, "^7 picked up the RED flag\n");
303                         else
304                                 bprint(other.netname, "^7 picked up the BLUE flag\n");
305                         other.frags = other.frags + cvar("g_ctf_flagscore_pickup");//FLAGSCORE_PICKUP;
306                         sound (self, CHAN_AUTO, self.noise, 1, ATTN_NONE);
307
308                         player = find(world, classname, "player");
309                         while(player) {
310                                 if(player.team == self.team) centerprint(player, "The enemy got your flag! Retrieve it!");
311                                 player = find(player, classname, "player");
312                         }                       
313                 }
314         }
315 };
316
317 /*QUAKED info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
318 CTF Starting point for a player
319 in team one (Red).
320
321 Keys:
322 "angle"
323  viewing angle when spawning
324 */
325 void() info_player_team1 = 
326 {
327         if(!cvar("g_ctf"))
328                 self.classname = "info_player_deathmatch";
329 };
330 //self.team = 4;self.classname = "info_player_start";info_player_start();};
331
332 /*QUAKED info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
333 CTF Starting point for a player in
334 team two (Blue).
335
336 Keys:
337 "angle"
338  viewing angle when spawning
339 */
340 void() info_player_team2 =
341 {
342         if(!cvar("g_ctf"))
343                 self.classname = "info_player_deathmatch";
344 };
345 //self.team = 13;self.classname = "info_player_start";info_player_start();};
346
347 /*QUAKED info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
348 CTF Starting point for a player in
349 team three (Green).
350
351 Keys:
352 "angle"
353  viewing angle when spawning
354 */
355 void() info_player_team3 =
356 {
357         if(!cvar("g_ctf"))
358                 self.classname = "info_player_deathmatch";
359 };
360
361
362 /*QUAKED info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
363 CTF Starting point for a player in
364 team four (Magenta).
365
366 Keys:
367 "angle"
368  viewing angle when spawning
369 */
370 void() info_player_team4 =
371 {
372         if(!cvar("g_ctf"))
373                 self.classname = "info_player_deathmatch";
374 };
375
376
377
378
379 /*QUAKED item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
380 CTF flag for team one (Red).
381 Multiple are allowed.
382
383 Keys:
384 "angle"
385  Angle the flag will point
386 (minus 90 degrees)
387 "model"
388  model to use, note this needs red and blue as skins 0 and 1
389  (default models/ctf/flag.md3)
390 "noise"
391  sound played when flag is picked up
392  (default ctf/take.wav)
393 "noise1"
394  sound played when flag is returned by a teammate
395  (default ctf/return.wav)
396 "noise2"
397  sound played when flag is captured
398  (default ctf/capture.wav)
399 "noise3"
400  sound played when flag is lost in the field and respawns itself
401  (default ctf/respawn.wav)
402 */
403
404 void() item_flag_team1 =
405 {
406         if (!cvar("g_ctf"))
407                 return;
408         //if(!cvar("teamplay"))
409         //      cvar_set("teamplay", "3");
410
411         self.team = 5; // color 4 team (red)
412         self.items = IT_KEY2; // gold key (redish enough)
413         self.skin = 0;
414         if (!self.model)
415                 self.model = "models/ctf/flag_red.md3";
416         if (!self.noise)
417                 self.noise = "ctf/take.wav";
418         if (!self.noise1)
419                 self.noise1 = "ctf/return.wav";
420         if (!self.noise2)
421                 self.noise2 = "ctf/capture.wav";
422         if (!self.noise3)
423                 self.noise3 = "ctf/respawn.wav";
424         precache_model (self.model);
425         setmodel (self, self.model);
426         precache_sound (self.noise);
427         precache_sound (self.noise1);
428         precache_sound (self.noise2);
429         precache_sound (self.noise3);
430         setsize(self, '-16 -16 -37', '16 16 37');
431         setorigin(self, self.origin + '0 0 37');
432         self.nextthink = time + 0.2; // start after doors etc
433         self.think = place_flag;
434
435         if(!self.scale)
436                 self.scale = 0.6;
437         //if(!self.glow_size)
438         //      self.glow_size = 50;
439         
440         self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
441 };
442
443 /*QUAKED item_flag_team2 (0 0.5 0.8) (-48 -48 -24) (48 48 64)
444 CTF flag for team two (Blue).
445 Multiple are allowed.
446
447 Keys:
448 "angle"
449  Angle the flag will point
450 (minus 90 degrees)
451
452 */
453
454 void() item_flag_team2 =
455 {
456         if (!cvar("g_ctf"))
457                 return;
458         //if(!cvar("teamplay"))
459         //      cvar_set("teamplay", "3");
460
461         self.team = 14; // color 13 team (blue)
462         self.items = IT_KEY1; // silver key (bluish enough)
463         self.skin = 1;
464         if (!self.model)
465                 self.model = "models/ctf/flag_blue.md3";
466         if (!self.noise)
467                 self.noise = "ctf/take.wav";
468         if (!self.noise1)
469                 self.noise1 = "ctf/return.wav";
470         if (!self.noise2)
471                 self.noise2 = "ctf/capture.wav";
472         if (!self.noise3)
473                 self.noise3 = "ctf/respawn.wav";
474         precache_model (self.model);
475         setmodel (self, self.model);
476         precache_sound (self.noise);
477         precache_sound (self.noise1);
478         precache_sound (self.noise2);
479         precache_sound (self.noise3);
480         setsize(self, '-16 -16 -37', '16 16 37');
481         setorigin(self, self.origin + '0 0 37');
482         self.nextthink = time + 0.2; // start after doors etc
483         self.think = place_flag;
484
485         if(!self.scale)
486                 self.scale = 0.6;
487         //if(!self.glow_size)
488         //      self.glow_size = 50;
489         
490         self.effects = self.effects | EF_FULLBRIGHT | EF_LOWPRECISION;
491 };
492
493
494 /*QUAKED ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
495 Team declaration for CTF gameplay, this allows you to decide what team
496 names and control point models are used in your map.
497
498 Note: If you use ctf_team entities you must define at least 2!  However, unlike
499 domination, you don't need to make a blank one too.
500
501 Keys:
502 "netname"
503  Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)
504 "cnt"
505  Scoreboard color of the team (for example 4 is red and 13 is blue)
506
507 */
508
509 void() ctf_team =
510 {
511         self.classname = "ctf_team";
512         self.team = self.cnt + 1;
513 };
514
515 // code from here on is just to support maps that don't have control point and team entities
516 void ctf_spawnteam (string teamname, float teamcolor)
517 {
518         local entity oldself;
519         oldself = self;
520         self = spawn();
521         self.classname = "ctf_team";
522         self.netname = teamname;
523         self.cnt = teamcolor;
524
525         ctf_team();
526
527         self = oldself;
528 };
529
530 // spawn some default teams if the map is not set up for ctf
531 void() ctf_spawnteams =
532 {
533         float numteams;
534
535         numteams = 2;//cvar("g_ctf_default_teams");
536
537         ctf_spawnteam("Red", 4);
538         ctf_spawnteam("Blue", 13);
539 };
540
541 void() ctf_delayedinit =
542 {
543         self.think = SUB_Remove;
544         self.nextthink = time;
545         // if no teams are found, spawn defaults
546         if (find(world, classname, "ctf_team") == world)
547                 ctf_spawnteams();
548 };
549
550 void() ctf_init =
551 {
552         local entity e;
553         e = spawn();
554         e.think = ctf_delayedinit;
555         e.nextthink = time + 0.1;
556 };
557