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