3 #include <common/effects/all.qh>
6 #include "clientkill.qh"
9 #include "miscfunctions.qh"
11 #include "teamplay.qh"
12 #include "weapons/throwing.qh"
13 #include "command/common.qh"
14 #include "../common/state.qh"
15 #include "../common/anim.qh"
16 #include "../common/animdecide.qh"
17 #include "../common/csqcmodel_settings.qh"
18 #include "../common/gamemodes/sv_rules.qh"
19 #include "../common/deathtypes/all.qh"
20 #include "../common/mapobjects/subs.qh"
21 #include "../common/playerstats.qh"
22 #include "../lib/csqcmodel/sv_model.qh"
24 #include "../common/minigames/sv_minigames.qh"
26 #include "../common/physics/player.qh"
27 #include "../common/effects/qc/_mod.qh"
28 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
29 #include "../common/mapobjects/_mod.qh"
30 #include "../common/wepent.qh"
32 #include "weapons/weaponstats.qh"
34 #include "../common/animdecide.qh"
36 void Drop_Special_Items(entity player)
38 // called when the player has become stuck or frozen
39 // so objective items aren't stuck with the player
41 MUTATOR_CALLHOOK(DropSpecialItems, player);
44 void CopyBody_Think(entity this)
46 if(this.CopyBody_nextthink && time > this.CopyBody_nextthink)
48 this.CopyBody_think(this);
51 this.CopyBody_nextthink = this.nextthink;
52 this.CopyBody_think = getthink(this);
53 setthink(this, CopyBody_Think);
55 CSQCMODEL_AUTOUPDATE(this);
56 this.nextthink = time;
58 void CopyBody(entity this, float keepvelocity)
60 if (this.effects & EF_NODRAW)
62 entity clone = new(body);
65 clone.colormap = this.colormap;
66 clone.iscreature = this.iscreature;
67 clone.teleportable = this.teleportable;
68 clone.damagedbycontents = this.damagedbycontents;
69 if(clone.damagedbycontents)
70 IL_PUSH(g_damagedbycontents, clone);
71 clone.angles = this.angles;
72 clone.v_angle = this.v_angle;
73 clone.avelocity = this.avelocity;
74 clone.damageforcescale = this.damageforcescale;
75 clone.effects = this.effects;
76 clone.glowmod = this.glowmod;
77 clone.event_damage = this.event_damage;
78 clone.event_heal = this.event_heal;
79 clone.anim_state = this.anim_state;
80 clone.anim_time = this.anim_time;
81 clone.anim_lower_action = this.anim_lower_action;
82 clone.anim_lower_time = this.anim_lower_time;
83 clone.anim_upper_action = this.anim_upper_action;
84 clone.anim_upper_time = this.anim_upper_time;
85 clone.anim_implicit_state = this.anim_implicit_state;
86 clone.anim_implicit_time = this.anim_implicit_time;
87 clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
88 clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
89 clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
90 clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
91 clone.dphitcontentsmask = this.dphitcontentsmask;
92 clone.death_time = this.death_time;
93 clone.pain_finished = this.pain_finished;
94 SetResourceAmountExplicit(clone, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH));
95 SetResourceAmountExplicit(clone, RESOURCE_ARMOR, GetResourceAmount(this, RESOURCE_ARMOR));
96 clone.armortype = this.armortype;
97 clone.model = this.model;
98 clone.modelindex = this.modelindex;
99 clone.skin = this.skin;
100 clone.species = this.species;
101 clone.move_qcphysics = false; // don't run gamecode logic on clones, too many
102 set_movetype(clone, this.move_movetype);
103 clone.solid = this.solid;
104 clone.takedamage = this.takedamage;
105 setcefc(clone, getcefc(this));
106 clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
107 clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
108 if (keepvelocity == 1)
109 clone.velocity = this.velocity;
110 clone.oldvelocity = clone.velocity;
111 clone.alpha = this.alpha;
112 clone.fade_time = this.fade_time;
113 clone.fade_rate = this.fade_rate;
114 //clone.weapon = this.weapon;
115 setorigin(clone, this.origin);
116 setsize(clone, this.mins, this.maxs);
117 clone.reset = SUB_Remove;
118 clone._ps = this._ps;
120 Drag_MoveDrag(this, clone);
122 if(clone.colormap <= maxclients && clone.colormap > 0)
123 clone.colormap = 1024 + this.clientcolors;
125 CSQCMODEL_AUTOINIT(clone);
126 clone.CopyBody_nextthink = this.nextthink;
127 clone.CopyBody_think = getthink(this);
128 clone.nextthink = time;
129 setthink(clone, CopyBody_Think);
130 // "bake" the current animation frame for clones (they don't get clientside animation)
131 animdecide_load_if_needed(clone);
132 animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
134 IL_PUSH(g_clones, clone);
136 MUTATOR_CALLHOOK(CopyBody, this, clone, keepvelocity);
139 void player_setupanimsformodel(entity this)
141 // load animation info
142 animdecide_load_if_needed(this);
143 animdecide_setstate(this, 0, false);
146 void player_anim(entity this)
148 int deadbits = (this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
151 // Decide on which death animation to use.
153 deadbits = ANIMSTATE_DEAD1;
155 deadbits = ANIMSTATE_DEAD2;
158 // Clear a previous death animation.
161 int animbits = deadbits;
162 if(STAT(FROZEN, this))
163 animbits |= ANIMSTATE_FROZEN;
164 if(this.move_movetype == MOVETYPE_FOLLOW)
165 animbits |= ANIMSTATE_FOLLOW;
167 animbits |= ANIMSTATE_DUCK;
168 animdecide_setstate(this, animbits, false);
169 animdecide_setimplicitstate(this, IS_ONGROUND(this));
172 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
176 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
178 v = healtharmor_applydamage(GetResourceAmount(this, RESOURCE_ARMOR), 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 TakeResource(this, RESOURCE_ARMOR, save);
198 TakeResource(this, RESOURCE_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 (GetResourceAmount(this, RESOURCE_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)
225 if(MUTATOR_CALLHOOK(CalculateRespawnTime, 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, .entity weaponentity, vector hitloc, vector force)
311 float take, save, dh, da;
315 dh = max(GetResourceAmount(this, RESOURCE_HEALTH), 0);
316 da = max(GetResourceAmount(this, RESOURCE_ARMOR), 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(GetResourceAmount(this, RESOURCE_ARMOR), 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), GetResourceAmount(this, RESOURCE_HEALTH));
394 save = bound(0, M_ARGV(5, float), GetResourceAmount(this, RESOURCE_ARMOR));
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 TakeResource(this, RESOURCE_ARMOR, save);
417 TakeResource(this, RESOURCE_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);
437 float myhp = GetResourceAmount(this, RESOURCE_HEALTH);
439 if(myhp < 25 || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || take > 20 || attacker != this)
440 if(sound_allowed(MSG_BROADCAST, attacker))
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);
446 PlayerSound(this, playersound_pain100, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
448 PlayerSound(this, playersound_pain75, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
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) && GetResourceAmount(this, RESOURCE_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);
467 if (this != attacker) {
468 float realdmg = damage - excess;
469 if (IS_PLAYER(attacker)) {
470 GameRules_scoring_add(attacker, DMG, realdmg);
472 if (IS_PLAYER(this)) {
473 GameRules_scoring_add(this, DMGTAKEN, realdmg);
478 this.max_armorvalue += (save + take);
480 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
481 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
482 this.dmg_inflictor = inflictor;
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;
490 if(vbot || IS_REAL_CLIENT(this))
491 if(abot || IS_REAL_CLIENT(attacker))
492 if(attacker && this != attacker)
493 if(DIFF_TEAM(this, attacker))
495 if(DEATH_ISSPECIAL(deathtype))
496 awep = attacker.(weaponentity).m_weapon;
498 awep = DEATH_WEAPONOF(deathtype);
499 valid_damage_for_weaponstats = true;
502 dh = dh - max(GetResourceAmount(this, RESOURCE_HEALTH), 0);
503 da = da - max(GetResourceAmount(this, RESOURCE_ARMOR), 0);
504 if(valid_damage_for_weaponstats)
506 WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);
509 MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
511 if (GetResourceAmount(this, RESOURCE_HEALTH) < 1)
513 float defer_ClientKill_Now_TeamChange;
514 defer_ClientKill_Now_TeamChange = false;
518 PlayerStats_GameReport_Event_Player(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
522 if(valid_damage_for_weaponstats)
523 WeaponStats_LogKill(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot);
525 if(autocvar_sv_gentle < 1)
526 if(sound_allowed(MSG_BROADCAST, attacker))
528 if(deathtype == DEATH_DROWN.m_id)
529 PlayerSound(this, playersound_drown, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
531 PlayerSound(this, playersound_death, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
534 // get rid of kill indicator
535 if(this.killindicator)
537 delete(this.killindicator);
538 this.killindicator = NULL;
539 if(this.killindicator_teamchange)
540 defer_ClientKill_Now_TeamChange = true;
542 if(this.classname == "body")
543 if(deathtype == DEATH_KILL.m_id)
545 // for the lemmings fans, a small harmless explosion
546 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
550 // print an obituary message
551 if(this.classname != "body")
552 Obituary (attacker, inflictor, this, deathtype, weaponentity);
554 // increment frag counter for used weapon type
555 Weapon w = DEATH_WEAPONOF(deathtype);
556 if(w != WEP_Null && accuracy_isgooddamage(attacker, this))
557 CS(attacker).accuracy.(accuracy_frags[w.m_id-1]) += 1;
559 this.respawn_time = 0;
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];
569 continue; // TODO: clones have no weapon, but we don't want to have to check this all the time
570 Weapon wep = this.(went).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(GetResourceAmount(this, RESOURCE_HEALTH) >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
588 if (!this.respawn_time) // can be set in the mutator hook PlayerDies
589 calculate_player_respawn_time(this);
591 // when we get here, player actually dies
593 Unfreeze(this); // remove any icy remains
594 SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); // Unfreeze resets health, so we need to set it back
597 WaypointSprite_PlayerDead(this);
599 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
601 .entity went = weaponentities[slot];
602 SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(went).m_weapon, went);
605 // become fully visible
606 this.alpha = default_player_alpha;
607 // make the corpse upright (not tilted)
611 this.avelocity = '0 0 0';
612 // view from the floor
613 this.view_ofs = '0 0 -8';
615 set_movetype(this, MOVETYPE_TOSS);
617 this.solid = SOLID_CORPSE;
618 PS(this).ballistics_density = autocvar_g_ballistics_density_corpse;
619 // don't stick to the floor
620 UNSET_ONGROUND(this);
622 this.deadflag = DEAD_DYING;
624 STAT(MOVEVARS_SPECIALCOMMAND, this) = false; // sweet release
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);
632 // set damage function to corpse damage
633 this.event_damage = PlayerCorpseDamage;
634 this.event_heal = func_null;
635 // call the corpse damage function just in case it wants to gib
636 this.event_damage(this, inflictor, attacker, excess, deathtype, weaponentity, hitloc, force);
638 // set up to fade out later
639 SUB_SetFade (this, time + 6 + random (), 1);
640 // reset body think wrapper broken by SUB_SetFade
641 if(this.classname == "body" && getthink(this) != CopyBody_Think) {
642 this.CopyBody_think = getthink(this);
643 this.CopyBody_nextthink = this.nextthink;
644 setthink(this, CopyBody_Think);
645 this.nextthink = time;
648 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
650 // clones don't run any animation code any more, so we must gib them when they die :(
651 this.event_damage(this, inflictor, attacker, autocvar_sv_gibhealth + 1, deathtype, weaponentity, hitloc, force);
654 // reset fields the weapons may use just in case
655 if(this.classname != "body")
657 FOREACH(Weapons, it != WEP_Null,
659 it.wr_resetplayer(it, this);
660 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
662 ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
666 MUTATOR_CALLHOOK(PlayerDied, this);
670 bool PlayerHeal(entity targ, entity inflictor, float amount, float limit)
672 if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= limit)
675 GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, limit);
680 * message "": do not say, just test flood control
686 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol)
688 if (!teamsay && !privatesay && substring(msgin, 0, 1) == " ")
689 msgin = substring(msgin, 1, -1); // work around DP say bug (say_team does not have this!)
692 msgin = formatmessage(source, msgin);
695 if (!IS_PLAYER(source))
696 colorstr = "^0"; // black for spectators
698 colorstr = Team_ColorCode(source.team);
714 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
717 * using bprint solves this... me stupid
718 // how can we prevent the message from appearing in a listen server?
719 // for now, just give "say" back and only handle say_team
722 clientcommand(source, strcat("say ", msgin));
729 namestr = playername(source, autocvar_g_chat_teamcolors);
731 string colorprefix = (strdecolorize(namestr) == namestr) ? "^3" : "^7";
733 string msgstr, cmsgstr;
734 string privatemsgprefix = string_null;
735 int privatemsgprefixlen = 0;
737 msgstr = cmsgstr = "";
741 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
742 privatemsgprefixlen = strlen(msgstr);
743 msgstr = strcat(msgstr, msgin);
744 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
745 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay, autocvar_g_chat_teamcolors), ": ^7");
749 if(strstrofs(msgin, "/me", 0) >= 0)
751 //msgin = strreplace("/me", "", msgin);
752 //msgin = substring(msgin, 3, strlen(msgin));
753 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
754 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
757 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
758 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
762 if(strstrofs(msgin, "/me", 0) >= 0)
764 //msgin = strreplace("/me", "", msgin);
765 //msgin = substring(msgin, 3, strlen(msgin));
766 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
767 msgstr = strcat("\{1}^4* ", "^7", msgin);
771 msgstr = strcat(msgstr, (namestr != "") ? strcat(colorprefix, namestr, "^7: ") : "^7");
772 msgstr = strcat(msgstr, msgin);
776 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
779 string fullmsgstr = msgstr;
780 string fullcmsgstr = cmsgstr;
784 var .float flood_field = floodcontrol_chat;
785 if(floodcontrol && source)
793 flood_spl = autocvar_g_chat_flood_spl_tell;
794 flood_burst = autocvar_g_chat_flood_burst_tell;
795 flood_lmax = autocvar_g_chat_flood_lmax_tell;
796 flood_field = floodcontrol_chattell;
800 flood_spl = autocvar_g_chat_flood_spl_team;
801 flood_burst = autocvar_g_chat_flood_burst_team;
802 flood_lmax = autocvar_g_chat_flood_lmax_team;
803 flood_field = floodcontrol_chatteam;
807 flood_spl = autocvar_g_chat_flood_spl;
808 flood_burst = autocvar_g_chat_flood_burst;
809 flood_lmax = autocvar_g_chat_flood_lmax;
810 flood_field = floodcontrol_chat;
812 flood_burst = max(0, flood_burst - 1);
813 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
815 // do flood control for the default line size
818 getWrappedLine_remaining = msgstr;
821 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
823 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
826 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
828 if(getWrappedLine_remaining != "")
830 msgstr = strcat(msgstr, "\n");
834 if (time >= source.(flood_field))
836 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
846 if (time >= source.(flood_field))
847 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
852 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
853 source.(flood_field) = flood = 0;
856 string sourcemsgstr, sourcecmsgstr;
857 if(flood == 2) // cannot happen for empty msgstr
859 if(autocvar_g_chat_flood_notify_flooder)
861 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
866 sourcemsgstr = fullmsgstr;
867 sourcecmsgstr = fullcmsgstr;
873 sourcemsgstr = msgstr;
874 sourcecmsgstr = cmsgstr;
877 if (!privatesay && source && !IS_PLAYER(source))
880 if (teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage))
881 teamsay = -1; // spectators
885 LOG_INFO("NOTE: ", playername(source, true), "^7 is flooding.");
887 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
889 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
892 if(source && CS(source).muted)
894 // always fake the message
899 if (autocvar_g_chat_flood_notify_flooder)
901 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
912 if (privatesay && source && !IS_PLAYER(source))
915 if ((privatesay && IS_PLAYER(privatesay)) && ((autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage)))
916 ret = -1; // just hide the message completely
919 MUTATOR_CALLHOOK(ChatMessage, source, ret);
920 ret = M_ARGV(1, int);
922 if(sourcemsgstr != "" && ret != 0)
924 if(ret < 0) // faked message, because the player is muted
926 sprint(source, sourcemsgstr);
927 if(sourcecmsgstr != "" && !privatesay)
928 centerprint(source, sourcecmsgstr);
930 else if(privatesay) // private message, between 2 people only
932 sprint(source, sourcemsgstr);
933 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
934 if(!MUTATOR_CALLHOOK(ChatMessageTo, privatesay, source))
936 sprint(privatesay, msgstr);
938 centerprint(privatesay, cmsgstr);
941 else if ( teamsay && CS(source).active_minigame )
943 sprint(source, sourcemsgstr);
944 dedicated_print(msgstr); // send to server console too
945 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && CS(it).active_minigame == CS(source).active_minigame && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
947 else if(teamsay > 0) // team message, only sent to team mates
949 sprint(source, sourcemsgstr);
950 dedicated_print(msgstr); // send to server console too
951 if(sourcecmsgstr != "")
952 centerprint(source, sourcecmsgstr);
953 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), {
956 centerprint(it, cmsgstr);
959 else if(teamsay < 0) // spectator message, only sent to spectators
961 sprint(source, sourcemsgstr);
962 dedicated_print(msgstr); // send to server console too
963 FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
968 sprint(source, sourcemsgstr);
969 dedicated_print(msgstr); // send to server console too
970 MX_Say(strcat(playername(source, true), "^7: ", msgin));
972 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));