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