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