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