4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../common/constants.qh"
7 #include "../common/teams.qh"
8 #include "../common/util.qh"
9 #include "../common/animdecide.qh"
10 #include "../common/weapons/weapons.qh"
11 #include "weapons/accuracy.qh"
13 #include "autocvars.qh"
14 #include "constants.qh"
16 #include "../common/deathtypes.qh"
17 #include "mutators/mutators_include.qh"
18 #include "../common/mapinfo.qh"
19 #include "command/common.qh"
20 #include "../csqcmodellib/sv_model.qh"
22 #include "../common/playerstats.qh"
30 .float CopyBody_nextthink;
31 .void(void) CopyBody_think;
32 void CopyBody_Think(void)
34 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
36 self.CopyBody_think();
39 self.CopyBody_nextthink = self.nextthink;
40 self.CopyBody_think = self.think;
41 self.think = CopyBody_Think;
43 CSQCMODEL_AUTOUPDATE();
44 self.nextthink = time;
46 void CopyBody(float keepvelocity)
49 if (self.effects & EF_NODRAW)
54 self.lip = oldself.lip;
55 self.colormap = oldself.colormap;
56 self.iscreature = oldself.iscreature;
57 self.teleportable = oldself.teleportable;
58 self.damagedbycontents = oldself.damagedbycontents;
59 self.angles = oldself.angles;
60 self.v_angle = oldself.v_angle;
61 self.avelocity = oldself.avelocity;
62 self.classname = "body";
63 self.damageforcescale = oldself.damageforcescale;
64 self.effects = oldself.effects;
65 self.glowmod = oldself.glowmod;
66 self.event_damage = oldself.event_damage;
67 self.anim_state = oldself.anim_state;
68 self.anim_time = oldself.anim_time;
69 self.anim_lower_action = oldself.anim_lower_action;
70 self.anim_lower_time = oldself.anim_lower_time;
71 self.anim_upper_action = oldself.anim_upper_action;
72 self.anim_upper_time = oldself.anim_upper_time;
73 self.anim_implicit_state = oldself.anim_implicit_state;
74 self.anim_implicit_time = oldself.anim_implicit_time;
75 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
76 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
77 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
78 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
79 self.dphitcontentsmask = oldself.dphitcontentsmask;
80 self.death_time = oldself.death_time;
81 self.pain_finished = oldself.pain_finished;
82 self.health = oldself.health;
83 self.armorvalue = oldself.armorvalue;
84 self.armortype = oldself.armortype;
85 self.model = oldself.model;
86 self.modelindex = oldself.modelindex;
87 self.skin = oldself.skin;
88 self.species = oldself.species;
89 self.movetype = oldself.movetype;
90 self.solid = oldself.solid;
91 self.ballistics_density = oldself.ballistics_density;
92 self.takedamage = oldself.takedamage;
93 self.customizeentityforclient = oldself.customizeentityforclient;
94 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
95 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
96 if (keepvelocity == 1)
97 self.velocity = oldself.velocity;
98 self.oldvelocity = self.velocity;
99 self.alpha = oldself.alpha;
100 self.fade_time = oldself.fade_time;
101 self.fade_rate = oldself.fade_rate;
102 //self.weapon = oldself.weapon;
103 setorigin(self, oldself.origin);
104 setsize(self, oldself.mins, oldself.maxs);
105 self.prevorigin = oldself.origin;
106 self.reset = SUB_Remove;
108 Drag_MoveDrag(oldself, self);
110 if(self.colormap <= maxclients && self.colormap > 0)
111 self.colormap = 1024 + oldself.clientcolors;
113 CSQCMODEL_AUTOINIT();
114 self.CopyBody_nextthink = oldself.nextthink;
115 self.CopyBody_think = oldself.think;
116 self.nextthink = time;
117 self.think = CopyBody_Think;
118 // "bake" the current animation frame for clones (they don't get clientside animation)
119 animdecide_load_if_needed(self);
120 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
125 float player_getspecies()
128 get_model_parameters(self.model, self.skin);
129 s = get_model_parameters_species;
130 get_model_parameters(string_null, 0);
132 return SPECIES_HUMAN;
136 void player_setupanimsformodel()
138 // load animation info
139 animdecide_load_if_needed(self);
140 animdecide_setstate(self, 0, false);
143 void player_anim (void)
145 float deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
148 // Decide on which death animation to use.
150 deadbits = ANIMSTATE_DEAD1;
152 deadbits = ANIMSTATE_DEAD2;
155 // Clear a previous death animation.
158 float animbits = deadbits;
160 animbits |= ANIMSTATE_FROZEN;
162 animbits |= ANIMSTATE_DUCK;
163 animdecide_setstate(self, animbits, false);
164 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
166 if (self.weaponentity)
168 updateanim(self.weaponentity);
169 if (!self.weaponentity.animstate_override)
170 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
174 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
178 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
180 // damage resistance (ignore most of the damage from a bullet or similar)
181 damage = max(damage - 5, 1);
183 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
187 if(sound_allowed(MSG_BROADCAST, attacker))
190 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
192 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
194 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
198 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
200 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
202 self.armorvalue = self.armorvalue - save;
203 self.health = self.health - take;
204 // pause regeneration for 5 seconds
205 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
207 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
208 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
209 self.dmg_inflictor = inflictor;
211 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
213 // don't use any animations as a gib
215 // view just above the floor
216 self.view_ofs = '0 0 4';
218 Violence_GibSplash(self, 1, 1, attacker);
220 self.solid = SOLID_NOT; // restore later
221 self.takedamage = DAMAGE_NO; // restore later
222 self.damagedbycontents = false;
227 // If 0, default is used.
229 // Otherwise, g_str (default value) is used.
230 // For consistency, negative values there are mapped to zero too.
231 #define GAMETYPE_DEFAULTED_SETTING(str) \
232 ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
233 (gametype_setting_tmp < 0) ? 0 : \
234 (gametype_setting_tmp == 0) ? max(0, autocvar_g_##str) : \
235 gametype_setting_tmp)
238 void calculate_player_respawn_time()
243 float gametype_setting_tmp;
244 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
245 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
246 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
247 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
248 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
249 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
251 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
257 if (pl.team == self.team)
259 if (sdelay_small_count == 0)
260 sdelay_small_count = 1;
261 if (sdelay_large_count == 0)
262 sdelay_large_count = 1;
269 if (sdelay_small_count == 0)
273 // Players play independently. No point in requiring enemies.
274 sdelay_small_count = 1;
278 // Players play AGAINST each other. Enemies required.
279 sdelay_small_count = 2;
282 if (sdelay_large_count == 0)
286 // Players play independently. No point in requiring enemies.
287 sdelay_large_count = 1;
291 // Players play AGAINST each other. Enemies required.
292 sdelay_large_count = 2;
299 if (pcount <= sdelay_small_count)
300 sdelay = sdelay_small;
301 else if (pcount >= sdelay_large_count)
302 sdelay = sdelay_large;
303 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
304 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
307 self.respawn_time = ceil((time + sdelay) / waves) * waves;
309 self.respawn_time = time + sdelay;
311 if(sdelay < sdelay_max)
312 self.respawn_time_max = time + sdelay_max;
314 self.respawn_time_max = self.respawn_time;
316 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
317 self.respawn_countdown = 10; // first number to count down from is 10
319 self.respawn_countdown = -1; // do not count down
321 if(autocvar_g_forced_respawn)
322 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
325 void ClientKill_Now_TeamChange();
327 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
329 float take, save, dh, da, j;
331 float valid_damage_for_weaponstats;
334 dh = max(self.health, 0);
335 da = max(self.armorvalue, 0);
337 if(!DEATH_ISSPECIAL(deathtype))
339 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
341 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
344 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
346 // tuba causes blood to come out of the ears
351 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
353 makevectors(self.angles);
354 ear1 += v_right * -10;
355 ear2 += v_right * +10;
356 d = inflictor.origin - self.origin;
358 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
360 f = 0; // Assum ecenter.
361 force = v_right * vlen(force);
362 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
363 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
372 // force is already good
376 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
379 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
385 // don't reset pushltime for self damage as it may be an attempt to
386 // escape a lava pit or similar
387 //self.pushltime = 0;
390 else if(IS_PLAYER(attacker))
392 self.pusher = attacker;
393 self.pushltime = time + autocvar_g_maxpushtime;
394 self.istypefrag = self.BUTTON_CHAT;
396 else if(time < self.pushltime)
398 attacker = self.pusher;
399 self.pushltime = max(self.pushltime, time + 0.6);
407 frag_inflictor = inflictor;
408 frag_attacker = attacker;
410 frag_damage = damage;
413 damage_force = force;
414 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
415 take = bound(0, damage_take, self.health);
416 save = bound(0, damage_save, self.armorvalue);
417 excess = max(0, damage - take - save);
419 if(sound_allowed(MSG_BROADCAST, attacker))
422 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
424 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
426 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
430 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
432 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
434 if (time >= self.spawnshieldtime)
436 if (!(self.flags & FL_GODMODE))
438 self.armorvalue = self.armorvalue - save;
439 self.health = self.health - take;
440 // pause regeneration for 5 seconds
442 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
444 if (time > self.pain_finished) //Don't switch pain sequences like crazy
446 self.pain_finished = time + 0.5; //Supajoe
448 if(autocvar_sv_gentle < 1) {
449 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
451 if (!self.animstate_override)
454 animdecide_setaction(self, ANIMACTION_PAIN1, true);
456 animdecide_setaction(self, ANIMACTION_PAIN2, true);
460 if(sound_allowed(MSG_BROADCAST, attacker))
461 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
463 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
465 if(deathtype == DEATH_FALL)
466 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
467 else if(self.health > 75) // TODO make a "gentle" version?
468 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
469 else if(self.health > 50)
470 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
471 else if(self.health > 25)
472 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
474 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
479 // throw off bot aim temporarily
481 if(IS_BOT_CLIENT(self) && self.health >= 1)
483 shake = damage * 5 / (bound(0,skill,100) + 1);
484 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
485 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
486 self.v_angle_x = bound(-90, self.v_angle.x, 90);
490 self.max_armorvalue += (save + take);
492 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
493 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
494 self.dmg_inflictor = inflictor;
496 float abot, vbot, awep;
497 abot = (IS_BOT_CLIENT(attacker));
498 vbot = (IS_BOT_CLIENT(self));
500 valid_damage_for_weaponstats = 0;
503 if(vbot || IS_REAL_CLIENT(self))
504 if(abot || IS_REAL_CLIENT(attacker))
505 if(attacker && self != attacker)
506 if(DIFF_TEAM(self, attacker))
508 if(DEATH_ISSPECIAL(deathtype))
509 awep = attacker.weapon;
511 awep = DEATH_WEAPONOF(deathtype);
512 valid_damage_for_weaponstats = 1;
515 if(valid_damage_for_weaponstats)
517 dh = dh - max(self.health, 0);
518 da = da - max(self.armorvalue, 0);
519 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
524 float defer_ClientKill_Now_TeamChange;
525 defer_ClientKill_Now_TeamChange = false;
529 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
533 if(valid_damage_for_weaponstats)
534 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
536 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
537 if(sound_allowed(MSG_BROADCAST, attacker))
539 if(deathtype == DEATH_DROWN)
540 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
542 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
545 // get rid of kill indicator
546 if(self.killindicator)
548 remove(self.killindicator);
549 self.killindicator = world;
550 if(self.killindicator_teamchange)
551 defer_ClientKill_Now_TeamChange = true;
553 if(self.classname == "body")
554 if(deathtype == DEATH_KILL)
556 // for the lemmings fans, a small harmless explosion
557 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
561 // print an obituary message
562 if(self.classname != "body")
563 Obituary (attacker, inflictor, self, deathtype);
565 // increment frag counter for used weapon type
567 w = DEATH_WEAPONOF(deathtype);
569 if(accuracy_isgooddamage(attacker, self))
570 attacker.accuracy.(accuracy_frags[w-1]) += 1;
572 frag_attacker = attacker;
573 frag_inflictor = inflictor;
575 frag_deathtype = deathtype;
576 MUTATOR_CALLHOOK(PlayerDies);
578 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
580 RemoveGrapplingHook(self);
582 Portal_ClearAllLater(self);
584 self.fixangle = true;
586 if(defer_ClientKill_Now_TeamChange)
587 ClientKill_Now_TeamChange(); // can turn player into spectator
589 // player could have been miraculously resuscitated ;)
590 // e.g. players in freezetag get frozen, they don't really die
591 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
594 // when we get here, player actually dies
596 Unfreeze(self); // remove any icy remains
597 self.health = 0; // Unfreeze resets health, so we need to set it back
600 WaypointSprite_PlayerDead();
602 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
604 // become fully visible
605 self.alpha = default_player_alpha;
606 // make the corpse upright (not tilted)
610 self.avelocity = '0 0 0';
611 // view from the floor
612 self.view_ofs = '0 0 -8';
614 self.movetype = MOVETYPE_TOSS;
616 self.solid = SOLID_CORPSE;
617 self.ballistics_density = autocvar_g_ballistics_density_corpse;
618 // don't stick to the floor
619 self.flags &= ~FL_ONGROUND;
621 self.deadflag = DEAD_DYING;
623 // when to allow respawn
624 calculate_player_respawn_time();
626 self.death_time = time;
628 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
630 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
634 setsize(self, self.mins, self.maxs);
636 // set damage function to corpse damage
637 self.event_damage = PlayerCorpseDamage;
638 // call the corpse damage function just in case it wants to gib
639 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
641 // set up to fade out later
642 SUB_SetFade (self, time + 6 + random (), 1);
643 // reset body think wrapper broken by SUB_SetFade
644 if(self.classname == "body" && self.think != CopyBody_Think) {
645 self.CopyBody_think = self.think;
646 self.CopyBody_nextthink = self.nextthink;
647 self.think = CopyBody_Think;
648 self.nextthink = time;
651 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
653 // clones don't run any animation code any more, so we must gib them when they die :(
654 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
657 // reset fields the weapons may use just in case
658 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
660 WEP_ACTION(j, WR_RESETPLAYER);
661 ATTACK_FINISHED_FOR(self, j) = 0;
666 .float muted; // to be used by prvm_edictset server playernumber muted 1
667 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
668 // message "": do not say, just test flood control
674 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
676 var .float flood_field;
679 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
681 if(!teamsay && !privatesay)
682 if(substring(msgin, 0, 1) == " ")
683 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
685 msgin = formatmessage(msgin);
687 if (!IS_PLAYER(source))
688 colorstr = "^0"; // black for spectators
690 colorstr = Team_ColorCode(source.team);
697 if(intermission_running)
701 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
704 * using bprint solves this... me stupid
705 // how can we prevent the message from appearing in a listen server?
706 // for now, just give "say" back and only handle say_team
709 clientcommand(self, strcat("say ", msgin));
714 if(autocvar_g_chat_teamcolors)
715 namestr = playername(source);
717 namestr = source.netname;
719 if(strdecolorize(namestr) == namestr)
728 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
729 privatemsgprefixlen = strlen(msgstr);
730 msgstr = strcat(msgstr, msgin);
731 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
732 if(autocvar_g_chat_teamcolors)
733 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
735 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
739 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
740 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
744 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
747 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
751 msgstr = cmsgstr = "";
755 fullcmsgstr = cmsgstr;
759 flood_field = floodcontrol_chat;
768 flood_spl = autocvar_g_chat_flood_spl_tell;
769 flood_burst = autocvar_g_chat_flood_burst_tell;
770 flood_lmax = autocvar_g_chat_flood_lmax_tell;
771 flood_field = floodcontrol_chattell;
775 flood_spl = autocvar_g_chat_flood_spl_team;
776 flood_burst = autocvar_g_chat_flood_burst_team;
777 flood_lmax = autocvar_g_chat_flood_lmax_team;
778 flood_field = floodcontrol_chatteam;
782 flood_spl = autocvar_g_chat_flood_spl;
783 flood_burst = autocvar_g_chat_flood_burst;
784 flood_lmax = autocvar_g_chat_flood_lmax;
785 flood_field = floodcontrol_chat;
787 flood_burst = max(0, flood_burst - 1);
788 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
790 // do flood control for the default line size
793 getWrappedLine_remaining = msgstr;
796 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
798 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
801 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
803 if(getWrappedLine_remaining != "")
805 msgstr = strcat(msgstr, "\n");
809 if(time >= source.flood_field)
811 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
821 if(time >= source.flood_field)
822 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
827 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
828 source.flood_field = flood = 0;
831 if(flood == 2) // cannot happen for empty msgstr
833 if(autocvar_g_chat_flood_notify_flooder)
835 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
840 sourcemsgstr = fullmsgstr;
841 sourcecmsgstr = fullcmsgstr;
847 sourcemsgstr = msgstr;
848 sourcecmsgstr = cmsgstr;
852 if (!IS_PLAYER(source))
854 if (!intermission_running)
855 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
856 teamsay = -1; // spectators
860 print("NOTE: ", playername(source), "^7 is flooding.\n");
862 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
864 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
868 // always fake the message
873 if(autocvar_g_chat_flood_notify_flooder)
875 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
886 if(sourcemsgstr != "" && ret != 0)
888 if(ret < 0) // faked message, because the player is muted
890 sprint(source, sourcemsgstr);
891 if(sourcecmsgstr != "" && !privatesay)
892 centerprint(source, sourcecmsgstr);
894 else if(privatesay) // private message, between 2 people only
896 sprint(source, sourcemsgstr);
897 sprint(privatesay, msgstr);
898 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
900 centerprint(privatesay, cmsgstr);
902 else if(teamsay > 0) // team message, only sent to team mates
904 sprint(source, sourcemsgstr);
905 dedicated_print(msgstr); // send to server console too
906 if(sourcecmsgstr != "")
907 centerprint(source, sourcecmsgstr);
908 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
911 sprint(head, msgstr);
913 centerprint(head, cmsgstr);
916 else if(teamsay < 0) // spectator message, only sent to spectators
918 sprint(source, sourcemsgstr);
919 dedicated_print(msgstr); // send to server console too
920 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
922 sprint(head, msgstr);
924 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
926 sprint(source, sourcemsgstr);
927 dedicated_print(msgstr); // send to server console too
928 FOR_EACH_REALCLIENT(head)
930 sprint(head, msgstr);
933 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
939 float GetVoiceMessageVoiceType(string type)
942 return VOICETYPE_TAUNT;
943 if(type == "teamshoot")
944 return VOICETYPE_LASTATTACKER;
945 return VOICETYPE_TEAMRADIO;
948 string allvoicesamples;
949 .string GetVoiceMessageSampleField(string type)
951 GetPlayerSoundSampleField_notFound = 0;
954 #define _VOICEMSG(m) case #m: return playersound_##m;
958 GetPlayerSoundSampleField_notFound = 1;
959 return playersound_taunt;
962 .string GetPlayerSoundSampleField(string type)
964 GetPlayerSoundSampleField_notFound = 0;
967 #define _VOICEMSG(m) case #m: return playersound_##m;
971 GetPlayerSoundSampleField_notFound = 1;
972 return playersound_taunt;
975 void PrecacheGlobalSound(string samplestring)
978 tokenize_console(samplestring);
982 for(i = 1; i <= n; ++i)
983 precache_sound(strcat(argv(0), ftos(i), ".wav"));
987 precache_sound(strcat(argv(0), ".wav"));
991 void PrecachePlayerSounds(string f)
995 fh = fopen(f, FILE_READ);
998 while((s = fgets(fh)))
1000 if(tokenize_console(s) != 3)
1002 dprint("Invalid sound info line: ", s, "\n");
1005 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1009 if (!allvoicesamples)
1011 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1014 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1018 void ClearPlayerSounds()
1020 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1026 float LoadPlayerSounds(string f, float first)
1031 fh = fopen(f, FILE_READ);
1034 dprint("Player sound file not found: ", f, "\n");
1037 while((s = fgets(fh)))
1039 if(tokenize_console(s) != 3)
1041 field = GetPlayerSoundSampleField(argv(0));
1042 if(GetPlayerSoundSampleField_notFound)
1043 field = GetVoiceMessageSampleField(argv(0));
1044 if(GetPlayerSoundSampleField_notFound)
1047 strunzone(self.field);
1048 self.field = strzone(strcat(argv(1), " ", argv(2)));
1054 .float modelindex_for_playersound;
1055 .float skin_for_playersound;
1056 void UpdatePlayerSounds()
1058 if(self.modelindex == self.modelindex_for_playersound)
1059 if(self.skin == self.skin_for_playersound)
1061 self.modelindex_for_playersound = self.modelindex;
1062 self.skin_for_playersound = self.skin;
1063 ClearPlayerSounds();
1064 LoadPlayerSounds("sound/player/default.sounds", 1);
1065 if(!autocvar_g_debug_defaultsounds)
1066 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1067 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1070 void FakeGlobalSound(string sample, float chan, float voicetype)
1078 tokenize_console(sample);
1081 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1083 sample = strcat(argv(0), ".wav"); // randomization
1087 case VOICETYPE_LASTATTACKER_ONLY:
1089 case VOICETYPE_LASTATTACKER:
1093 if(IS_REAL_CLIENT(msg_entity))
1094 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1097 case VOICETYPE_TEAMRADIO:
1099 if(msg_entity.cvar_cl_voice_directional == 1)
1100 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1102 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1104 case VOICETYPE_AUTOTAUNT:
1109 if(autocvar_sv_gentle)
1111 tauntrand = random();
1113 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1115 if (msg_entity.cvar_cl_voice_directional >= 1)
1116 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1118 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1121 case VOICETYPE_TAUNT:
1123 if(self.deadflag == DEAD_NO)
1124 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1127 if(autocvar_sv_gentle)
1130 if (msg_entity.cvar_cl_voice_directional >= 1)
1131 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1133 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1135 case VOICETYPE_PLAYERSOUND:
1137 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1140 backtrace("Invalid voice type!");
1145 void GlobalSound(string sample, float chan, float voicetype)
1153 tokenize_console(sample);
1156 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1158 sample = strcat(argv(0), ".wav"); // randomization
1162 case VOICETYPE_LASTATTACKER_ONLY:
1165 msg_entity = self.pusher;
1166 if(IS_REAL_CLIENT(msg_entity))
1168 if(msg_entity.cvar_cl_voice_directional == 1)
1169 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1171 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1175 case VOICETYPE_LASTATTACKER:
1178 msg_entity = self.pusher;
1179 if(IS_REAL_CLIENT(msg_entity))
1181 if(msg_entity.cvar_cl_voice_directional == 1)
1182 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1184 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1187 if(IS_REAL_CLIENT(msg_entity))
1188 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1191 case VOICETYPE_TEAMRADIO:
1192 FOR_EACH_REALCLIENT(msg_entity)
1193 if(!teamplay || msg_entity.team == self.team)
1195 if(msg_entity.cvar_cl_voice_directional == 1)
1196 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1198 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1201 case VOICETYPE_AUTOTAUNT:
1206 if(autocvar_sv_gentle)
1208 tauntrand = random();
1209 FOR_EACH_REALCLIENT(msg_entity)
1210 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1212 if (msg_entity.cvar_cl_voice_directional >= 1)
1213 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1215 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1218 case VOICETYPE_TAUNT:
1220 if(self.deadflag == DEAD_NO)
1221 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1224 if(autocvar_sv_gentle)
1226 FOR_EACH_REALCLIENT(msg_entity)
1228 if (msg_entity.cvar_cl_voice_directional >= 1)
1229 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1231 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1234 case VOICETYPE_PLAYERSOUND:
1235 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1238 backtrace("Invalid voice type!");
1243 void PlayerSound(.string samplefield, float chan, float voicetype)
1245 GlobalSound(self.samplefield, chan, voicetype);
1248 void VoiceMessage(string type, string msg)
1251 float voicetype, ownteam;
1253 sample = GetVoiceMessageSampleField(type);
1255 if(GetPlayerSoundSampleField_notFound)
1257 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1261 voicetype = GetVoiceMessageVoiceType(type);
1262 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1264 flood = Say(self, ownteam, world, msg, 1);
1266 if(IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1267 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1269 GlobalSound(self.sample, CH_VOICE, voicetype);
1272 void MoveToTeam(entity client, float team_colour, float type)
1274 float lockteams_backup;
1276 lockteams_backup = lockteams; // backup any team lock
1278 lockteams = 0; // disable locked teams
1280 TeamchangeFrags(client); // move the players frags
1281 SetPlayerColors(client, team_colour - 1); // set the players colour
1282 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1284 lockteams = lockteams_backup; // restore the team lock
1286 LogTeamchange(client.playerid, client.team, type);