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