2 .float accuracy_frags[WEP_MAXCOUNT];
4 float weaponstats_buffer;
6 void WeaponStats_Init()
8 if(autocvar_sv_weaponstats_file != "")
9 weaponstats_buffer = buf_create();
11 weaponstats_buffer = -1;
14 #define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot))
16 void WeaponStats_ready(entity fh, entity pass, float status)
18 float i, j, n, ibot, jbot, idx;
23 case URL_READY_CANWRITE:
24 // url_fopen returned, we can write
25 prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
26 url_fputs(fh, "#begin statsfile\n");
27 url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
29 url_fputs(fh, strcat("#version ", WATERMARK(), "\n"));
31 url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_purechanges)), "\n"));
32 url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n"));
33 n = tokenizebyseparator(cvar_purechanges, "\n");
34 for(i = 0; i < n; ++i)
35 url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n"));
36 for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot)
37 for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot)
39 idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot);
40 v = stov(bufstr_get(weaponstats_buffer, idx));
43 //vector is: kills hits damage
44 url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
45 url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
48 url_fputs(fh, "#end\n\n");
49 url_fclose(fh, WeaponStats_ready, world);
50 buf_del(weaponstats_buffer);
51 weaponstats_buffer = -1;
53 case URL_READY_CANREAD:
54 // url_fclose is processing, we got a response for writing the data
55 // this must come from HTTP
56 print("Got response from weapon stats server:\n");
57 while((s = url_fgets(fh)))
59 print("End of response.\n");
60 url_fclose(fh, WeaponStats_ready, world);
62 case URL_READY_CLOSED:
63 // url_fclose has finished
64 print("Weapon stats written\n");
68 print("Weapon stats writing failed: ", ftos(status), "\n");
73 void WeaponStats_Shutdown()
75 if(weaponstats_buffer < 0)
77 if(autocvar_sv_weaponstats_file != "")
79 url_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world);
83 buf_del(weaponstats_buffer);
84 weaponstats_buffer = -1;
88 void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item)
91 if(weaponstats_buffer < 0)
93 if(awep < WEP_FIRST || vwep < WEP_FIRST)
95 if(awep > WEP_LAST || vwep > WEP_LAST)
97 idx = WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot);
98 bufstr_set(weaponstats_buffer, idx, vtos(stov(bufstr_get(weaponstats_buffer, idx)) + item));
100 void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage)
103 error("negative damage?");
104 WeaponStats_LogItem(awep, abot, vwep, vbot, '0 0 1' * damage + '0 1 0');
106 void WeaponStats_LogKill(float awep, float abot, float vwep, float vbot)
108 WeaponStats_LogItem(awep, abot, vwep, vbot, '1 0 0');
111 // changes by LordHavoc on 03/29/04 and 03/30/04 at Vermeulen's request
112 // merged player_run and player_stand to player_anim
113 // added death animations to player_anim
114 // can now spawn thrown weapons from anywhere, not just from players
115 // thrown weapons now fade out after 20 seconds
116 // created PlayerGib function
117 // PlayerDie no longer uses hitloc or damage
118 // PlayerDie now supports dying animations as well as gibbing
119 // cleaned up PlayerDie a lot
125 void CopyBody(float keepvelocity)
127 local entity oldself;
128 if (self.effects & EF_NODRAW)
132 self.enemy = oldself;
133 self.lip = oldself.lip;
134 self.colormap = oldself.colormap;
135 self.glowmod = oldself.glowmod;
136 self.iscreature = oldself.iscreature;
137 self.damagedbycontents = oldself.damagedbycontents;
138 self.angles = oldself.angles;
139 self.avelocity = oldself.avelocity;
140 self.classname = "body";
141 self.damageforcescale = oldself.damageforcescale;
142 self.effects = oldself.effects;
143 self.event_damage = oldself.event_damage;
144 self.animstate_startframe = oldself.animstate_startframe;
145 self.animstate_numframes = oldself.animstate_numframes;
146 self.animstate_framerate = oldself.animstate_framerate;
147 self.animstate_starttime = oldself.animstate_starttime;
148 self.animstate_endtime = oldself.animstate_endtime;
149 self.animstate_override = oldself.animstate_override;
150 self.animstate_looping = oldself.animstate_looping;
151 self.frame = oldself.frame;
152 self.dead_frame = oldself.dead_frame;
153 self.pain_finished = oldself.pain_finished;
154 self.health = oldself.health;
155 self.armorvalue = oldself.armorvalue;
156 self.armortype = oldself.armortype;
157 self.model = oldself.model;
158 self.modelindex = oldself.modelindex;
159 self.modelindex_lod0 = oldself.modelindex_lod0;
160 self.modelindex_lod0_from_xonotic = oldself.modelindex_lod0_from_xonotic;
161 self.modelindex_lod1 = oldself.modelindex_lod1;
162 self.modelindex_lod2 = oldself.modelindex_lod2;
163 self.skinindex = oldself.skinindex;
164 self.species = oldself.species;
165 self.movetype = oldself.movetype;
166 self.nextthink = oldself.nextthink;
167 self.solid = oldself.solid;
168 self.ballistics_density = oldself.ballistics_density;
169 self.takedamage = oldself.takedamage;
170 self.think = oldself.think;
171 self.customizeentityforclient = oldself.customizeentityforclient;
172 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
173 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
174 if (keepvelocity == 1)
175 self.velocity = oldself.velocity;
176 self.oldvelocity = self.velocity;
177 self.fade_time = oldself.fade_time;
178 self.fade_rate = oldself.fade_rate;
179 //self.weapon = oldself.weapon;
180 setorigin(self, oldself.origin);
181 setsize(self, oldself.mins, oldself.maxs);
182 self.prevorigin = oldself.origin;
183 self.reset = SUB_Remove;
185 Drag_MoveDrag(oldself, self);
190 float player_getspecies()
193 get_model_parameters(self.model, self.skinindex);
194 s = get_model_parameters_species;
195 get_model_parameters(string_null, 0);
197 return SPECIES_HUMAN;
201 void player_setupanimsformodel()
203 local string animfilename;
204 local float animfile;
205 // defaults for legacy .zym models without animinfo files
206 self.anim_die1 = '0 1 0.5'; // 2 seconds
207 self.anim_die2 = '1 1 0.5'; // 2 seconds
208 self.anim_draw = '2 1 3'; // TODO: analyze models and set framerate
209 self.anim_duck = '3 1 100'; // this anim seems bogus in most models, so make it play VERY briefly!
210 self.anim_duckwalk = '4 1 1';
211 self.anim_duckjump = '5 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
212 self.anim_duckidle = '6 1 1';
213 self.anim_idle = '7 1 1';
214 self.anim_jump = '8 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
215 self.anim_pain1 = '9 1 2'; // 0.5 seconds
216 self.anim_pain2 = '10 1 2'; // 0.5 seconds
217 self.anim_shoot = '11 1 5'; // TODO: analyze models and set framerate
218 self.anim_taunt = '12 1 0.33'; // FIXME? there is no code using this anim
219 self.anim_run = '13 1 1';
220 self.anim_runbackwards = '14 1 1';
221 self.anim_strafeleft = '15 1 1';
222 self.anim_straferight = '16 1 1';
223 self.anim_dead1 = '17 1 1';
224 self.anim_dead2 = '18 1 1';
225 self.anim_forwardright = '19 1 1';
226 self.anim_forwardleft = '20 1 1';
227 self.anim_backright = '21 1 1';
228 self.anim_backleft = '22 1 1';
229 self.anim_melee = '23 1 1';
230 animparseerror = FALSE;
231 animfilename = strcat(self.model, ".animinfo");
232 animfile = fopen(animfilename, FILE_READ);
235 self.anim_die1 = animparseline(animfile);
236 self.anim_die2 = animparseline(animfile);
237 self.anim_draw = animparseline(animfile);
238 self.anim_duck = animparseline(animfile);
239 self.anim_duckwalk = animparseline(animfile);
240 self.anim_duckjump = animparseline(animfile);
241 self.anim_duckidle = animparseline(animfile);
242 self.anim_idle = animparseline(animfile);
243 self.anim_jump = animparseline(animfile);
244 self.anim_pain1 = animparseline(animfile);
245 self.anim_pain2 = animparseline(animfile);
246 self.anim_shoot = animparseline(animfile);
247 self.anim_taunt = animparseline(animfile);
248 self.anim_run = animparseline(animfile);
249 self.anim_runbackwards = animparseline(animfile);
250 self.anim_strafeleft = animparseline(animfile);
251 self.anim_straferight = animparseline(animfile);
252 self.anim_forwardright = animparseline(animfile);
253 self.anim_forwardleft = animparseline(animfile);
254 self.anim_backright = animparseline(animfile);
255 self.anim_backleft = animparseline(animfile);
256 self.anim_melee = animparseline(animfile);
260 self.anim_dead1 = '0 1 1' + '1 0 0' * (self.anim_die1_x + self.anim_die1_y - 1);
261 self.anim_dead2 = '0 1 1' + '1 0 0' * (self.anim_die2_x + self.anim_die2_y - 1);
264 print("Parse error in ", animfilename, ", some player animations are broken\n");
267 dprint("File ", animfilename, " not found, assuming legacy .zym model animation timings\n");
268 // reset animstate now
269 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
272 void player_anim (void)
275 if (self.weaponentity)
276 updateanim(self.weaponentity);
278 if (self.deadflag != DEAD_NO)
280 if (time > self.animstate_endtime)
285 setsize(self, self.mins, self.maxs);
287 self.frame = self.dead_frame;
292 if (!self.animstate_override)
294 if (!(self.flags & FL_ONGROUND))
297 setanim(self, self.anim_duckjump, FALSE, TRUE, self.restart_jump);
299 setanim(self, self.anim_jump, FALSE, TRUE, self.restart_jump);
300 self.restart_jump = FALSE;
302 else if (self.crouch)
304 if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
305 setanim(self, self.anim_duckwalk, TRUE, FALSE, FALSE);
307 setanim(self, self.anim_duckidle, TRUE, FALSE, FALSE);
309 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
311 if (self.movement_x > 0 && self.movement_y == 0)
312 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
313 else if (self.movement_x < 0 && self.movement_y == 0)
314 setanim(self, self.anim_runbackwards, TRUE, FALSE, FALSE);
315 else if (self.movement_x == 0 && self.movement_y > 0)
316 setanim(self, self.anim_straferight, TRUE, FALSE, FALSE);
317 else if (self.movement_x == 0 && self.movement_y < 0)
318 setanim(self, self.anim_strafeleft, TRUE, FALSE, FALSE);
319 else if (self.movement_x > 0 && self.movement_y > 0)
320 setanim(self, self.anim_forwardright, TRUE, FALSE, FALSE);
321 else if (self.movement_x > 0 && self.movement_y < 0)
322 setanim(self, self.anim_forwardleft, TRUE, FALSE, FALSE);
323 else if (self.movement_x < 0 && self.movement_y > 0)
324 setanim(self, self.anim_backright, TRUE, FALSE, FALSE);
325 else if (self.movement_x < 0 && self.movement_y < 0)
326 setanim(self, self.anim_backleft, TRUE, FALSE, FALSE);
328 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
331 setanim(self, self.anim_idle, TRUE, FALSE, FALSE);
334 if (self.weaponentity)
335 if (!self.weaponentity.animstate_override)
336 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
339 void SpawnThrownWeapon (vector org, float w)
342 if(self.ammo_cells <= 0)
348 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
350 if(self.weapons & W_WeaponBit(j))
351 if(W_IsWeaponThrowable(j))
352 W_ThrowNewWeapon(self, j, FALSE, org, randomvec() * 175 + '0 0 325');
357 if(W_IsWeaponThrowable(self.weapon))
358 W_ThrowNewWeapon(self, self.weapon, FALSE, org, randomvec() * 125 + '0 0 200');
362 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
364 local float take, save;
366 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
368 // damage resistance (ignore most of the damage from a bullet or similar)
369 damage = max(damage - 5, 1);
371 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
375 if(sound_allowed(MSG_BROADCAST, attacker))
378 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
380 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
382 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
386 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
388 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
390 if (!(self.flags & FL_GODMODE))
392 self.armorvalue = self.armorvalue - save;
393 self.health = self.health - take;
394 // pause regeneration for 5 seconds
395 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
397 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
398 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
399 self.dmg_inflictor = inflictor;
401 if (self.health <= -autocvar_sv_gibhealth && self.modelindex != 0)
403 // don't use any animations as a gib
406 // view just above the floor
407 self.view_ofs = '0 0 4';
409 Violence_GibSplash(self, 1, 1, attacker);
410 self.modelindex = 0; // restore later
411 self.solid = SOLID_NOT; // restore later
415 void ClientKill_Now_TeamChange();
416 void freezetag_CheckWinner();
418 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
420 local float take, save, waves, sdelay, dh, da, j;
422 float valid_damage_for_weaponstats;
425 if((g_arena && numspawned < 2) || (g_ca && !ca_teams_ok) && !inWarmupStage)
428 dh = max(self.health, 0);
429 da = max(self.armorvalue, 0);
431 if(!DEATH_ISSPECIAL(deathtype))
433 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
435 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
438 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
440 // tuba causes blood to come out of the ears
445 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
447 makevectors(self.angles);
448 ear1 += v_right * -10;
449 ear2 += v_right * +10;
450 d = inflictor.origin - self.origin;
451 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
452 force = v_right * vlen(force);
453 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
454 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
463 // force is already good
467 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
471 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
481 frag_inflictor = inflictor;
482 frag_attacker = attacker;
486 damage_force = force;
487 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
488 take = bound(0, damage_take, self.health);
489 save = bound(0, damage_save, self.armorvalue);
490 excess = max(0, damage - take - save);
492 if(sound_allowed(MSG_BROADCAST, attacker))
495 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
497 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
499 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
503 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
505 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
507 if (time >= self.spawnshieldtime)
509 if (!(self.flags & FL_GODMODE))
511 self.armorvalue = self.armorvalue - save;
512 self.health = self.health - take;
513 // pause regeneration for 5 seconds
514 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
516 if (time > self.pain_finished) //Don't switch pain sequences like crazy
518 self.pain_finished = time + 0.5; //Supajoe
521 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
524 setanim(self, self.anim_pain1, FALSE, TRUE, TRUE);
526 setanim(self, self.anim_pain2, FALSE, TRUE, TRUE);
529 if(sound_allowed(MSG_BROADCAST, attacker))
530 if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * autocvar_g_balance_laser_primary_damage * autocvar_g_balance_selfdamagepercent + 1)
532 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
534 if(deathtype == DEATH_FALL)
535 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
536 else if(self.health > 75) // TODO make a "gentle" version?
537 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
538 else if(self.health > 50)
539 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
540 else if(self.health > 25)
541 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
543 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
547 // throw off bot aim temporarily
549 shake = damage * 5 / (bound(0,skill,100) + 1);
550 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
551 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
555 self.max_armorvalue += (save + take);
557 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
558 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
559 self.dmg_inflictor = inflictor;
563 // don't reset pushltime for self damage as it may be an attempt to
564 // escape a lava pit or similar
565 //self.pushltime = 0;
567 else if(attacker.classname == "player")
569 self.pusher = attacker;
570 self.pushltime = time + autocvar_g_maxpushtime;
572 else if(time < self.pushltime)
574 attacker = self.pusher;
575 self.pushltime = max(self.pushltime, time + 0.6);
580 float abot, vbot, awep;
581 abot = (clienttype(attacker) == CLIENTTYPE_BOT);
582 vbot = (clienttype(self) == CLIENTTYPE_BOT);
584 valid_damage_for_weaponstats = 0;
585 if(vbot || clienttype(self) == CLIENTTYPE_REAL)
586 if(abot || clienttype(attacker) == CLIENTTYPE_REAL)
587 if(attacker && self != attacker)
588 if(IsDifferentTeam(self, attacker))
590 if(DEATH_ISSPECIAL(deathtype))
591 awep = attacker.weapon;
593 awep = DEATH_WEAPONOF(deathtype);
594 valid_damage_for_weaponstats = 1;
597 if(valid_damage_for_weaponstats)
599 dh = dh - max(self.health, 0);
600 da = da - max(self.armorvalue, 0);
601 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
606 float defer_ClientKill_Now_TeamChange;
607 defer_ClientKill_Now_TeamChange = FALSE;
611 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
615 if(valid_damage_for_weaponstats)
616 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
618 if(sv_gentle < 1) // TODO make a "gentle" version?
619 if(sound_allowed(MSG_BROADCAST, attacker))
621 if(deathtype == DEATH_DROWN)
622 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
624 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
627 // get rid of kill indicator
628 if(self.killindicator)
630 remove(self.killindicator);
631 self.killindicator = world;
632 if(self.killindicator_teamchange)
633 defer_ClientKill_Now_TeamChange = TRUE;
635 if(self.classname == "body")
636 if(deathtype == DEATH_KILL)
638 // for the lemmings fans, a small harmless explosion
639 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
645 // become fully visible
648 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
651 // print an obituary message
652 Obituary (attacker, inflictor, self, deathtype);
656 // increment frag counter for used weapon type
658 w = DEATH_WEAPONOF(deathtype);
660 if(self.classname == "player")
662 attacker.accuracy.(accuracy_frags[w-1]) += 1;
664 if(deathtype == DEATH_HURTTRIGGER && g_freezetag)
667 count_alive_players(); // re-count players
668 freezetag_CheckWinner();
672 frag_attacker = attacker;
673 frag_inflictor = inflictor;
675 MUTATOR_CALLHOOK(PlayerDies);
676 weapon_action(self.weapon, WR_PLAYERDEATH);
680 if(attacker.classname != "player")
681 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
682 else if(attacker.team == self.team)
683 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
685 DropFlag(self.flagcarried, world, attacker);
687 if(self.ballcarried && g_nexball)
688 DropBall(self.ballcarried, self.origin, self.velocity);
689 Portal_ClearAllLater(self);
691 if(clienttype(self) == CLIENTTYPE_REAL)
693 stuffcmd(self, "-zoom\n");
694 self.fixangle = TRUE;
696 //WriteByte (MSG_ONE, SVC_SETANGLE);
697 //WriteAngle (MSG_ONE, self.v_angle_x);
698 //WriteAngle (MSG_ONE, self.v_angle_y);
699 //WriteAngle (MSG_ONE, 80);
702 if(defer_ClientKill_Now_TeamChange) // TODO does this work with FreezeTag?
703 ClientKill_Now_TeamChange();
706 Spawnqueue_Unmark(self);
711 // when we get here, player actually dies
712 // clear waypoints (do this AFTER FreezeTag)
713 WaypointSprite_PlayerDead();
715 // make the corpse upright (not tilted)
719 self.avelocity = '0 0 0';
720 // view from the floor
721 self.view_ofs = '0 0 -8';
723 self.movetype = MOVETYPE_TOSS;
725 self.solid = SOLID_CORPSE;
726 self.ballistics_density = autocvar_g_ballistics_density_corpse;
727 // don't stick to the floor
728 self.flags &~= FL_ONGROUND;
730 self.deadflag = DEAD_DYING;
731 // when to allow respawn
734 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
738 sdelay = 0; // no respawn delay in CTS
740 sdelay = autocvar_g_respawn_delay;
742 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
744 waves = autocvar_g_respawn_waves;
746 self.death_time = ceil((time + sdelay) / waves) * waves;
748 self.death_time = time + sdelay;
749 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
750 self.respawn_countdown = 10; // first number to count down from is 10
752 self.respawn_countdown = -1; // do not count down
755 setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
756 self.dead_frame = self.anim_dead1_x;
760 setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
761 self.dead_frame = self.anim_dead2_x;
763 // set damage function to corpse damage
764 self.event_damage = PlayerCorpseDamage;
765 // call the corpse damage function just in case it wants to gib
766 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
767 // set up to fade out later
768 SUB_SetFade (self, time + 6 + random (), 1);
770 if(sv_gentle > 0 || autocvar_ekg) {
772 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
775 // reset fields the weapons may use just in case
776 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
778 weapon_action(j, WR_RESETPLAYER);
779 ATTACK_FINISHED_FOR(self, j) = 0;
784 .float muted; // to be used by prvm_edictset server playernumber muted 1
785 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
786 // message "": do not say, just test flood control
792 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, privatemsgprefix;
793 float flood, privatemsgprefixlen;
794 var .float flood_field;
798 if(Ban_MaybeEnforceBan(source))
801 if(!teamsay && !privatesay)
802 if(substring(msgin, 0, 1) == " ")
803 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
805 msgin = formatmessage(msgin);
807 if(source.classname != "player")
808 colorstr = "^0"; // black for spectators
810 colorstr = Team_ColorCode(source.team);
814 if(intermission_running)
818 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
821 * using bprint solves this... me stupid
822 // how can we prevent the message from appearing in a listen server?
823 // for now, just give "say" back and only handle say_team
826 clientcommand(self, strcat("say ", msgin));
831 if(autocvar_g_chat_teamcolors)
832 namestr = playername(source);
834 namestr = source.netname;
840 msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
841 privatemsgprefixlen = strlen(msgstr);
842 msgstr = strcat(msgstr, msgin);
843 cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
844 if(autocvar_g_chat_teamcolors)
845 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
847 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
851 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
852 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
856 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
859 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
863 msgstr = cmsgstr = "";
867 fullcmsgstr = cmsgstr;
879 flood_spl = autocvar_g_chat_flood_spl_tell;
880 flood_burst = autocvar_g_chat_flood_burst_tell;
881 flood_lmax = autocvar_g_chat_flood_lmax_tell;
882 flood_field = floodcontrol_chattell;
886 flood_spl = autocvar_g_chat_flood_spl_team;
887 flood_burst = autocvar_g_chat_flood_burst_team;
888 flood_lmax = autocvar_g_chat_flood_lmax_team;
889 flood_field = floodcontrol_chatteam;
893 flood_spl = autocvar_g_chat_flood_spl;
894 flood_burst = autocvar_g_chat_flood_burst;
895 flood_lmax = autocvar_g_chat_flood_lmax;
896 flood_field = floodcontrol_chat;
898 flood_burst = max(0, flood_burst - 1);
899 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
901 // do flood control for the default line size
904 getWrappedLine_remaining = msgstr;
907 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
909 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
912 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
914 if(getWrappedLine_remaining != "")
916 msgstr = strcat(msgstr, "\n");
920 if(time >= source.flood_field)
922 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
932 if(time >= source.flood_field)
933 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
938 if (timeoutStatus == 2) //when game is paused, no flood protection
939 source.flood_field = flood = 0;
942 if(flood == 2) // cannot happen for empty msgstr
944 if(autocvar_g_chat_flood_notify_flooder)
946 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
951 sourcemsgstr = fullmsgstr;
952 sourcecmsgstr = fullcmsgstr;
958 sourcemsgstr = msgstr;
959 sourcecmsgstr = cmsgstr;
963 if(source.classname != "player")
965 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !inWarmupStage))
966 teamsay = -1; // spectators
970 print("NOTE: ", playername(source), "^7 is flooding.\n");
972 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
974 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
978 // always fake the message
983 if(autocvar_g_chat_flood_notify_flooder)
985 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
996 if(sourcemsgstr != "" && ret != 0)
1000 sprint(source, sourcemsgstr);
1001 if(sourcecmsgstr != "" && !privatesay)
1002 centerprint(source, sourcecmsgstr);
1006 sprint(source, sourcemsgstr);
1007 sprint(privatesay, msgstr);
1009 centerprint(privatesay, cmsgstr);
1011 else if(teamsay > 0)
1013 sprint(source, sourcemsgstr);
1014 if(sourcecmsgstr != "")
1015 centerprint(source, sourcecmsgstr);
1016 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
1019 sprint(head, msgstr);
1021 centerprint(head, cmsgstr);
1024 else if(teamsay < 0)
1026 sprint(source, sourcemsgstr);
1027 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
1029 sprint(head, msgstr);
1031 else if(sourcemsgstr != msgstr)
1033 sprint(source, sourcemsgstr);
1034 FOR_EACH_REALCLIENT(head)
1036 sprint(head, msgstr);
1045 float GetVoiceMessageVoiceType(string type)
1048 return VOICETYPE_TAUNT;
1049 if(type == "teamshoot")
1050 return VOICETYPE_LASTATTACKER;
1051 return VOICETYPE_TEAMRADIO;
1054 string allvoicesamples;
1055 .string GetVoiceMessageSampleField(string type)
1057 GetPlayerSoundSampleField_notFound = 0;
1060 #define _VOICEMSG(m) case #m: return playersound_##m;
1064 GetPlayerSoundSampleField_notFound = 1;
1065 return playersound_taunt;
1068 .string GetPlayerSoundSampleField(string type)
1070 GetPlayerSoundSampleField_notFound = 0;
1073 #define _VOICEMSG(m) case #m: return playersound_##m;
1077 GetPlayerSoundSampleField_notFound = 1;
1078 return playersound_taunt;
1081 void PrecacheGlobalSound(string samplestring)
1084 tokenize_console(samplestring);
1088 for(i = 1; i <= n; ++i)
1089 precache_sound(strcat(argv(0), ftos(i), ".wav"));
1093 precache_sound(strcat(argv(0), ".wav"));
1097 void PrecachePlayerSounds(string f)
1101 fh = fopen(f, FILE_READ);
1104 while((s = fgets(fh)))
1106 if(tokenize_console(s) != 3)
1108 dprint("Invalid sound info line: ", s, "\n");
1111 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1115 if not(allvoicesamples)
1117 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1120 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1124 void ClearPlayerSounds()
1126 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1132 float LoadPlayerSounds(string f, float first)
1137 fh = fopen(f, FILE_READ);
1140 dprint("Player sound file not found: ", f, "\n");
1143 while((s = fgets(fh)))
1145 if(tokenize_console(s) != 3)
1147 field = GetPlayerSoundSampleField(argv(0));
1148 if(GetPlayerSoundSampleField_notFound)
1149 field = GetVoiceMessageSampleField(argv(0));
1150 if(GetPlayerSoundSampleField_notFound)
1153 strunzone(self.field);
1154 self.field = strzone(strcat(argv(1), " ", argv(2)));
1160 .float modelindex_for_playersound;
1161 .float skinindex_for_playersound;
1162 void UpdatePlayerSounds()
1164 if(self.modelindex == self.modelindex_for_playersound)
1165 if(self.skinindex == self.skinindex_for_playersound)
1167 self.modelindex_for_playersound = self.modelindex;
1168 self.skinindex_for_playersound = self.skinindex;
1169 ClearPlayerSounds();
1170 LoadPlayerSounds("sound/player/default.sounds", 1);
1171 if(!autocvar_g_debug_defaultsounds)
1172 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skinindex, "sounds"), 0))
1173 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1176 void FakeGlobalSound(string sample, float chan, float voicetype)
1184 tokenize_console(sample);
1187 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1189 sample = strcat(argv(0), ".wav"); // randomization
1193 case VOICETYPE_LASTATTACKER_ONLY:
1195 case VOICETYPE_LASTATTACKER:
1199 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1200 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1203 case VOICETYPE_TEAMRADIO:
1205 if(msg_entity.cvar_cl_voice_directional == 1)
1206 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1208 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1210 case VOICETYPE_AUTOTAUNT:
1217 tauntrand = random();
1219 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1221 if (msg_entity.cvar_cl_voice_directional >= 1)
1222 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1224 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1227 case VOICETYPE_TAUNT:
1228 if(self.classname == "player")
1229 if(self.deadflag == DEAD_NO)
1230 setanim(self, self.anim_taunt, FALSE, TRUE, TRUE);
1236 if (msg_entity.cvar_cl_voice_directional >= 1)
1237 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1239 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1241 case VOICETYPE_PLAYERSOUND:
1243 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NORM);
1246 backtrace("Invalid voice type!");
1251 void GlobalSound(string sample, float chan, float voicetype)
1259 tokenize_console(sample);
1262 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1264 sample = strcat(argv(0), ".wav"); // randomization
1268 case VOICETYPE_LASTATTACKER_ONLY:
1271 msg_entity = self.pusher;
1272 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1274 if(msg_entity.cvar_cl_voice_directional == 1)
1275 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1277 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1281 case VOICETYPE_LASTATTACKER:
1284 msg_entity = self.pusher;
1285 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1287 if(msg_entity.cvar_cl_voice_directional == 1)
1288 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1290 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1293 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1294 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1297 case VOICETYPE_TEAMRADIO:
1298 FOR_EACH_REALCLIENT(msg_entity)
1299 if(!teamplay || msg_entity.team == self.team)
1301 if(msg_entity.cvar_cl_voice_directional == 1)
1302 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1304 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1307 case VOICETYPE_AUTOTAUNT:
1314 tauntrand = random();
1315 FOR_EACH_REALCLIENT(msg_entity)
1316 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1318 if (msg_entity.cvar_cl_voice_directional >= 1)
1319 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1321 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1324 case VOICETYPE_TAUNT:
1325 if(self.classname == "player")
1326 if(self.deadflag == DEAD_NO)
1327 setanim(self, self.anim_taunt, FALSE, TRUE, TRUE);
1332 FOR_EACH_REALCLIENT(msg_entity)
1334 if (msg_entity.cvar_cl_voice_directional >= 1)
1335 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1337 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1340 case VOICETYPE_PLAYERSOUND:
1341 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1344 backtrace("Invalid voice type!");
1349 void PlayerSound(.string samplefield, float chan, float voicetype)
1351 GlobalSound(self.samplefield, chan, voicetype);
1354 void VoiceMessage(string type, string msg)
1357 float voicetype, ownteam;
1359 sample = GetVoiceMessageSampleField(type);
1361 if(GetPlayerSoundSampleField_notFound)
1363 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1367 voicetype = GetVoiceMessageVoiceType(type);
1368 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1370 flood = Say(self, ownteam, world, msg, 1);
1373 GlobalSound(self.sample, CH_VOICE, voicetype);
1375 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1378 void MoveToTeam(entity client, float team_colour, float type, float show_message)
1381 // 0 (00) automove centerprint, admin message
1382 // 1 (01) automove centerprint, no admin message
1383 // 2 (10) no centerprint, admin message
1384 // 3 (11) no centerprint, no admin message
1386 float lockteams_backup;
1388 lockteams_backup = lockteams; // backup any team lock
1390 lockteams = 0; // disable locked teams
1392 TeamchangeFrags(client); // move the players frags
1393 SetPlayerColors(client, team_colour - 1); // set the players colour
1394 Damage(client, client, client, 100000, ((show_message & 2) ? DEATH_QUIET : DEATH_AUTOTEAMCHANGE), client.origin, '0 0 0'); // kill the player
1396 lockteams = lockteams_backup; // restore the team lock
1398 LogTeamchange(client.playerid, client.team, type);
1400 if not(show_message & 1) // admin message
1401 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
1403 bprint(strcat(client.netname, " joined the ", ColoredTeamName(client.team), "\n"));