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