1 #include "cl_player.qh"
7 #include "g_violence.qh"
8 #include "miscfunctions.qh"
10 #include "teamplay.qh"
11 #include "weapons/throwing.qh"
12 #include "command/common.qh"
13 #include "../common/anim.qh"
14 #include "../common/animdecide.qh"
15 #include "../common/csqcmodel_settings.qh"
16 #include "../common/deathtypes/all.qh"
17 #include "../common/triggers/subs.qh"
18 #include "../common/playerstats.qh"
19 #include "../lib/csqcmodel/sv_model.qh"
21 #include "../common/minigames/sv_minigames.qh"
23 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
24 #include "../common/triggers/include.qh"
26 #include "weapons/weaponstats.qh"
28 #include "../common/animdecide.qh"
30 void Drop_Special_Items(entity player)
32 // called when the player has become stuck or frozen
33 // so objective items aren't stuck with the player
35 MUTATOR_CALLHOOK(DropSpecialItems, player);
38 void CopyBody_Think(void)
40 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
42 self.CopyBody_think();
45 self.CopyBody_nextthink = self.nextthink;
46 self.CopyBody_think = self.think;
47 self.think = CopyBody_Think;
49 CSQCMODEL_AUTOUPDATE(self);
50 self.nextthink = time;
52 void CopyBody(float keepvelocity)
54 if (self.effects & EF_NODRAW)
59 self.colormap = this.colormap;
60 self.iscreature = this.iscreature;
61 self.teleportable = this.teleportable;
62 self.damagedbycontents = this.damagedbycontents;
63 self.angles = this.angles;
64 self.v_angle = this.v_angle;
65 self.avelocity = this.avelocity;
66 self.classname = "body";
67 self.damageforcescale = this.damageforcescale;
68 self.effects = this.effects;
69 self.glowmod = this.glowmod;
70 self.event_damage = this.event_damage;
71 self.anim_state = this.anim_state;
72 self.anim_time = this.anim_time;
73 self.anim_lower_action = this.anim_lower_action;
74 self.anim_lower_time = this.anim_lower_time;
75 self.anim_upper_action = this.anim_upper_action;
76 self.anim_upper_time = this.anim_upper_time;
77 self.anim_implicit_state = this.anim_implicit_state;
78 self.anim_implicit_time = this.anim_implicit_time;
79 self.anim_lower_implicit_action = this.anim_lower_implicit_action;
80 self.anim_lower_implicit_time = this.anim_lower_implicit_time;
81 self.anim_upper_implicit_action = this.anim_upper_implicit_action;
82 self.anim_upper_implicit_time = this.anim_upper_implicit_time;
83 self.dphitcontentsmask = this.dphitcontentsmask;
84 self.death_time = this.death_time;
85 self.pain_finished = this.pain_finished;
86 self.health = this.health;
87 self.armorvalue = this.armorvalue;
88 self.armortype = this.armortype;
89 self.model = this.model;
90 self.modelindex = this.modelindex;
91 self.skin = this.skin;
92 self.species = this.species;
93 self.movetype = this.movetype;
94 self.solid = this.solid;
95 self.ballistics_density = this.ballistics_density;
96 self.takedamage = this.takedamage;
97 self.customizeentityforclient = this.customizeentityforclient;
98 self.uncustomizeentityforclient = this.uncustomizeentityforclient;
99 self.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
100 if (keepvelocity == 1)
101 self.velocity = this.velocity;
102 self.oldvelocity = self.velocity;
103 self.alpha = this.alpha;
104 self.fade_time = this.fade_time;
105 self.fade_rate = this.fade_rate;
106 //self.weapon = this.weapon;
107 setorigin(self, this.origin);
108 setsize(self, this.mins, this.maxs);
109 self.prevorigin = this.origin;
110 self.reset = SUB_Remove;
112 Drag_MoveDrag(this, self);
114 if(self.colormap <= maxclients && self.colormap > 0)
115 self.colormap = 1024 + this.clientcolors;
117 CSQCMODEL_AUTOINIT(self);
118 self.CopyBody_nextthink = this.nextthink;
119 self.CopyBody_think = this.think;
120 self.nextthink = time;
121 self.think = CopyBody_Think;
122 // "bake" the current animation frame for clones (they don't get clientside animation)
123 animdecide_load_if_needed(self);
124 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
129 float player_getspecies()
132 get_model_parameters(self.model, self.skin);
133 s = get_model_parameters_species;
134 get_model_parameters(string_null, 0);
136 return SPECIES_HUMAN;
140 void player_setupanimsformodel()
142 // load animation info
143 animdecide_load_if_needed(self);
144 animdecide_setstate(self, 0, false);
147 void player_anim (void)
149 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
152 // Decide on which death animation to use.
154 deadbits = ANIMSTATE_DEAD1;
156 deadbits = ANIMSTATE_DEAD2;
159 // Clear a previous death animation.
162 int animbits = deadbits;
164 animbits |= ANIMSTATE_FROZEN;
165 if(self.movetype == MOVETYPE_FOLLOW)
166 animbits |= ANIMSTATE_FOLLOW;
168 animbits |= ANIMSTATE_DUCK;
169 animdecide_setstate(self, animbits, false);
170 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
173 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
177 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
179 // damage resistance (ignore most of the damage from a bullet or similar)
180 damage = max(damage - 5, 1);
182 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
186 if(sound_allowed(MSG_BROADCAST, attacker))
189 sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
191 sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
193 sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
197 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
199 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
201 self.armorvalue = self.armorvalue - save;
202 self.health = self.health - take;
203 // pause regeneration for 5 seconds
204 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
206 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
207 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
208 self.dmg_inflictor = inflictor;
210 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
212 // don't use any animations as a gib
214 // view just above the floor
215 self.view_ofs = '0 0 4';
217 Violence_GibSplash(self, 1, 1, attacker);
219 self.solid = SOLID_NOT; // restore later
220 self.takedamage = DAMAGE_NO; // restore later
221 self.damagedbycontents = false;
225 void calculate_player_respawn_time()
230 float gametype_setting_tmp;
231 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
232 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
233 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
234 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
235 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
236 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
238 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
244 if (pl.team == self.team)
246 if (sdelay_small_count == 0)
247 sdelay_small_count = 1;
248 if (sdelay_large_count == 0)
249 sdelay_large_count = 1;
256 if (sdelay_small_count == 0)
260 // Players play independently. No point in requiring enemies.
261 sdelay_small_count = 1;
265 // Players play AGAINST each other. Enemies required.
266 sdelay_small_count = 2;
269 if (sdelay_large_count == 0)
273 // Players play independently. No point in requiring enemies.
274 sdelay_large_count = 1;
278 // Players play AGAINST each other. Enemies required.
279 sdelay_large_count = 2;
286 if (pcount <= sdelay_small_count)
287 sdelay = sdelay_small;
288 else if (pcount >= sdelay_large_count)
289 sdelay = sdelay_large;
290 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
291 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
294 self.respawn_time = ceil((time + sdelay) / waves) * waves;
296 self.respawn_time = time + sdelay;
298 if(sdelay < sdelay_max)
299 self.respawn_time_max = time + sdelay_max;
301 self.respawn_time_max = self.respawn_time;
303 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
304 self.respawn_countdown = 10; // first number to count down from is 10
306 self.respawn_countdown = -1; // do not count down
308 if(autocvar_g_forced_respawn)
309 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
312 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
314 float take, save, dh, da;
317 float valid_damage_for_weaponstats;
320 dh = max(self.health, 0);
321 da = max(self.armorvalue, 0);
323 if(!DEATH_ISSPECIAL(deathtype))
325 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
327 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
330 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
332 // tuba causes blood to come out of the ears
337 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
339 makevectors(self.angles);
340 ear1 += v_right * -10;
341 ear2 += v_right * +10;
342 d = inflictor.origin - self.origin;
344 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
346 f = 0; // Assum ecenter.
347 force = v_right * vlen(force);
348 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
349 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
358 // force is already good
362 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
365 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
371 // don't reset pushltime for self damage as it may be an attempt to
372 // escape a lava pit or similar
373 //self.pushltime = 0;
376 else if(IS_PLAYER(attacker))
378 self.pusher = attacker;
379 self.pushltime = time + autocvar_g_maxpushtime;
380 self.istypefrag = self.BUTTON_CHAT;
382 else if(time < self.pushltime)
384 attacker = self.pusher;
385 self.pushltime = max(self.pushltime, time + 0.6);
393 frag_damage = damage;
394 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
395 take = bound(0, damage_take, self.health);
396 save = bound(0, damage_save, self.armorvalue);
397 excess = max(0, damage - take - save);
399 if(sound_allowed(MSG_BROADCAST, attacker))
402 sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
404 sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
406 sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
410 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
412 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
414 if (time >= self.spawnshieldtime)
416 if (!(self.flags & FL_GODMODE))
418 self.armorvalue = self.armorvalue - save;
419 self.health = self.health - take;
420 // pause regeneration for 5 seconds
422 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
424 if (time > self.pain_finished) //Don't switch pain sequences like crazy
426 self.pain_finished = time + 0.5; //Supajoe
428 if(autocvar_sv_gentle < 1) {
429 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
431 if (!self.animstate_override)
434 animdecide_setaction(self, ANIMACTION_PAIN1, true);
436 animdecide_setaction(self, ANIMACTION_PAIN2, true);
440 if(sound_allowed(MSG_BROADCAST, attacker))
441 if((self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || attacker != self) // WEAPONTODO: create separate limit for pain notification with laser
443 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
445 if(deathtype == DEATH_FALL.m_id)
446 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
447 else if(self.health > 75) // TODO make a "gentle" version?
448 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
449 else if(self.health > 50)
450 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
451 else if(self.health > 25)
452 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
454 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
459 // throw off bot aim temporarily
461 if(IS_BOT_CLIENT(self) && self.health >= 1)
463 shake = damage * 5 / (bound(0,skill,100) + 1);
464 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
465 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
466 self.v_angle_x = bound(-90, self.v_angle.x, 90);
470 self.max_armorvalue += (save + take);
472 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
473 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
474 self.dmg_inflictor = inflictor;
476 if (self != attacker) {
477 float realdmg = damage - excess;
478 if (IS_PLAYER(attacker)) {
479 PlayerScore_Add(attacker, SP_DMG, realdmg);
481 if (IS_PLAYER(self)) {
482 PlayerScore_Add(self, SP_DMGTAKEN, realdmg);
486 bool abot = (IS_BOT_CLIENT(attacker));
487 bool vbot = (IS_BOT_CLIENT(self));
489 valid_damage_for_weaponstats = 0;
490 Weapon awep = WEP_Null;
492 if(vbot || IS_REAL_CLIENT(self))
493 if(abot || IS_REAL_CLIENT(attacker))
494 if(attacker && self != attacker)
495 if(DIFF_TEAM(self, attacker))
497 if(DEATH_ISSPECIAL(deathtype))
498 awep = get_weaponinfo(attacker.weapon);
500 awep = DEATH_WEAPONOF(deathtype);
501 valid_damage_for_weaponstats = 1;
504 if(valid_damage_for_weaponstats)
506 dh = dh - max(self.health, 0);
507 da = da - max(self.armorvalue, 0);
508 WeaponStats_LogDamage(awep.m_id, abot, self.weapon, vbot, dh + da);
509 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc, deathtype);
514 float defer_ClientKill_Now_TeamChange;
515 defer_ClientKill_Now_TeamChange = false;
519 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
523 if(valid_damage_for_weaponstats)
524 WeaponStats_LogKill(awep.m_id, abot, self.weapon, vbot);
526 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
527 if(sound_allowed(MSG_BROADCAST, attacker))
529 if(deathtype == DEATH_DROWN.m_id)
530 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
532 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
535 // get rid of kill indicator
536 if(self.killindicator)
538 remove(self.killindicator);
539 self.killindicator = world;
540 if(self.killindicator_teamchange)
541 defer_ClientKill_Now_TeamChange = true;
543 if(self.classname == "body")
544 if(deathtype == DEATH_KILL.m_id)
546 // for the lemmings fans, a small harmless explosion
547 Send_Effect(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
551 // print an obituary message
552 if(self.classname != "body")
553 Obituary (attacker, inflictor, self, deathtype);
555 // increment frag counter for used weapon type
556 Weapon w = DEATH_WEAPONOF(deathtype);
558 if(accuracy_isgooddamage(attacker, self))
559 attacker.accuracy.(accuracy_frags[w.m_id-1]) += 1;
561 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
562 excess = frag_damage;
564 Weapon wep = get_weaponinfo(self.weapon);
565 wep.wr_playerdeath(wep);
567 RemoveGrapplingHook(self);
569 Portal_ClearAllLater(self);
571 self.fixangle = true;
573 if(defer_ClientKill_Now_TeamChange)
574 ClientKill_Now_TeamChange(); // can turn player into spectator
576 // player could have been miraculously resuscitated ;)
577 // e.g. players in freezetag get frozen, they don't really die
578 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
581 // when we get here, player actually dies
583 Unfreeze(self); // remove any icy remains
584 self.health = 0; // Unfreeze resets health, so we need to set it back
587 WaypointSprite_PlayerDead();
589 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
591 // become fully visible
592 self.alpha = default_player_alpha;
593 // make the corpse upright (not tilted)
597 self.avelocity = '0 0 0';
598 // view from the floor
599 self.view_ofs = '0 0 -8';
601 self.movetype = MOVETYPE_TOSS;
603 self.solid = SOLID_CORPSE;
604 self.ballistics_density = autocvar_g_ballistics_density_corpse;
605 // don't stick to the floor
606 self.flags &= ~FL_ONGROUND;
608 self.deadflag = DEAD_DYING;
610 // when to allow respawn
611 calculate_player_respawn_time();
613 self.death_time = time;
615 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
617 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
621 setsize(self, self.mins, self.maxs);
623 // set damage function to corpse damage
624 self.event_damage = PlayerCorpseDamage;
625 // call the corpse damage function just in case it wants to gib
626 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
628 // set up to fade out later
629 SUB_SetFade (self, time + 6 + random (), 1);
630 // reset body think wrapper broken by SUB_SetFade
631 if(self.classname == "body" && self.think != CopyBody_Think) {
632 self.CopyBody_think = self.think;
633 self.CopyBody_nextthink = self.nextthink;
634 self.think = CopyBody_Think;
635 self.nextthink = time;
638 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
640 // clones don't run any animation code any more, so we must gib them when they die :(
641 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
644 // reset fields the weapons may use just in case
645 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
647 Weapon w = get_weaponinfo(j);
649 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
651 ATTACK_FINISHED_FOR(self, j, slot) = 0;
657 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
658 // message "": do not say, just test flood control
664 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
666 var .float flood_field;
669 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
671 if(!teamsay && !privatesay)
672 if(substring(msgin, 0, 1) == " ")
673 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
675 msgin = formatmessage(msgin);
677 if (!IS_PLAYER(source))
678 colorstr = "^0"; // black for spectators
680 colorstr = Team_ColorCode(source.team);
687 if(intermission_running)
691 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
694 * using bprint solves this... me stupid
695 // how can we prevent the message from appearing in a listen server?
696 // for now, just give "say" back and only handle say_team
699 clientcommand(self, strcat("say ", msgin));
704 if(autocvar_g_chat_teamcolors)
705 namestr = playername(source);
707 namestr = source.netname;
709 if(strdecolorize(namestr) == namestr)
718 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
719 privatemsgprefixlen = strlen(msgstr);
720 msgstr = strcat(msgstr, msgin);
721 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
722 if(autocvar_g_chat_teamcolors)
723 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
725 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
729 if(strstrofs(msgin, "/me", 0) >= 0)
731 //msgin = strreplace("/me", "", msgin);
732 //msgin = substring(msgin, 3, strlen(msgin));
733 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
734 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
737 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
738 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
742 if(strstrofs(msgin, "/me", 0) >= 0)
744 //msgin = strreplace("/me", "", msgin);
745 //msgin = substring(msgin, 3, strlen(msgin));
746 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
747 msgstr = strcat("\{1}^4* ", "^7", msgin);
750 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
753 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
757 msgstr = cmsgstr = "";
761 fullcmsgstr = cmsgstr;
765 flood_field = floodcontrol_chat;
774 flood_spl = autocvar_g_chat_flood_spl_tell;
775 flood_burst = autocvar_g_chat_flood_burst_tell;
776 flood_lmax = autocvar_g_chat_flood_lmax_tell;
777 flood_field = floodcontrol_chattell;
781 flood_spl = autocvar_g_chat_flood_spl_team;
782 flood_burst = autocvar_g_chat_flood_burst_team;
783 flood_lmax = autocvar_g_chat_flood_lmax_team;
784 flood_field = floodcontrol_chatteam;
788 flood_spl = autocvar_g_chat_flood_spl;
789 flood_burst = autocvar_g_chat_flood_burst;
790 flood_lmax = autocvar_g_chat_flood_lmax;
791 flood_field = floodcontrol_chat;
793 flood_burst = max(0, flood_burst - 1);
794 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
796 // do flood control for the default line size
799 getWrappedLine_remaining = msgstr;
802 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
804 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
807 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
809 if(getWrappedLine_remaining != "")
811 msgstr = strcat(msgstr, "\n");
815 if (time >= source.(flood_field))
817 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
827 if (time >= source.(flood_field))
828 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
833 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
834 source.(flood_field) = flood = 0;
837 if(flood == 2) // cannot happen for empty msgstr
839 if(autocvar_g_chat_flood_notify_flooder)
841 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
846 sourcemsgstr = fullmsgstr;
847 sourcecmsgstr = fullcmsgstr;
853 sourcemsgstr = msgstr;
854 sourcecmsgstr = cmsgstr;
858 if (!IS_PLAYER(source))
860 if (!intermission_running)
861 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
862 teamsay = -1; // spectators
866 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
868 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
870 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
874 // always fake the message
879 if (autocvar_g_chat_flood_notify_flooder)
881 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
892 if(sourcemsgstr != "" && ret != 0)
894 if(ret < 0) // faked message, because the player is muted
896 sprint(source, sourcemsgstr);
897 if(sourcecmsgstr != "" && !privatesay)
898 centerprint(source, sourcecmsgstr);
900 else if(privatesay) // private message, between 2 people only
902 sprint(source, sourcemsgstr);
903 sprint(privatesay, msgstr);
904 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
906 centerprint(privatesay, cmsgstr);
908 else if ( teamsay && source.active_minigame )
910 sprint(source, sourcemsgstr);
911 dedicated_print(msgstr); // send to server console too
912 FOR_EACH_REALCLIENT(head)
914 if(head.active_minigame == source.active_minigame)
915 sprint(head, msgstr);
917 else if(teamsay > 0) // team message, only sent to team mates
919 sprint(source, sourcemsgstr);
920 dedicated_print(msgstr); // send to server console too
921 if(sourcecmsgstr != "")
922 centerprint(source, sourcecmsgstr);
923 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
926 sprint(head, msgstr);
928 centerprint(head, cmsgstr);
931 else if(teamsay < 0) // spectator message, only sent to spectators
933 sprint(source, sourcemsgstr);
934 dedicated_print(msgstr); // send to server console too
935 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
937 sprint(head, msgstr);
939 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
941 sprint(source, sourcemsgstr);
942 dedicated_print(msgstr); // send to server console too
943 FOR_EACH_REALCLIENT(head)
945 sprint(head, msgstr);
948 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
954 float GetVoiceMessageVoiceType(string type)
957 return VOICETYPE_TAUNT;
958 if(type == "teamshoot")
959 return VOICETYPE_LASTATTACKER;
960 return VOICETYPE_TEAMRADIO;
963 .string GetVoiceMessageSampleField(string type)
965 GetPlayerSoundSampleField_notFound = 0;
968 #define _VOICEMSG(m) case #m: return playersound_##m;
972 GetPlayerSoundSampleField_notFound = 1;
973 return playersound_taunt;
976 .string GetPlayerSoundSampleField(string type)
978 GetPlayerSoundSampleField_notFound = 0;
981 #define _VOICEMSG(m) case #m: return playersound_##m;
985 GetPlayerSoundSampleField_notFound = 1;
986 return playersound_taunt;
989 void PrecacheGlobalSound(string samplestring)
992 tokenize_console(samplestring);
996 for(i = 1; i <= n; ++i)
997 precache_sound(strcat(argv(0), ftos(i), ".wav"));
1001 precache_sound(strcat(argv(0), ".wav"));
1005 void PrecachePlayerSounds(string f)
1007 int fh = fopen(f, FILE_READ);
1010 for (string s; (s = fgets(fh)); )
1012 int n = tokenize_console(s);
1015 if (n != 0) LOG_TRACEF("Invalid sound info line: %s\n", s);
1018 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1022 if (!allvoicesamples)
1024 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1027 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1031 void ClearPlayerSounds()
1033 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1039 float LoadPlayerSounds(string f, float first)
1044 fh = fopen(f, FILE_READ);
1047 LOG_TRACE("Player sound file not found: ", f, "\n");
1050 while((s = fgets(fh)))
1052 if(tokenize_console(s) != 3)
1054 field = GetPlayerSoundSampleField(argv(0));
1055 if(GetPlayerSoundSampleField_notFound)
1056 field = GetVoiceMessageSampleField(argv(0));
1057 if(GetPlayerSoundSampleField_notFound)
1060 strunzone(self.(field));
1061 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1067 void UpdatePlayerSounds()
1069 if(self.modelindex == self.modelindex_for_playersound)
1070 if(self.skin == self.skin_for_playersound)
1072 self.modelindex_for_playersound = self.modelindex;
1073 self.skin_for_playersound = self.skin;
1074 ClearPlayerSounds();
1075 LoadPlayerSounds("sound/player/default.sounds", 1);
1076 if(!autocvar_g_debug_defaultsounds)
1077 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1078 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1081 void FakeGlobalSound(string sample, float chan, float voicetype)
1089 tokenize_console(sample);
1092 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1094 sample = strcat(argv(0), ".wav"); // randomization
1098 case VOICETYPE_LASTATTACKER_ONLY:
1100 case VOICETYPE_LASTATTACKER:
1104 if(IS_REAL_CLIENT(msg_entity))
1105 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1108 case VOICETYPE_TEAMRADIO:
1110 if(msg_entity.cvar_cl_voice_directional == 1)
1111 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1113 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1115 case VOICETYPE_AUTOTAUNT:
1120 if(autocvar_sv_gentle)
1122 tauntrand = random();
1124 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1126 if (msg_entity.cvar_cl_voice_directional >= 1)
1127 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1129 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1132 case VOICETYPE_TAUNT:
1134 if(self.deadflag == DEAD_NO)
1135 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1138 if(autocvar_sv_gentle)
1141 if (msg_entity.cvar_cl_voice_directional >= 1)
1142 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1144 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1146 case VOICETYPE_PLAYERSOUND:
1148 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1151 backtrace("Invalid voice type!");
1156 void GlobalSound(string sample, float chan, float voicetype)
1164 tokenize_console(sample);
1167 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1169 sample = strcat(argv(0), ".wav"); // randomization
1173 case VOICETYPE_LASTATTACKER_ONLY:
1176 msg_entity = self.pusher;
1177 if(IS_REAL_CLIENT(msg_entity))
1179 if(msg_entity.cvar_cl_voice_directional == 1)
1180 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1182 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1186 case VOICETYPE_LASTATTACKER:
1189 msg_entity = self.pusher;
1190 if(IS_REAL_CLIENT(msg_entity))
1192 if(msg_entity.cvar_cl_voice_directional == 1)
1193 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1195 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1198 if(IS_REAL_CLIENT(msg_entity))
1199 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1202 case VOICETYPE_TEAMRADIO:
1203 FOR_EACH_REALCLIENT(msg_entity)
1204 if(!teamplay || msg_entity.team == self.team)
1206 if(msg_entity.cvar_cl_voice_directional == 1)
1207 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1209 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1212 case VOICETYPE_AUTOTAUNT:
1217 if(autocvar_sv_gentle)
1219 tauntrand = random();
1220 FOR_EACH_REALCLIENT(msg_entity)
1221 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1223 if (msg_entity.cvar_cl_voice_directional >= 1)
1224 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1226 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1229 case VOICETYPE_TAUNT:
1231 if(self.deadflag == DEAD_NO)
1232 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1235 if(autocvar_sv_gentle)
1237 FOR_EACH_REALCLIENT(msg_entity)
1239 if (msg_entity.cvar_cl_voice_directional >= 1)
1240 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1242 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1245 case VOICETYPE_PLAYERSOUND:
1246 _sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1249 backtrace("Invalid voice type!");
1254 void PlayerSound(.string samplefield, float chan, float voicetype)
1256 GlobalSound(self.(samplefield), chan, voicetype);
1259 void VoiceMessage(string type, string msg)
1261 float voicetype, ownteam;
1263 var .string sample = GetVoiceMessageSampleField(type);
1265 if(GetPlayerSoundSampleField_notFound)
1267 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1271 voicetype = GetVoiceMessageVoiceType(type);
1272 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1274 flood = Say(self, ownteam, world, msg, 1);
1276 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1277 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1279 GlobalSound(self.(sample), CH_VOICE, voicetype);
1282 void MoveToTeam(entity client, float team_colour, float type)
1284 float lockteams_backup;
1286 lockteams_backup = lockteams; // backup any team lock
1288 lockteams = 0; // disable locked teams
1290 TeamchangeFrags(client); // move the players frags
1291 SetPlayerColors(client, team_colour - 1); // set the players colour
1292 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
1294 lockteams = lockteams_backup; // restore the team lock
1296 LogTeamchange(client.playerid, client.team, type);