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