4 #include "../dpdefs/progsdefs.qc"
5 #include "../dpdefs/dpextensions.qc"
7 #include "../common/constants.qh"
8 #include "../common/teams.qh"
9 #include "../common/util.qh"
10 #include "../common/animdecide.qh"
11 #include "../common/weapons/weapons.qh"
12 #include "weapons/accuracy.qh"
14 #include "autocvars.qh"
15 #include "constants.qh"
17 #include "../common/deathtypes.qh"
18 #include "mutators/mutators_include.qh"
19 #include "../common/mapinfo.qh"
20 #include "command/common.qh"
21 #include "../csqcmodellib/sv_model.qh"
23 #include "../common/playerstats.qh"
31 .float CopyBody_nextthink;
32 .void(void) CopyBody_think;
33 void CopyBody_Think(void)
35 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
37 self.CopyBody_think();
40 self.CopyBody_nextthink = self.nextthink;
41 self.CopyBody_think = self.think;
42 self.think = CopyBody_Think;
44 CSQCMODEL_AUTOUPDATE();
45 self.nextthink = time;
47 void CopyBody(float keepvelocity)
50 if (self.effects & EF_NODRAW)
55 self.lip = oldself.lip;
56 self.colormap = oldself.colormap;
57 self.iscreature = oldself.iscreature;
58 self.teleportable = oldself.teleportable;
59 self.damagedbycontents = oldself.damagedbycontents;
60 self.angles = oldself.angles;
61 self.v_angle = oldself.v_angle;
62 self.avelocity = oldself.avelocity;
63 self.classname = "body";
64 self.damageforcescale = oldself.damageforcescale;
65 self.effects = oldself.effects;
66 self.glowmod = oldself.glowmod;
67 self.event_damage = oldself.event_damage;
68 self.anim_state = oldself.anim_state;
69 self.anim_time = oldself.anim_time;
70 self.anim_lower_action = oldself.anim_lower_action;
71 self.anim_lower_time = oldself.anim_lower_time;
72 self.anim_upper_action = oldself.anim_upper_action;
73 self.anim_upper_time = oldself.anim_upper_time;
74 self.anim_implicit_state = oldself.anim_implicit_state;
75 self.anim_implicit_time = oldself.anim_implicit_time;
76 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
77 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
78 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
79 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
80 self.dphitcontentsmask = oldself.dphitcontentsmask;
81 self.death_time = oldself.death_time;
82 self.pain_finished = oldself.pain_finished;
83 self.health = oldself.health;
84 self.armorvalue = oldself.armorvalue;
85 self.armortype = oldself.armortype;
86 self.model = oldself.model;
87 self.modelindex = oldself.modelindex;
88 self.skin = oldself.skin;
89 self.species = oldself.species;
90 self.movetype = oldself.movetype;
91 self.solid = oldself.solid;
92 self.ballistics_density = oldself.ballistics_density;
93 self.takedamage = oldself.takedamage;
94 self.customizeentityforclient = oldself.customizeentityforclient;
95 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
96 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
97 if (keepvelocity == 1)
98 self.velocity = oldself.velocity;
99 self.oldvelocity = self.velocity;
100 self.alpha = oldself.alpha;
101 self.fade_time = oldself.fade_time;
102 self.fade_rate = oldself.fade_rate;
103 //self.weapon = oldself.weapon;
104 setorigin(self, oldself.origin);
105 setsize(self, oldself.mins, oldself.maxs);
106 self.prevorigin = oldself.origin;
107 self.reset = SUB_Remove;
109 Drag_MoveDrag(oldself, self);
111 if(self.colormap <= maxclients && self.colormap > 0)
112 self.colormap = 1024 + oldself.clientcolors;
114 CSQCMODEL_AUTOINIT();
115 self.CopyBody_nextthink = oldself.nextthink;
116 self.CopyBody_think = oldself.think;
117 self.nextthink = time;
118 self.think = CopyBody_Think;
119 // "bake" the current animation frame for clones (they don't get clientside animation)
120 animdecide_load_if_needed(self);
121 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
126 float player_getspecies()
129 get_model_parameters(self.model, self.skin);
130 s = get_model_parameters_species;
131 get_model_parameters(string_null, 0);
133 return SPECIES_HUMAN;
137 void player_setupanimsformodel()
139 // load animation info
140 animdecide_load_if_needed(self);
141 animdecide_setstate(self, 0, false);
144 void player_anim (void)
146 float deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
149 // Decide on which death animation to use.
151 deadbits = ANIMSTATE_DEAD1;
153 deadbits = ANIMSTATE_DEAD2;
156 // Clear a previous death animation.
159 float animbits = deadbits;
161 animbits |= ANIMSTATE_FROZEN;
163 animbits |= ANIMSTATE_DUCK;
164 animdecide_setstate(self, animbits, false);
165 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
167 if (self.weaponentity)
169 updateanim(self.weaponentity);
170 if (!self.weaponentity.animstate_override)
171 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
175 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
179 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
181 // damage resistance (ignore most of the damage from a bullet or similar)
182 damage = max(damage - 5, 1);
184 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
188 if(sound_allowed(MSG_BROADCAST, attacker))
191 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
193 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
195 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
199 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
201 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
203 self.armorvalue = self.armorvalue - save;
204 self.health = self.health - take;
205 // pause regeneration for 5 seconds
206 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
208 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
209 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
210 self.dmg_inflictor = inflictor;
212 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
214 // don't use any animations as a gib
216 // view just above the floor
217 self.view_ofs = '0 0 4';
219 Violence_GibSplash(self, 1, 1, attacker);
221 self.solid = SOLID_NOT; // restore later
222 self.takedamage = DAMAGE_NO; // restore later
223 self.damagedbycontents = false;
228 // If 0, default is used.
230 // Otherwise, g_str (default value) is used.
231 // For consistency, negative values there are mapped to zero too.
232 #define GAMETYPE_DEFAULTED_SETTING(str) \
233 ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
234 (gametype_setting_tmp < 0) ? 0 : \
235 (gametype_setting_tmp == 0) ? max(0, autocvar_g_##str) : \
236 gametype_setting_tmp)
239 void calculate_player_respawn_time()
244 float gametype_setting_tmp;
245 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
246 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
247 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
248 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
249 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
250 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
252 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
258 if (pl.team == self.team)
260 if (sdelay_small_count == 0)
261 sdelay_small_count = 1;
262 if (sdelay_large_count == 0)
263 sdelay_large_count = 1;
270 if (sdelay_small_count == 0)
274 // Players play independently. No point in requiring enemies.
275 sdelay_small_count = 1;
279 // Players play AGAINST each other. Enemies required.
280 sdelay_small_count = 2;
283 if (sdelay_large_count == 0)
287 // Players play independently. No point in requiring enemies.
288 sdelay_large_count = 1;
292 // Players play AGAINST each other. Enemies required.
293 sdelay_large_count = 2;
300 if (pcount <= sdelay_small_count)
301 sdelay = sdelay_small;
302 else if (pcount >= sdelay_large_count)
303 sdelay = sdelay_large;
304 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
305 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
308 self.respawn_time = ceil((time + sdelay) / waves) * waves;
310 self.respawn_time = time + sdelay;
312 if(sdelay < sdelay_max)
313 self.respawn_time_max = time + sdelay_max;
315 self.respawn_time_max = self.respawn_time;
317 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
318 self.respawn_countdown = 10; // first number to count down from is 10
320 self.respawn_countdown = -1; // do not count down
322 if(autocvar_g_forced_respawn)
323 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
326 void ClientKill_Now_TeamChange();
328 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
330 float take, save, dh, da, j;
332 float valid_damage_for_weaponstats;
335 dh = max(self.health, 0);
336 da = max(self.armorvalue, 0);
338 if(!DEATH_ISSPECIAL(deathtype))
340 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
342 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
345 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
347 // tuba causes blood to come out of the ears
352 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
354 makevectors(self.angles);
355 ear1 += v_right * -10;
356 ear2 += v_right * +10;
357 d = inflictor.origin - self.origin;
359 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
361 f = 0; // Assum ecenter.
362 force = v_right * vlen(force);
363 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
364 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
373 // force is already good
377 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
380 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
386 // don't reset pushltime for self damage as it may be an attempt to
387 // escape a lava pit or similar
388 //self.pushltime = 0;
391 else if(IS_PLAYER(attacker))
393 self.pusher = attacker;
394 self.pushltime = time + autocvar_g_maxpushtime;
395 self.istypefrag = self.BUTTON_CHAT;
397 else if(time < self.pushltime)
399 attacker = self.pusher;
400 self.pushltime = max(self.pushltime, time + 0.6);
408 frag_inflictor = inflictor;
409 frag_attacker = attacker;
411 frag_damage = damage;
414 damage_force = force;
415 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
416 take = bound(0, damage_take, self.health);
417 save = bound(0, damage_save, self.armorvalue);
418 excess = max(0, damage - take - save);
420 if(sound_allowed(MSG_BROADCAST, attacker))
423 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
425 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
427 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
431 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
433 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
435 if (time >= self.spawnshieldtime)
437 if (!(self.flags & FL_GODMODE))
439 self.armorvalue = self.armorvalue - save;
440 self.health = self.health - take;
441 // pause regeneration for 5 seconds
443 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
445 if (time > self.pain_finished) //Don't switch pain sequences like crazy
447 self.pain_finished = time + 0.5; //Supajoe
449 if(autocvar_sv_gentle < 1) {
450 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
452 if (!self.animstate_override)
455 animdecide_setaction(self, ANIMACTION_PAIN1, true);
457 animdecide_setaction(self, ANIMACTION_PAIN2, true);
461 if(sound_allowed(MSG_BROADCAST, attacker))
462 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
464 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
466 if(deathtype == DEATH_FALL)
467 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
468 else if(self.health > 75) // TODO make a "gentle" version?
469 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
470 else if(self.health > 50)
471 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
472 else if(self.health > 25)
473 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
475 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
480 // throw off bot aim temporarily
482 if(IS_BOT_CLIENT(self) && self.health >= 1)
484 shake = damage * 5 / (bound(0,skill,100) + 1);
485 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
486 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
487 self.v_angle_x = bound(-90, self.v_angle.x, 90);
491 self.max_armorvalue += (save + take);
493 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
494 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
495 self.dmg_inflictor = inflictor;
497 float abot, vbot, awep;
498 abot = (IS_BOT_CLIENT(attacker));
499 vbot = (IS_BOT_CLIENT(self));
501 valid_damage_for_weaponstats = 0;
504 if(vbot || IS_REAL_CLIENT(self))
505 if(abot || IS_REAL_CLIENT(attacker))
506 if(attacker && self != attacker)
507 if(DIFF_TEAM(self, attacker))
509 if(DEATH_ISSPECIAL(deathtype))
510 awep = attacker.weapon;
512 awep = DEATH_WEAPONOF(deathtype);
513 valid_damage_for_weaponstats = 1;
516 if(valid_damage_for_weaponstats)
518 dh = dh - max(self.health, 0);
519 da = da - max(self.armorvalue, 0);
520 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
525 float defer_ClientKill_Now_TeamChange;
526 defer_ClientKill_Now_TeamChange = false;
530 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
534 if(valid_damage_for_weaponstats)
535 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
537 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
538 if(sound_allowed(MSG_BROADCAST, attacker))
540 if(deathtype == DEATH_DROWN)
541 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
543 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
546 // get rid of kill indicator
547 if(self.killindicator)
549 remove(self.killindicator);
550 self.killindicator = world;
551 if(self.killindicator_teamchange)
552 defer_ClientKill_Now_TeamChange = true;
554 if(self.classname == "body")
555 if(deathtype == DEATH_KILL)
557 // for the lemmings fans, a small harmless explosion
558 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
562 // print an obituary message
563 if(self.classname != "body")
564 Obituary (attacker, inflictor, self, deathtype);
566 // increment frag counter for used weapon type
568 w = DEATH_WEAPONOF(deathtype);
570 if(accuracy_isgooddamage(attacker, self))
571 attacker.accuracy.(accuracy_frags[w-1]) += 1;
573 frag_attacker = attacker;
574 frag_inflictor = inflictor;
576 frag_deathtype = deathtype;
577 MUTATOR_CALLHOOK(PlayerDies);
579 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
581 RemoveGrapplingHook(self);
583 Portal_ClearAllLater(self);
585 self.fixangle = true;
587 if(defer_ClientKill_Now_TeamChange)
588 ClientKill_Now_TeamChange(); // can turn player into spectator
590 // player could have been miraculously resuscitated ;)
591 // e.g. players in freezetag get frozen, they don't really die
592 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
595 // when we get here, player actually dies
597 Unfreeze(self); // remove any icy remains
598 self.health = 0; // Unfreeze resets health, so we need to set it back
601 WaypointSprite_PlayerDead();
603 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
605 // become fully visible
606 self.alpha = default_player_alpha;
607 // make the corpse upright (not tilted)
611 self.avelocity = '0 0 0';
612 // view from the floor
613 self.view_ofs = '0 0 -8';
615 self.movetype = MOVETYPE_TOSS;
617 self.solid = SOLID_CORPSE;
618 self.ballistics_density = autocvar_g_ballistics_density_corpse;
619 // don't stick to the floor
620 self.flags &= ~FL_ONGROUND;
622 self.deadflag = DEAD_DYING;
624 // when to allow respawn
625 calculate_player_respawn_time();
627 self.death_time = time;
629 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
631 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
635 setsize(self, self.mins, self.maxs);
637 // set damage function to corpse damage
638 self.event_damage = PlayerCorpseDamage;
639 // call the corpse damage function just in case it wants to gib
640 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
642 // set up to fade out later
643 SUB_SetFade (self, time + 6 + random (), 1);
644 // reset body think wrapper broken by SUB_SetFade
645 if(self.classname == "body" && self.think != CopyBody_Think) {
646 self.CopyBody_think = self.think;
647 self.CopyBody_nextthink = self.nextthink;
648 self.think = CopyBody_Think;
649 self.nextthink = time;
652 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
654 // clones don't run any animation code any more, so we must gib them when they die :(
655 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
658 // reset fields the weapons may use just in case
659 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
661 WEP_ACTION(j, WR_RESETPLAYER);
662 ATTACK_FINISHED_FOR(self, j) = 0;
667 .float muted; // to be used by prvm_edictset server playernumber muted 1
668 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
669 // message "": do not say, just test flood control
675 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
677 var .float flood_field;
680 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
682 if(!teamsay && !privatesay)
683 if(substring(msgin, 0, 1) == " ")
684 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
686 msgin = formatmessage(msgin);
688 if (!IS_PLAYER(source))
689 colorstr = "^0"; // black for spectators
691 colorstr = Team_ColorCode(source.team);
698 if(intermission_running)
702 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
705 * using bprint solves this... me stupid
706 // how can we prevent the message from appearing in a listen server?
707 // for now, just give "say" back and only handle say_team
710 clientcommand(self, strcat("say ", msgin));
715 if(autocvar_g_chat_teamcolors)
716 namestr = playername(source);
718 namestr = source.netname;
720 if(strdecolorize(namestr) == namestr)
729 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
730 privatemsgprefixlen = strlen(msgstr);
731 msgstr = strcat(msgstr, msgin);
732 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
733 if(autocvar_g_chat_teamcolors)
734 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
736 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
740 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
741 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
745 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
748 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
752 msgstr = cmsgstr = "";
756 fullcmsgstr = cmsgstr;
760 flood_field = floodcontrol_chat;
769 flood_spl = autocvar_g_chat_flood_spl_tell;
770 flood_burst = autocvar_g_chat_flood_burst_tell;
771 flood_lmax = autocvar_g_chat_flood_lmax_tell;
772 flood_field = floodcontrol_chattell;
776 flood_spl = autocvar_g_chat_flood_spl_team;
777 flood_burst = autocvar_g_chat_flood_burst_team;
778 flood_lmax = autocvar_g_chat_flood_lmax_team;
779 flood_field = floodcontrol_chatteam;
783 flood_spl = autocvar_g_chat_flood_spl;
784 flood_burst = autocvar_g_chat_flood_burst;
785 flood_lmax = autocvar_g_chat_flood_lmax;
786 flood_field = floodcontrol_chat;
788 flood_burst = max(0, flood_burst - 1);
789 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
791 // do flood control for the default line size
794 getWrappedLine_remaining = msgstr;
797 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
799 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
802 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
804 if(getWrappedLine_remaining != "")
806 msgstr = strcat(msgstr, "\n");
810 if(time >= source.flood_field)
812 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
822 if(time >= source.flood_field)
823 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
828 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
829 source.flood_field = flood = 0;
832 if(flood == 2) // cannot happen for empty msgstr
834 if(autocvar_g_chat_flood_notify_flooder)
836 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
841 sourcemsgstr = fullmsgstr;
842 sourcecmsgstr = fullcmsgstr;
848 sourcemsgstr = msgstr;
849 sourcecmsgstr = cmsgstr;
853 if (!IS_PLAYER(source))
855 if (!intermission_running)
856 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
857 teamsay = -1; // spectators
861 print("NOTE: ", playername(source), "^7 is flooding.\n");
863 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
865 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
869 // always fake the message
874 if(autocvar_g_chat_flood_notify_flooder)
876 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
887 if(sourcemsgstr != "" && ret != 0)
889 if(ret < 0) // faked message, because the player is muted
891 sprint(source, sourcemsgstr);
892 if(sourcecmsgstr != "" && !privatesay)
893 centerprint(source, sourcecmsgstr);
895 else if(privatesay) // private message, between 2 people only
897 sprint(source, sourcemsgstr);
898 sprint(privatesay, msgstr);
899 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
901 centerprint(privatesay, cmsgstr);
903 else if(teamsay > 0) // team message, only sent to team mates
905 sprint(source, sourcemsgstr);
906 dedicated_print(msgstr); // send to server console too
907 if(sourcecmsgstr != "")
908 centerprint(source, sourcecmsgstr);
909 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
912 sprint(head, msgstr);
914 centerprint(head, cmsgstr);
917 else if(teamsay < 0) // spectator message, only sent to spectators
919 sprint(source, sourcemsgstr);
920 dedicated_print(msgstr); // send to server console too
921 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
923 sprint(head, msgstr);
925 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
927 sprint(source, sourcemsgstr);
928 dedicated_print(msgstr); // send to server console too
929 FOR_EACH_REALCLIENT(head)
931 sprint(head, msgstr);
934 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
940 float GetVoiceMessageVoiceType(string type)
943 return VOICETYPE_TAUNT;
944 if(type == "teamshoot")
945 return VOICETYPE_LASTATTACKER;
946 return VOICETYPE_TEAMRADIO;
949 string allvoicesamples;
950 .string GetVoiceMessageSampleField(string type)
952 GetPlayerSoundSampleField_notFound = 0;
955 #define _VOICEMSG(m) case #m: return playersound_##m;
959 GetPlayerSoundSampleField_notFound = 1;
960 return playersound_taunt;
963 .string GetPlayerSoundSampleField(string type)
965 GetPlayerSoundSampleField_notFound = 0;
968 #define _VOICEMSG(m) case #m: return playersound_##m;
972 GetPlayerSoundSampleField_notFound = 1;
973 return playersound_taunt;
976 void PrecacheGlobalSound(string samplestring)
979 tokenize_console(samplestring);
983 for(i = 1; i <= n; ++i)
984 precache_sound(strcat(argv(0), ftos(i), ".wav"));
988 precache_sound(strcat(argv(0), ".wav"));
992 void PrecachePlayerSounds(string f)
996 fh = fopen(f, FILE_READ);
999 while((s = fgets(fh)))
1001 if(tokenize_console(s) != 3)
1003 dprint("Invalid sound info line: ", s, "\n");
1006 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1010 if (!allvoicesamples)
1012 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1015 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1019 void ClearPlayerSounds()
1021 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1027 float LoadPlayerSounds(string f, float first)
1032 fh = fopen(f, FILE_READ);
1035 dprint("Player sound file not found: ", f, "\n");
1038 while((s = fgets(fh)))
1040 if(tokenize_console(s) != 3)
1042 field = GetPlayerSoundSampleField(argv(0));
1043 if(GetPlayerSoundSampleField_notFound)
1044 field = GetVoiceMessageSampleField(argv(0));
1045 if(GetPlayerSoundSampleField_notFound)
1048 strunzone(self.field);
1049 self.field = strzone(strcat(argv(1), " ", argv(2)));
1055 .float modelindex_for_playersound;
1056 .float skin_for_playersound;
1057 void UpdatePlayerSounds()
1059 if(self.modelindex == self.modelindex_for_playersound)
1060 if(self.skin == self.skin_for_playersound)
1062 self.modelindex_for_playersound = self.modelindex;
1063 self.skin_for_playersound = self.skin;
1064 ClearPlayerSounds();
1065 LoadPlayerSounds("sound/player/default.sounds", 1);
1066 if(!autocvar_g_debug_defaultsounds)
1067 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1068 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1071 void FakeGlobalSound(string sample, float chan, float voicetype)
1079 tokenize_console(sample);
1082 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1084 sample = strcat(argv(0), ".wav"); // randomization
1088 case VOICETYPE_LASTATTACKER_ONLY:
1090 case VOICETYPE_LASTATTACKER:
1094 if(IS_REAL_CLIENT(msg_entity))
1095 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1098 case VOICETYPE_TEAMRADIO:
1100 if(msg_entity.cvar_cl_voice_directional == 1)
1101 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1103 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1105 case VOICETYPE_AUTOTAUNT:
1110 if(autocvar_sv_gentle)
1112 tauntrand = random();
1114 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1116 if (msg_entity.cvar_cl_voice_directional >= 1)
1117 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1119 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1122 case VOICETYPE_TAUNT:
1124 if(self.deadflag == DEAD_NO)
1125 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1128 if(autocvar_sv_gentle)
1131 if (msg_entity.cvar_cl_voice_directional >= 1)
1132 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1134 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1136 case VOICETYPE_PLAYERSOUND:
1138 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1141 backtrace("Invalid voice type!");
1146 void GlobalSound(string sample, float chan, float voicetype)
1154 tokenize_console(sample);
1157 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1159 sample = strcat(argv(0), ".wav"); // randomization
1163 case VOICETYPE_LASTATTACKER_ONLY:
1166 msg_entity = self.pusher;
1167 if(IS_REAL_CLIENT(msg_entity))
1169 if(msg_entity.cvar_cl_voice_directional == 1)
1170 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1172 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1176 case VOICETYPE_LASTATTACKER:
1179 msg_entity = self.pusher;
1180 if(IS_REAL_CLIENT(msg_entity))
1182 if(msg_entity.cvar_cl_voice_directional == 1)
1183 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1185 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1188 if(IS_REAL_CLIENT(msg_entity))
1189 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1192 case VOICETYPE_TEAMRADIO:
1193 FOR_EACH_REALCLIENT(msg_entity)
1194 if(!teamplay || msg_entity.team == self.team)
1196 if(msg_entity.cvar_cl_voice_directional == 1)
1197 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1199 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1202 case VOICETYPE_AUTOTAUNT:
1207 if(autocvar_sv_gentle)
1209 tauntrand = random();
1210 FOR_EACH_REALCLIENT(msg_entity)
1211 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1213 if (msg_entity.cvar_cl_voice_directional >= 1)
1214 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1216 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1219 case VOICETYPE_TAUNT:
1221 if(self.deadflag == DEAD_NO)
1222 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1225 if(autocvar_sv_gentle)
1227 FOR_EACH_REALCLIENT(msg_entity)
1229 if (msg_entity.cvar_cl_voice_directional >= 1)
1230 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1232 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1235 case VOICETYPE_PLAYERSOUND:
1236 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1239 backtrace("Invalid voice type!");
1244 void PlayerSound(.string samplefield, float chan, float voicetype)
1246 GlobalSound(self.samplefield, chan, voicetype);
1249 void VoiceMessage(string type, string msg)
1252 float voicetype, ownteam;
1254 sample = GetVoiceMessageSampleField(type);
1256 if(GetPlayerSoundSampleField_notFound)
1258 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1262 voicetype = GetVoiceMessageVoiceType(type);
1263 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1265 flood = Say(self, ownteam, world, msg, 1);
1267 if(IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1268 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1270 GlobalSound(self.sample, CH_VOICE, voicetype);
1273 void MoveToTeam(entity client, float team_colour, float type)
1275 float lockteams_backup;
1277 lockteams_backup = lockteams; // backup any team lock
1279 lockteams = 0; // disable locked teams
1281 TeamchangeFrags(client); // move the players frags
1282 SetPlayerColors(client, team_colour - 1); // set the players colour
1283 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1285 lockteams = lockteams_backup; // restore the team lock
1287 LogTeamchange(client.playerid, client.team, type);