1 #include "cl_player.qh"
8 #include "g_violence.qh"
9 #include "miscfunctions.qh"
11 #include "teamplay.qh"
12 #include "weapons/throwing.qh"
13 #include "command/common.qh"
14 #include "../common/animdecide.qh"
15 #include "../common/csqcmodel_settings.qh"
16 #include "../common/deathtypes.qh"
17 #include "../common/triggers/subs.qh"
18 #include "../common/playerstats.qh"
19 #include "../csqcmodellib/sv_model.qh"
21 #include "../common/minigames/sv_minigames.qh"
23 #include "weapons/weaponstats.qh"
25 #include "../common/animdecide.qh"
27 void CopyBody_Think(void)
29 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
31 self.CopyBody_think();
34 self.CopyBody_nextthink = self.nextthink;
35 self.CopyBody_think = self.think;
36 self.think = CopyBody_Think;
38 CSQCMODEL_AUTOUPDATE();
39 self.nextthink = time;
41 void CopyBody(float keepvelocity)
44 if (self.effects & EF_NODRAW)
49 self.lip = oldself.lip;
50 self.colormap = oldself.colormap;
51 self.iscreature = oldself.iscreature;
52 self.teleportable = oldself.teleportable;
53 self.damagedbycontents = oldself.damagedbycontents;
54 self.angles = oldself.angles;
55 self.v_angle = oldself.v_angle;
56 self.avelocity = oldself.avelocity;
57 self.classname = "body";
58 self.damageforcescale = oldself.damageforcescale;
59 self.effects = oldself.effects;
60 self.glowmod = oldself.glowmod;
61 self.event_damage = oldself.event_damage;
62 self.anim_state = oldself.anim_state;
63 self.anim_time = oldself.anim_time;
64 self.anim_lower_action = oldself.anim_lower_action;
65 self.anim_lower_time = oldself.anim_lower_time;
66 self.anim_upper_action = oldself.anim_upper_action;
67 self.anim_upper_time = oldself.anim_upper_time;
68 self.anim_implicit_state = oldself.anim_implicit_state;
69 self.anim_implicit_time = oldself.anim_implicit_time;
70 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
71 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
72 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
73 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
74 self.dphitcontentsmask = oldself.dphitcontentsmask;
75 self.death_time = oldself.death_time;
76 self.pain_finished = oldself.pain_finished;
77 self.health = oldself.health;
78 self.armorvalue = oldself.armorvalue;
79 self.armortype = oldself.armortype;
80 self.model = oldself.model;
81 self.modelindex = oldself.modelindex;
82 self.skin = oldself.skin;
83 self.species = oldself.species;
84 self.movetype = oldself.movetype;
85 self.solid = oldself.solid;
86 self.ballistics_density = oldself.ballistics_density;
87 self.takedamage = oldself.takedamage;
88 self.customizeentityforclient = oldself.customizeentityforclient;
89 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
90 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
91 if (keepvelocity == 1)
92 self.velocity = oldself.velocity;
93 self.oldvelocity = self.velocity;
94 self.alpha = oldself.alpha;
95 self.fade_time = oldself.fade_time;
96 self.fade_rate = oldself.fade_rate;
97 //self.weapon = oldself.weapon;
98 setorigin(self, oldself.origin);
99 setsize(self, oldself.mins, oldself.maxs);
100 self.prevorigin = oldself.origin;
101 self.reset = SUB_Remove;
103 Drag_MoveDrag(oldself, self);
105 if(self.colormap <= maxclients && self.colormap > 0)
106 self.colormap = 1024 + oldself.clientcolors;
108 CSQCMODEL_AUTOINIT();
109 self.CopyBody_nextthink = oldself.nextthink;
110 self.CopyBody_think = oldself.think;
111 self.nextthink = time;
112 self.think = CopyBody_Think;
113 // "bake" the current animation frame for clones (they don't get clientside animation)
114 animdecide_load_if_needed(self);
115 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
120 float player_getspecies()
123 get_model_parameters(self.model, self.skin);
124 s = get_model_parameters_species;
125 get_model_parameters(string_null, 0);
127 return SPECIES_HUMAN;
131 void player_setupanimsformodel()
133 // load animation info
134 animdecide_load_if_needed(self);
135 animdecide_setstate(self, 0, false);
138 void player_anim (void)
140 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
143 // Decide on which death animation to use.
145 deadbits = ANIMSTATE_DEAD1;
147 deadbits = ANIMSTATE_DEAD2;
150 // Clear a previous death animation.
153 int animbits = deadbits;
155 animbits |= ANIMSTATE_FROZEN;
156 if(self.movetype == MOVETYPE_FOLLOW)
157 animbits |= ANIMSTATE_FOLLOW;
159 animbits |= ANIMSTATE_DUCK;
160 animdecide_setstate(self, animbits, false);
161 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
163 if (self.weaponentity)
165 updateanim(self.weaponentity);
166 if (!self.weaponentity.animstate_override)
167 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
171 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
175 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
177 // damage resistance (ignore most of the damage from a bullet or similar)
178 damage = max(damage - 5, 1);
180 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
184 if(sound_allowed(MSG_BROADCAST, attacker))
187 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
189 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
191 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
195 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
197 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
199 self.armorvalue = self.armorvalue - save;
200 self.health = self.health - take;
201 // pause regeneration for 5 seconds
202 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
204 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
205 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
206 self.dmg_inflictor = inflictor;
208 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
210 // don't use any animations as a gib
212 // view just above the floor
213 self.view_ofs = '0 0 4';
215 Violence_GibSplash(self, 1, 1, attacker);
217 self.solid = SOLID_NOT; // restore later
218 self.takedamage = DAMAGE_NO; // restore later
219 self.damagedbycontents = false;
223 void calculate_player_respawn_time()
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".
242 if (pl.team == self.team)
244 if (sdelay_small_count == 0)
245 sdelay_small_count = 1;
246 if (sdelay_large_count == 0)
247 sdelay_large_count = 1;
254 if (sdelay_small_count == 0)
258 // Players play independently. No point in requiring enemies.
259 sdelay_small_count = 1;
263 // Players play AGAINST each other. Enemies required.
264 sdelay_small_count = 2;
267 if (sdelay_large_count == 0)
271 // Players play independently. No point in requiring enemies.
272 sdelay_large_count = 1;
276 // Players play AGAINST each other. Enemies required.
277 sdelay_large_count = 2;
284 if (pcount <= sdelay_small_count)
285 sdelay = sdelay_small;
286 else if (pcount >= sdelay_large_count)
287 sdelay = sdelay_large;
288 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
289 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
292 self.respawn_time = ceil((time + sdelay) / waves) * waves;
294 self.respawn_time = time + sdelay;
296 if(sdelay < sdelay_max)
297 self.respawn_time_max = time + sdelay_max;
299 self.respawn_time_max = self.respawn_time;
301 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
302 self.respawn_countdown = 10; // first number to count down from is 10
304 self.respawn_countdown = -1; // do not count down
306 if(autocvar_g_forced_respawn)
307 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
310 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
312 float take, save, dh, da;
315 float valid_damage_for_weaponstats;
318 dh = max(self.health, 0);
319 da = max(self.armorvalue, 0);
321 if(!DEATH_ISSPECIAL(deathtype))
323 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
325 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
328 if(DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
330 // tuba causes blood to come out of the ears
335 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
337 makevectors(self.angles);
338 ear1 += v_right * -10;
339 ear2 += v_right * +10;
340 d = inflictor.origin - self.origin;
342 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
344 f = 0; // Assum ecenter.
345 force = v_right * vlen(force);
346 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
347 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
356 // force is already good
360 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
363 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
369 // don't reset pushltime for self damage as it may be an attempt to
370 // escape a lava pit or similar
371 //self.pushltime = 0;
374 else if(IS_PLAYER(attacker))
376 self.pusher = attacker;
377 self.pushltime = time + autocvar_g_maxpushtime;
378 self.istypefrag = self.BUTTON_CHAT;
380 else if(time < self.pushltime)
382 attacker = self.pusher;
383 self.pushltime = max(self.pushltime, time + 0.6);
391 frag_damage = damage;
392 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
393 take = bound(0, damage_take, self.health);
394 save = bound(0, damage_save, self.armorvalue);
395 excess = max(0, damage - take - save);
397 if(sound_allowed(MSG_BROADCAST, attacker))
400 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
402 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
404 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
408 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
410 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
412 if (time >= self.spawnshieldtime)
414 if (!(self.flags & FL_GODMODE))
416 self.armorvalue = self.armorvalue - save;
417 self.health = self.health - take;
418 // pause regeneration for 5 seconds
420 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
422 if (time > self.pain_finished) //Don't switch pain sequences like crazy
424 self.pain_finished = time + 0.5; //Supajoe
426 if(autocvar_sv_gentle < 1) {
427 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
429 if (!self.animstate_override)
432 animdecide_setaction(self, ANIMACTION_PAIN1, true);
434 animdecide_setaction(self, ANIMACTION_PAIN2, true);
438 if(sound_allowed(MSG_BROADCAST, attacker))
439 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
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)
444 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
445 else if(self.health > 75) // TODO make a "gentle" version?
446 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
447 else if(self.health > 50)
448 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
449 else if(self.health > 25)
450 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
452 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
457 // throw off bot aim temporarily
459 if(IS_BOT_CLIENT(self) && self.health >= 1)
461 shake = damage * 5 / (bound(0,skill,100) + 1);
462 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
463 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
464 self.v_angle_x = bound(-90, self.v_angle.x, 90);
468 self.max_armorvalue += (save + take);
470 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
471 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
472 self.dmg_inflictor = inflictor;
474 float abot, vbot, awep;
475 abot = (IS_BOT_CLIENT(attacker));
476 vbot = (IS_BOT_CLIENT(self));
478 valid_damage_for_weaponstats = 0;
481 if(vbot || IS_REAL_CLIENT(self))
482 if(abot || IS_REAL_CLIENT(attacker))
483 if(attacker && self != attacker)
484 if(DIFF_TEAM(self, attacker))
486 if(DEATH_ISSPECIAL(deathtype))
487 awep = attacker.weapon;
489 awep = DEATH_WEAPONOF(deathtype);
490 valid_damage_for_weaponstats = 1;
493 if(valid_damage_for_weaponstats)
495 dh = dh - max(self.health, 0);
496 da = da - max(self.armorvalue, 0);
497 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
498 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc);
503 float defer_ClientKill_Now_TeamChange;
504 defer_ClientKill_Now_TeamChange = false;
508 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
512 if(valid_damage_for_weaponstats)
513 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
515 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
516 if(sound_allowed(MSG_BROADCAST, attacker))
518 if(deathtype == DEATH_DROWN)
519 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
521 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
524 // get rid of kill indicator
525 if(self.killindicator)
527 remove(self.killindicator);
528 self.killindicator = world;
529 if(self.killindicator_teamchange)
530 defer_ClientKill_Now_TeamChange = true;
532 if(self.classname == "body")
533 if(deathtype == DEATH_KILL)
535 // for the lemmings fans, a small harmless explosion
536 Send_Effect(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
540 // print an obituary message
541 if(self.classname != "body")
542 Obituary (attacker, inflictor, self, deathtype);
544 // increment frag counter for used weapon type
545 int w = DEATH_WEAPONOF(deathtype);
547 if(accuracy_isgooddamage(attacker, self))
548 attacker.accuracy.(accuracy_frags[w-1]) += 1;
550 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
552 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
554 RemoveGrapplingHook(self);
556 Portal_ClearAllLater(self);
558 self.fixangle = true;
560 if(defer_ClientKill_Now_TeamChange)
561 ClientKill_Now_TeamChange(); // can turn player into spectator
563 // player could have been miraculously resuscitated ;)
564 // e.g. players in freezetag get frozen, they don't really die
565 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
568 // when we get here, player actually dies
570 Unfreeze(self); // remove any icy remains
571 self.health = 0; // Unfreeze resets health, so we need to set it back
574 WaypointSprite_PlayerDead();
576 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
578 // become fully visible
579 self.alpha = default_player_alpha;
580 // make the corpse upright (not tilted)
584 self.avelocity = '0 0 0';
585 // view from the floor
586 self.view_ofs = '0 0 -8';
588 self.movetype = MOVETYPE_TOSS;
590 self.solid = SOLID_CORPSE;
591 self.ballistics_density = autocvar_g_ballistics_density_corpse;
592 // don't stick to the floor
593 self.flags &= ~FL_ONGROUND;
595 self.deadflag = DEAD_DYING;
597 // when to allow respawn
598 calculate_player_respawn_time();
600 self.death_time = time;
602 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
604 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
608 setsize(self, self.mins, self.maxs);
610 // set damage function to corpse damage
611 self.event_damage = PlayerCorpseDamage;
612 // call the corpse damage function just in case it wants to gib
613 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
615 // set up to fade out later
616 SUB_SetFade (self, time + 6 + random (), 1);
617 // reset body think wrapper broken by SUB_SetFade
618 if(self.classname == "body" && self.think != CopyBody_Think) {
619 self.CopyBody_think = self.think;
620 self.CopyBody_nextthink = self.nextthink;
621 self.think = CopyBody_Think;
622 self.nextthink = time;
625 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
627 // clones don't run any animation code any more, so we must gib them when they die :(
628 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
631 // reset fields the weapons may use just in case
632 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
634 WEP_ACTION(j, WR_RESETPLAYER);
635 ATTACK_FINISHED_FOR(self, j) = 0;
640 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
641 // message "": do not say, just test flood control
647 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
649 var .float flood_field;
652 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
654 if(!teamsay && !privatesay)
655 if(substring(msgin, 0, 1) == " ")
656 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
658 msgin = formatmessage(msgin);
660 if (!IS_PLAYER(source))
661 colorstr = "^0"; // black for spectators
663 colorstr = Team_ColorCode(source.team);
670 if(intermission_running)
674 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
677 * using bprint solves this... me stupid
678 // how can we prevent the message from appearing in a listen server?
679 // for now, just give "say" back and only handle say_team
682 clientcommand(self, strcat("say ", msgin));
687 if(autocvar_g_chat_teamcolors)
688 namestr = playername(source);
690 namestr = source.netname;
692 if(strdecolorize(namestr) == namestr)
701 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
702 privatemsgprefixlen = strlen(msgstr);
703 msgstr = strcat(msgstr, msgin);
704 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
705 if(autocvar_g_chat_teamcolors)
706 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
708 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
712 if(strstrofs(msgin, "/me", 0) >= 0)
714 //msgin = strreplace("/me", "", msgin);
715 //msgin = substring(msgin, 3, strlen(msgin));
716 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
717 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
720 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
721 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
725 if(strstrofs(msgin, "/me", 0) >= 0)
727 //msgin = strreplace("/me", "", msgin);
728 //msgin = substring(msgin, 3, strlen(msgin));
729 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
730 msgstr = strcat("\{1}^4* ", "^7", msgin);
733 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
736 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
740 msgstr = cmsgstr = "";
744 fullcmsgstr = cmsgstr;
748 flood_field = floodcontrol_chat;
757 flood_spl = autocvar_g_chat_flood_spl_tell;
758 flood_burst = autocvar_g_chat_flood_burst_tell;
759 flood_lmax = autocvar_g_chat_flood_lmax_tell;
760 flood_field = floodcontrol_chattell;
764 flood_spl = autocvar_g_chat_flood_spl_team;
765 flood_burst = autocvar_g_chat_flood_burst_team;
766 flood_lmax = autocvar_g_chat_flood_lmax_team;
767 flood_field = floodcontrol_chatteam;
771 flood_spl = autocvar_g_chat_flood_spl;
772 flood_burst = autocvar_g_chat_flood_burst;
773 flood_lmax = autocvar_g_chat_flood_lmax;
774 flood_field = floodcontrol_chat;
776 flood_burst = max(0, flood_burst - 1);
777 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
779 // do flood control for the default line size
782 getWrappedLine_remaining = msgstr;
785 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
787 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
790 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
792 if(getWrappedLine_remaining != "")
794 msgstr = strcat(msgstr, "\n");
798 if (time >= source.(flood_field))
800 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
810 if (time >= source.(flood_field))
811 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
816 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
817 source.(flood_field) = flood = 0;
820 if(flood == 2) // cannot happen for empty msgstr
822 if(autocvar_g_chat_flood_notify_flooder)
824 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
829 sourcemsgstr = fullmsgstr;
830 sourcecmsgstr = fullcmsgstr;
836 sourcemsgstr = msgstr;
837 sourcecmsgstr = cmsgstr;
841 if (!IS_PLAYER(source))
843 if (!intermission_running)
844 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
845 teamsay = -1; // spectators
849 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
851 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
853 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
857 // always fake the message
862 if (autocvar_g_chat_flood_notify_flooder)
864 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
875 if(sourcemsgstr != "" && ret != 0)
877 if(ret < 0) // faked message, because the player is muted
879 sprint(source, sourcemsgstr);
880 if(sourcecmsgstr != "" && !privatesay)
881 centerprint(source, sourcecmsgstr);
883 else if(privatesay) // private message, between 2 people only
885 sprint(source, sourcemsgstr);
886 sprint(privatesay, msgstr);
887 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
889 centerprint(privatesay, cmsgstr);
891 else if ( teamsay && source.active_minigame )
893 sprint(source, sourcemsgstr);
894 dedicated_print(msgstr); // send to server console too
895 FOR_EACH_REALCLIENT(head)
897 if(head.active_minigame == source.active_minigame)
898 sprint(head, msgstr);
900 else if(teamsay > 0) // team message, only sent to team mates
902 sprint(source, sourcemsgstr);
903 dedicated_print(msgstr); // send to server console too
904 if(sourcecmsgstr != "")
905 centerprint(source, sourcecmsgstr);
906 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
909 sprint(head, msgstr);
911 centerprint(head, cmsgstr);
914 else if(teamsay < 0) // spectator message, only sent to spectators
916 sprint(source, sourcemsgstr);
917 dedicated_print(msgstr); // send to server console too
918 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
920 sprint(head, msgstr);
922 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
924 sprint(source, sourcemsgstr);
925 dedicated_print(msgstr); // send to server console too
926 FOR_EACH_REALCLIENT(head)
928 sprint(head, msgstr);
931 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
937 float GetVoiceMessageVoiceType(string type)
940 return VOICETYPE_TAUNT;
941 if(type == "teamshoot")
942 return VOICETYPE_LASTATTACKER;
943 return VOICETYPE_TEAMRADIO;
946 .string GetVoiceMessageSampleField(string type)
948 GetPlayerSoundSampleField_notFound = 0;
951 #define _VOICEMSG(m) case #m: return playersound_##m;
955 GetPlayerSoundSampleField_notFound = 1;
956 return playersound_taunt;
959 .string GetPlayerSoundSampleField(string type)
961 GetPlayerSoundSampleField_notFound = 0;
964 #define _VOICEMSG(m) case #m: return playersound_##m;
968 GetPlayerSoundSampleField_notFound = 1;
969 return playersound_taunt;
972 void PrecacheGlobalSound(string samplestring)
975 tokenize_console(samplestring);
979 for(i = 1; i <= n; ++i)
980 precache_sound(strcat(argv(0), ftos(i), ".wav"));
984 precache_sound(strcat(argv(0), ".wav"));
988 void PrecachePlayerSounds(string f)
992 fh = fopen(f, FILE_READ);
995 while((s = fgets(fh)))
997 if(tokenize_console(s) != 3)
999 LOG_TRACE("Invalid sound info line: ", s, "\n");
1002 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1006 if (!allvoicesamples)
1008 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1011 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1015 void ClearPlayerSounds()
1017 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1023 float LoadPlayerSounds(string f, float first)
1028 fh = fopen(f, FILE_READ);
1031 LOG_TRACE("Player sound file not found: ", f, "\n");
1034 while((s = fgets(fh)))
1036 if(tokenize_console(s) != 3)
1038 field = GetPlayerSoundSampleField(argv(0));
1039 if(GetPlayerSoundSampleField_notFound)
1040 field = GetVoiceMessageSampleField(argv(0));
1041 if(GetPlayerSoundSampleField_notFound)
1044 strunzone(self.(field));
1045 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1051 void UpdatePlayerSounds()
1053 if(self.modelindex == self.modelindex_for_playersound)
1054 if(self.skin == self.skin_for_playersound)
1056 self.modelindex_for_playersound = self.modelindex;
1057 self.skin_for_playersound = self.skin;
1058 ClearPlayerSounds();
1059 LoadPlayerSounds("sound/player/default.sounds", 1);
1060 if(!autocvar_g_debug_defaultsounds)
1061 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1062 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1065 void FakeGlobalSound(string sample, float chan, float voicetype)
1073 tokenize_console(sample);
1076 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1078 sample = strcat(argv(0), ".wav"); // randomization
1082 case VOICETYPE_LASTATTACKER_ONLY:
1084 case VOICETYPE_LASTATTACKER:
1088 if(IS_REAL_CLIENT(msg_entity))
1089 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1092 case VOICETYPE_TEAMRADIO:
1094 if(msg_entity.cvar_cl_voice_directional == 1)
1095 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1097 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1099 case VOICETYPE_AUTOTAUNT:
1104 if(autocvar_sv_gentle)
1106 tauntrand = random();
1108 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1110 if (msg_entity.cvar_cl_voice_directional >= 1)
1111 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1113 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1116 case VOICETYPE_TAUNT:
1118 if(self.deadflag == DEAD_NO)
1119 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1122 if(autocvar_sv_gentle)
1125 if (msg_entity.cvar_cl_voice_directional >= 1)
1126 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1128 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1130 case VOICETYPE_PLAYERSOUND:
1132 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1135 backtrace("Invalid voice type!");
1140 void GlobalSound(string sample, float chan, float voicetype)
1148 tokenize_console(sample);
1151 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1153 sample = strcat(argv(0), ".wav"); // randomization
1157 case VOICETYPE_LASTATTACKER_ONLY:
1160 msg_entity = self.pusher;
1161 if(IS_REAL_CLIENT(msg_entity))
1163 if(msg_entity.cvar_cl_voice_directional == 1)
1164 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1166 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1170 case VOICETYPE_LASTATTACKER:
1173 msg_entity = self.pusher;
1174 if(IS_REAL_CLIENT(msg_entity))
1176 if(msg_entity.cvar_cl_voice_directional == 1)
1177 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1179 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1182 if(IS_REAL_CLIENT(msg_entity))
1183 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1186 case VOICETYPE_TEAMRADIO:
1187 FOR_EACH_REALCLIENT(msg_entity)
1188 if(!teamplay || msg_entity.team == self.team)
1190 if(msg_entity.cvar_cl_voice_directional == 1)
1191 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1193 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1196 case VOICETYPE_AUTOTAUNT:
1201 if(autocvar_sv_gentle)
1203 tauntrand = random();
1204 FOR_EACH_REALCLIENT(msg_entity)
1205 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1207 if (msg_entity.cvar_cl_voice_directional >= 1)
1208 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1210 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1213 case VOICETYPE_TAUNT:
1215 if(self.deadflag == DEAD_NO)
1216 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1219 if(autocvar_sv_gentle)
1221 FOR_EACH_REALCLIENT(msg_entity)
1223 if (msg_entity.cvar_cl_voice_directional >= 1)
1224 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1226 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1229 case VOICETYPE_PLAYERSOUND:
1230 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1233 backtrace("Invalid voice type!");
1238 void PlayerSound(.string samplefield, float chan, float voicetype)
1240 GlobalSound(self.(samplefield), chan, voicetype);
1243 void VoiceMessage(string type, string msg)
1246 float voicetype, ownteam;
1248 sample = GetVoiceMessageSampleField(type);
1250 if(GetPlayerSoundSampleField_notFound)
1252 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1256 voicetype = GetVoiceMessageVoiceType(type);
1257 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1259 flood = Say(self, ownteam, world, msg, 1);
1261 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1262 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1264 GlobalSound(self.(sample), CH_VOICE, voicetype);
1267 void MoveToTeam(entity client, float team_colour, float type)
1269 float lockteams_backup;
1271 lockteams_backup = lockteams; // backup any team lock
1273 lockteams = 0; // disable locked teams
1275 TeamchangeFrags(client); // move the players frags
1276 SetPlayerColors(client, team_colour - 1); // set the players colour
1277 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1279 lockteams = lockteams_backup; // restore the team lock
1281 LogTeamchange(client.playerid, client.team, type);