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