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