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