]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_player.qc
Merge branch 'master' of git://de.git.xonotic.org/xonotic/xonotic-data.pk3dir
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
1 .entity accuracy;
2 .float accuracy_frags[WEP_MAXCOUNT];
3
4 float weaponstats_buffer;
5
6 void WeaponStats_Init()
7 {
8         if(autocvar_sv_weaponstats_file != "")
9                 weaponstats_buffer = buf_create();
10         else
11                 weaponstats_buffer = -1;
12 }
13
14 #define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot))
15
16 void WeaponStats_ready(entity fh, entity pass, float status)
17 {
18         float i, j, n, ibot, jbot, idx;
19         vector v;
20         string prefix, s;
21         switch(status)
22         {
23                 case URL_READY_CANWRITE:
24                         // we can write
25                         prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
26                         url_fputs(fh, "#begin statsfile\n");
27                         url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
28 #ifdef WATERMARK
29                         url_fputs(fh, strcat("#version ", WATERMARK(), "\n"));
30 #endif
31                         url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_purechanges)), "\n"));
32                         url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n"));
33                         n = tokenizebyseparator(cvar_purechanges, "\n");
34                         for(i = 0; i < n; ++i)
35                                 url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n"));
36                         for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot)
37                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot)
38                                 {
39                                         idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot);
40                                         v = stov(bufstr_get(weaponstats_buffer, idx));
41                                         if(v != '0 0 0')
42                                         {
43                                                 //vector is: kills hits damage
44                                                 url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
45                                                 url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
46                                         }
47                                 }
48                         url_fputs(fh, "#end\n\n");
49                         url_fclose(fh);
50                         break;
51                 case URL_READY_CANREAD:
52                         // url_fclose is processing, we got a response for writing the data
53                         // this must come from HTTP
54                         print("Got response from weapon stats server:\n");
55                         while((s = url_fgets(fh)))
56                                 print("  ", s, "\n");
57                         print("End of response.\n");
58                         url_fclose(fh);
59                         break;
60                 case URL_READY_CLOSED:
61                         // url_fclose has finished
62                         print("Weapon stats written\n");
63                         buf_del(weaponstats_buffer);
64                         weaponstats_buffer = -1;
65                         break;
66                 case URL_READY_ERROR:
67                 default:
68                         print("Weapon stats writing failed: ", ftos(status), "\n");
69                         buf_del(weaponstats_buffer);
70                         weaponstats_buffer = -1;
71                         break;
72         }
73 }
74
75 void WeaponStats_Shutdown()
76 {
77         if(weaponstats_buffer < 0)
78                 return;
79         if(autocvar_sv_weaponstats_file != "")
80         {
81                 url_multi_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world);
82         }
83         else
84         {
85                 buf_del(weaponstats_buffer);
86                 weaponstats_buffer = -1;
87         }
88 }
89
90 void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item)
91 {
92         float idx;
93         if(weaponstats_buffer < 0)
94                 return;
95         if(awep < WEP_FIRST || vwep < WEP_FIRST)
96                 return;
97         if(awep > WEP_LAST || vwep > WEP_LAST)
98                 return;
99         idx = WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot);
100         bufstr_set(weaponstats_buffer, idx, vtos(stov(bufstr_get(weaponstats_buffer, idx)) + item));
101 }
102 void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage)
103 {
104         if(damage < 0)
105                 error("negative damage?");
106         WeaponStats_LogItem(awep, abot, vwep, vbot, '0 0 1' * damage + '0 1 0');
107 }
108 void WeaponStats_LogKill(float awep, float abot, float vwep, float vbot)
109 {
110         WeaponStats_LogItem(awep, abot, vwep, vbot, '1 0 0');
111 }
112
113 // changes by LordHavoc on 03/29/04 and 03/30/04 at Vermeulen's request
114 // merged player_run and player_stand to player_anim
115 // added death animations to player_anim
116 // can now spawn thrown weapons from anywhere, not just from players
117 // thrown weapons now fade out after 20 seconds
118 // created PlayerGib function
119 // PlayerDie no longer uses hitloc or damage
120 // PlayerDie now supports dying animations as well as gibbing
121 // cleaned up PlayerDie a lot
122 // added CopyBody
123
124 .entity pusher;
125 .float pushltime;
126
127 void CopyBody(float keepvelocity)
128 {
129         entity oldself;
130         if (self.effects & EF_NODRAW)
131                 return;
132         oldself = self;
133         self = spawn();
134         self.enemy = oldself;
135         self.lip = oldself.lip;
136         self.colormap = oldself.colormap;
137         self.glowmod = oldself.glowmod;
138         self.iscreature = oldself.iscreature;
139         self.damagedbycontents = oldself.damagedbycontents;
140         self.angles = oldself.angles;
141         self.avelocity = oldself.avelocity;
142         self.classname = "body";
143         self.damageforcescale = oldself.damageforcescale;
144         self.effects = oldself.effects;
145         self.event_damage = oldself.event_damage;
146         self.animstate_startframe = oldself.animstate_startframe;
147         self.animstate_numframes = oldself.animstate_numframes;
148         self.animstate_framerate = oldself.animstate_framerate;
149         self.animstate_starttime = oldself.animstate_starttime;
150         self.animstate_endtime = oldself.animstate_endtime;
151         self.animstate_override = oldself.animstate_override;
152         self.animstate_looping = oldself.animstate_looping;
153         self.frame = oldself.frame;
154         self.dead_frame = oldself.dead_frame;
155         self.pain_finished = oldself.pain_finished;
156         self.health = oldself.health;
157         self.armorvalue = oldself.armorvalue;
158         self.armortype = oldself.armortype;
159         self.model = oldself.model;
160         self.modelindex = oldself.modelindex;
161         self.modelindex_lod0 = oldself.modelindex_lod0;
162         self.modelindex_lod0_from_xonotic = oldself.modelindex_lod0_from_xonotic;
163         self.modelindex_lod1 = oldself.modelindex_lod1;
164         self.modelindex_lod2 = oldself.modelindex_lod2;
165         self.skinindex = oldself.skinindex;
166         self.species = oldself.species;
167         self.movetype = oldself.movetype;
168         self.nextthink = oldself.nextthink;
169         self.solid = oldself.solid;
170         self.ballistics_density = oldself.ballistics_density;
171         self.takedamage = oldself.takedamage;
172         self.think = oldself.think;
173         self.customizeentityforclient = oldself.customizeentityforclient;
174         self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
175         self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
176         if (keepvelocity == 1)
177                 self.velocity = oldself.velocity;
178         self.oldvelocity = self.velocity;
179         self.fade_time = oldself.fade_time;
180         self.fade_rate = oldself.fade_rate;
181         //self.weapon = oldself.weapon;
182         setorigin(self, oldself.origin);
183         setsize(self, oldself.mins, oldself.maxs);
184         self.prevorigin = oldself.origin;
185         self.reset = SUB_Remove;
186
187         Drag_MoveDrag(oldself, self);
188
189         if(self.colormap <= maxclients && self.colormap > 0)
190                 self.colormap = 1024 + self.clientcolors;
191
192         self = oldself;
193 }
194
195 float player_getspecies()
196 {
197         float s;
198         get_model_parameters(self.model, self.skinindex);
199         s = get_model_parameters_species;
200         get_model_parameters(string_null, 0);
201         if(s < 0)
202                 return SPECIES_HUMAN;
203         return s;
204 }
205
206 void player_setupanimsformodel()
207 {
208         // defaults for legacy .zym models without animinfo files
209         self.anim_die1 = animfixfps(self, '0 1 0.5'); // 2 seconds
210         self.anim_die2 = animfixfps(self, '1 1 0.5'); // 2 seconds
211         self.anim_draw = animfixfps(self, '2 1 3');
212         // self.anim_duck = '3 1 100'; // This anim is broken, use slot 3 as a new free slot in the future ;)
213         self.anim_duckwalk = animfixfps(self, '4 1 1');
214         self.anim_duckjump = '5 1 100'; // NOTE: zym anims keep playing until changed, so this only has to start the anim, landing will end it
215         self.anim_duckidle = animfixfps(self, '6 1 1');
216         self.anim_idle = animfixfps(self, '7 1 1');
217         self.anim_jump = '8 1 100'; // NOTE: zym anims keep playing until changed, so this only has to start the anim, landing will end it
218         self.anim_pain1 = animfixfps(self, '9 1 2'); // 0.5 seconds
219         self.anim_pain2 = animfixfps(self, '10 1 2'); // 0.5 seconds
220         self.anim_shoot = animfixfps(self, '11 1 5'); // analyze models and set framerate
221         self.anim_taunt = animfixfps(self, '12 1 0.33');
222         self.anim_run = animfixfps(self, '13 1 1');
223         self.anim_runbackwards = animfixfps(self, '14 1 1');
224         self.anim_strafeleft = animfixfps(self, '15 1 1');
225         self.anim_straferight = animfixfps(self, '16 1 1');
226         self.anim_dead1 = animfixfps(self, '17 1 1');
227         self.anim_dead2 = animfixfps(self, '18 1 1');
228         self.anim_forwardright = animfixfps(self, '19 1 1');
229         self.anim_forwardleft = animfixfps(self, '20 1 1');
230         self.anim_backright = animfixfps(self, '21 1 1');
231         self.anim_backleft  = animfixfps(self, '22 1 1');
232         self.anim_melee = animfixfps(self, '23 1 1');
233         // TODO introspect models for finding right "fps" value (1/duration)
234         // reset animstate now
235         setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
236 }
237
238 void player_anim (void)
239 {
240         updateanim(self);
241         if (self.weaponentity)
242                 updateanim(self.weaponentity);
243
244         if (self.deadflag != DEAD_NO)
245         {
246                 if (time > self.animstate_endtime)
247                 {
248                         if (self.maxs_z > 5)
249                         {
250                                 self.maxs_z = 5;
251                                 setsize(self, self.mins, self.maxs);
252                         }
253                         self.frame = self.dead_frame;
254                 }
255                 return;
256         }
257
258         if (!self.animstate_override)
259         {
260                 if (!(self.flags & FL_ONGROUND) || self.BUTTON_JUMP)
261                 {
262                         if (self.crouch)
263                         {
264                                 if (self.animstate_startframe != self.anim_duckjump_x) // don't perform another trace if already playing the crouch jump anim
265                                 {
266                                         traceline(self.origin + '0 0 1' * PL_CROUCH_MIN_z, self.origin + '0 0 1' * (PL_CROUCH_MIN_z - autocvar_sv_player_jumpanim_minfall), TRUE, self);
267                                         if(!trace_startsolid && trace_fraction == 1 || !(self.animstate_startframe == self.anim_duckwalk_x || self.animstate_startframe == self.anim_duckidle_x)) // don't get stuck on non-crouch anims
268                                         {
269                                                 setanim(self, self.anim_duckjump, FALSE, TRUE, self.restart_jump);
270                                                 self.restart_jump = FALSE;
271                                         }
272                                 }
273                         }
274                         else
275                         {
276                 if (self.animstate_startframe != self.anim_jump_x) // don't perform another trace if already playing the jump anim
277                 {
278                     traceline(self.origin + '0 0 1' * PL_MIN_z, self.origin + '0 0 1' * (PL_MIN_z - autocvar_sv_player_jumpanim_minfall), TRUE, self);
279                     if(!trace_startsolid && trace_fraction == 1 || self.animstate_startframe == self.anim_idle_x || (self.animstate_startframe == self.anim_melee_x && time - self.animstate_starttime >= 21/20)) // don't get stuck on idle animation in midair, nor melee after it finished
280                     {
281                         setanim(self, self.anim_jump, FALSE, TRUE, self.restart_jump);
282                         self.restart_jump = FALSE;
283                     }
284                 }
285                         }
286                 }
287                 else if (self.crouch)
288                 {
289                         if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
290                                 setanim(self, self.anim_duckwalk, TRUE, FALSE, FALSE);
291                         else
292                                 setanim(self, self.anim_duckidle, TRUE, FALSE, FALSE);
293                 }
294                 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
295                 {
296                         if (self.movement_x > 0 && self.movement_y == 0)
297                                 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
298                         else if (self.movement_x < 0 && self.movement_y == 0)
299                                 setanim(self, self.anim_runbackwards, TRUE, FALSE, FALSE);
300                         else if (self.movement_x == 0 && self.movement_y > 0)
301                                 setanim(self, self.anim_straferight, TRUE, FALSE, FALSE);
302                         else if (self.movement_x == 0 && self.movement_y < 0)
303                                 setanim(self, self.anim_strafeleft, TRUE, FALSE, FALSE);
304                         else if (self.movement_x > 0 && self.movement_y > 0)
305                                 setanim(self, self.anim_forwardright, TRUE, FALSE, FALSE);
306                         else if (self.movement_x > 0 && self.movement_y < 0)
307                                 setanim(self, self.anim_forwardleft, TRUE, FALSE, FALSE);
308                         else if (self.movement_x < 0 && self.movement_y > 0)
309                                 setanim(self, self.anim_backright, TRUE, FALSE, FALSE);
310                         else if (self.movement_x < 0 && self.movement_y < 0)
311                                 setanim(self, self.anim_backleft, TRUE, FALSE, FALSE);
312                         else
313                                 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
314                 }
315                 else
316                         setanim(self, self.anim_idle, TRUE, FALSE, FALSE);
317         }
318
319         if (self.weaponentity)
320         if (!self.weaponentity.animstate_override)
321                 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
322 }
323
324 void SpawnThrownWeapon (vector org, float w)
325 {
326         if(g_minstagib)
327         if(self.ammo_cells <= 0)
328                 return;
329
330         if(g_pinata)
331         {
332                 float j;
333                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
334                 {
335                         if(self.weapons & W_WeaponBit(j))
336                                 if(W_IsWeaponThrowable(j))
337                                         W_ThrowNewWeapon(self, j, FALSE, org, randomvec() * 175 + '0 0 325');
338                 }
339         }
340         else
341         {
342                 if(W_IsWeaponThrowable(self.weapon))
343                         W_ThrowNewWeapon(self, self.weapon, FALSE, org, randomvec() * 125 + '0 0 200');
344         }
345 }
346
347 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
348 {
349         float take, save;
350         vector v;
351         Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
352
353         // damage resistance (ignore most of the damage from a bullet or similar)
354         damage = max(damage - 5, 1);
355
356         v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
357         take = v_x;
358         save = v_y;
359
360         if(sound_allowed(MSG_BROADCAST, attacker))
361         {
362                 if (save > 10)
363                         sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
364                 else if (take > 30)
365                         sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
366                 else if (take > 10)
367                         sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
368         }
369
370         if (take > 50)
371                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
372         if (take > 100)
373                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
374
375         if (!(self.flags & FL_GODMODE))
376         {
377                 self.armorvalue = self.armorvalue - save;
378                 self.health = self.health - take;
379                 // pause regeneration for 5 seconds
380                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
381         }
382         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
383         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
384         self.dmg_inflictor = inflictor;
385
386         if (self.health <= -autocvar_sv_gibhealth && self.modelindex != 0)
387         {
388                 // don't use any animations as a gib
389                 self.frame = 0;
390                 self.dead_frame = 0;
391                 // view just above the floor
392                 self.view_ofs = '0 0 4';
393
394                 Violence_GibSplash(self, 1, 1, attacker);
395                 self.modelindex = 0; // restore later
396                 self.solid = SOLID_NOT; // restore later
397         }
398 }
399
400 void ClientKill_Now_TeamChange();
401 void freezetag_CheckWinner();
402
403 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
404 {
405         float take, save, waves, sdelay, dh, da, j;
406         vector v;
407         float valid_damage_for_weaponstats;
408         float excess;
409
410         if((g_arena && numspawned < 2) || (g_ca && !ca_teams_ok) && !inWarmupStage)
411                 return;
412
413         dh = max(self.health, 0);
414         da = max(self.armorvalue, 0);
415
416         if(!DEATH_ISSPECIAL(deathtype))
417         {
418                 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
419                 if(self != attacker)
420                         damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
421         }
422
423         if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
424         {
425                 // tuba causes blood to come out of the ears
426                 vector ear1, ear2;
427                 vector d;
428                 float f;
429                 ear1 = self.origin;
430                 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
431                 ear2 = ear1;
432                 makevectors(self.angles);
433                 ear1 += v_right * -10;
434                 ear2 += v_right * +10;
435                 d = inflictor.origin - self.origin;
436                 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
437                 force = v_right * vlen(force);
438                 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
439                 Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
440                 if(f > 0)
441                 {
442                         hitloc = ear1;
443                         force = force * -1;
444                 }
445                 else
446                 {
447                         hitloc = ear2;
448                         // force is already good
449                 }
450         }
451         else
452                 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
453
454         if (!g_minstagib)
455         {
456                 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
457                 take = v_x;
458                 save = v_y;
459         }
460         else
461         {
462                 save = 0;
463                 take = damage;
464         }
465
466         frag_inflictor = inflictor;
467         frag_attacker = attacker;
468         frag_target = self;
469         damage_take = take;
470         damage_save = save;
471         damage_force = force;
472         MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
473         take = bound(0, damage_take, self.health);
474         save = bound(0, damage_save, self.armorvalue);
475         excess = max(0, damage - take - save);
476
477         if(sound_allowed(MSG_BROADCAST, attacker))
478         {
479                 if (save > 10)
480                         sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
481                 else if (take > 30)
482                         sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
483                 else if (take > 10)
484                         sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
485         }
486
487         if (take > 50)
488                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
489         if (take > 100)
490                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
491
492         if (time >= self.spawnshieldtime)
493         {
494                 if (!(self.flags & FL_GODMODE))
495                 {
496                         self.armorvalue = self.armorvalue - save;
497                         self.health = self.health - take;
498                         // pause regeneration for 5 seconds
499                         if(take)
500                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
501
502                         if (time > self.pain_finished)          //Don't switch pain sequences like crazy
503                         {
504                                 self.pain_finished = time + 0.5;        //Supajoe
505
506                                 if(sv_gentle < 1) {
507                                         if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
508                                         {
509                                                 if (!self.animstate_override)
510                                                 {
511                                                         if (random() > 0.5)
512                                                                 setanim(self, self.anim_pain1, FALSE, TRUE, TRUE);
513                                                         else
514                                                                 setanim(self, self.anim_pain2, FALSE, TRUE, TRUE);
515                                                 }
516                                         }
517
518                                         if(sound_allowed(MSG_BROADCAST, attacker))
519                                         if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * autocvar_g_balance_laser_primary_damage * autocvar_g_balance_selfdamagepercent + 1)
520                                         if(self.health > 1)
521                                         // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
522                                         {
523                                                 if(deathtype == DEATH_FALL)
524                                                         PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
525                                                 else if(self.health > 75) // TODO make a "gentle" version?
526                                                         PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
527                                                 else if(self.health > 50)
528                                                         PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
529                                                 else if(self.health > 25)
530                                                         PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
531                                                 else
532                                                         PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
533                                         }
534                                 }
535
536                                 // throw off bot aim temporarily
537                                 float shake;
538                                 shake = damage * 5 / (bound(0,skill,100) + 1);
539                                 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
540                                 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
541                         }
542                 }
543                 else
544                         self.max_armorvalue += (save + take);
545         }
546         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
547         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
548         self.dmg_inflictor = inflictor;
549
550         if(attacker == self)
551         {
552                 // don't reset pushltime for self damage as it may be an attempt to
553                 // escape a lava pit or similar
554                 //self.pushltime = 0;
555         }
556         else if(attacker.classname == "player")
557         {
558                 self.pusher = attacker;
559                 self.pushltime = time + autocvar_g_maxpushtime;
560         }
561         else if(time < self.pushltime)
562         {
563                 attacker = self.pusher;
564                 self.pushltime = max(self.pushltime, time + 0.6);
565         }
566         else
567                 self.pushltime = 0;
568
569         float abot, vbot, awep;
570         abot = (clienttype(attacker) == CLIENTTYPE_BOT);
571         vbot = (clienttype(self) == CLIENTTYPE_BOT);
572
573         valid_damage_for_weaponstats = 0;
574         if(vbot || clienttype(self) == CLIENTTYPE_REAL)
575         if(abot || clienttype(attacker) == CLIENTTYPE_REAL)
576         if(attacker && self != attacker)
577         if(IsDifferentTeam(self, attacker))
578         {
579                 if(DEATH_ISSPECIAL(deathtype))
580                         awep = attacker.weapon;
581                 else
582                         awep = DEATH_WEAPONOF(deathtype);
583                 valid_damage_for_weaponstats = 1;
584         }
585
586         if(valid_damage_for_weaponstats)
587         {
588                 dh = dh - max(self.health, 0);
589                 da = da - max(self.armorvalue, 0);
590                 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
591         }
592
593         if (self.health < 1)
594         {
595                 float defer_ClientKill_Now_TeamChange;
596                 defer_ClientKill_Now_TeamChange = FALSE;
597
598                 if(self.alivetime)
599                 {
600                         PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
601                         self.alivetime = 0;
602                 }
603
604                 if(valid_damage_for_weaponstats)
605                         WeaponStats_LogKill(awep, abot, self.weapon, vbot);
606
607                 if(sv_gentle < 1) // TODO make a "gentle" version?
608                 if(sound_allowed(MSG_BROADCAST, attacker))
609                 {
610                         if(deathtype == DEATH_DROWN)
611                                 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
612                         else
613                                 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
614                 }
615
616                 // get rid of kill indicator
617                 if(self.killindicator)
618                 {
619                         remove(self.killindicator);
620                         self.killindicator = world;
621                         if(self.killindicator_teamchange)
622                                 defer_ClientKill_Now_TeamChange = TRUE;
623
624                         if(self.classname == "body")
625                         if(deathtype == DEATH_KILL)
626                         {
627                                 // for the lemmings fans, a small harmless explosion
628                                 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
629                         }
630                 }
631
632                 if(!g_freezetag)
633                 {
634                         // become fully visible
635                         self.alpha = 1;
636                         // throw a weapon
637                         SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
638                 }
639
640                 // print an obituary message
641                 Obituary (attacker, inflictor, self, deathtype);
642                 race_PreDie();
643                 DropAllRunes(self);
644
645         // increment frag counter for used weapon type
646         float w;
647         w = DEATH_WEAPONOF(deathtype);
648         if(WEP_VALID(w))
649         if(self.classname == "player")
650         if(self != attacker)
651         attacker.accuracy.(accuracy_frags[w-1]) += 1;
652
653                 if(deathtype == DEATH_HURTTRIGGER && g_freezetag)
654                 {
655                         PutClientInServer();
656                         count_alive_players(); // re-count players
657                         freezetag_CheckWinner();
658                         return;
659                 }
660
661                 frag_attacker = attacker;
662                 frag_inflictor = inflictor;
663                 frag_target = self;
664                 MUTATOR_CALLHOOK(PlayerDies);
665                 weapon_action(self.weapon, WR_PLAYERDEATH);
666
667                 RemoveGrapplingHook(self);
668
669                 if(self.flagcarried)
670                 {
671                         if(attacker.classname != "player")
672                                 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
673                         else if(attacker.team == self.team)
674                                 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
675                         else
676                                 DropFlag(self.flagcarried, world, attacker);
677                 }
678                 if(self.ballcarried && g_nexball)
679                         DropBall(self.ballcarried, self.origin, self.velocity);
680                 Portal_ClearAllLater(self);
681
682                 if(clienttype(self) == CLIENTTYPE_REAL)
683                 {
684                         stuffcmd(self, "-zoom\n");
685                         self.fixangle = TRUE;
686                         //msg_entity = self;
687                         //WriteByte (MSG_ONE, SVC_SETANGLE);
688                         //WriteAngle (MSG_ONE, self.v_angle_x);
689                         //WriteAngle (MSG_ONE, self.v_angle_y);
690                         //WriteAngle (MSG_ONE, 80);
691                 }
692
693                 if(defer_ClientKill_Now_TeamChange) // TODO does this work with FreezeTag?
694                         ClientKill_Now_TeamChange();
695
696                 if(g_arena)
697                         Spawnqueue_Unmark(self);
698
699                 if(g_freezetag)
700                         return;
701
702                 // when we get here, player actually dies
703                 // clear waypoints (do this AFTER FreezeTag)
704                 WaypointSprite_PlayerDead();
705
706                 // make the corpse upright (not tilted)
707                 self.angles_x = 0;
708                 self.angles_z = 0;
709                 // don't spin
710                 self.avelocity = '0 0 0';
711                 // view from the floor
712                 self.view_ofs = '0 0 -8';
713                 // toss the corpse
714                 self.movetype = MOVETYPE_TOSS;
715                 // shootable corpse
716                 self.solid = SOLID_CORPSE;
717                 self.ballistics_density = autocvar_g_ballistics_density_corpse;
718                 // don't stick to the floor
719                 self.flags &~= FL_ONGROUND;
720                 // dying animation
721                 self.deadflag = DEAD_DYING;
722                 // when to allow respawn
723                 sdelay = 0;
724                 waves = 0;
725                 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
726                 if(!sdelay)
727                 {
728                         if(g_cts)
729                                 sdelay = 0; // no respawn delay in CTS
730                         else
731                                 sdelay = autocvar_g_respawn_delay;
732                 }
733                 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
734                 if(!waves)
735                         waves = autocvar_g_respawn_waves;
736                 if(waves)
737                         self.death_time = ceil((time + sdelay) / waves) * waves;
738                 else
739                         self.death_time = time + sdelay;
740                 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
741                         self.respawn_countdown = 10; // first number to count down from is 10
742                 else
743                         self.respawn_countdown = -1; // do not count down
744                 if (random() < 0.5)
745                 {
746                         setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
747                         self.dead_frame = self.anim_dead1_x;
748                 }
749                 else
750                 {
751                         setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
752                         self.dead_frame = self.anim_dead2_x;
753                 }
754                 // set damage function to corpse damage
755                 self.event_damage = PlayerCorpseDamage;
756                 // call the corpse damage function just in case it wants to gib
757                 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
758                 // set up to fade out later
759                 SUB_SetFade (self, time + 6 + random (), 1);
760
761                 if(sv_gentle > 0 || autocvar_ekg) {
762                         // remove corpse
763                         PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
764                 }
765
766                 // reset fields the weapons may use just in case
767                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
768                 {
769                         weapon_action(j, WR_RESETPLAYER);
770                         ATTACK_FINISHED_FOR(self, j) = 0;
771                 }
772         }
773 }
774
775 .float muted; // to be used by prvm_edictset server playernumber muted 1
776 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
777 // message "": do not say, just test flood control
778 // return value:
779 //   1 = accept
780 //   0 = reject
781 //  -1 = fake accept
782 {
783         string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, privatemsgprefix;
784         float flood, privatemsgprefixlen;
785         var .float flood_field;
786         entity head;
787         float ret;
788
789         if(Ban_MaybeEnforceBan(source))
790                 return 0;
791
792         if(!teamsay && !privatesay)
793                 if(substring(msgin, 0, 1) == " ")
794                         msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
795
796         msgin = formatmessage(msgin);
797
798         if(source.classname != "player")
799                 colorstr = "^0"; // black for spectators
800         else if(teamplay)
801                 colorstr = Team_ColorCode(source.team);
802         else
803                 teamsay = FALSE;
804
805         if(intermission_running)
806                 teamsay = FALSE;
807
808         if(msgin != "")
809                 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
810
811         /*
812          * using bprint solves this... me stupid
813         // how can we prevent the message from appearing in a listen server?
814         // for now, just give "say" back and only handle say_team
815         if(!teamsay)
816         {
817                 clientcommand(self, strcat("say ", msgin));
818                 return;
819         }
820         */
821
822         if(autocvar_g_chat_teamcolors)
823                 namestr = playername(source);
824         else
825                 namestr = source.netname;
826
827         if(msgin != "")
828         {
829                 if(privatesay)
830                 {
831                         msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
832                         privatemsgprefixlen = strlen(msgstr);
833                         msgstr = strcat(msgstr, msgin);
834                         cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
835                         if(autocvar_g_chat_teamcolors)
836                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
837                         else
838                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
839                 }
840                 else if(teamsay)
841                 {
842                         msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
843                         cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
844                 }
845                 else
846                 {
847                         msgstr = strcat("\{1}", namestr, "^7: ", msgin);
848                         cmsgstr = "";
849                 }
850                 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
851         }
852         else
853         {
854                 msgstr = cmsgstr = "";
855         }
856
857         fullmsgstr = msgstr;
858         fullcmsgstr = cmsgstr;
859
860         // FLOOD CONTROL
861         flood = 0;
862         if(floodcontrol)
863         {
864                 float flood_spl;
865                 float flood_burst;
866                 float flood_lmax;
867                 float lines;
868                 if(privatesay)
869                 {
870                         flood_spl = autocvar_g_chat_flood_spl_tell;
871                         flood_burst = autocvar_g_chat_flood_burst_tell;
872                         flood_lmax = autocvar_g_chat_flood_lmax_tell;
873                         flood_field = floodcontrol_chattell;
874                 }
875                 else if(teamsay)
876                 {
877                         flood_spl = autocvar_g_chat_flood_spl_team;
878                         flood_burst = autocvar_g_chat_flood_burst_team;
879                         flood_lmax = autocvar_g_chat_flood_lmax_team;
880                         flood_field = floodcontrol_chatteam;
881                 }
882                 else
883                 {
884                         flood_spl = autocvar_g_chat_flood_spl;
885                         flood_burst = autocvar_g_chat_flood_burst;
886                         flood_lmax = autocvar_g_chat_flood_lmax;
887                         flood_field = floodcontrol_chat;
888                 }
889                 flood_burst = max(0, flood_burst - 1);
890                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
891
892                 // do flood control for the default line size
893                 if(msgstr != "")
894                 {
895                         getWrappedLine_remaining = msgstr;
896                         msgstr = "";
897                         lines = 0;
898                         while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
899                         {
900                                 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
901                                 ++lines;
902                         }
903                         msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
904
905                         if(getWrappedLine_remaining != "")
906                         {
907                                 msgstr = strcat(msgstr, "\n");
908                                 flood = 2;
909                         }
910
911                         if(time >= source.flood_field)
912                         {
913                                 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
914                         }
915                         else
916                         {
917                                 flood = 1;
918                                 msgstr = fullmsgstr;
919                         }
920                 }
921                 else
922                 {
923                         if(time >= source.flood_field)
924                                 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
925                         else
926                                 flood = 1;
927                 }
928
929                 if (timeoutStatus == 2) //when game is paused, no flood protection
930                         source.flood_field = flood = 0;
931         }
932
933         if(flood == 2) // cannot happen for empty msgstr
934         {
935                 if(autocvar_g_chat_flood_notify_flooder)
936                 {
937                         sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
938                         sourcecmsgstr = "";
939                 }
940                 else
941                 {
942                         sourcemsgstr = fullmsgstr;
943                         sourcecmsgstr = fullcmsgstr;
944                 }
945                 cmsgstr = "";
946         }
947         else
948         {
949                 sourcemsgstr = msgstr;
950                 sourcecmsgstr = cmsgstr;
951         }
952
953         if(!privatesay)
954         if(source.classname != "player")
955         {
956                 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !inWarmupStage))
957                         teamsay = -1; // spectators
958         }
959
960         if(flood)
961                 print("NOTE: ", playername(source), "^7 is flooding.\n");
962
963         // build sourcemsgstr by cutting off a prefix and replacing it by the other one
964         if(privatesay)
965                 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
966
967         if(source.muted)
968         {
969                 // always fake the message
970                 ret = -1;
971         }
972         else if(flood == 1)
973         {
974                 if(autocvar_g_chat_flood_notify_flooder)
975                 {
976                         sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
977                         ret = 0;
978                 }
979                 else
980                         ret = -1;
981         }
982         else
983         {
984                 ret = 1;
985         }
986
987         if(sourcemsgstr != "" && ret != 0)
988         {
989                 if(ret < 0) // fake
990                 {
991                         sprint(source, sourcemsgstr);
992                         if(sourcecmsgstr != "" && !privatesay)
993                                 centerprint(source, sourcecmsgstr);
994                 }
995                 else if(privatesay)
996                 {
997                         sprint(source, sourcemsgstr);
998                         sprint(privatesay, msgstr);
999                         if(cmsgstr != "")
1000                                 centerprint(privatesay, cmsgstr);
1001                 }
1002                 else if(teamsay > 0)
1003                 {
1004                         sprint(source, sourcemsgstr);
1005                         if(sourcecmsgstr != "")
1006                                 centerprint(source, sourcecmsgstr);
1007                         FOR_EACH_REALPLAYER(head) if(head.team == source.team)
1008                                 if(head != source)
1009                                 {
1010                                         sprint(head, msgstr);
1011                                         if(cmsgstr != "")
1012                                                 centerprint(head, cmsgstr);
1013                                 }
1014                 }
1015                 else if(teamsay < 0)
1016                 {
1017                         sprint(source, sourcemsgstr);
1018                         FOR_EACH_REALCLIENT(head) if(head.classname != "player")
1019                                 if(head != source)
1020                                         sprint(head, msgstr);
1021                 }
1022                 else if(sourcemsgstr != msgstr)
1023                 {
1024                         sprint(source, sourcemsgstr);
1025                         FOR_EACH_REALCLIENT(head)
1026                                 if(head != source)
1027                                         sprint(head, msgstr);
1028                 }
1029                 else
1030                         bprint(msgstr);
1031         }
1032
1033         return ret;
1034 }
1035
1036 float GetVoiceMessageVoiceType(string type)
1037 {
1038         if(type == "taunt")
1039                 return VOICETYPE_TAUNT;
1040         if(type == "teamshoot")
1041                 return VOICETYPE_LASTATTACKER;
1042         return VOICETYPE_TEAMRADIO;
1043 }
1044
1045 string allvoicesamples;
1046 .string GetVoiceMessageSampleField(string type)
1047 {
1048         GetPlayerSoundSampleField_notFound = 0;
1049         switch(type)
1050         {
1051 #define _VOICEMSG(m) case #m: return playersound_##m;
1052                 ALLVOICEMSGS
1053 #undef _VOICEMSG
1054         }
1055         GetPlayerSoundSampleField_notFound = 1;
1056         return playersound_taunt;
1057 }
1058
1059 .string GetPlayerSoundSampleField(string type)
1060 {
1061         GetPlayerSoundSampleField_notFound = 0;
1062         switch(type)
1063         {
1064 #define _VOICEMSG(m) case #m: return playersound_##m;
1065                 ALLPLAYERSOUNDS
1066 #undef _VOICEMSG
1067         }
1068         GetPlayerSoundSampleField_notFound = 1;
1069         return playersound_taunt;
1070 }
1071
1072 void PrecacheGlobalSound(string samplestring)
1073 {
1074         float n, i;
1075         tokenize_console(samplestring);
1076         n = stof(argv(1));
1077         if(n > 0)
1078         {
1079                 for(i = 1; i <= n; ++i)
1080                         precache_sound(strcat(argv(0), ftos(i), ".wav"));
1081         }
1082         else
1083         {
1084                 precache_sound(strcat(argv(0), ".wav"));
1085         }
1086 }
1087
1088 void PrecachePlayerSounds(string f)
1089 {
1090         float fh;
1091         string s;
1092         fh = fopen(f, FILE_READ);
1093         if(fh < 0)
1094                 return;
1095         while((s = fgets(fh)))
1096         {
1097                 if(tokenize_console(s) != 3)
1098                 {
1099                         dprint("Invalid sound info line: ", s, "\n");
1100                         continue;
1101                 }
1102                 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1103         }
1104         fclose(fh);
1105
1106         if not(allvoicesamples)
1107         {
1108 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1109                 ALLVOICEMSGS
1110 #undef _VOICEMSG
1111                 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1112         }
1113 }
1114
1115 void ClearPlayerSounds()
1116 {
1117 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1118         ALLPLAYERSOUNDS
1119         ALLVOICEMSGS
1120 #undef _VOICEMSG
1121 }
1122
1123 float LoadPlayerSounds(string f, float first)
1124 {
1125         float fh;
1126         string s;
1127         var .string field;
1128         fh = fopen(f, FILE_READ);
1129         if(fh < 0)
1130         {
1131                 dprint("Player sound file not found: ", f, "\n");
1132                 return 0;
1133         }
1134         while((s = fgets(fh)))
1135         {
1136                 if(tokenize_console(s) != 3)
1137                         continue;
1138                 field = GetPlayerSoundSampleField(argv(0));
1139                 if(GetPlayerSoundSampleField_notFound)
1140                         field = GetVoiceMessageSampleField(argv(0));
1141                 if(GetPlayerSoundSampleField_notFound)
1142                         continue;
1143                 if(self.field)
1144                         strunzone(self.field);
1145                 self.field = strzone(strcat(argv(1), " ", argv(2)));
1146         }
1147         fclose(fh);
1148         return 1;
1149 }
1150
1151 .float modelindex_for_playersound;
1152 .float skinindex_for_playersound;
1153 void UpdatePlayerSounds()
1154 {
1155         if(self.modelindex == self.modelindex_for_playersound)
1156         if(self.skinindex == self.skinindex_for_playersound)
1157                 return;
1158         self.modelindex_for_playersound = self.modelindex;
1159         self.skinindex_for_playersound = self.skinindex;
1160         ClearPlayerSounds();
1161         LoadPlayerSounds("sound/player/default.sounds", 1);
1162         if(!autocvar_g_debug_defaultsounds)
1163                 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skinindex, "sounds"), 0))
1164                         LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1165 }
1166
1167 void FakeGlobalSound(string sample, float chan, float voicetype)
1168 {
1169         float n;
1170         float tauntrand;
1171
1172         if(sample == "")
1173                 return;
1174
1175         tokenize_console(sample);
1176         n = stof(argv(1));
1177         if(n > 0)
1178                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1179         else
1180                 sample = strcat(argv(0), ".wav"); // randomization
1181
1182         switch(voicetype)
1183         {
1184                 case VOICETYPE_LASTATTACKER_ONLY:
1185                         break;
1186                 case VOICETYPE_LASTATTACKER:
1187                         if(self.pusher)
1188                         {
1189                                 msg_entity = self;
1190                                 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1191                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1192                         }
1193                         break;
1194                 case VOICETYPE_TEAMRADIO:
1195                         msg_entity = self;
1196                         if(msg_entity.cvar_cl_voice_directional == 1)
1197                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1198                         else
1199                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1200                         break;
1201                 case VOICETYPE_AUTOTAUNT:
1202                         if(!sv_autotaunt)
1203                                 break;
1204                         if(!sv_taunt)
1205                                 break;
1206                         if(sv_gentle)
1207                                 break;
1208                         tauntrand = random();
1209                         msg_entity = self;
1210                         if (tauntrand < msg_entity.cvar_cl_autotaunt)
1211                         {
1212                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1213                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1214                                 else
1215                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1216                         }
1217                         break;
1218                 case VOICETYPE_TAUNT:
1219                         if(self.classname == "player")
1220                                 if(self.deadflag == DEAD_NO)
1221                                         setanim(self, self.anim_taunt, FALSE, TRUE, TRUE);
1222                         if(!sv_taunt)
1223                                 break;
1224                         if(sv_gentle)
1225                                 break;
1226                         msg_entity = self;
1227                         if (msg_entity.cvar_cl_voice_directional >= 1)
1228                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1229                         else
1230                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1231                         break;
1232                 case VOICETYPE_PLAYERSOUND:
1233                         msg_entity = self;
1234                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NORM);
1235                         break;
1236                 default:
1237                         backtrace("Invalid voice type!");
1238                         break;
1239         }
1240 }
1241
1242 void GlobalSound(string sample, float chan, float voicetype)
1243 {
1244         float n;
1245         float tauntrand;
1246
1247         if(sample == "")
1248                 return;
1249
1250         tokenize_console(sample);
1251         n = stof(argv(1));
1252         if(n > 0)
1253                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1254         else
1255                 sample = strcat(argv(0), ".wav"); // randomization
1256
1257         switch(voicetype)
1258         {
1259                 case VOICETYPE_LASTATTACKER_ONLY:
1260                         if(self.pusher)
1261                         {
1262                                 msg_entity = self.pusher;
1263                                 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1264                                 {
1265                                         if(msg_entity.cvar_cl_voice_directional == 1)
1266                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1267                                         else
1268                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1269                                 }
1270                         }
1271                         break;
1272                 case VOICETYPE_LASTATTACKER:
1273                         if(self.pusher)
1274                         {
1275                                 msg_entity = self.pusher;
1276                                 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1277                                 {
1278                                         if(msg_entity.cvar_cl_voice_directional == 1)
1279                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1280                                         else
1281                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1282                                 }
1283                                 msg_entity = self;
1284                                 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1285                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1286                         }
1287                         break;
1288                 case VOICETYPE_TEAMRADIO:
1289                         FOR_EACH_REALCLIENT(msg_entity)
1290                                 if(!teamplay || msg_entity.team == self.team)
1291                                 {
1292                                         if(msg_entity.cvar_cl_voice_directional == 1)
1293                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1294                                         else
1295                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1296                                 }
1297                         break;
1298                 case VOICETYPE_AUTOTAUNT:
1299                         if(!sv_autotaunt)
1300                                 break;
1301                         if(!sv_taunt)
1302                                 break;
1303                         if(sv_gentle)
1304                                 break;
1305                         tauntrand = random();
1306                         FOR_EACH_REALCLIENT(msg_entity)
1307                                 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1308                                 {
1309                                         if (msg_entity.cvar_cl_voice_directional >= 1)
1310                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1311                                         else
1312                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1313                                 }
1314                         break;
1315                 case VOICETYPE_TAUNT:
1316                         if(self.classname == "player")
1317                                 if(self.deadflag == DEAD_NO)
1318                                         setanim(self, self.anim_taunt, FALSE, TRUE, TRUE);
1319                         if(!sv_taunt)
1320                                 break;
1321                         if(sv_gentle)
1322                                 break;
1323                         FOR_EACH_REALCLIENT(msg_entity)
1324                         {
1325                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1326                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1327                                 else
1328                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1329                         }
1330                         break;
1331                 case VOICETYPE_PLAYERSOUND:
1332                         sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1333                         break;
1334                 default:
1335                         backtrace("Invalid voice type!");
1336                         break;
1337         }
1338 }
1339
1340 void PlayerSound(.string samplefield, float chan, float voicetype)
1341 {
1342         GlobalSound(self.samplefield, chan, voicetype);
1343 }
1344
1345 void VoiceMessage(string type, string msg)
1346 {
1347         var .string sample;
1348         float voicetype, ownteam;
1349         float flood;
1350         sample = GetVoiceMessageSampleField(type);
1351
1352         if(GetPlayerSoundSampleField_notFound)
1353         {
1354                 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1355                 return;
1356         }
1357
1358         voicetype = GetVoiceMessageVoiceType(type);
1359         ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1360
1361         flood = Say(self, ownteam, world, msg, 1);
1362
1363         if (flood > 0)
1364                 GlobalSound(self.sample, CH_VOICE, voicetype);
1365         else if (flood < 0)
1366                 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1367 }
1368
1369 void MoveToTeam(entity client, float team_colour, float type, float show_message)
1370 {
1371 //      show_message
1372 //      0 (00) automove centerprint, admin message
1373 //      1 (01) automove centerprint, no admin message
1374 //      2 (10) no centerprint, admin message
1375 //      3 (11) no centerprint, no admin message
1376
1377         float lockteams_backup;
1378
1379         lockteams_backup = lockteams;  // backup any team lock
1380
1381         lockteams = 0;  // disable locked teams
1382
1383         TeamchangeFrags(client);  // move the players frags
1384         SetPlayerColors(client, team_colour - 1);  // set the players colour
1385         Damage(client, client, client, 100000, ((show_message & 2) ? DEATH_QUIET : DEATH_AUTOTEAMCHANGE), client.origin, '0 0 0');  // kill the player
1386
1387         lockteams = lockteams_backup;  // restore the team lock
1388
1389         LogTeamchange(client.playerid, client.team, type);
1390
1391         if not(show_message & 1) // admin message
1392                 sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: You have been moved to the ", Team_ColorNameLowerCase(team_colour), " team\n"));  // send a chat message
1393
1394         bprint(strcat(client.netname, " joined the ", ColoredTeamName(client.team), "\n"));
1395 }