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