1 #include "cl_player.qh"
7 #include "miscfunctions.qh"
10 #include "weapons/throwing.qh"
11 #include "command/common.qh"
12 #include "../common/anim.qh"
13 #include "../common/animdecide.qh"
14 #include "../common/csqcmodel_settings.qh"
15 #include "../common/deathtypes/all.qh"
16 #include "../common/triggers/subs.qh"
17 #include "../common/playerstats.qh"
18 #include "../lib/csqcmodel/sv_model.qh"
20 #include "../common/minigames/sv_minigames.qh"
22 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
23 #include "../common/triggers/include.qh"
25 #include "weapons/weaponstats.qh"
27 #include "../common/animdecide.qh"
29 void Drop_Special_Items(entity player)
31 // called when the player has become stuck or frozen
32 // so objective items aren't stuck with the player
34 MUTATOR_CALLHOOK(DropSpecialItems, player);
39 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
41 self.CopyBody_think();
44 self.CopyBody_nextthink = self.nextthink;
45 self.CopyBody_think = self.think;
46 self.think = CopyBody_Think;
48 CSQCMODEL_AUTOUPDATE(self);
49 self.nextthink = time;
51 void CopyBody(entity this, float keepvelocity)
53 if (this.effects & EF_NODRAW)
55 entity clone = new(body);
58 clone.colormap = this.colormap;
59 clone.iscreature = this.iscreature;
60 clone.teleportable = this.teleportable;
61 clone.damagedbycontents = this.damagedbycontents;
62 clone.angles = this.angles;
63 clone.v_angle = this.v_angle;
64 clone.avelocity = this.avelocity;
65 clone.damageforcescale = this.damageforcescale;
66 clone.effects = this.effects;
67 clone.glowmod = this.glowmod;
68 clone.event_damage = this.event_damage;
69 clone.anim_state = this.anim_state;
70 clone.anim_time = this.anim_time;
71 clone.anim_lower_action = this.anim_lower_action;
72 clone.anim_lower_time = this.anim_lower_time;
73 clone.anim_upper_action = this.anim_upper_action;
74 clone.anim_upper_time = this.anim_upper_time;
75 clone.anim_implicit_state = this.anim_implicit_state;
76 clone.anim_implicit_time = this.anim_implicit_time;
77 clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
78 clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
79 clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
80 clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
81 clone.dphitcontentsmask = this.dphitcontentsmask;
82 clone.death_time = this.death_time;
83 clone.pain_finished = this.pain_finished;
84 clone.health = this.health;
85 clone.armorvalue = this.armorvalue;
86 clone.armortype = this.armortype;
87 clone.model = this.model;
88 clone.modelindex = this.modelindex;
89 clone.skin = this.skin;
90 clone.species = this.species;
91 clone.movetype = this.movetype;
92 clone.solid = this.solid;
93 clone.ballistics_density = this.ballistics_density;
94 clone.takedamage = this.takedamage;
95 clone.customizeentityforclient = this.customizeentityforclient;
96 clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
97 clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
98 if (keepvelocity == 1)
99 clone.velocity = this.velocity;
100 clone.oldvelocity = clone.velocity;
101 clone.alpha = this.alpha;
102 clone.fade_time = this.fade_time;
103 clone.fade_rate = this.fade_rate;
104 //clone.weapon = this.weapon;
105 setorigin(clone, this.origin);
106 setsize(clone, this.mins, this.maxs);
107 clone.prevorigin = this.origin;
108 clone.reset = SUB_Remove;
109 clone._ps = this._ps;
111 Drag_MoveDrag(this, clone);
113 if(clone.colormap <= maxclients && clone.colormap > 0)
114 clone.colormap = 1024 + this.clientcolors;
116 CSQCMODEL_AUTOINIT(clone);
117 clone.CopyBody_nextthink = this.nextthink;
118 clone.CopyBody_think = this.think;
119 clone.nextthink = time;
120 clone.think = CopyBody_Think;
121 // "bake" the current animation frame for clones (they don't get clientside animation)
122 animdecide_load_if_needed(clone);
123 animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
126 void player_setupanimsformodel()
128 // load animation info
129 animdecide_load_if_needed(self);
130 animdecide_setstate(self, 0, false);
135 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
138 // Decide on which death animation to use.
140 deadbits = ANIMSTATE_DEAD1;
142 deadbits = ANIMSTATE_DEAD2;
145 // Clear a previous death animation.
148 int animbits = deadbits;
149 if(STAT(FROZEN, self))
150 animbits |= ANIMSTATE_FROZEN;
151 if(self.movetype == MOVETYPE_FOLLOW)
152 animbits |= ANIMSTATE_FOLLOW;
154 animbits |= ANIMSTATE_DUCK;
155 animdecide_setstate(self, animbits, false);
156 animdecide_setimplicitstate(self, IS_ONGROUND(self));
159 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
163 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
165 // damage resistance (ignore most of the damage from a bullet or similar)
166 damage = max(damage - 5, 1);
168 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
172 if(sound_allowed(MSG_BROADCAST, attacker))
175 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
177 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
179 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
183 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
185 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
187 this.armorvalue = this.armorvalue - save;
188 this.health = this.health - take;
189 // pause regeneration for 5 seconds
190 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
192 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
193 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
194 this.dmg_inflictor = inflictor;
196 if (this.health <= -autocvar_sv_gibhealth && this.alpha >= 0)
198 // don't use any animations as a gib
200 // view just above the floor
201 this.view_ofs = '0 0 4';
203 Violence_GibSplash(this, 1, 1, attacker);
205 this.solid = SOLID_NOT; // restore later
206 this.takedamage = DAMAGE_NO; // restore later
207 this.damagedbycontents = false;
211 void calculate_player_respawn_time(entity this)
216 float gametype_setting_tmp;
217 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
218 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
219 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
220 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
221 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
222 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
224 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
227 FOREACH_CLIENT(IS_PLAYER(it) && it != this, LAMBDA(
228 if(it.team == this.team)
231 if (sdelay_small_count == 0)
232 sdelay_small_count = 1;
233 if (sdelay_large_count == 0)
234 sdelay_large_count = 1;
238 FOREACH_CLIENT(IS_PLAYER(it) && it != this, LAMBDA(
241 if (sdelay_small_count == 0)
245 // Players play independently. No point in requiring enemies.
246 sdelay_small_count = 1;
250 // Players play AGAINST each other. Enemies required.
251 sdelay_small_count = 2;
254 if (sdelay_large_count == 0)
258 // Players play independently. No point in requiring enemies.
259 sdelay_large_count = 1;
263 // Players play AGAINST each other. Enemies required.
264 sdelay_large_count = 2;
271 if (pcount <= sdelay_small_count)
272 sdelay = sdelay_small;
273 else if (pcount >= sdelay_large_count)
274 sdelay = sdelay_large;
275 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
276 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
279 this.respawn_time = ceil((time + sdelay) / waves) * waves;
281 this.respawn_time = time + sdelay;
283 if(sdelay < sdelay_max)
284 this.respawn_time_max = time + sdelay_max;
286 this.respawn_time_max = this.respawn_time;
288 if((sdelay + waves >= 5.0) && (this.respawn_time - time > 1.75))
289 this.respawn_countdown = 10; // first number to count down from is 10
291 this.respawn_countdown = -1; // do not count down
293 if(autocvar_g_forced_respawn)
294 this.respawn_flags = this.respawn_flags | RESPAWN_FORCE;
297 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
299 float take, save, dh, da;
301 float valid_damage_for_weaponstats;
304 dh = max(this.health, 0);
305 da = max(this.armorvalue, 0);
307 if(!DEATH_ISSPECIAL(deathtype))
309 damage *= sqrt(bound(1.0, this.cvar_cl_handicap, 100.0));
311 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
314 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
316 // tuba causes blood to come out of the ears
321 ear1_z += 0.125 * this.view_ofs.z + 0.875 * this.maxs.z; // 7/8
323 makevectors(this.angles);
324 ear1 += v_right * -10;
325 ear2 += v_right * +10;
326 d = inflictor.origin - this.origin;
328 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
330 f = 0; // Assum ecenter.
331 force = v_right * vlen(force);
332 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), this, attacker);
333 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), this, attacker);
342 // force is already good
346 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
349 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
355 // don't reset pushltime for this damage as it may be an attempt to
356 // escape a lava pit or similar
357 //this.pushltime = 0;
360 else if(IS_PLAYER(attacker))
362 this.pusher = attacker;
363 this.pushltime = time + autocvar_g_maxpushtime;
364 this.istypefrag = this.BUTTON_CHAT;
366 else if(time < this.pushltime)
368 attacker = this.pusher;
369 this.pushltime = max(this.pushltime, time + 0.6);
377 frag_damage = damage;
378 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, this, force, take, save);
379 take = bound(0, damage_take, this.health);
380 save = bound(0, damage_save, this.armorvalue);
381 excess = max(0, damage - take - save);
383 if(sound_allowed(MSG_BROADCAST, attacker))
386 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
388 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
390 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
394 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
396 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
398 if (time >= this.spawnshieldtime)
400 if (!(this.flags & FL_GODMODE))
402 this.armorvalue = this.armorvalue - save;
403 this.health = this.health - take;
404 // pause regeneration for 5 seconds
406 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
408 if (time > this.pain_finished) //Don't switch pain sequences like crazy
410 this.pain_finished = time + 0.5; //Supajoe
412 if(autocvar_sv_gentle < 1) {
413 if(this.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
415 if (!this.animstate_override)
418 animdecide_setaction(this, ANIMACTION_PAIN1, true);
420 animdecide_setaction(this, ANIMACTION_PAIN2, true);
424 if(sound_allowed(MSG_BROADCAST, attacker))
425 if((this.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || attacker != this) // WEAPONTODO: create separate limit for pain notification with laser
427 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
429 if(deathtype == DEATH_FALL.m_id)
430 PlayerSound(this, playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
431 else if(this.health > 75) // TODO make a "gentle" version?
432 PlayerSound(this, playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
433 else if(this.health > 50)
434 PlayerSound(this, playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
435 else if(this.health > 25)
436 PlayerSound(this, playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
438 PlayerSound(this, playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
443 // throw off bot aim temporarily
445 if(IS_BOT_CLIENT(this) && this.health >= 1)
447 shake = damage * 5 / (bound(0,skill,100) + 1);
448 this.v_angle_x = this.v_angle.x + (random() * 2 - 1) * shake;
449 this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
450 this.v_angle_x = bound(-90, this.v_angle.x, 90);
454 this.max_armorvalue += (save + take);
456 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
457 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
458 this.dmg_inflictor = inflictor;
460 if (this != attacker) {
461 float realdmg = damage - excess;
462 if (IS_PLAYER(attacker)) {
463 PlayerScore_Add(attacker, SP_DMG, realdmg);
465 if (IS_PLAYER(this)) {
466 PlayerScore_Add(this, SP_DMGTAKEN, realdmg);
470 bool abot = (IS_BOT_CLIENT(attacker));
471 bool vbot = (IS_BOT_CLIENT(this));
473 valid_damage_for_weaponstats = 0;
474 Weapon awep = WEP_Null;
476 if(vbot || IS_REAL_CLIENT(this))
477 if(abot || IS_REAL_CLIENT(attacker))
478 if(attacker && this != attacker)
479 if(DIFF_TEAM(this, attacker))
481 if(DEATH_ISSPECIAL(deathtype))
482 awep = PS(attacker).m_weapon;
484 awep = DEATH_WEAPONOF(deathtype);
485 valid_damage_for_weaponstats = 1;
488 if(valid_damage_for_weaponstats)
490 dh = dh - max(this.health, 0);
491 da = da - max(this.armorvalue, 0);
492 WeaponStats_LogDamage(awep.m_id, abot, PS(this).m_weapon.m_id, vbot, dh + da);
493 MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype);
498 float defer_ClientKill_Now_TeamChange;
499 defer_ClientKill_Now_TeamChange = false;
503 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
507 if(valid_damage_for_weaponstats)
508 WeaponStats_LogKill(awep.m_id, abot, PS(this).m_weapon.m_id, vbot);
510 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
511 if(sound_allowed(MSG_BROADCAST, attacker))
513 if(deathtype == DEATH_DROWN.m_id)
514 PlayerSound(this, playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
516 PlayerSound(this, playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
519 // get rid of kill indicator
520 if(this.killindicator)
522 remove(this.killindicator);
523 this.killindicator = world;
524 if(this.killindicator_teamchange)
525 defer_ClientKill_Now_TeamChange = true;
527 if(this.classname == "body")
528 if(deathtype == DEATH_KILL.m_id)
530 // for the lemmings fans, a small harmless explosion
531 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
535 // print an obituary message
536 if(this.classname != "body")
537 Obituary (attacker, inflictor, this, deathtype);
539 // increment frag counter for used weapon type
540 Weapon w = DEATH_WEAPONOF(deathtype);
542 if(accuracy_isgooddamage(attacker, this))
543 attacker.accuracy.(accuracy_frags[w.m_id-1]) += 1;
545 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, this, deathtype);
546 excess = frag_damage;
548 Weapon wep = PS(this).m_weapon;
549 WITH(entity, self, this, wep.wr_playerdeath(wep));
551 RemoveGrapplingHook(this);
553 Portal_ClearAllLater(this);
555 this.fixangle = true;
557 if(defer_ClientKill_Now_TeamChange)
558 ClientKill_Now_TeamChange(this); // can turn player into spectator
560 // player could have been miraculously resuscitated ;)
561 // e.g. players in freezetag get frozen, they don't really die
562 if(this.health >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
565 // when we get here, player actually dies
567 Unfreeze(this); // remove any icy remains
568 this.health = 0; // Unfreeze resets health, so we need to set it back
571 WaypointSprite_PlayerDead(this);
573 SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, PS(this).m_switchweapon.m_id);
575 // become fully visible
576 this.alpha = default_player_alpha;
577 // make the corpse upright (not tilted)
581 this.avelocity = '0 0 0';
582 // view from the floor
583 this.view_ofs = '0 0 -8';
585 this.movetype = MOVETYPE_TOSS;
587 this.solid = SOLID_CORPSE;
588 this.ballistics_density = autocvar_g_ballistics_density_corpse;
589 // don't stick to the floor
590 UNSET_ONGROUND(this);
592 this.deadflag = DEAD_DYING;
594 // when to allow respawn
595 calculate_player_respawn_time(this);
597 this.death_time = time;
599 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD1, true);
601 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD2, true);
605 setsize(this, this.mins, this.maxs);
607 // set damage function to corpse damage
608 this.event_damage = PlayerCorpseDamage;
609 // call the corpse damage function just in case it wants to gib
610 this.event_damage(this, inflictor, attacker, excess, deathtype, hitloc, force);
612 // set up to fade out later
613 SUB_SetFade (this, time + 6 + random (), 1);
614 // reset body think wrapper broken by SUB_SetFade
615 if(this.classname == "body" && this.think != CopyBody_Think) {
616 this.CopyBody_think = this.think;
617 this.CopyBody_nextthink = this.nextthink;
618 this.think = CopyBody_Think;
619 this.nextthink = time;
622 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
624 // clones don't run any animation code any more, so we must gib them when they die :(
625 PlayerCorpseDamage(this, inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
628 // reset fields the weapons may use just in case
629 FOREACH(Weapons, it != WEP_Null, LAMBDA(
630 WITH(entity, self, this, it.wr_resetplayer(it));
631 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
633 ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
639 void MoveToTeam(entity client, int team_colour, int type)
641 int lockteams_backup = lockteams; // backup any team lock
642 lockteams = 0; // disable locked teams
643 TeamchangeFrags(client); // move the players frags
644 SetPlayerColors(client, team_colour - 1); // set the players colour
645 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
646 lockteams = lockteams_backup; // restore the team lock
647 LogTeamchange(client.playerid, client.team, type);
651 * message "": do not say, just test flood control
657 int Say(entity source, float teamsay, entity privatesay, string msgin, bool floodcontrol)
659 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
661 var .float flood_field;
663 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
665 if(!teamsay && !privatesay)
666 if(substring(msgin, 0, 1) == " ")
667 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
669 msgin = formatmessage(msgin);
671 if (!IS_PLAYER(source))
672 colorstr = "^0"; // black for spectators
674 colorstr = Team_ColorCode(source.team);
681 if(intermission_running)
685 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
688 * using bprint solves this... me stupid
689 // how can we prevent the message from appearing in a listen server?
690 // for now, just give "say" back and only handle say_team
693 clientcommand(self, strcat("say ", msgin));
698 if(autocvar_g_chat_teamcolors)
699 namestr = playername(source);
701 namestr = source.netname;
703 if(strdecolorize(namestr) == namestr)
712 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
713 privatemsgprefixlen = strlen(msgstr);
714 msgstr = strcat(msgstr, msgin);
715 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
716 if(autocvar_g_chat_teamcolors)
717 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
719 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
723 if(strstrofs(msgin, "/me", 0) >= 0)
725 //msgin = strreplace("/me", "", msgin);
726 //msgin = substring(msgin, 3, strlen(msgin));
727 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
728 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
731 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
732 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
736 if(strstrofs(msgin, "/me", 0) >= 0)
738 //msgin = strreplace("/me", "", msgin);
739 //msgin = substring(msgin, 3, strlen(msgin));
740 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
741 msgstr = strcat("\{1}^4* ", "^7", msgin);
744 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
747 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
751 msgstr = cmsgstr = "";
755 fullcmsgstr = cmsgstr;
759 flood_field = floodcontrol_chat;
768 flood_spl = autocvar_g_chat_flood_spl_tell;
769 flood_burst = autocvar_g_chat_flood_burst_tell;
770 flood_lmax = autocvar_g_chat_flood_lmax_tell;
771 flood_field = floodcontrol_chattell;
775 flood_spl = autocvar_g_chat_flood_spl_team;
776 flood_burst = autocvar_g_chat_flood_burst_team;
777 flood_lmax = autocvar_g_chat_flood_lmax_team;
778 flood_field = floodcontrol_chatteam;
782 flood_spl = autocvar_g_chat_flood_spl;
783 flood_burst = autocvar_g_chat_flood_burst;
784 flood_lmax = autocvar_g_chat_flood_lmax;
785 flood_field = floodcontrol_chat;
787 flood_burst = max(0, flood_burst - 1);
788 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
790 // do flood control for the default line size
793 getWrappedLine_remaining = msgstr;
796 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
798 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
801 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
803 if(getWrappedLine_remaining != "")
805 msgstr = strcat(msgstr, "\n");
809 if (time >= source.(flood_field))
811 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
821 if (time >= source.(flood_field))
822 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
827 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
828 source.(flood_field) = flood = 0;
831 if(flood == 2) // cannot happen for empty msgstr
833 if(autocvar_g_chat_flood_notify_flooder)
835 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
840 sourcemsgstr = fullmsgstr;
841 sourcecmsgstr = fullcmsgstr;
847 sourcemsgstr = msgstr;
848 sourcecmsgstr = cmsgstr;
852 if (!IS_PLAYER(source))
854 if (!intermission_running)
855 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
856 teamsay = -1; // spectators
860 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
862 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
864 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
868 // always fake the message
873 if (autocvar_g_chat_flood_notify_flooder)
875 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
886 if(sourcemsgstr != "" && ret != 0)
888 if(ret < 0) // faked message, because the player is muted
890 sprint(source, sourcemsgstr);
891 if(sourcecmsgstr != "" && !privatesay)
892 centerprint(source, sourcecmsgstr);
894 else if(privatesay) // private message, between 2 people only
896 sprint(source, sourcemsgstr);
897 sprint(privatesay, msgstr);
898 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
900 centerprint(privatesay, cmsgstr);
902 else if ( teamsay && source.active_minigame )
904 sprint(source, sourcemsgstr);
905 dedicated_print(msgstr); // send to server console too
906 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame, LAMBDA(sprint(it, msgstr)));
908 else if(teamsay > 0) // team message, only sent to team mates
910 sprint(source, sourcemsgstr);
911 dedicated_print(msgstr); // send to server console too
912 if(sourcecmsgstr != "")
913 centerprint(source, sourcecmsgstr);
914 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team, LAMBDA(
917 centerprint(it, cmsgstr);
920 else if(teamsay < 0) // spectator message, only sent to spectators
922 sprint(source, sourcemsgstr);
923 dedicated_print(msgstr); // send to server console too
924 FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
926 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
928 sprint(source, sourcemsgstr);
929 dedicated_print(msgstr); // send to server console too
930 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
933 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.