3 #include <common/effects/all.qh>
8 #include "miscfunctions.qh"
10 #include "teamplay.qh"
11 #include "weapons/throwing.qh"
12 #include "command/common.qh"
13 #include "../common/state.qh"
14 #include "../common/anim.qh"
15 #include "../common/animdecide.qh"
16 #include "../common/csqcmodel_settings.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/triggers/subs.qh"
19 #include "../common/playerstats.qh"
20 #include "../lib/csqcmodel/sv_model.qh"
22 #include "../common/minigames/sv_minigames.qh"
24 #include "../common/physics/player.qh"
25 #include "../common/effects/qc/_mod.qh"
26 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
27 #include "../common/triggers/include.qh"
28 #include "../common/wepent.qh"
30 #include "weapons/weaponstats.qh"
32 #include "../common/animdecide.qh"
34 void Drop_Special_Items(entity player)
36 // called when the player has become stuck or frozen
37 // so objective items aren't stuck with the player
39 MUTATOR_CALLHOOK(DropSpecialItems, player);
42 void CopyBody_Think(entity this)
44 if(this.CopyBody_nextthink && time > this.CopyBody_nextthink)
46 this.CopyBody_think(this);
49 this.CopyBody_nextthink = this.nextthink;
50 this.CopyBody_think = getthink(this);
51 setthink(this, CopyBody_Think);
53 CSQCMODEL_AUTOUPDATE(this);
54 this.nextthink = time;
56 void CopyBody(entity this, float keepvelocity)
58 if (this.effects & EF_NODRAW)
60 entity clone = new(body);
63 clone.colormap = this.colormap;
64 clone.iscreature = this.iscreature;
65 clone.teleportable = this.teleportable;
66 clone.damagedbycontents = this.damagedbycontents;
67 if(clone.damagedbycontents)
68 IL_PUSH(g_damagedbycontents, clone);
69 clone.angles = this.angles;
70 clone.v_angle = this.v_angle;
71 clone.avelocity = this.avelocity;
72 clone.damageforcescale = this.damageforcescale;
73 clone.effects = this.effects;
74 clone.glowmod = this.glowmod;
75 clone.event_damage = this.event_damage;
76 clone.anim_state = this.anim_state;
77 clone.anim_time = this.anim_time;
78 clone.anim_lower_action = this.anim_lower_action;
79 clone.anim_lower_time = this.anim_lower_time;
80 clone.anim_upper_action = this.anim_upper_action;
81 clone.anim_upper_time = this.anim_upper_time;
82 clone.anim_implicit_state = this.anim_implicit_state;
83 clone.anim_implicit_time = this.anim_implicit_time;
84 clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
85 clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
86 clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
87 clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
88 clone.dphitcontentsmask = this.dphitcontentsmask;
89 clone.death_time = this.death_time;
90 clone.pain_finished = this.pain_finished;
91 clone.health = this.health;
92 clone.armorvalue = this.armorvalue;
93 clone.armortype = this.armortype;
94 clone.model = this.model;
95 clone.modelindex = this.modelindex;
96 clone.skin = this.skin;
97 clone.species = this.species;
98 clone.move_qcphysics = false; // don't run gamecode logic on clones, too many
99 set_movetype(clone, this.move_movetype);
100 clone.solid = this.solid;
101 clone.takedamage = this.takedamage;
102 setcefc(clone, getcefc(this));
103 clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
104 clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
105 if (keepvelocity == 1)
106 clone.velocity = this.velocity;
107 clone.oldvelocity = clone.velocity;
108 clone.alpha = this.alpha;
109 clone.fade_time = this.fade_time;
110 clone.fade_rate = this.fade_rate;
111 //clone.weapon = this.weapon;
112 setorigin(clone, this.origin);
113 setsize(clone, this.mins, this.maxs);
114 clone.reset = SUB_Remove;
115 clone._ps = this._ps;
117 Drag_MoveDrag(this, clone);
119 if(clone.colormap <= maxclients && clone.colormap > 0)
120 clone.colormap = 1024 + this.clientcolors;
122 CSQCMODEL_AUTOINIT(clone);
123 clone.CopyBody_nextthink = this.nextthink;
124 clone.CopyBody_think = getthink(this);
125 clone.nextthink = time;
126 setthink(clone, CopyBody_Think);
127 // "bake" the current animation frame for clones (they don't get clientside animation)
128 animdecide_load_if_needed(clone);
129 animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
131 IL_PUSH(g_clones, clone);
133 MUTATOR_CALLHOOK(CopyBody, this, clone, keepvelocity);
136 void player_setupanimsformodel(entity this)
138 // load animation info
139 animdecide_load_if_needed(this);
140 animdecide_setstate(this, 0, false);
143 void player_anim(entity this)
145 int deadbits = (this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
148 // Decide on which death animation to use.
150 deadbits = ANIMSTATE_DEAD1;
152 deadbits = ANIMSTATE_DEAD2;
155 // Clear a previous death animation.
158 int animbits = deadbits;
159 if(STAT(FROZEN, this))
160 animbits |= ANIMSTATE_FROZEN;
161 if(this.move_movetype == MOVETYPE_FOLLOW)
162 animbits |= ANIMSTATE_FOLLOW;
164 animbits |= ANIMSTATE_DUCK;
165 animdecide_setstate(this, animbits, false);
166 animdecide_setimplicitstate(this, IS_ONGROUND(this));
169 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
173 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
175 // damage resistance (ignore most of the damage from a bullet or similar)
176 damage = max(damage - 5, 1);
178 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
182 if(sound_allowed(MSG_BROADCAST, attacker))
185 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
187 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
189 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
193 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
195 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
197 this.armorvalue = this.armorvalue - save;
198 this.health = this.health - take;
199 // pause regeneration for 5 seconds
200 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
202 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
203 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
204 this.dmg_inflictor = inflictor;
206 if (this.health <= -autocvar_sv_gibhealth && this.alpha >= 0)
208 // don't use any animations as a gib
210 // view just above the floor
211 this.view_ofs = '0 0 4';
213 Violence_GibSplash(this, 1, 1, attacker);
215 this.solid = SOLID_NOT; // restore later
216 this.takedamage = DAMAGE_NO; // restore later
217 if(this.damagedbycontents)
218 IL_REMOVE(g_damagedbycontents, this);
219 this.damagedbycontents = false;
223 void calculate_player_respawn_time(entity this)
228 float gametype_setting_tmp;
229 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
230 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
231 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
232 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
233 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
234 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
236 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
239 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
240 if(it.team == this.team)
243 if (sdelay_small_count == 0)
244 sdelay_small_count = 1;
245 if (sdelay_large_count == 0)
246 sdelay_large_count = 1;
250 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
253 if (sdelay_small_count == 0)
255 if (IS_INDEPENDENT_PLAYER(this))
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)
268 if (IS_INDEPENDENT_PLAYER(this))
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 this.respawn_time = ceil((time + sdelay) / waves) * waves;
293 this.respawn_time = time + sdelay;
295 if(sdelay < sdelay_max)
296 this.respawn_time_max = time + sdelay_max;
298 this.respawn_time_max = this.respawn_time;
300 if((sdelay + waves >= 5.0) && (this.respawn_time - time > 1.75))
301 this.respawn_countdown = 10; // first number to count down from is 10
303 this.respawn_countdown = -1; // do not count down
305 if(autocvar_g_forced_respawn)
306 this.respawn_flags = this.respawn_flags | RESPAWN_FORCE;
309 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
311 float take, save, dh, da;
315 dh = max(this.health, 0);
316 da = max(this.armorvalue, 0);
318 if(!DEATH_ISSPECIAL(deathtype))
320 damage *= Handicap_GetTotalHandicap(this);
321 if (this != attacker && IS_PLAYER(attacker))
323 damage /= Handicap_GetTotalHandicap(attacker);
327 if (time < this.spawnshieldtime && autocvar_g_spawnshield_blockdamage < 1)
328 damage *= 1 - max(0, autocvar_g_spawnshield_blockdamage);
330 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
332 // tuba causes blood to come out of the ears
337 ear1_z += 0.125 * this.view_ofs.z + 0.875 * this.maxs.z; // 7/8
339 makevectors(this.angles);
340 ear1 += v_right * -10;
341 ear2 += v_right * +10;
342 d = inflictor.origin - this.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), this, attacker);
349 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), this, attacker);
358 // force is already good
362 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
364 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
370 // don't reset pushltime for this damage as it may be an attempt to
371 // escape a lava pit or similar
372 //this.pushltime = 0;
375 else if(IS_PLAYER(attacker))
377 this.pusher = attacker;
378 this.pushltime = time + autocvar_g_maxpushtime;
379 this.istypefrag = PHYS_INPUT_BUTTON_CHAT(this);
381 else if(time < this.pushltime)
383 attacker = this.pusher;
384 this.pushltime = max(this.pushltime, time + 0.6);
392 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, this, force, take, save, deathtype, damage);
393 take = bound(0, M_ARGV(4, float), this.health);
394 save = bound(0, M_ARGV(5, float), this.armorvalue);
395 excess = max(0, damage - take - save);
397 if(sound_allowed(MSG_BROADCAST, attacker))
400 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
402 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
404 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
408 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
410 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
412 if (time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
414 if (!(this.flags & FL_GODMODE))
416 this.armorvalue = this.armorvalue - save;
417 this.health = this.health - take;
418 // pause regeneration for 5 seconds
420 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
422 if (time > this.pain_finished) //Don't switch pain sequences like crazy
424 this.pain_finished = time + 0.5; //Supajoe
426 if(autocvar_sv_gentle < 1) {
427 if(this.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
429 if (!this.animstate_override)
432 animdecide_setaction(this, ANIMACTION_PAIN1, true);
434 animdecide_setaction(this, ANIMACTION_PAIN2, true);
438 if(sound_allowed(MSG_BROADCAST, attacker))
439 if(this.health < 25 || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || take > 20 || attacker != this)
441 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
443 if(deathtype == DEATH_FALL.m_id)
444 PlayerSound(this, playersound_fall, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
445 else if(this.health > 75)
446 PlayerSound(this, playersound_pain100, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
447 else if(this.health > 50)
448 PlayerSound(this, playersound_pain75, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
449 else if(this.health > 25)
450 PlayerSound(this, playersound_pain50, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
452 PlayerSound(this, playersound_pain25, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
457 // throw off bot aim temporarily
459 if(IS_BOT_CLIENT(this) && this.health >= 1)
461 shake = damage * 5 / (bound(0,skill,100) + 1);
462 this.v_angle_x = this.v_angle.x + (random() * 2 - 1) * shake;
463 this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
464 this.v_angle_x = bound(-90, this.v_angle.x, 90);
468 this.max_armorvalue += (save + take);
470 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
471 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
472 this.dmg_inflictor = inflictor;
474 if (this != attacker) {
475 float realdmg = damage - excess;
476 if (IS_PLAYER(attacker)) {
477 GameRules_scoring_add(attacker, DMG, realdmg);
479 if (IS_PLAYER(this)) {
480 GameRules_scoring_add(this, DMGTAKEN, realdmg);
484 bool abot = (IS_BOT_CLIENT(attacker));
485 bool vbot = (IS_BOT_CLIENT(this));
487 bool valid_damage_for_weaponstats = false;
488 Weapon awep = WEP_Null;
489 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
491 if(vbot || IS_REAL_CLIENT(this))
492 if(abot || IS_REAL_CLIENT(attacker))
493 if(attacker && this != attacker)
494 if(DIFF_TEAM(this, attacker))
496 if(DEATH_ISSPECIAL(deathtype))
497 awep = attacker.(weaponentity).m_weapon;
499 awep = DEATH_WEAPONOF(deathtype);
500 valid_damage_for_weaponstats = true;
503 dh = dh - max(this.health, 0);
504 da = da - max(this.armorvalue, 0);
505 if(valid_damage_for_weaponstats)
507 WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);
510 MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
514 float defer_ClientKill_Now_TeamChange;
515 defer_ClientKill_Now_TeamChange = false;
519 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
523 if(valid_damage_for_weaponstats)
524 WeaponStats_LogKill(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot);
526 if(autocvar_sv_gentle < 1)
527 if(sound_allowed(MSG_BROADCAST, attacker))
529 if(deathtype == DEATH_DROWN.m_id)
530 PlayerSound(this, playersound_drown, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
532 PlayerSound(this, playersound_death, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
535 // get rid of kill indicator
536 if(this.killindicator)
538 delete(this.killindicator);
539 this.killindicator = NULL;
540 if(CS(this).killindicator_teamchange)
541 defer_ClientKill_Now_TeamChange = true;
543 if(this.classname == "body")
544 if(deathtype == DEATH_KILL.m_id)
546 // for the lemmings fans, a small harmless explosion
547 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
551 // print an obituary message
552 if(this.classname != "body")
553 Obituary (attacker, inflictor, this, deathtype);
555 // increment frag counter for used weapon type
556 Weapon w = DEATH_WEAPONOF(deathtype);
557 if(w != WEP_Null && accuracy_isgooddamage(attacker, this))
558 CS(attacker).accuracy.(accuracy_frags[w.m_id-1]) += 1;
560 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, this, deathtype, damage);
561 damage = M_ARGV(4, float);
562 excess = max(0, damage - take - save);
564 //Weapon wep = this.(weaponentity).m_weapon;
565 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
567 .entity went = weaponentities[slot];
568 if(!this.(weaponentity))
569 continue; // TODO: clones have no weapon, but we don't want to have to check this all the time
570 Weapon wep = this.(weaponentity).m_weapon;
571 wep.wr_playerdeath(wep, this, went);
574 RemoveGrapplingHooks(this);
576 Portal_ClearAllLater(this);
578 this.fixangle = true;
580 if(defer_ClientKill_Now_TeamChange)
581 ClientKill_Now_TeamChange(this); // can turn player into spectator
583 // player could have been miraculously resuscitated ;)
584 // e.g. players in freezetag get frozen, they don't really die
585 if(this.health >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
588 // when we get here, player actually dies
590 Unfreeze(this); // remove any icy remains
591 this.health = 0; // Unfreeze resets health, so we need to set it back
594 WaypointSprite_PlayerDead(this);
596 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
598 .entity went = weaponentities[slot];
599 SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(went).m_weapon, went);
602 // become fully visible
603 this.alpha = default_player_alpha;
604 // make the corpse upright (not tilted)
608 this.avelocity = '0 0 0';
609 // view from the floor
610 this.view_ofs = '0 0 -8';
612 set_movetype(this, MOVETYPE_TOSS);
614 this.solid = SOLID_CORPSE;
615 PS(this).ballistics_density = autocvar_g_ballistics_density_corpse;
616 // don't stick to the floor
617 UNSET_ONGROUND(this);
619 this.deadflag = DEAD_DYING;
621 STAT(MOVEVARS_SPECIALCOMMAND, this) = false; // sweet release
623 // when to allow respawn
624 calculate_player_respawn_time(this);
626 this.death_time = time;
628 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD1, true);
630 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD2, true);
634 setsize(this, this.mins, this.maxs);
636 // set damage function to corpse damage
637 this.event_damage = PlayerCorpseDamage;
638 // call the corpse damage function just in case it wants to gib
639 this.event_damage(this, inflictor, attacker, excess, deathtype, hitloc, force);
641 // set up to fade out later
642 SUB_SetFade (this, time + 6 + random (), 1);
643 // reset body think wrapper broken by SUB_SetFade
644 if(this.classname == "body" && getthink(this) != CopyBody_Think) {
645 this.CopyBody_think = getthink(this);
646 this.CopyBody_nextthink = this.nextthink;
647 setthink(this, CopyBody_Think);
648 this.nextthink = time;
651 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
653 // clones don't run any animation code any more, so we must gib them when they die :(
654 PlayerCorpseDamage(this, inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
657 // reset fields the weapons may use just in case
658 if(this.classname != "body")
660 FOREACH(Weapons, it != WEP_Null,
662 it.wr_resetplayer(it, this);
663 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
665 ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
669 MUTATOR_CALLHOOK(PlayerDied, this);
673 bool MoveToTeam(entity client, int team_colour, int type)
675 int lockteams_backup = lockteams; // backup any team lock
676 lockteams = 0; // disable locked teams
677 TeamchangeFrags(client); // move the players frags
678 if (!SetPlayerTeamSimple(client, team_colour))
682 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
683 lockteams = lockteams_backup; // restore the team lock
684 LogTeamchange(client.playerid, client.team, type);
688 /** print(), but only print if the server is not local */
689 void dedicated_print(string input)
691 if (server_is_dedicated) print(input);
694 void PrintToChat(entity player, string text)
696 text = strcat("\{1}^7", text, "\n");
697 sprint(player, text);
700 void DebugPrintToChat(entity player, string text)
702 if (autocvar_developer)
704 PrintToChat(player, text);
708 void PrintToChatAll(string text)
710 text = strcat("\{1}^7", text, "\n");
714 void DebugPrintToChatAll(string text)
716 if (autocvar_developer)
718 PrintToChatAll(text);
722 void PrintToChatTeam(int teamnum, string text)
724 text = strcat("\{1}^7", text, "\n");
725 FOREACH_CLIENT(IS_REAL_CLIENT(it),
727 if (it.team == teamnum)
734 void DebugPrintToChatTeam(int teamnum, string text)
736 if (autocvar_developer)
738 PrintToChatTeam(teamnum, text);
743 * message "": do not say, just test flood control
749 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol)
751 if (!teamsay && !privatesay && substring(msgin, 0, 1) == " ")
752 msgin = substring(msgin, 1, -1); // work around DP say bug (say_team does not have this!)
755 msgin = formatmessage(source, msgin);
758 if (!IS_PLAYER(source))
759 colorstr = "^0"; // black for spectators
761 colorstr = Team_ColorCode(source.team);
777 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
780 * using bprint solves this... me stupid
781 // how can we prevent the message from appearing in a listen server?
782 // for now, just give "say" back and only handle say_team
785 clientcommand(source, strcat("say ", msgin));
792 namestr = playername(source, autocvar_g_chat_teamcolors);
794 string colorprefix = (strdecolorize(namestr) == namestr) ? "^3" : "^7";
796 string msgstr, cmsgstr;
797 string privatemsgprefix = string_null;
798 int privatemsgprefixlen = 0;
800 msgstr = cmsgstr = "";
804 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
805 privatemsgprefixlen = strlen(msgstr);
806 msgstr = strcat(msgstr, msgin);
807 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
808 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay, autocvar_g_chat_teamcolors), ": ^7");
812 if(strstrofs(msgin, "/me", 0) >= 0)
814 //msgin = strreplace("/me", "", msgin);
815 //msgin = substring(msgin, 3, strlen(msgin));
816 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
817 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
820 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
821 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
825 if(strstrofs(msgin, "/me", 0) >= 0)
827 //msgin = strreplace("/me", "", msgin);
828 //msgin = substring(msgin, 3, strlen(msgin));
829 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
830 msgstr = strcat("\{1}^4* ", "^7", msgin);
834 msgstr = strcat(msgstr, (namestr != "") ? strcat(colorprefix, namestr, "^7: ") : "^7");
835 msgstr = strcat(msgstr, msgin);
839 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
842 string fullmsgstr = msgstr;
843 string fullcmsgstr = cmsgstr;
847 var .float flood_field = floodcontrol_chat;
848 if(floodcontrol && source)
856 flood_spl = autocvar_g_chat_flood_spl_tell;
857 flood_burst = autocvar_g_chat_flood_burst_tell;
858 flood_lmax = autocvar_g_chat_flood_lmax_tell;
859 flood_field = floodcontrol_chattell;
863 flood_spl = autocvar_g_chat_flood_spl_team;
864 flood_burst = autocvar_g_chat_flood_burst_team;
865 flood_lmax = autocvar_g_chat_flood_lmax_team;
866 flood_field = floodcontrol_chatteam;
870 flood_spl = autocvar_g_chat_flood_spl;
871 flood_burst = autocvar_g_chat_flood_burst;
872 flood_lmax = autocvar_g_chat_flood_lmax;
873 flood_field = floodcontrol_chat;
875 flood_burst = max(0, flood_burst - 1);
876 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
878 // do flood control for the default line size
881 getWrappedLine_remaining = msgstr;
884 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
886 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
889 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
891 if(getWrappedLine_remaining != "")
893 msgstr = strcat(msgstr, "\n");
897 if (time >= source.(flood_field))
899 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
909 if (time >= source.(flood_field))
910 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
915 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
916 source.(flood_field) = flood = 0;
919 string sourcemsgstr, sourcecmsgstr;
920 if(flood == 2) // cannot happen for empty msgstr
922 if(autocvar_g_chat_flood_notify_flooder)
924 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
929 sourcemsgstr = fullmsgstr;
930 sourcecmsgstr = fullcmsgstr;
936 sourcemsgstr = msgstr;
937 sourcecmsgstr = cmsgstr;
940 if (!privatesay && source && !IS_PLAYER(source))
943 if (teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage))
944 teamsay = -1; // spectators
948 LOG_INFO("NOTE: ", playername(source, true), "^7 is flooding.");
950 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
952 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
955 if(source && CS(source).muted)
957 // always fake the message
962 if (autocvar_g_chat_flood_notify_flooder)
964 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
975 if (privatesay && source && !IS_PLAYER(source))
978 if ((privatesay && !IS_PLAYER(privatesay)) || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage))
979 ret = -1; // just hide the message completely
982 MUTATOR_CALLHOOK(ChatMessage, source, ret);
983 ret = M_ARGV(1, int);
985 if(sourcemsgstr != "" && ret != 0)
987 if(ret < 0) // faked message, because the player is muted
989 sprint(source, sourcemsgstr);
990 if(sourcecmsgstr != "" && !privatesay)
991 centerprint(source, sourcecmsgstr);
993 else if(privatesay) // private message, between 2 people only
995 sprint(source, sourcemsgstr);
996 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
997 if(!MUTATOR_CALLHOOK(ChatMessageTo, privatesay, source))
999 sprint(privatesay, msgstr);
1001 centerprint(privatesay, cmsgstr);
1004 else if ( teamsay && CS(source).active_minigame )
1006 sprint(source, sourcemsgstr);
1007 dedicated_print(msgstr); // send to server console too
1008 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && CS(it).active_minigame == CS(source).active_minigame && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
1010 else if(teamsay > 0) // team message, only sent to team mates
1012 sprint(source, sourcemsgstr);
1013 dedicated_print(msgstr); // send to server console too
1014 if(sourcecmsgstr != "")
1015 centerprint(source, sourcecmsgstr);
1016 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), {
1019 centerprint(it, cmsgstr);
1022 else if(teamsay < 0) // spectator message, only sent to spectators
1024 sprint(source, sourcemsgstr);
1025 dedicated_print(msgstr); // send to server console too
1026 FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
1031 sprint(source, sourcemsgstr);
1032 dedicated_print(msgstr); // send to server console too
1033 MX_Say(strcat(playername(source, true), "^7: ", msgin));
1035 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));