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