1 #include "cl_player.qh"
8 #include "g_violence.qh"
9 #include "miscfunctions.qh"
11 #include "teamplay.qh"
12 #include "waypointsprites.qh"
13 #include "weapons/throwing.qh"
14 #include "command/common.qh"
15 #include "../common/animdecide.qh"
16 #include "../common/csqcmodel_settings.qh"
17 #include "../common/deathtypes.qh"
18 #include "../common/triggers/subs.qh"
19 #include "../common/playerstats.qh"
20 #include "../csqcmodellib/sv_model.qh"
22 #include "../common/minigames/sv_minigames.qh"
24 #include "weapons/weaponstats.qh"
26 #include "../common/animdecide.qh"
28 void CopyBody_Think(void)
30 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
32 self.CopyBody_think();
35 self.CopyBody_nextthink = self.nextthink;
36 self.CopyBody_think = self.think;
37 self.think = CopyBody_Think;
39 CSQCMODEL_AUTOUPDATE();
40 self.nextthink = time;
42 void CopyBody(float keepvelocity)
45 if (self.effects & EF_NODRAW)
50 self.lip = oldself.lip;
51 self.colormap = oldself.colormap;
52 self.iscreature = oldself.iscreature;
53 self.teleportable = oldself.teleportable;
54 self.damagedbycontents = oldself.damagedbycontents;
55 self.angles = oldself.angles;
56 self.v_angle = oldself.v_angle;
57 self.avelocity = oldself.avelocity;
58 self.classname = "body";
59 self.damageforcescale = oldself.damageforcescale;
60 self.effects = oldself.effects;
61 self.glowmod = oldself.glowmod;
62 self.event_damage = oldself.event_damage;
63 self.anim_state = oldself.anim_state;
64 self.anim_time = oldself.anim_time;
65 self.anim_lower_action = oldself.anim_lower_action;
66 self.anim_lower_time = oldself.anim_lower_time;
67 self.anim_upper_action = oldself.anim_upper_action;
68 self.anim_upper_time = oldself.anim_upper_time;
69 self.anim_implicit_state = oldself.anim_implicit_state;
70 self.anim_implicit_time = oldself.anim_implicit_time;
71 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
72 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
73 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
74 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
75 self.dphitcontentsmask = oldself.dphitcontentsmask;
76 self.death_time = oldself.death_time;
77 self.pain_finished = oldself.pain_finished;
78 self.health = oldself.health;
79 self.armorvalue = oldself.armorvalue;
80 self.armortype = oldself.armortype;
81 self.model = oldself.model;
82 self.modelindex = oldself.modelindex;
83 self.skin = oldself.skin;
84 self.species = oldself.species;
85 self.movetype = oldself.movetype;
86 self.solid = oldself.solid;
87 self.ballistics_density = oldself.ballistics_density;
88 self.takedamage = oldself.takedamage;
89 self.customizeentityforclient = oldself.customizeentityforclient;
90 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
91 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
92 if (keepvelocity == 1)
93 self.velocity = oldself.velocity;
94 self.oldvelocity = self.velocity;
95 self.alpha = oldself.alpha;
96 self.fade_time = oldself.fade_time;
97 self.fade_rate = oldself.fade_rate;
98 //self.weapon = oldself.weapon;
99 setorigin(self, oldself.origin);
100 setsize(self, oldself.mins, oldself.maxs);
101 self.prevorigin = oldself.origin;
102 self.reset = SUB_Remove;
104 Drag_MoveDrag(oldself, self);
106 if(self.colormap <= maxclients && self.colormap > 0)
107 self.colormap = 1024 + oldself.clientcolors;
109 CSQCMODEL_AUTOINIT();
110 self.CopyBody_nextthink = oldself.nextthink;
111 self.CopyBody_think = oldself.think;
112 self.nextthink = time;
113 self.think = CopyBody_Think;
114 // "bake" the current animation frame for clones (they don't get clientside animation)
115 animdecide_load_if_needed(self);
116 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
121 float player_getspecies()
124 get_model_parameters(self.model, self.skin);
125 s = get_model_parameters_species;
126 get_model_parameters(string_null, 0);
128 return SPECIES_HUMAN;
132 void player_setupanimsformodel()
134 // load animation info
135 animdecide_load_if_needed(self);
136 animdecide_setstate(self, 0, false);
139 void player_anim (void)
141 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
144 // Decide on which death animation to use.
146 deadbits = ANIMSTATE_DEAD1;
148 deadbits = ANIMSTATE_DEAD2;
151 // Clear a previous death animation.
154 int animbits = deadbits;
156 animbits |= ANIMSTATE_FROZEN;
158 animbits |= ANIMSTATE_DUCK;
159 animdecide_setstate(self, animbits, false);
160 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
162 if (self.weaponentity)
164 updateanim(self.weaponentity);
165 if (!self.weaponentity.animstate_override)
166 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
170 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
174 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
176 // damage resistance (ignore most of the damage from a bullet or similar)
177 damage = max(damage - 5, 1);
179 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
183 if(sound_allowed(MSG_BROADCAST, attacker))
186 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
188 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
190 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
194 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
196 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
198 self.armorvalue = self.armorvalue - save;
199 self.health = self.health - take;
200 // pause regeneration for 5 seconds
201 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
203 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
204 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
205 self.dmg_inflictor = inflictor;
207 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
209 // don't use any animations as a gib
211 // view just above the floor
212 self.view_ofs = '0 0 4';
214 Violence_GibSplash(self, 1, 1, attacker);
216 self.solid = SOLID_NOT; // restore later
217 self.takedamage = DAMAGE_NO; // restore later
218 self.damagedbycontents = false;
222 void calculate_player_respawn_time()
227 float gametype_setting_tmp;
228 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
229 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
230 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
231 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
232 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
233 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
235 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
241 if (pl.team == self.team)
243 if (sdelay_small_count == 0)
244 sdelay_small_count = 1;
245 if (sdelay_large_count == 0)
246 sdelay_large_count = 1;
253 if (sdelay_small_count == 0)
257 // Players play independently. No point in requiring enemies.
258 sdelay_small_count = 1;
262 // Players play AGAINST each other. Enemies required.
263 sdelay_small_count = 2;
266 if (sdelay_large_count == 0)
270 // Players play independently. No point in requiring enemies.
271 sdelay_large_count = 1;
275 // Players play AGAINST each other. Enemies required.
276 sdelay_large_count = 2;
283 if (pcount <= sdelay_small_count)
284 sdelay = sdelay_small;
285 else if (pcount >= sdelay_large_count)
286 sdelay = sdelay_large;
287 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
288 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
291 self.respawn_time = ceil((time + sdelay) / waves) * waves;
293 self.respawn_time = time + sdelay;
295 if(sdelay < sdelay_max)
296 self.respawn_time_max = time + sdelay_max;
298 self.respawn_time_max = self.respawn_time;
300 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
301 self.respawn_countdown = 10; // first number to count down from is 10
303 self.respawn_countdown = -1; // do not count down
305 if(autocvar_g_forced_respawn)
306 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
309 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
311 float take, save, dh, da;
314 float valid_damage_for_weaponstats;
317 dh = max(self.health, 0);
318 da = max(self.armorvalue, 0);
320 if(!DEATH_ISSPECIAL(deathtype))
322 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
324 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
327 if(DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
329 // tuba causes blood to come out of the ears
334 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
336 makevectors(self.angles);
337 ear1 += v_right * -10;
338 ear2 += v_right * +10;
339 d = inflictor.origin - self.origin;
341 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
343 f = 0; // Assum ecenter.
344 force = v_right * vlen(force);
345 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
346 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
355 // force is already good
359 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
362 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
368 // don't reset pushltime for self damage as it may be an attempt to
369 // escape a lava pit or similar
370 //self.pushltime = 0;
373 else if(IS_PLAYER(attacker))
375 self.pusher = attacker;
376 self.pushltime = time + autocvar_g_maxpushtime;
377 self.istypefrag = self.BUTTON_CHAT;
379 else if(time < self.pushltime)
381 attacker = self.pusher;
382 self.pushltime = max(self.pushltime, time + 0.6);
390 frag_damage = damage;
391 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
392 take = bound(0, damage_take, self.health);
393 save = bound(0, damage_save, self.armorvalue);
394 excess = max(0, damage - take - save);
396 if(sound_allowed(MSG_BROADCAST, attacker))
399 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
401 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
403 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
407 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
409 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
411 if (time >= self.spawnshieldtime)
413 if (!(self.flags & FL_GODMODE))
415 self.armorvalue = self.armorvalue - save;
416 self.health = self.health - take;
417 // pause regeneration for 5 seconds
419 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
421 if (time > self.pain_finished) //Don't switch pain sequences like crazy
423 self.pain_finished = time + 0.5; //Supajoe
425 if(autocvar_sv_gentle < 1) {
426 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
428 if (!self.animstate_override)
431 animdecide_setaction(self, ANIMACTION_PAIN1, true);
433 animdecide_setaction(self, ANIMACTION_PAIN2, true);
437 if(sound_allowed(MSG_BROADCAST, attacker))
438 if((self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !((get_weaponinfo(DEATH_WEAPONOF(deathtype))).spawnflags & WEP_FLAG_CANCLIMB) || attacker != self) // WEAPONTODO: create separate limit for pain notification with laser
440 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
442 if(deathtype == DEATH_FALL)
443 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
444 else if(self.health > 75) // TODO make a "gentle" version?
445 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
446 else if(self.health > 50)
447 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
448 else if(self.health > 25)
449 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
451 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
456 // throw off bot aim temporarily
458 if(IS_BOT_CLIENT(self) && self.health >= 1)
460 shake = damage * 5 / (bound(0,skill,100) + 1);
461 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
462 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
463 self.v_angle_x = bound(-90, self.v_angle.x, 90);
467 self.max_armorvalue += (save + take);
469 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
470 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
471 self.dmg_inflictor = inflictor;
473 float abot, vbot, awep;
474 abot = (IS_BOT_CLIENT(attacker));
475 vbot = (IS_BOT_CLIENT(self));
477 valid_damage_for_weaponstats = 0;
480 if(vbot || IS_REAL_CLIENT(self))
481 if(abot || IS_REAL_CLIENT(attacker))
482 if(attacker && self != attacker)
483 if(DIFF_TEAM(self, attacker))
485 if(DEATH_ISSPECIAL(deathtype))
486 awep = attacker.weapon;
488 awep = DEATH_WEAPONOF(deathtype);
489 valid_damage_for_weaponstats = 1;
492 if(valid_damage_for_weaponstats)
494 dh = dh - max(self.health, 0);
495 da = da - max(self.armorvalue, 0);
496 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
497 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc);
502 float defer_ClientKill_Now_TeamChange;
503 defer_ClientKill_Now_TeamChange = false;
507 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
511 if(valid_damage_for_weaponstats)
512 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
514 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
515 if(sound_allowed(MSG_BROADCAST, attacker))
517 if(deathtype == DEATH_DROWN)
518 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
520 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
523 // get rid of kill indicator
524 if(self.killindicator)
526 remove(self.killindicator);
527 self.killindicator = world;
528 if(self.killindicator_teamchange)
529 defer_ClientKill_Now_TeamChange = true;
531 if(self.classname == "body")
532 if(deathtype == DEATH_KILL)
534 // for the lemmings fans, a small harmless explosion
535 Send_Effect("rocket_explode", self.origin, '0 0 0', 1);
539 // print an obituary message
540 if(self.classname != "body")
541 Obituary (attacker, inflictor, self, deathtype);
543 // increment frag counter for used weapon type
544 int w = DEATH_WEAPONOF(deathtype);
546 if(accuracy_isgooddamage(attacker, self))
547 attacker.accuracy.(accuracy_frags[w-1]) += 1;
549 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
551 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
553 RemoveGrapplingHook(self);
555 Portal_ClearAllLater(self);
557 self.fixangle = true;
559 if(defer_ClientKill_Now_TeamChange)
560 ClientKill_Now_TeamChange(); // can turn player into spectator
562 // player could have been miraculously resuscitated ;)
563 // e.g. players in freezetag get frozen, they don't really die
564 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
567 // when we get here, player actually dies
569 Unfreeze(self); // remove any icy remains
570 self.health = 0; // Unfreeze resets health, so we need to set it back
573 WaypointSprite_PlayerDead();
575 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
577 // become fully visible
578 self.alpha = default_player_alpha;
579 // make the corpse upright (not tilted)
583 self.avelocity = '0 0 0';
584 // view from the floor
585 self.view_ofs = '0 0 -8';
587 self.movetype = MOVETYPE_TOSS;
589 self.solid = SOLID_CORPSE;
590 self.ballistics_density = autocvar_g_ballistics_density_corpse;
591 // don't stick to the floor
592 self.flags &= ~FL_ONGROUND;
594 self.deadflag = DEAD_DYING;
596 // when to allow respawn
597 calculate_player_respawn_time();
599 self.death_time = time;
601 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
603 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
607 setsize(self, self.mins, self.maxs);
609 // set damage function to corpse damage
610 self.event_damage = PlayerCorpseDamage;
611 // call the corpse damage function just in case it wants to gib
612 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
614 // set up to fade out later
615 SUB_SetFade (self, time + 6 + random (), 1);
616 // reset body think wrapper broken by SUB_SetFade
617 if(self.classname == "body" && self.think != CopyBody_Think) {
618 self.CopyBody_think = self.think;
619 self.CopyBody_nextthink = self.nextthink;
620 self.think = CopyBody_Think;
621 self.nextthink = time;
624 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
626 // clones don't run any animation code any more, so we must gib them when they die :(
627 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
630 // reset fields the weapons may use just in case
631 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
633 WEP_ACTION(j, WR_RESETPLAYER);
634 ATTACK_FINISHED_FOR(self, j) = 0;
639 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
640 // message "": do not say, just test flood control
646 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
648 var .float flood_field;
651 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
653 if(!teamsay && !privatesay)
654 if(substring(msgin, 0, 1) == " ")
655 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
657 msgin = formatmessage(msgin);
659 if (!IS_PLAYER(source))
660 colorstr = "^0"; // black for spectators
662 colorstr = Team_ColorCode(source.team);
669 if(intermission_running)
673 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
676 * using bprint solves this... me stupid
677 // how can we prevent the message from appearing in a listen server?
678 // for now, just give "say" back and only handle say_team
681 clientcommand(self, strcat("say ", msgin));
686 if(autocvar_g_chat_teamcolors)
687 namestr = playername(source);
689 namestr = source.netname;
691 if(strdecolorize(namestr) == namestr)
700 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
701 privatemsgprefixlen = strlen(msgstr);
702 msgstr = strcat(msgstr, msgin);
703 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
704 if(autocvar_g_chat_teamcolors)
705 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
707 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
711 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
712 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
716 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
719 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
723 msgstr = cmsgstr = "";
727 fullcmsgstr = cmsgstr;
731 flood_field = floodcontrol_chat;
740 flood_spl = autocvar_g_chat_flood_spl_tell;
741 flood_burst = autocvar_g_chat_flood_burst_tell;
742 flood_lmax = autocvar_g_chat_flood_lmax_tell;
743 flood_field = floodcontrol_chattell;
747 flood_spl = autocvar_g_chat_flood_spl_team;
748 flood_burst = autocvar_g_chat_flood_burst_team;
749 flood_lmax = autocvar_g_chat_flood_lmax_team;
750 flood_field = floodcontrol_chatteam;
754 flood_spl = autocvar_g_chat_flood_spl;
755 flood_burst = autocvar_g_chat_flood_burst;
756 flood_lmax = autocvar_g_chat_flood_lmax;
757 flood_field = floodcontrol_chat;
759 flood_burst = max(0, flood_burst - 1);
760 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
762 // do flood control for the default line size
765 getWrappedLine_remaining = msgstr;
768 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
770 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
773 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
775 if(getWrappedLine_remaining != "")
777 msgstr = strcat(msgstr, "\n");
781 if (time >= source.(flood_field))
783 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
793 if (time >= source.(flood_field))
794 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
799 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
800 source.(flood_field) = flood = 0;
803 if(flood == 2) // cannot happen for empty msgstr
805 if(autocvar_g_chat_flood_notify_flooder)
807 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
812 sourcemsgstr = fullmsgstr;
813 sourcecmsgstr = fullcmsgstr;
819 sourcemsgstr = msgstr;
820 sourcecmsgstr = cmsgstr;
824 if (!IS_PLAYER(source))
826 if (!intermission_running)
827 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
828 teamsay = -1; // spectators
832 print("NOTE: ", playername(source), "^7 is flooding.\n");
834 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
836 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
840 // always fake the message
845 if (autocvar_g_chat_flood_notify_flooder)
847 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
858 if(sourcemsgstr != "" && ret != 0)
860 if(ret < 0) // faked message, because the player is muted
862 sprint(source, sourcemsgstr);
863 if(sourcecmsgstr != "" && !privatesay)
864 centerprint(source, sourcecmsgstr);
866 else if(privatesay) // private message, between 2 people only
868 sprint(source, sourcemsgstr);
869 sprint(privatesay, msgstr);
870 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
872 centerprint(privatesay, cmsgstr);
874 else if ( teamsay && source.active_minigame )
876 sprint(source, sourcemsgstr);
877 dedicated_print(msgstr); // send to server console too
878 FOR_EACH_REALCLIENT(head)
880 if(head.active_minigame == source.active_minigame)
881 sprint(head, msgstr);
883 else if(teamsay > 0) // team message, only sent to team mates
885 sprint(source, sourcemsgstr);
886 dedicated_print(msgstr); // send to server console too
887 if(sourcecmsgstr != "")
888 centerprint(source, sourcecmsgstr);
889 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
892 sprint(head, msgstr);
894 centerprint(head, cmsgstr);
897 else if(teamsay < 0) // spectator message, only sent to spectators
899 sprint(source, sourcemsgstr);
900 dedicated_print(msgstr); // send to server console too
901 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
903 sprint(head, msgstr);
905 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
907 sprint(source, sourcemsgstr);
908 dedicated_print(msgstr); // send to server console too
909 FOR_EACH_REALCLIENT(head)
911 sprint(head, msgstr);
914 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
920 float GetVoiceMessageVoiceType(string type)
923 return VOICETYPE_TAUNT;
924 if(type == "teamshoot")
925 return VOICETYPE_LASTATTACKER;
926 return VOICETYPE_TEAMRADIO;
929 .string GetVoiceMessageSampleField(string type)
931 GetPlayerSoundSampleField_notFound = 0;
934 #define _VOICEMSG(m) case #m: return playersound_##m;
938 GetPlayerSoundSampleField_notFound = 1;
939 return playersound_taunt;
942 .string GetPlayerSoundSampleField(string type)
944 GetPlayerSoundSampleField_notFound = 0;
947 #define _VOICEMSG(m) case #m: return playersound_##m;
951 GetPlayerSoundSampleField_notFound = 1;
952 return playersound_taunt;
955 void PrecacheGlobalSound(string samplestring)
958 tokenize_console(samplestring);
962 for(i = 1; i <= n; ++i)
963 precache_sound(strcat(argv(0), ftos(i), ".wav"));
967 precache_sound(strcat(argv(0), ".wav"));
971 void PrecachePlayerSounds(string f)
975 fh = fopen(f, FILE_READ);
978 while((s = fgets(fh)))
980 if(tokenize_console(s) != 3)
982 dprint("Invalid sound info line: ", s, "\n");
985 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
989 if (!allvoicesamples)
991 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
994 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
998 void ClearPlayerSounds()
1000 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1006 float LoadPlayerSounds(string f, float first)
1011 fh = fopen(f, FILE_READ);
1014 dprint("Player sound file not found: ", f, "\n");
1017 while((s = fgets(fh)))
1019 if(tokenize_console(s) != 3)
1021 field = GetPlayerSoundSampleField(argv(0));
1022 if(GetPlayerSoundSampleField_notFound)
1023 field = GetVoiceMessageSampleField(argv(0));
1024 if(GetPlayerSoundSampleField_notFound)
1027 strunzone(self.(field));
1028 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1034 void UpdatePlayerSounds()
1036 if(self.modelindex == self.modelindex_for_playersound)
1037 if(self.skin == self.skin_for_playersound)
1039 self.modelindex_for_playersound = self.modelindex;
1040 self.skin_for_playersound = self.skin;
1041 ClearPlayerSounds();
1042 LoadPlayerSounds("sound/player/default.sounds", 1);
1043 if(!autocvar_g_debug_defaultsounds)
1044 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1045 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1048 void FakeGlobalSound(string sample, float chan, float voicetype)
1056 tokenize_console(sample);
1059 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1061 sample = strcat(argv(0), ".wav"); // randomization
1065 case VOICETYPE_LASTATTACKER_ONLY:
1067 case VOICETYPE_LASTATTACKER:
1071 if(IS_REAL_CLIENT(msg_entity))
1072 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1075 case VOICETYPE_TEAMRADIO:
1077 if(msg_entity.cvar_cl_voice_directional == 1)
1078 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1080 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1082 case VOICETYPE_AUTOTAUNT:
1087 if(autocvar_sv_gentle)
1089 tauntrand = random();
1091 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1093 if (msg_entity.cvar_cl_voice_directional >= 1)
1094 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1096 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1099 case VOICETYPE_TAUNT:
1101 if(self.deadflag == DEAD_NO)
1102 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1105 if(autocvar_sv_gentle)
1108 if (msg_entity.cvar_cl_voice_directional >= 1)
1109 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1111 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1113 case VOICETYPE_PLAYERSOUND:
1115 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1118 backtrace("Invalid voice type!");
1123 void GlobalSound(string sample, float chan, float voicetype)
1131 tokenize_console(sample);
1134 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1136 sample = strcat(argv(0), ".wav"); // randomization
1140 case VOICETYPE_LASTATTACKER_ONLY:
1143 msg_entity = self.pusher;
1144 if(IS_REAL_CLIENT(msg_entity))
1146 if(msg_entity.cvar_cl_voice_directional == 1)
1147 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1149 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1153 case VOICETYPE_LASTATTACKER:
1156 msg_entity = self.pusher;
1157 if(IS_REAL_CLIENT(msg_entity))
1159 if(msg_entity.cvar_cl_voice_directional == 1)
1160 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1162 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1165 if(IS_REAL_CLIENT(msg_entity))
1166 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1169 case VOICETYPE_TEAMRADIO:
1170 FOR_EACH_REALCLIENT(msg_entity)
1171 if(!teamplay || msg_entity.team == self.team)
1173 if(msg_entity.cvar_cl_voice_directional == 1)
1174 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1176 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1179 case VOICETYPE_AUTOTAUNT:
1184 if(autocvar_sv_gentle)
1186 tauntrand = random();
1187 FOR_EACH_REALCLIENT(msg_entity)
1188 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1190 if (msg_entity.cvar_cl_voice_directional >= 1)
1191 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1193 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1196 case VOICETYPE_TAUNT:
1198 if(self.deadflag == DEAD_NO)
1199 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1202 if(autocvar_sv_gentle)
1204 FOR_EACH_REALCLIENT(msg_entity)
1206 if (msg_entity.cvar_cl_voice_directional >= 1)
1207 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1209 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1212 case VOICETYPE_PLAYERSOUND:
1213 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1216 backtrace("Invalid voice type!");
1221 void PlayerSound(.string samplefield, float chan, float voicetype)
1223 GlobalSound(self.(samplefield), chan, voicetype);
1226 void VoiceMessage(string type, string msg)
1229 float voicetype, ownteam;
1231 sample = GetVoiceMessageSampleField(type);
1233 if(GetPlayerSoundSampleField_notFound)
1235 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1239 voicetype = GetVoiceMessageVoiceType(type);
1240 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1242 flood = Say(self, ownteam, world, msg, 1);
1244 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1245 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1247 GlobalSound(self.(sample), CH_VOICE, voicetype);
1250 void MoveToTeam(entity client, float team_colour, float type)
1252 float lockteams_backup;
1254 lockteams_backup = lockteams; // backup any team lock
1256 lockteams = 0; // disable locked teams
1258 TeamchangeFrags(client); // move the players frags
1259 SetPlayerColors(client, team_colour - 1); // set the players colour
1260 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1262 lockteams = lockteams_backup; // restore the team lock
1264 LogTeamchange(client.playerid, client.team, type);