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