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/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);
37 void CopyBody_Think(void)
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(float keepvelocity)
53 if (self.effects & EF_NODRAW)
58 self.colormap = this.colormap;
59 self.iscreature = this.iscreature;
60 self.teleportable = this.teleportable;
61 self.damagedbycontents = this.damagedbycontents;
62 self.angles = this.angles;
63 self.v_angle = this.v_angle;
64 self.avelocity = this.avelocity;
65 self.classname = "body";
66 self.damageforcescale = this.damageforcescale;
67 self.effects = this.effects;
68 self.glowmod = this.glowmod;
69 self.event_damage = this.event_damage;
70 self.anim_state = this.anim_state;
71 self.anim_time = this.anim_time;
72 self.anim_lower_action = this.anim_lower_action;
73 self.anim_lower_time = this.anim_lower_time;
74 self.anim_upper_action = this.anim_upper_action;
75 self.anim_upper_time = this.anim_upper_time;
76 self.anim_implicit_state = this.anim_implicit_state;
77 self.anim_implicit_time = this.anim_implicit_time;
78 self.anim_lower_implicit_action = this.anim_lower_implicit_action;
79 self.anim_lower_implicit_time = this.anim_lower_implicit_time;
80 self.anim_upper_implicit_action = this.anim_upper_implicit_action;
81 self.anim_upper_implicit_time = this.anim_upper_implicit_time;
82 self.dphitcontentsmask = this.dphitcontentsmask;
83 self.death_time = this.death_time;
84 self.pain_finished = this.pain_finished;
85 self.health = this.health;
86 self.armorvalue = this.armorvalue;
87 self.armortype = this.armortype;
88 self.model = this.model;
89 self.modelindex = this.modelindex;
90 self.skin = this.skin;
91 self.species = this.species;
92 self.movetype = this.movetype;
93 self.solid = this.solid;
94 self.ballistics_density = this.ballistics_density;
95 self.takedamage = this.takedamage;
96 self.customizeentityforclient = this.customizeentityforclient;
97 self.uncustomizeentityforclient = this.uncustomizeentityforclient;
98 self.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
99 if (keepvelocity == 1)
100 self.velocity = this.velocity;
101 self.oldvelocity = self.velocity;
102 self.alpha = this.alpha;
103 self.fade_time = this.fade_time;
104 self.fade_rate = this.fade_rate;
105 //self.weapon = this.weapon;
106 setorigin(self, this.origin);
107 setsize(self, this.mins, this.maxs);
108 self.prevorigin = this.origin;
109 self.reset = SUB_Remove;
111 Drag_MoveDrag(this, self);
113 if(self.colormap <= maxclients && self.colormap > 0)
114 self.colormap = 1024 + this.clientcolors;
116 CSQCMODEL_AUTOINIT(self);
117 self.CopyBody_nextthink = this.nextthink;
118 self.CopyBody_think = this.think;
119 self.nextthink = time;
120 self.think = CopyBody_Think;
121 // "bake" the current animation frame for clones (they don't get clientside animation)
122 animdecide_load_if_needed(self);
123 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
128 float player_getspecies()
131 get_model_parameters(self.model, self.skin);
132 s = get_model_parameters_species;
133 get_model_parameters(string_null, 0);
135 return SPECIES_HUMAN;
139 void player_setupanimsformodel()
141 // load animation info
142 animdecide_load_if_needed(self);
143 animdecide_setstate(self, 0, false);
146 void player_anim (void)
148 int deadbits = (self.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;
163 animbits |= ANIMSTATE_FROZEN;
164 if(self.movetype == MOVETYPE_FOLLOW)
165 animbits |= ANIMSTATE_FOLLOW;
167 animbits |= ANIMSTATE_DUCK;
168 animdecide_setstate(self, animbits, false);
169 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
171 if (self.weaponentity)
173 updateanim(self.weaponentity);
174 if (!self.weaponentity.animstate_override)
175 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
179 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
183 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
185 // damage resistance (ignore most of the damage from a bullet or similar)
186 damage = max(damage - 5, 1);
188 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
192 if(sound_allowed(MSG_BROADCAST, attacker))
195 sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
197 sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
199 sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
203 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
205 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
207 self.armorvalue = self.armorvalue - save;
208 self.health = self.health - take;
209 // pause regeneration for 5 seconds
210 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
212 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
213 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
214 self.dmg_inflictor = inflictor;
216 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
218 // don't use any animations as a gib
220 // view just above the floor
221 self.view_ofs = '0 0 4';
223 Violence_GibSplash(self, 1, 1, attacker);
225 self.solid = SOLID_NOT; // restore later
226 self.takedamage = DAMAGE_NO; // restore later
227 self.damagedbycontents = false;
231 void calculate_player_respawn_time()
236 float gametype_setting_tmp;
237 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
238 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
239 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
240 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
241 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
242 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
244 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
250 if (pl.team == self.team)
252 if (sdelay_small_count == 0)
253 sdelay_small_count = 1;
254 if (sdelay_large_count == 0)
255 sdelay_large_count = 1;
262 if (sdelay_small_count == 0)
266 // Players play independently. No point in requiring enemies.
267 sdelay_small_count = 1;
271 // Players play AGAINST each other. Enemies required.
272 sdelay_small_count = 2;
275 if (sdelay_large_count == 0)
279 // Players play independently. No point in requiring enemies.
280 sdelay_large_count = 1;
284 // Players play AGAINST each other. Enemies required.
285 sdelay_large_count = 2;
292 if (pcount <= sdelay_small_count)
293 sdelay = sdelay_small;
294 else if (pcount >= sdelay_large_count)
295 sdelay = sdelay_large;
296 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
297 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
300 self.respawn_time = ceil((time + sdelay) / waves) * waves;
302 self.respawn_time = time + sdelay;
304 if(sdelay < sdelay_max)
305 self.respawn_time_max = time + sdelay_max;
307 self.respawn_time_max = self.respawn_time;
309 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
310 self.respawn_countdown = 10; // first number to count down from is 10
312 self.respawn_countdown = -1; // do not count down
314 if(autocvar_g_forced_respawn)
315 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
318 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
320 float take, save, dh, da;
323 float valid_damage_for_weaponstats;
326 dh = max(self.health, 0);
327 da = max(self.armorvalue, 0);
329 if(!DEATH_ISSPECIAL(deathtype))
331 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
333 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
336 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
338 // tuba causes blood to come out of the ears
343 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
345 makevectors(self.angles);
346 ear1 += v_right * -10;
347 ear2 += v_right * +10;
348 d = inflictor.origin - self.origin;
350 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
352 f = 0; // Assum ecenter.
353 force = v_right * vlen(force);
354 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
355 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
364 // force is already good
368 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
371 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
377 // don't reset pushltime for self damage as it may be an attempt to
378 // escape a lava pit or similar
379 //self.pushltime = 0;
382 else if(IS_PLAYER(attacker))
384 self.pusher = attacker;
385 self.pushltime = time + autocvar_g_maxpushtime;
386 self.istypefrag = self.BUTTON_CHAT;
388 else if(time < self.pushltime)
390 attacker = self.pusher;
391 self.pushltime = max(self.pushltime, time + 0.6);
399 frag_damage = damage;
400 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
401 take = bound(0, damage_take, self.health);
402 save = bound(0, damage_save, self.armorvalue);
403 excess = max(0, damage - take - save);
405 if(sound_allowed(MSG_BROADCAST, attacker))
408 sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
410 sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
412 sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
416 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
418 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
420 if (time >= self.spawnshieldtime)
422 if (!(self.flags & FL_GODMODE))
424 self.armorvalue = self.armorvalue - save;
425 self.health = self.health - take;
426 // pause regeneration for 5 seconds
428 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
430 if (time > self.pain_finished) //Don't switch pain sequences like crazy
432 self.pain_finished = time + 0.5; //Supajoe
434 if(autocvar_sv_gentle < 1) {
435 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
437 if (!self.animstate_override)
440 animdecide_setaction(self, ANIMACTION_PAIN1, true);
442 animdecide_setaction(self, ANIMACTION_PAIN2, true);
446 if(sound_allowed(MSG_BROADCAST, attacker))
447 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
449 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
451 if(deathtype == DEATH_FALL.m_id)
452 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
453 else if(self.health > 75) // TODO make a "gentle" version?
454 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
455 else if(self.health > 50)
456 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
457 else if(self.health > 25)
458 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
460 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
465 // throw off bot aim temporarily
467 if(IS_BOT_CLIENT(self) && self.health >= 1)
469 shake = damage * 5 / (bound(0,skill,100) + 1);
470 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
471 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
472 self.v_angle_x = bound(-90, self.v_angle.x, 90);
476 self.max_armorvalue += (save + take);
478 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
479 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
480 self.dmg_inflictor = inflictor;
483 abot = (IS_BOT_CLIENT(attacker));
484 vbot = (IS_BOT_CLIENT(self));
486 valid_damage_for_weaponstats = 0;
487 Weapon awep = WEP_Null;
489 if(vbot || IS_REAL_CLIENT(self))
490 if(abot || IS_REAL_CLIENT(attacker))
491 if(attacker && self != attacker)
492 if(DIFF_TEAM(self, attacker))
494 if(DEATH_ISSPECIAL(deathtype))
495 awep = get_weaponinfo(attacker.weapon);
497 awep = DEATH_WEAPONOF(deathtype);
498 valid_damage_for_weaponstats = 1;
501 if(valid_damage_for_weaponstats)
503 dh = dh - max(self.health, 0);
504 da = da - max(self.armorvalue, 0);
505 WeaponStats_LogDamage(awep.m_id, abot, self.weapon, vbot, dh + da);
506 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc);
511 float defer_ClientKill_Now_TeamChange;
512 defer_ClientKill_Now_TeamChange = false;
516 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
520 if(valid_damage_for_weaponstats)
521 WeaponStats_LogKill(awep.m_id, abot, self.weapon, vbot);
523 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
524 if(sound_allowed(MSG_BROADCAST, attacker))
526 if(deathtype == DEATH_DROWN.m_id)
527 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
529 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
532 // get rid of kill indicator
533 if(self.killindicator)
535 remove(self.killindicator);
536 self.killindicator = world;
537 if(self.killindicator_teamchange)
538 defer_ClientKill_Now_TeamChange = true;
540 if(self.classname == "body")
541 if(deathtype == DEATH_KILL.m_id)
543 // for the lemmings fans, a small harmless explosion
544 Send_Effect(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
548 // print an obituary message
549 if(self.classname != "body")
550 Obituary (attacker, inflictor, self, deathtype);
552 // increment frag counter for used weapon type
553 Weapon w = DEATH_WEAPONOF(deathtype);
555 if(accuracy_isgooddamage(attacker, self))
556 attacker.accuracy.(accuracy_frags[w.m_id-1]) += 1;
558 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
559 excess = frag_damage;
561 Weapon wep = get_weaponinfo(self.weapon);
562 wep.wr_playerdeath(wep);
564 RemoveGrapplingHook(self);
566 Portal_ClearAllLater(self);
568 self.fixangle = true;
570 if(defer_ClientKill_Now_TeamChange)
571 ClientKill_Now_TeamChange(); // can turn player into spectator
573 // player could have been miraculously resuscitated ;)
574 // e.g. players in freezetag get frozen, they don't really die
575 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
578 // when we get here, player actually dies
580 Unfreeze(self); // remove any icy remains
581 self.health = 0; // Unfreeze resets health, so we need to set it back
584 WaypointSprite_PlayerDead();
586 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
588 // become fully visible
589 self.alpha = default_player_alpha;
590 // make the corpse upright (not tilted)
594 self.avelocity = '0 0 0';
595 // view from the floor
596 self.view_ofs = '0 0 -8';
598 self.movetype = MOVETYPE_TOSS;
600 self.solid = SOLID_CORPSE;
601 self.ballistics_density = autocvar_g_ballistics_density_corpse;
602 // don't stick to the floor
603 self.flags &= ~FL_ONGROUND;
605 self.deadflag = DEAD_DYING;
607 // when to allow respawn
608 calculate_player_respawn_time();
610 self.death_time = time;
612 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
614 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
618 setsize(self, self.mins, self.maxs);
620 // set damage function to corpse damage
621 self.event_damage = PlayerCorpseDamage;
622 // call the corpse damage function just in case it wants to gib
623 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
625 // set up to fade out later
626 SUB_SetFade (self, time + 6 + random (), 1);
627 // reset body think wrapper broken by SUB_SetFade
628 if(self.classname == "body" && self.think != CopyBody_Think) {
629 self.CopyBody_think = self.think;
630 self.CopyBody_nextthink = self.nextthink;
631 self.think = CopyBody_Think;
632 self.nextthink = time;
635 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
637 // clones don't run any animation code any more, so we must gib them when they die :(
638 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
641 // reset fields the weapons may use just in case
642 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
644 Weapon w = get_weaponinfo(j);
646 ATTACK_FINISHED_FOR(self, j) = 0;
651 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
652 // message "": do not say, just test flood control
658 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
660 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 FOR_EACH_REALCLIENT(head)
908 if(head.active_minigame == source.active_minigame)
909 sprint(head, msgstr);
911 else if(teamsay > 0) // team message, only sent to team mates
913 sprint(source, sourcemsgstr);
914 dedicated_print(msgstr); // send to server console too
915 if(sourcecmsgstr != "")
916 centerprint(source, sourcecmsgstr);
917 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
920 sprint(head, msgstr);
922 centerprint(head, cmsgstr);
925 else if(teamsay < 0) // spectator message, only sent to spectators
927 sprint(source, sourcemsgstr);
928 dedicated_print(msgstr); // send to server console too
929 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
931 sprint(head, msgstr);
933 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
935 sprint(source, sourcemsgstr);
936 dedicated_print(msgstr); // send to server console too
937 FOR_EACH_REALCLIENT(head)
939 sprint(head, msgstr);
942 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
948 float GetVoiceMessageVoiceType(string type)
951 return VOICETYPE_TAUNT;
952 if(type == "teamshoot")
953 return VOICETYPE_LASTATTACKER;
954 return VOICETYPE_TEAMRADIO;
957 .string GetVoiceMessageSampleField(string type)
959 GetPlayerSoundSampleField_notFound = 0;
962 #define _VOICEMSG(m) case #m: return playersound_##m;
966 GetPlayerSoundSampleField_notFound = 1;
967 return playersound_taunt;
970 .string GetPlayerSoundSampleField(string type)
972 GetPlayerSoundSampleField_notFound = 0;
975 #define _VOICEMSG(m) case #m: return playersound_##m;
979 GetPlayerSoundSampleField_notFound = 1;
980 return playersound_taunt;
983 void PrecacheGlobalSound(string samplestring)
986 tokenize_console(samplestring);
990 for(i = 1; i <= n; ++i)
991 precache_sound(strcat(argv(0), ftos(i), ".wav"));
995 precache_sound(strcat(argv(0), ".wav"));
999 void PrecachePlayerSounds(string f)
1001 int fh = fopen(f, FILE_READ);
1004 for (string s; (s = fgets(fh)); )
1006 int n = tokenize_console(s);
1009 if (n != 0) LOG_TRACEF("Invalid sound info line: %s\n", s);
1012 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1016 if (!allvoicesamples)
1018 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1021 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1025 void ClearPlayerSounds()
1027 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1033 float LoadPlayerSounds(string f, float first)
1038 fh = fopen(f, FILE_READ);
1041 LOG_TRACE("Player sound file not found: ", f, "\n");
1044 while((s = fgets(fh)))
1046 if(tokenize_console(s) != 3)
1048 field = GetPlayerSoundSampleField(argv(0));
1049 if(GetPlayerSoundSampleField_notFound)
1050 field = GetVoiceMessageSampleField(argv(0));
1051 if(GetPlayerSoundSampleField_notFound)
1054 strunzone(self.(field));
1055 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1061 void UpdatePlayerSounds()
1063 if(self.modelindex == self.modelindex_for_playersound)
1064 if(self.skin == self.skin_for_playersound)
1066 self.modelindex_for_playersound = self.modelindex;
1067 self.skin_for_playersound = self.skin;
1068 ClearPlayerSounds();
1069 LoadPlayerSounds("sound/player/default.sounds", 1);
1070 if(!autocvar_g_debug_defaultsounds)
1071 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1072 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1075 void FakeGlobalSound(string sample, float chan, float voicetype)
1083 tokenize_console(sample);
1086 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1088 sample = strcat(argv(0), ".wav"); // randomization
1092 case VOICETYPE_LASTATTACKER_ONLY:
1094 case VOICETYPE_LASTATTACKER:
1098 if(IS_REAL_CLIENT(msg_entity))
1099 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1102 case VOICETYPE_TEAMRADIO:
1104 if(msg_entity.cvar_cl_voice_directional == 1)
1105 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1107 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1109 case VOICETYPE_AUTOTAUNT:
1114 if(autocvar_sv_gentle)
1116 tauntrand = random();
1118 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1120 if (msg_entity.cvar_cl_voice_directional >= 1)
1121 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1123 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1126 case VOICETYPE_TAUNT:
1128 if(self.deadflag == DEAD_NO)
1129 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1132 if(autocvar_sv_gentle)
1135 if (msg_entity.cvar_cl_voice_directional >= 1)
1136 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1138 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1140 case VOICETYPE_PLAYERSOUND:
1142 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1145 backtrace("Invalid voice type!");
1150 void GlobalSound(string sample, float chan, float voicetype)
1158 tokenize_console(sample);
1161 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1163 sample = strcat(argv(0), ".wav"); // randomization
1167 case VOICETYPE_LASTATTACKER_ONLY:
1170 msg_entity = self.pusher;
1171 if(IS_REAL_CLIENT(msg_entity))
1173 if(msg_entity.cvar_cl_voice_directional == 1)
1174 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1176 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1180 case VOICETYPE_LASTATTACKER:
1183 msg_entity = self.pusher;
1184 if(IS_REAL_CLIENT(msg_entity))
1186 if(msg_entity.cvar_cl_voice_directional == 1)
1187 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1189 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1192 if(IS_REAL_CLIENT(msg_entity))
1193 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1196 case VOICETYPE_TEAMRADIO:
1197 FOR_EACH_REALCLIENT(msg_entity)
1198 if(!teamplay || msg_entity.team == self.team)
1200 if(msg_entity.cvar_cl_voice_directional == 1)
1201 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1203 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1206 case VOICETYPE_AUTOTAUNT:
1211 if(autocvar_sv_gentle)
1213 tauntrand = random();
1214 FOR_EACH_REALCLIENT(msg_entity)
1215 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1217 if (msg_entity.cvar_cl_voice_directional >= 1)
1218 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1220 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1223 case VOICETYPE_TAUNT:
1225 if(self.deadflag == DEAD_NO)
1226 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1229 if(autocvar_sv_gentle)
1231 FOR_EACH_REALCLIENT(msg_entity)
1233 if (msg_entity.cvar_cl_voice_directional >= 1)
1234 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1236 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1239 case VOICETYPE_PLAYERSOUND:
1240 _sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1243 backtrace("Invalid voice type!");
1248 void PlayerSound(.string samplefield, float chan, float voicetype)
1250 GlobalSound(self.(samplefield), chan, voicetype);
1253 void VoiceMessage(string type, string msg)
1255 float voicetype, ownteam;
1257 var .string sample = GetVoiceMessageSampleField(type);
1259 if(GetPlayerSoundSampleField_notFound)
1261 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1265 voicetype = GetVoiceMessageVoiceType(type);
1266 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1268 flood = Say(self, ownteam, world, msg, 1);
1270 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1271 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1273 GlobalSound(self.(sample), CH_VOICE, voicetype);
1276 void MoveToTeam(entity client, float team_colour, float type)
1278 float lockteams_backup;
1280 lockteams_backup = lockteams; // backup any team lock
1282 lockteams = 0; // disable locked teams
1284 TeamchangeFrags(client); // move the players frags
1285 SetPlayerColors(client, team_colour - 1); // set the players colour
1286 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
1288 lockteams = lockteams_backup; // restore the team lock
1290 LogTeamchange(client.playerid, client.team, type);