1 #include "cl_player.qh"
8 #include "g_violence.qh"
9 #include "miscfunctions.qh"
11 #include "teamplay.qh"
12 #include "waypointsprites.qh"
13 #include "weapons/throwing.qh"
14 #include "command/common.qh"
15 #include "../common/animdecide.qh"
16 #include "../common/csqcmodel_settings.qh"
17 #include "../common/deathtypes.qh"
18 #include "../common/triggers/subs.qh"
19 #include "../common/playerstats.qh"
20 #include "../csqcmodellib/sv_model.qh"
22 #include "weapons/weaponstats.qh"
24 #include "../common/animdecide.qh"
26 void CopyBody_Think(void)
28 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
30 self.CopyBody_think();
33 self.CopyBody_nextthink = self.nextthink;
34 self.CopyBody_think = self.think;
35 self.think = CopyBody_Think;
37 CSQCMODEL_AUTOUPDATE();
38 self.nextthink = time;
40 void CopyBody(float keepvelocity)
43 if (self.effects & EF_NODRAW)
48 self.lip = oldself.lip;
49 self.colormap = oldself.colormap;
50 self.iscreature = oldself.iscreature;
51 self.teleportable = oldself.teleportable;
52 self.damagedbycontents = oldself.damagedbycontents;
53 self.angles = oldself.angles;
54 self.v_angle = oldself.v_angle;
55 self.avelocity = oldself.avelocity;
56 self.classname = "body";
57 self.damageforcescale = oldself.damageforcescale;
58 self.effects = oldself.effects;
59 self.glowmod = oldself.glowmod;
60 self.event_damage = oldself.event_damage;
61 self.anim_state = oldself.anim_state;
62 self.anim_time = oldself.anim_time;
63 self.anim_lower_action = oldself.anim_lower_action;
64 self.anim_lower_time = oldself.anim_lower_time;
65 self.anim_upper_action = oldself.anim_upper_action;
66 self.anim_upper_time = oldself.anim_upper_time;
67 self.anim_implicit_state = oldself.anim_implicit_state;
68 self.anim_implicit_time = oldself.anim_implicit_time;
69 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
70 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
71 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
72 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
73 self.dphitcontentsmask = oldself.dphitcontentsmask;
74 self.death_time = oldself.death_time;
75 self.pain_finished = oldself.pain_finished;
76 self.health = oldself.health;
77 self.armorvalue = oldself.armorvalue;
78 self.armortype = oldself.armortype;
79 self.model = oldself.model;
80 self.modelindex = oldself.modelindex;
81 self.skin = oldself.skin;
82 self.species = oldself.species;
83 self.movetype = oldself.movetype;
84 self.solid = oldself.solid;
85 self.ballistics_density = oldself.ballistics_density;
86 self.takedamage = oldself.takedamage;
87 self.customizeentityforclient = oldself.customizeentityforclient;
88 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
89 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
90 if (keepvelocity == 1)
91 self.velocity = oldself.velocity;
92 self.oldvelocity = self.velocity;
93 self.alpha = oldself.alpha;
94 self.fade_time = oldself.fade_time;
95 self.fade_rate = oldself.fade_rate;
96 //self.weapon = oldself.weapon;
97 setorigin(self, oldself.origin);
98 setsize(self, oldself.mins, oldself.maxs);
99 self.prevorigin = oldself.origin;
100 self.reset = SUB_Remove;
102 Drag_MoveDrag(oldself, self);
104 if(self.colormap <= maxclients && self.colormap > 0)
105 self.colormap = 1024 + oldself.clientcolors;
107 CSQCMODEL_AUTOINIT();
108 self.CopyBody_nextthink = oldself.nextthink;
109 self.CopyBody_think = oldself.think;
110 self.nextthink = time;
111 self.think = CopyBody_Think;
112 // "bake" the current animation frame for clones (they don't get clientside animation)
113 animdecide_load_if_needed(self);
114 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
119 float player_getspecies()
122 get_model_parameters(self.model, self.skin);
123 s = get_model_parameters_species;
124 get_model_parameters(string_null, 0);
126 return SPECIES_HUMAN;
130 void player_setupanimsformodel()
132 // load animation info
133 animdecide_load_if_needed(self);
134 animdecide_setstate(self, 0, false);
137 void player_anim (void)
139 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
142 // Decide on which death animation to use.
144 deadbits = ANIMSTATE_DEAD1;
146 deadbits = ANIMSTATE_DEAD2;
149 // Clear a previous death animation.
152 int animbits = deadbits;
154 animbits |= ANIMSTATE_FROZEN;
156 animbits |= ANIMSTATE_DUCK;
157 animdecide_setstate(self, animbits, false);
158 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
160 if (self.weaponentity)
162 updateanim(self.weaponentity);
163 if (!self.weaponentity.animstate_override)
164 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
168 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
172 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
174 // damage resistance (ignore most of the damage from a bullet or similar)
175 damage = max(damage - 5, 1);
177 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
181 if(sound_allowed(MSG_BROADCAST, attacker))
184 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
186 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
188 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
192 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
194 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
196 self.armorvalue = self.armorvalue - save;
197 self.health = self.health - take;
198 // pause regeneration for 5 seconds
199 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
201 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
202 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
203 self.dmg_inflictor = inflictor;
205 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
207 // don't use any animations as a gib
209 // view just above the floor
210 self.view_ofs = '0 0 4';
212 Violence_GibSplash(self, 1, 1, attacker);
214 self.solid = SOLID_NOT; // restore later
215 self.takedamage = DAMAGE_NO; // restore later
216 self.damagedbycontents = false;
220 void calculate_player_respawn_time()
225 float gametype_setting_tmp;
226 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
227 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
228 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
229 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
230 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
231 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
233 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
239 if (pl.team == self.team)
241 if (sdelay_small_count == 0)
242 sdelay_small_count = 1;
243 if (sdelay_large_count == 0)
244 sdelay_large_count = 1;
251 if (sdelay_small_count == 0)
255 // Players play independently. No point in requiring enemies.
256 sdelay_small_count = 1;
260 // Players play AGAINST each other. Enemies required.
261 sdelay_small_count = 2;
264 if (sdelay_large_count == 0)
268 // Players play independently. No point in requiring enemies.
269 sdelay_large_count = 1;
273 // Players play AGAINST each other. Enemies required.
274 sdelay_large_count = 2;
281 if (pcount <= sdelay_small_count)
282 sdelay = sdelay_small;
283 else if (pcount >= sdelay_large_count)
284 sdelay = sdelay_large;
285 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
286 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
289 self.respawn_time = ceil((time + sdelay) / waves) * waves;
291 self.respawn_time = time + sdelay;
293 if(sdelay < sdelay_max)
294 self.respawn_time_max = time + sdelay_max;
296 self.respawn_time_max = self.respawn_time;
298 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
299 self.respawn_countdown = 10; // first number to count down from is 10
301 self.respawn_countdown = -1; // do not count down
303 if(autocvar_g_forced_respawn)
304 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
307 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
309 float take, save, dh, da;
312 float valid_damage_for_weaponstats;
315 dh = max(self.health, 0);
316 da = max(self.armorvalue, 0);
318 if(!DEATH_ISSPECIAL(deathtype))
320 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
322 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
325 if(DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
327 // tuba causes blood to come out of the ears
332 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
334 makevectors(self.angles);
335 ear1 += v_right * -10;
336 ear2 += v_right * +10;
337 d = inflictor.origin - self.origin;
339 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
341 f = 0; // Assum ecenter.
342 force = v_right * vlen(force);
343 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
344 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
353 // force is already good
357 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
360 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
366 // don't reset pushltime for self damage as it may be an attempt to
367 // escape a lava pit or similar
368 //self.pushltime = 0;
371 else if(IS_PLAYER(attacker))
373 self.pusher = attacker;
374 self.pushltime = time + autocvar_g_maxpushtime;
375 self.istypefrag = self.BUTTON_CHAT;
377 else if(time < self.pushltime)
379 attacker = self.pusher;
380 self.pushltime = max(self.pushltime, time + 0.6);
388 frag_damage = damage;
389 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
390 take = bound(0, damage_take, self.health);
391 save = bound(0, damage_save, self.armorvalue);
392 excess = max(0, damage - take - save);
394 if(sound_allowed(MSG_BROADCAST, attacker))
397 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
399 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
401 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
405 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
407 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
409 if (time >= self.spawnshieldtime)
411 if (!(self.flags & FL_GODMODE))
413 self.armorvalue = self.armorvalue - save;
414 self.health = self.health - take;
415 // pause regeneration for 5 seconds
417 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
419 if (time > self.pain_finished) //Don't switch pain sequences like crazy
421 self.pain_finished = time + 0.5; //Supajoe
423 if(autocvar_sv_gentle < 1) {
424 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
426 if (!self.animstate_override)
429 animdecide_setaction(self, ANIMACTION_PAIN1, true);
431 animdecide_setaction(self, ANIMACTION_PAIN2, true);
435 if(sound_allowed(MSG_BROADCAST, attacker))
436 if((self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !((get_weaponinfo(DEATH_WEAPONOF(deathtype))).spawnflags & WEP_FLAG_CANCLIMB) || attacker != self) // WEAPONTODO: create separate limit for pain notification with laser
438 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
440 if(deathtype == DEATH_FALL)
441 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
442 else if(self.health > 75) // TODO make a "gentle" version?
443 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
444 else if(self.health > 50)
445 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
446 else if(self.health > 25)
447 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
449 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
454 // throw off bot aim temporarily
456 if(IS_BOT_CLIENT(self) && self.health >= 1)
458 shake = damage * 5 / (bound(0,skill,100) + 1);
459 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
460 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
461 self.v_angle_x = bound(-90, self.v_angle.x, 90);
465 self.max_armorvalue += (save + take);
467 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
468 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
469 self.dmg_inflictor = inflictor;
471 float abot, vbot, awep;
472 abot = (IS_BOT_CLIENT(attacker));
473 vbot = (IS_BOT_CLIENT(self));
475 valid_damage_for_weaponstats = 0;
478 if(vbot || IS_REAL_CLIENT(self))
479 if(abot || IS_REAL_CLIENT(attacker))
480 if(attacker && self != attacker)
481 if(DIFF_TEAM(self, attacker))
483 if(DEATH_ISSPECIAL(deathtype))
484 awep = attacker.weapon;
486 awep = DEATH_WEAPONOF(deathtype);
487 valid_damage_for_weaponstats = 1;
490 if(valid_damage_for_weaponstats)
492 dh = dh - max(self.health, 0);
493 da = da - max(self.armorvalue, 0);
494 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
495 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc);
500 float defer_ClientKill_Now_TeamChange;
501 defer_ClientKill_Now_TeamChange = false;
505 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
509 if(valid_damage_for_weaponstats)
510 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
512 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
513 if(sound_allowed(MSG_BROADCAST, attacker))
515 if(deathtype == DEATH_DROWN)
516 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
518 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
521 // get rid of kill indicator
522 if(self.killindicator)
524 remove(self.killindicator);
525 self.killindicator = world;
526 if(self.killindicator_teamchange)
527 defer_ClientKill_Now_TeamChange = true;
529 if(self.classname == "body")
530 if(deathtype == DEATH_KILL)
532 // for the lemmings fans, a small harmless explosion
533 Send_Effect("rocket_explode", self.origin, '0 0 0', 1);
537 // print an obituary message
538 if(self.classname != "body")
539 Obituary (attacker, inflictor, self, deathtype);
541 // increment frag counter for used weapon type
542 int w = DEATH_WEAPONOF(deathtype);
544 if(accuracy_isgooddamage(attacker, self))
545 attacker.accuracy.(accuracy_frags[w-1]) += 1;
547 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
549 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
551 RemoveGrapplingHook(self);
553 Portal_ClearAllLater(self);
555 self.fixangle = true;
557 if(defer_ClientKill_Now_TeamChange)
558 ClientKill_Now_TeamChange(); // 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(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
565 // when we get here, player actually dies
567 Unfreeze(self); // remove any icy remains
568 self.health = 0; // Unfreeze resets health, so we need to set it back
571 WaypointSprite_PlayerDead();
573 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
575 // become fully visible
576 self.alpha = default_player_alpha;
577 // make the corpse upright (not tilted)
581 self.avelocity = '0 0 0';
582 // view from the floor
583 self.view_ofs = '0 0 -8';
585 self.movetype = MOVETYPE_TOSS;
587 self.solid = SOLID_CORPSE;
588 self.ballistics_density = autocvar_g_ballistics_density_corpse;
589 // don't stick to the floor
590 self.flags &= ~FL_ONGROUND;
592 self.deadflag = DEAD_DYING;
594 // when to allow respawn
595 calculate_player_respawn_time();
597 self.death_time = time;
599 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
601 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
605 setsize(self, self.mins, self.maxs);
607 // set damage function to corpse damage
608 self.event_damage = PlayerCorpseDamage;
609 // call the corpse damage function just in case it wants to gib
610 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
612 // set up to fade out later
613 SUB_SetFade (self, time + 6 + random (), 1);
614 // reset body think wrapper broken by SUB_SetFade
615 if(self.classname == "body" && self.think != CopyBody_Think) {
616 self.CopyBody_think = self.think;
617 self.CopyBody_nextthink = self.nextthink;
618 self.think = CopyBody_Think;
619 self.nextthink = time;
622 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
624 // clones don't run any animation code any more, so we must gib them when they die :(
625 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
628 // reset fields the weapons may use just in case
629 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
631 WEP_ACTION(j, WR_RESETPLAYER);
632 ATTACK_FINISHED_FOR(self, j) = 0;
637 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
638 // message "": do not say, just test flood control
644 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
646 var .float flood_field;
649 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
651 if(!teamsay && !privatesay)
652 if(substring(msgin, 0, 1) == " ")
653 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
655 msgin = formatmessage(msgin);
657 if (!IS_PLAYER(source))
658 colorstr = "^0"; // black for spectators
660 colorstr = Team_ColorCode(source.team);
667 if(intermission_running)
671 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
674 * using bprint solves this... me stupid
675 // how can we prevent the message from appearing in a listen server?
676 // for now, just give "say" back and only handle say_team
679 clientcommand(self, strcat("say ", msgin));
684 if(autocvar_g_chat_teamcolors)
685 namestr = playername(source);
687 namestr = source.netname;
689 if(strdecolorize(namestr) == namestr)
698 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
699 privatemsgprefixlen = strlen(msgstr);
700 msgstr = strcat(msgstr, msgin);
701 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
702 if(autocvar_g_chat_teamcolors)
703 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
705 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
709 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
710 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
714 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
717 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
721 msgstr = cmsgstr = "";
725 fullcmsgstr = cmsgstr;
729 flood_field = floodcontrol_chat;
738 flood_spl = autocvar_g_chat_flood_spl_tell;
739 flood_burst = autocvar_g_chat_flood_burst_tell;
740 flood_lmax = autocvar_g_chat_flood_lmax_tell;
741 flood_field = floodcontrol_chattell;
745 flood_spl = autocvar_g_chat_flood_spl_team;
746 flood_burst = autocvar_g_chat_flood_burst_team;
747 flood_lmax = autocvar_g_chat_flood_lmax_team;
748 flood_field = floodcontrol_chatteam;
752 flood_spl = autocvar_g_chat_flood_spl;
753 flood_burst = autocvar_g_chat_flood_burst;
754 flood_lmax = autocvar_g_chat_flood_lmax;
755 flood_field = floodcontrol_chat;
757 flood_burst = max(0, flood_burst - 1);
758 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
760 // do flood control for the default line size
763 getWrappedLine_remaining = msgstr;
766 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
768 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
771 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
773 if(getWrappedLine_remaining != "")
775 msgstr = strcat(msgstr, "\n");
779 if (time >= source.(flood_field))
781 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
791 if (time >= source.(flood_field))
792 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
797 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
798 source.(flood_field) = flood = 0;
801 if(flood == 2) // cannot happen for empty msgstr
803 if(autocvar_g_chat_flood_notify_flooder)
805 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
810 sourcemsgstr = fullmsgstr;
811 sourcecmsgstr = fullcmsgstr;
817 sourcemsgstr = msgstr;
818 sourcecmsgstr = cmsgstr;
822 if (!IS_PLAYER(source))
824 if (!intermission_running)
825 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
826 teamsay = -1; // spectators
830 print("NOTE: ", playername(source), "^7 is flooding.\n");
832 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
834 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
838 // always fake the message
843 if (autocvar_g_chat_flood_notify_flooder)
845 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
856 if(sourcemsgstr != "" && ret != 0)
858 if(ret < 0) // faked message, because the player is muted
860 sprint(source, sourcemsgstr);
861 if(sourcecmsgstr != "" && !privatesay)
862 centerprint(source, sourcecmsgstr);
864 else if(privatesay) // private message, between 2 people only
866 sprint(source, sourcemsgstr);
867 sprint(privatesay, msgstr);
868 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
870 centerprint(privatesay, cmsgstr);
872 else if(teamsay > 0) // team message, only sent to team mates
874 sprint(source, sourcemsgstr);
875 dedicated_print(msgstr); // send to server console too
876 if(sourcecmsgstr != "")
877 centerprint(source, sourcecmsgstr);
878 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
881 sprint(head, msgstr);
883 centerprint(head, cmsgstr);
886 else if(teamsay < 0) // spectator message, only sent to spectators
888 sprint(source, sourcemsgstr);
889 dedicated_print(msgstr); // send to server console too
890 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
892 sprint(head, msgstr);
894 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
896 sprint(source, sourcemsgstr);
897 dedicated_print(msgstr); // send to server console too
898 FOR_EACH_REALCLIENT(head)
900 sprint(head, msgstr);
903 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
909 float GetVoiceMessageVoiceType(string type)
912 return VOICETYPE_TAUNT;
913 if(type == "teamshoot")
914 return VOICETYPE_LASTATTACKER;
915 return VOICETYPE_TEAMRADIO;
918 .string GetVoiceMessageSampleField(string type)
920 GetPlayerSoundSampleField_notFound = 0;
923 #define _VOICEMSG(m) case #m: return playersound_##m;
927 GetPlayerSoundSampleField_notFound = 1;
928 return playersound_taunt;
931 .string GetPlayerSoundSampleField(string type)
933 GetPlayerSoundSampleField_notFound = 0;
936 #define _VOICEMSG(m) case #m: return playersound_##m;
940 GetPlayerSoundSampleField_notFound = 1;
941 return playersound_taunt;
944 void PrecacheGlobalSound(string samplestring)
947 tokenize_console(samplestring);
951 for(i = 1; i <= n; ++i)
952 precache_sound(strcat(argv(0), ftos(i), ".wav"));
956 precache_sound(strcat(argv(0), ".wav"));
960 void PrecachePlayerSounds(string f)
964 fh = fopen(f, FILE_READ);
967 while((s = fgets(fh)))
969 if(tokenize_console(s) != 3)
971 dprint("Invalid sound info line: ", s, "\n");
974 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
978 if (!allvoicesamples)
980 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
983 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
987 void ClearPlayerSounds()
989 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
995 float LoadPlayerSounds(string f, float first)
1000 fh = fopen(f, FILE_READ);
1003 dprint("Player sound file not found: ", f, "\n");
1006 while((s = fgets(fh)))
1008 if(tokenize_console(s) != 3)
1010 field = GetPlayerSoundSampleField(argv(0));
1011 if(GetPlayerSoundSampleField_notFound)
1012 field = GetVoiceMessageSampleField(argv(0));
1013 if(GetPlayerSoundSampleField_notFound)
1016 strunzone(self.(field));
1017 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1023 void UpdatePlayerSounds()
1025 if(self.modelindex == self.modelindex_for_playersound)
1026 if(self.skin == self.skin_for_playersound)
1028 self.modelindex_for_playersound = self.modelindex;
1029 self.skin_for_playersound = self.skin;
1030 ClearPlayerSounds();
1031 LoadPlayerSounds("sound/player/default.sounds", 1);
1032 if(!autocvar_g_debug_defaultsounds)
1033 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1034 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1037 void FakeGlobalSound(string sample, float chan, float voicetype)
1045 tokenize_console(sample);
1048 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1050 sample = strcat(argv(0), ".wav"); // randomization
1054 case VOICETYPE_LASTATTACKER_ONLY:
1056 case VOICETYPE_LASTATTACKER:
1060 if(IS_REAL_CLIENT(msg_entity))
1061 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1064 case VOICETYPE_TEAMRADIO:
1066 if(msg_entity.cvar_cl_voice_directional == 1)
1067 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1069 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1071 case VOICETYPE_AUTOTAUNT:
1076 if(autocvar_sv_gentle)
1078 tauntrand = random();
1080 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1082 if (msg_entity.cvar_cl_voice_directional >= 1)
1083 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1085 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1088 case VOICETYPE_TAUNT:
1090 if(self.deadflag == DEAD_NO)
1091 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1094 if(autocvar_sv_gentle)
1097 if (msg_entity.cvar_cl_voice_directional >= 1)
1098 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1100 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1102 case VOICETYPE_PLAYERSOUND:
1104 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1107 backtrace("Invalid voice type!");
1112 void GlobalSound(string sample, float chan, float voicetype)
1120 tokenize_console(sample);
1123 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1125 sample = strcat(argv(0), ".wav"); // randomization
1129 case VOICETYPE_LASTATTACKER_ONLY:
1132 msg_entity = self.pusher;
1133 if(IS_REAL_CLIENT(msg_entity))
1135 if(msg_entity.cvar_cl_voice_directional == 1)
1136 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1138 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1142 case VOICETYPE_LASTATTACKER:
1145 msg_entity = self.pusher;
1146 if(IS_REAL_CLIENT(msg_entity))
1148 if(msg_entity.cvar_cl_voice_directional == 1)
1149 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1151 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1154 if(IS_REAL_CLIENT(msg_entity))
1155 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1158 case VOICETYPE_TEAMRADIO:
1159 FOR_EACH_REALCLIENT(msg_entity)
1160 if(!teamplay || msg_entity.team == self.team)
1162 if(msg_entity.cvar_cl_voice_directional == 1)
1163 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1165 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1168 case VOICETYPE_AUTOTAUNT:
1173 if(autocvar_sv_gentle)
1175 tauntrand = random();
1176 FOR_EACH_REALCLIENT(msg_entity)
1177 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1179 if (msg_entity.cvar_cl_voice_directional >= 1)
1180 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1182 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1185 case VOICETYPE_TAUNT:
1187 if(self.deadflag == DEAD_NO)
1188 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1191 if(autocvar_sv_gentle)
1193 FOR_EACH_REALCLIENT(msg_entity)
1195 if (msg_entity.cvar_cl_voice_directional >= 1)
1196 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1198 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1201 case VOICETYPE_PLAYERSOUND:
1202 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1205 backtrace("Invalid voice type!");
1210 void PlayerSound(.string samplefield, float chan, float voicetype)
1212 GlobalSound(self.(samplefield), chan, voicetype);
1215 void VoiceMessage(string type, string msg)
1218 float voicetype, ownteam;
1220 sample = GetVoiceMessageSampleField(type);
1222 if(GetPlayerSoundSampleField_notFound)
1224 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1228 voicetype = GetVoiceMessageVoiceType(type);
1229 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1231 flood = Say(self, ownteam, world, msg, 1);
1233 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1234 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1236 GlobalSound(self.(sample), CH_VOICE, voicetype);
1239 void MoveToTeam(entity client, float team_colour, float type)
1241 float lockteams_backup;
1243 lockteams_backup = lockteams; // backup any team lock
1245 lockteams = 0; // disable locked teams
1247 TeamchangeFrags(client); // move the players frags
1248 SetPlayerColors(client, team_colour - 1); // set the players colour
1249 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1251 lockteams = lockteams_backup; // restore the team lock
1253 LogTeamchange(client.playerid, client.team, type);