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