]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/player.qc
ab4b8edc38d1556435adf7c8aea56b006ad284e6
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / player.qc
1 #include "player.qh"
2
3 #include <common/effects/all.qh>
4 #include "bot/api.qh"
5 #include "cheats.qh"
6 #include "g_damage.qh"
7 #include "g_subs.qh"
8 #include "miscfunctions.qh"
9 #include "portals.qh"
10 #include "teamplay.qh"
11 #include "weapons/throwing.qh"
12 #include "command/common.qh"
13 #include "../common/state.qh"
14 #include "../common/anim.qh"
15 #include "../common/animdecide.qh"
16 #include "../common/csqcmodel_settings.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/triggers/subs.qh"
19 #include "../common/playerstats.qh"
20 #include "../lib/csqcmodel/sv_model.qh"
21
22 #include "../common/minigames/sv_minigames.qh"
23
24 #include "../common/physics/player.qh"
25 #include "../common/effects/qc/_mod.qh"
26 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
27 #include "../common/triggers/include.qh"
28 #include "../common/wepent.qh"
29
30 #include "weapons/weaponstats.qh"
31
32 #include "../common/animdecide.qh"
33
34 void Drop_Special_Items(entity player)
35 {
36         // called when the player has become stuck or frozen
37         // so objective items aren't stuck with the player
38
39         MUTATOR_CALLHOOK(DropSpecialItems, player);
40 }
41
42 void CopyBody_Think(entity this)
43 {
44         if(this.CopyBody_nextthink && time > this.CopyBody_nextthink)
45         {
46                 this.CopyBody_think(this);
47                 if(wasfreed(this))
48                         return;
49                 this.CopyBody_nextthink = this.nextthink;
50                 this.CopyBody_think = getthink(this);
51                 setthink(this, CopyBody_Think);
52         }
53         CSQCMODEL_AUTOUPDATE(this);
54         this.nextthink = time;
55 }
56 void CopyBody(entity this, float keepvelocity)
57 {
58         if (this.effects & EF_NODRAW)
59                 return;
60         entity clone = new(body);
61         clone.enemy = this;
62         clone.lip = this.lip;
63         clone.colormap = this.colormap;
64         clone.iscreature = this.iscreature;
65         clone.teleportable = this.teleportable;
66         clone.damagedbycontents = this.damagedbycontents;
67         if(clone.damagedbycontents)
68                 IL_PUSH(g_damagedbycontents, clone);
69         clone.angles = this.angles;
70         clone.v_angle = this.v_angle;
71         clone.avelocity = this.avelocity;
72         clone.damageforcescale = this.damageforcescale;
73         clone.effects = this.effects;
74         clone.glowmod = this.glowmod;
75         clone.event_damage = this.event_damage;
76         clone.anim_state = this.anim_state;
77         clone.anim_time = this.anim_time;
78         clone.anim_lower_action = this.anim_lower_action;
79         clone.anim_lower_time = this.anim_lower_time;
80         clone.anim_upper_action = this.anim_upper_action;
81         clone.anim_upper_time = this.anim_upper_time;
82         clone.anim_implicit_state = this.anim_implicit_state;
83         clone.anim_implicit_time = this.anim_implicit_time;
84         clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
85         clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
86         clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
87         clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
88         clone.dphitcontentsmask = this.dphitcontentsmask;
89         clone.death_time = this.death_time;
90         clone.pain_finished = this.pain_finished;
91         clone.health = this.health;
92         clone.armorvalue = this.armorvalue;
93         clone.armortype = this.armortype;
94         clone.model = this.model;
95         clone.modelindex = this.modelindex;
96         clone.skin = this.skin;
97         clone.species = this.species;
98         clone.move_qcphysics = false; // don't run gamecode logic on clones, too many
99         set_movetype(clone, this.move_movetype);
100         clone.solid = this.solid;
101         clone.takedamage = this.takedamage;
102         setcefc(clone, getcefc(this));
103         clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
104         clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
105         if (keepvelocity == 1)
106                 clone.velocity = this.velocity;
107         clone.oldvelocity = clone.velocity;
108         clone.alpha = this.alpha;
109         clone.fade_time = this.fade_time;
110         clone.fade_rate = this.fade_rate;
111         //clone.weapon = this.weapon;
112         setorigin(clone, this.origin);
113         setsize(clone, this.mins, this.maxs);
114         clone.reset = SUB_Remove;
115         clone._ps = this._ps;
116
117         Drag_MoveDrag(this, clone);
118
119         if(clone.colormap <= maxclients && clone.colormap > 0)
120                 clone.colormap = 1024 + this.clientcolors;
121
122         CSQCMODEL_AUTOINIT(clone);
123         clone.CopyBody_nextthink = this.nextthink;
124         clone.CopyBody_think = getthink(this);
125         clone.nextthink = time;
126         setthink(clone, CopyBody_Think);
127         // "bake" the current animation frame for clones (they don't get clientside animation)
128         animdecide_load_if_needed(clone);
129         animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
130
131         IL_PUSH(g_clones, clone);
132
133         MUTATOR_CALLHOOK(CopyBody, this, clone, keepvelocity);
134 }
135
136 void player_setupanimsformodel(entity this)
137 {
138         // load animation info
139         animdecide_load_if_needed(this);
140         animdecide_setstate(this, 0, false);
141 }
142
143 void player_anim(entity this)
144 {
145         int deadbits = (this.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
146         if(IS_DEAD(this)) {
147                 if (!deadbits) {
148                         // Decide on which death animation to use.
149                         if(random() < 0.5)
150                                 deadbits = ANIMSTATE_DEAD1;
151                         else
152                                 deadbits = ANIMSTATE_DEAD2;
153                 }
154         } else {
155                 // Clear a previous death animation.
156                 deadbits = 0;
157         }
158         int animbits = deadbits;
159         if(STAT(FROZEN, this))
160                 animbits |= ANIMSTATE_FROZEN;
161         if(this.move_movetype == MOVETYPE_FOLLOW)
162                 animbits |= ANIMSTATE_FOLLOW;
163         if(this.crouch)
164                 animbits |= ANIMSTATE_DUCK;
165         animdecide_setstate(this, animbits, false);
166         animdecide_setimplicitstate(this, IS_ONGROUND(this));
167 }
168
169 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
170 {
171         float take, save;
172         vector v;
173         Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
174
175         // damage resistance (ignore most of the damage from a bullet or similar)
176         damage = max(damage - 5, 1);
177
178         v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
179         take = v.x;
180         save = v.y;
181
182         if(sound_allowed(MSG_BROADCAST, attacker))
183         {
184                 if (save > 10)
185                         sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
186                 else if (take > 30)
187                         sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
188                 else if (take > 10)
189                         sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
190         }
191
192         if (take > 50)
193                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
194         if (take > 100)
195                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
196
197         this.armorvalue = this.armorvalue - save;
198         this.health = this.health - take;
199         // pause regeneration for 5 seconds
200         this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
201
202         this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
203         this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
204         this.dmg_inflictor = inflictor;
205
206         if (this.health <= -autocvar_sv_gibhealth && this.alpha >= 0)
207         {
208                 // don't use any animations as a gib
209                 this.frame = 0;
210                 // view just above the floor
211                 this.view_ofs = '0 0 4';
212
213                 Violence_GibSplash(this, 1, 1, attacker);
214                 this.alpha = -1;
215                 this.solid = SOLID_NOT; // restore later
216                 this.takedamage = DAMAGE_NO; // restore later
217                 if(this.damagedbycontents)
218                         IL_REMOVE(g_damagedbycontents, this);
219                 this.damagedbycontents = false;
220         }
221 }
222
223 void calculate_player_respawn_time(entity this)
224 {
225         if(g_ca)
226                 return;
227
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);
235
236         float pcount = 1;  // Include myself whether or not team is already set right and I'm a "player".
237         if (teamplay)
238         {
239                 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
240                         if(it.team == this.team)
241                                 ++pcount;
242                 });
243                 if (sdelay_small_count == 0)
244                         sdelay_small_count = 1;
245                 if (sdelay_large_count == 0)
246                         sdelay_large_count = 1;
247         }
248         else
249         {
250                 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
251                         ++pcount;
252                 });
253                 if (sdelay_small_count == 0)
254                 {
255                         if (IS_INDEPENDENT_PLAYER(this))
256                         {
257                                 // Players play independently. No point in requiring enemies.
258                                 sdelay_small_count = 1;
259                         }
260                         else
261                         {
262                                 // Players play AGAINST each other. Enemies required.
263                                 sdelay_small_count = 2;
264                         }
265                 }
266                 if (sdelay_large_count == 0)
267                 {
268                         if (IS_INDEPENDENT_PLAYER(this))
269                         {
270                                 // Players play independently. No point in requiring enemies.
271                                 sdelay_large_count = 1;
272                         }
273                         else
274                         {
275                                 // Players play AGAINST each other. Enemies required.
276                                 sdelay_large_count = 2;
277                         }
278                 }
279         }
280
281         float sdelay;
282
283         if (pcount <= sdelay_small_count)
284                 sdelay = sdelay_small;
285         else if (pcount >= sdelay_large_count)
286                 sdelay = sdelay_large;
287         else  // NOTE: this case implies sdelay_large_count > sdelay_small_count.
288                 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
289
290         if(waves)
291                 this.respawn_time = ceil((time + sdelay) / waves) * waves;
292         else
293                 this.respawn_time = time + sdelay;
294
295         if(sdelay < sdelay_max)
296                 this.respawn_time_max = time + sdelay_max;
297         else
298                 this.respawn_time_max = this.respawn_time;
299
300         if((sdelay + waves >= 5.0) && (this.respawn_time - time > 1.75))
301                 this.respawn_countdown = 10; // first number to count down from is 10
302         else
303                 this.respawn_countdown = -1; // do not count down
304
305         if(autocvar_g_forced_respawn)
306                 this.respawn_flags = this.respawn_flags | RESPAWN_FORCE;
307 }
308
309 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
310 {
311         float take, save, dh, da;
312         vector v;
313         float excess;
314
315         dh = max(this.health, 0);
316         da = max(this.armorvalue, 0);
317
318         if(!DEATH_ISSPECIAL(deathtype))
319         {
320                 damage *= Handicap_GetTotalHandicap(this);
321                 if (this != attacker && IS_PLAYER(attacker))
322                 {
323                         damage /= Handicap_GetTotalHandicap(attacker);
324                 }
325         }
326
327         if (time < this.spawnshieldtime && autocvar_g_spawnshield_blockdamage < 1)
328                 damage *= 1 - max(0, autocvar_g_spawnshield_blockdamage);
329
330         if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
331         {
332                 // tuba causes blood to come out of the ears
333                 vector ear1, ear2;
334                 vector d;
335                 float f;
336                 ear1 = this.origin;
337                 ear1_z += 0.125 * this.view_ofs.z + 0.875 * this.maxs.z; // 7/8
338                 ear2 = ear1;
339                 makevectors(this.angles);
340                 ear1 += v_right * -10;
341                 ear2 += v_right * +10;
342                 d = inflictor.origin - this.origin;
343                 if (d)
344                         f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
345                 else
346                         f = 0;  // Assum ecenter.
347                 force = v_right * vlen(force);
348                 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), this, attacker);
349                 Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), this, attacker);
350                 if(f > 0)
351                 {
352                         hitloc = ear1;
353                         force = force * -1;
354                 }
355                 else
356                 {
357                         hitloc = ear2;
358                         // force is already good
359                 }
360         }
361         else
362                 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
363
364         v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
365         take = v.x;
366         save = v.y;
367
368         if(attacker == this)
369         {
370                 // don't reset pushltime for this damage as it may be an attempt to
371                 // escape a lava pit or similar
372                 //this.pushltime = 0;
373                 this.istypefrag = 0;
374         }
375         else if(IS_PLAYER(attacker))
376         {
377                 this.pusher = attacker;
378                 this.pushltime = time + autocvar_g_maxpushtime;
379                 this.istypefrag = PHYS_INPUT_BUTTON_CHAT(this);
380         }
381         else if(time < this.pushltime)
382         {
383                 attacker = this.pusher;
384                 this.pushltime = max(this.pushltime, time + 0.6);
385         }
386         else
387         {
388                 this.pushltime = 0;
389                 this.istypefrag = 0;
390         }
391
392         MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, this, force, take, save, deathtype, damage);
393         take = bound(0, M_ARGV(4, float), this.health);
394         save = bound(0, M_ARGV(5, float), this.armorvalue);
395         excess = max(0, damage - take - save);
396
397         if(sound_allowed(MSG_BROADCAST, attacker))
398         {
399                 if (save > 10)
400                         sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
401                 else if (take > 30)
402                         sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
403                 else if (take > 10)
404                         sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
405         }
406
407         if (take > 50)
408                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
409         if (take > 100)
410                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
411
412         if (time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
413         {
414                 if (!(this.flags & FL_GODMODE))
415                 {
416                         this.armorvalue = this.armorvalue - save;
417                         this.health = this.health - take;
418                         // pause regeneration for 5 seconds
419                         if(take)
420                                 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
421
422                         if (time > this.pain_finished)          //Don't switch pain sequences like crazy
423                         {
424                                 this.pain_finished = time + 0.5;        //Supajoe
425
426                                 if(autocvar_sv_gentle < 1) {
427                                         if(this.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
428                                         {
429                                                 if (!this.animstate_override)
430                                                 {
431                                                         if (random() > 0.5)
432                                                                 animdecide_setaction(this, ANIMACTION_PAIN1, true);
433                                                         else
434                                                                 animdecide_setaction(this, ANIMACTION_PAIN2, true);
435                                                 }
436                                         }
437
438                                         if(sound_allowed(MSG_BROADCAST, attacker))
439                                         if(this.health < 25 || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || take > 20 || attacker != this)
440                                         if(this.health > 1)
441                                         // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
442                                         {
443                                                 if(deathtype == DEATH_FALL.m_id)
444                                                         PlayerSound(this, playersound_fall, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
445                                                 else if(this.health > 75)
446                                                         PlayerSound(this, playersound_pain100, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
447                                                 else if(this.health > 50)
448                                                         PlayerSound(this, playersound_pain75, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
449                                                 else if(this.health > 25)
450                                                         PlayerSound(this, playersound_pain50, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
451                                                 else
452                                                         PlayerSound(this, playersound_pain25, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
453                                         }
454                                 }
455                         }
456
457                         // throw off bot aim temporarily
458                         float shake;
459                         if(IS_BOT_CLIENT(this) && this.health >= 1)
460                         {
461                                 shake = damage * 5 / (bound(0,skill,100) + 1);
462                                 this.v_angle_x = this.v_angle.x + (random() * 2 - 1) * shake;
463                                 this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
464                                 this.v_angle_x = bound(-90, this.v_angle.x, 90);
465                         }
466                 }
467                 else
468                         this.max_armorvalue += (save + take);
469         }
470         this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
471         this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
472         this.dmg_inflictor = inflictor;
473
474         if (this != attacker) {
475                 float realdmg = damage - excess;
476                 if (IS_PLAYER(attacker)) {
477                         GameRules_scoring_add(attacker, DMG, realdmg);
478                 }
479                 if (IS_PLAYER(this)) {
480                         GameRules_scoring_add(this, DMGTAKEN, realdmg);
481                 }
482         }
483
484         bool abot = (IS_BOT_CLIENT(attacker));
485         bool vbot = (IS_BOT_CLIENT(this));
486
487         bool valid_damage_for_weaponstats = false;
488         Weapon awep = WEP_Null;
489         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
490
491         if(vbot || IS_REAL_CLIENT(this))
492         if(abot || IS_REAL_CLIENT(attacker))
493         if(attacker && this != attacker)
494         if(DIFF_TEAM(this, attacker))
495         {
496                 if(DEATH_ISSPECIAL(deathtype))
497                         awep = attacker.(weaponentity).m_weapon;
498                 else
499                         awep = DEATH_WEAPONOF(deathtype);
500                 valid_damage_for_weaponstats = true;
501         }
502
503         dh = dh - max(this.health, 0);
504         da = da - max(this.armorvalue, 0);
505         if(valid_damage_for_weaponstats)
506         {
507                 WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);
508         }
509
510         MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
511
512         if (this.health < 1)
513         {
514                 float defer_ClientKill_Now_TeamChange;
515                 defer_ClientKill_Now_TeamChange = false;
516
517                 if(this.alivetime)
518                 {
519                         PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
520                         this.alivetime = 0;
521                 }
522
523                 if(valid_damage_for_weaponstats)
524                         WeaponStats_LogKill(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot);
525
526                 if(autocvar_sv_gentle < 1)
527                 if(sound_allowed(MSG_BROADCAST, attacker))
528                 {
529                         if(deathtype == DEATH_DROWN.m_id)
530                                 PlayerSound(this, playersound_drown, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
531                         else
532                                 PlayerSound(this, playersound_death, CH_PAIN, VOL_BASE, VOICETYPE_PLAYERSOUND);
533                 }
534
535                 // get rid of kill indicator
536                 if(this.killindicator)
537                 {
538                         delete(this.killindicator);
539                         this.killindicator = NULL;
540                         if(CS(this).killindicator_teamchange)
541                                 defer_ClientKill_Now_TeamChange = true;
542
543                         if(this.classname == "body")
544                         if(deathtype == DEATH_KILL.m_id)
545                         {
546                                 // for the lemmings fans, a small harmless explosion
547                                 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
548                         }
549                 }
550
551                 // print an obituary message
552                 if(this.classname != "body")
553                         Obituary (attacker, inflictor, this, deathtype);
554
555         // increment frag counter for used weapon type
556         Weapon w = DEATH_WEAPONOF(deathtype);
557                 if(w != WEP_Null && accuracy_isgooddamage(attacker, this))
558                         CS(attacker).accuracy.(accuracy_frags[w.m_id-1]) += 1;
559
560                 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, this, deathtype, damage);
561                 damage = M_ARGV(4, float);
562                 excess = max(0, damage - take - save);
563
564                 //Weapon wep = this.(weaponentity).m_weapon;
565                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
566                 {
567                         .entity went = weaponentities[slot];
568                         if(!this.(weaponentity))
569                                 continue; // TODO: clones have no weapon, but we don't want to have to check this all the time
570                         Weapon wep = this.(weaponentity).m_weapon;
571                         wep.wr_playerdeath(wep, this, went);
572                 }
573
574                 RemoveGrapplingHooks(this);
575
576                 Portal_ClearAllLater(this);
577
578                 this.fixangle = true;
579
580                 if(defer_ClientKill_Now_TeamChange)
581                         ClientKill_Now_TeamChange(this); // can turn player into spectator
582
583                 // player could have been miraculously resuscitated ;)
584                 // e.g. players in freezetag get frozen, they don't really die
585                 if(this.health >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
586                         return;
587
588                 // when we get here, player actually dies
589
590                 Unfreeze(this); // remove any icy remains
591                 this.health = 0; // Unfreeze resets health, so we need to set it back
592
593                 // clear waypoints
594                 WaypointSprite_PlayerDead(this);
595                 // throw a weapon
596                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
597                 {
598                         .entity went = weaponentities[slot];
599                         SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, this.(went).m_weapon, went);
600                 }
601
602                 // become fully visible
603                 this.alpha = default_player_alpha;
604                 // make the corpse upright (not tilted)
605                 this.angles_x = 0;
606                 this.angles_z = 0;
607                 // don't spin
608                 this.avelocity = '0 0 0';
609                 // view from the floor
610                 this.view_ofs = '0 0 -8';
611                 // toss the corpse
612                 set_movetype(this, MOVETYPE_TOSS);
613                 // shootable corpse
614                 this.solid = SOLID_CORPSE;
615                 PS(this).ballistics_density = autocvar_g_ballistics_density_corpse;
616                 // don't stick to the floor
617                 UNSET_ONGROUND(this);
618                 // dying animation
619                 this.deadflag = DEAD_DYING;
620
621                 STAT(MOVEVARS_SPECIALCOMMAND, this) = false; // sweet release
622
623                 // when to allow respawn
624                 calculate_player_respawn_time(this);
625
626                 this.death_time = time;
627                 if (random() < 0.5)
628                         animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD1, true);
629                 else
630                         animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD2, true);
631                 if (this.maxs.z > 5)
632                 {
633                         this.maxs_z = 5;
634                         setsize(this, this.mins, this.maxs);
635                 }
636                 // set damage function to corpse damage
637                 this.event_damage = PlayerCorpseDamage;
638                 // call the corpse damage function just in case it wants to gib
639                 this.event_damage(this, inflictor, attacker, excess, deathtype, hitloc, force);
640
641                 // set up to fade out later
642                 SUB_SetFade (this, time + 6 + random (), 1);
643                 // reset body think wrapper broken by SUB_SetFade
644                 if(this.classname == "body" && getthink(this) != CopyBody_Think) {
645                         this.CopyBody_think = getthink(this);
646                         this.CopyBody_nextthink = this.nextthink;
647                         setthink(this, CopyBody_Think);
648                         this.nextthink = time;
649                 }
650
651                 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
652                         // remove corpse
653                         // clones don't run any animation code any more, so we must gib them when they die :(
654                         PlayerCorpseDamage(this, inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
655                 }
656
657                 // reset fields the weapons may use just in case
658                 if(this.classname != "body")
659                 {
660                         FOREACH(Weapons, it != WEP_Null,
661                         {
662                                 it.wr_resetplayer(it, this);
663                                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
664                                 {
665                                         ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
666                                 }
667                         });
668                 }
669                 MUTATOR_CALLHOOK(PlayerDied, this);
670         }
671 }
672
673 bool MoveToTeam(entity client, int team_colour, int type)
674 {
675         int lockteams_backup = lockteams;  // backup any team lock
676         lockteams = 0;  // disable locked teams
677         TeamchangeFrags(client);  // move the players frags
678         if (!SetPlayerTeamSimple(client, team_colour))
679         {
680                 return false;
681         }
682         Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0');  // kill the player
683         lockteams = lockteams_backup;  // restore the team lock
684         LogTeamchange(client.playerid, client.team, type);
685         return true;
686 }
687
688 /** print(), but only print if the server is not local */
689 void dedicated_print(string input)
690 {
691         if (server_is_dedicated) print(input);
692 }
693
694 void PrintToChat(entity player, string text)
695 {
696         text = strcat("\{1}^7", text, "\n");
697         sprint(player, text);
698 }
699
700 void DebugPrintToChat(entity player, string text)
701 {
702         if (autocvar_developer)
703         {
704                 PrintToChat(player, text);
705         }
706 }
707
708 void PrintToChatAll(string text)
709 {
710         text = strcat("\{1}^7", text, "\n");
711         bprint(text);
712 }
713
714 void DebugPrintToChatAll(string text)
715 {
716         if (autocvar_developer)
717         {
718                 PrintToChatAll(text);
719         }
720 }
721
722 void PrintToChatTeam(int teamnum, string text)
723 {
724         text = strcat("\{1}^7", text, "\n");
725         FOREACH_CLIENT(IS_REAL_CLIENT(it),
726         {
727                 if (it.team == teamnum)
728                 {
729                         sprint(it, text);
730                 }
731         });
732 }
733
734 void DebugPrintToChatTeam(int teamnum, string text)
735 {
736         if (autocvar_developer)
737         {
738                 PrintToChatTeam(teamnum, text);
739         }
740 }
741
742 /**
743  * message "": do not say, just test flood control
744  * return value:
745  *   1 = accept
746  *   0 = reject
747  *  -1 = fake accept
748  */
749 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol)
750 {
751         if (!teamsay && !privatesay && substring(msgin, 0, 1) == " ")
752         msgin = substring(msgin, 1, -1); // work around DP say bug (say_team does not have this!)
753
754     if(source)
755                 msgin = formatmessage(source, msgin);
756
757     string colorstr;
758         if (!IS_PLAYER(source))
759                 colorstr = "^0"; // black for spectators
760         else if(teamplay)
761                 colorstr = Team_ColorCode(source.team);
762         else
763         {
764                 colorstr = "";
765                 teamsay = false;
766         }
767
768         if(game_stopped)
769                 teamsay = false;
770
771     if (!source) {
772                 colorstr = "";
773                 teamsay = false;
774     }
775
776         if(msgin != "")
777                 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
778
779         /*
780          * using bprint solves this... me stupid
781         // how can we prevent the message from appearing in a listen server?
782         // for now, just give "say" back and only handle say_team
783         if(!teamsay)
784         {
785                 clientcommand(source, strcat("say ", msgin));
786                 return;
787         }
788         */
789
790     string namestr = "";
791     if (source)
792         namestr = playername(source, autocvar_g_chat_teamcolors);
793
794     string colorprefix = (strdecolorize(namestr) == namestr) ? "^3" : "^7";
795
796     string msgstr, cmsgstr;
797     string privatemsgprefix = string_null;
798     int privatemsgprefixlen = 0;
799         if (msgin == "") {
800         msgstr = cmsgstr = "";
801         } else {
802                 if(privatesay)
803                 {
804                         msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
805                         privatemsgprefixlen = strlen(msgstr);
806                         msgstr = strcat(msgstr, msgin);
807                         cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
808                         privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay, autocvar_g_chat_teamcolors), ": ^7");
809                 }
810                 else if(teamsay)
811                 {
812                         if(strstrofs(msgin, "/me", 0) >= 0)
813                         {
814                                 //msgin = strreplace("/me", "", msgin);
815                                 //msgin = substring(msgin, 3, strlen(msgin));
816                                 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
817                                 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
818                         }
819                         else
820                                 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
821                         cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
822                 }
823                 else
824                 {
825                         if(strstrofs(msgin, "/me", 0) >= 0)
826                         {
827                                 //msgin = strreplace("/me", "", msgin);
828                                 //msgin = substring(msgin, 3, strlen(msgin));
829                                 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
830                                 msgstr = strcat("\{1}^4* ", "^7", msgin);
831                         }
832                         else {
833                 msgstr = "\{1}";
834                 msgstr = strcat(msgstr, (namestr != "") ? strcat(colorprefix, namestr, "^7: ") : "^7");
835                 msgstr = strcat(msgstr, msgin);
836             }
837                         cmsgstr = "";
838                 }
839                 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
840         }
841
842         string fullmsgstr = msgstr;
843         string fullcmsgstr = cmsgstr;
844
845         // FLOOD CONTROL
846         int flood = 0;
847         var .float flood_field = floodcontrol_chat;
848         if(floodcontrol && source)
849         {
850                 float flood_spl;
851                 float flood_burst;
852                 float flood_lmax;
853                 float lines;
854                 if(privatesay)
855                 {
856                         flood_spl = autocvar_g_chat_flood_spl_tell;
857                         flood_burst = autocvar_g_chat_flood_burst_tell;
858                         flood_lmax = autocvar_g_chat_flood_lmax_tell;
859                         flood_field = floodcontrol_chattell;
860                 }
861                 else if(teamsay)
862                 {
863                         flood_spl = autocvar_g_chat_flood_spl_team;
864                         flood_burst = autocvar_g_chat_flood_burst_team;
865                         flood_lmax = autocvar_g_chat_flood_lmax_team;
866                         flood_field = floodcontrol_chatteam;
867                 }
868                 else
869                 {
870                         flood_spl = autocvar_g_chat_flood_spl;
871                         flood_burst = autocvar_g_chat_flood_burst;
872                         flood_lmax = autocvar_g_chat_flood_lmax;
873                         flood_field = floodcontrol_chat;
874                 }
875                 flood_burst = max(0, flood_burst - 1);
876                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
877
878                 // do flood control for the default line size
879                 if(msgstr != "")
880                 {
881                         getWrappedLine_remaining = msgstr;
882                         msgstr = "";
883                         lines = 0;
884                         while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
885                         {
886                                 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
887                                 ++lines;
888                         }
889                         msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
890
891                         if(getWrappedLine_remaining != "")
892                         {
893                                 msgstr = strcat(msgstr, "\n");
894                                 flood = 2;
895                         }
896
897                         if (time >= source.(flood_field))
898                         {
899                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
900                         }
901                         else
902                         {
903                                 flood = 1;
904                                 msgstr = fullmsgstr;
905                         }
906                 }
907                 else
908                 {
909                         if (time >= source.(flood_field))
910                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
911                         else
912                                 flood = 1;
913                 }
914
915                 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
916                         source.(flood_field) = flood = 0;
917         }
918
919     string sourcemsgstr, sourcecmsgstr;
920         if(flood == 2) // cannot happen for empty msgstr
921         {
922                 if(autocvar_g_chat_flood_notify_flooder)
923                 {
924                         sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
925                         sourcecmsgstr = "";
926                 }
927                 else
928                 {
929                         sourcemsgstr = fullmsgstr;
930                         sourcecmsgstr = fullcmsgstr;
931                 }
932                 cmsgstr = "";
933         }
934         else
935         {
936                 sourcemsgstr = msgstr;
937                 sourcecmsgstr = cmsgstr;
938         }
939
940         if (!privatesay && source && !IS_PLAYER(source))
941         {
942                 if (!game_stopped)
943                 if (teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage))
944                         teamsay = -1; // spectators
945         }
946
947         if(flood)
948                 LOG_INFO("NOTE: ", playername(source, true), "^7 is flooding.");
949
950         // build sourcemsgstr by cutting off a prefix and replacing it by the other one
951         if(privatesay)
952                 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
953
954     int ret;
955         if(source && CS(source).muted)
956         {
957                 // always fake the message
958                 ret = -1;
959         }
960         else if(flood == 1)
961         {
962                 if (autocvar_g_chat_flood_notify_flooder)
963                 {
964                         sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
965                         ret = 0;
966                 }
967                 else
968                         ret = -1;
969         }
970         else
971         {
972                 ret = 1;
973         }
974
975         if (privatesay && source && !IS_PLAYER(source))
976         {
977                 if (!game_stopped)
978                 if ((privatesay && !IS_PLAYER(privatesay)) || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !warmup_stage))
979                         ret = -1; // just hide the message completely
980         }
981
982         MUTATOR_CALLHOOK(ChatMessage, source, ret);
983         ret = M_ARGV(1, int);
984
985         if(sourcemsgstr != "" && ret != 0)
986         {
987                 if(ret < 0) // faked message, because the player is muted
988                 {
989                         sprint(source, sourcemsgstr);
990                         if(sourcecmsgstr != "" && !privatesay)
991                                 centerprint(source, sourcecmsgstr);
992                 }
993                 else if(privatesay) // private message, between 2 people only
994                 {
995                         sprint(source, sourcemsgstr);
996                         if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
997                         if(!MUTATOR_CALLHOOK(ChatMessageTo, privatesay, source))
998                         {
999                                 sprint(privatesay, msgstr);
1000                                 if(cmsgstr != "")
1001                                         centerprint(privatesay, cmsgstr);
1002                         }
1003                 }
1004                 else if ( teamsay && CS(source).active_minigame )
1005                 {
1006                         sprint(source, sourcemsgstr);
1007                         dedicated_print(msgstr); // send to server console too
1008                         FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && CS(it).active_minigame == CS(source).active_minigame && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
1009                 }
1010                 else if(teamsay > 0) // team message, only sent to team mates
1011                 {
1012                         sprint(source, sourcemsgstr);
1013                         dedicated_print(msgstr); // send to server console too
1014                         if(sourcecmsgstr != "")
1015                                 centerprint(source, sourcecmsgstr);
1016                         FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), {
1017                                 sprint(it, msgstr);
1018                                 if(cmsgstr != "")
1019                                         centerprint(it, cmsgstr);
1020                         });
1021                 }
1022                 else if(teamsay < 0) // spectator message, only sent to spectators
1023                 {
1024                         sprint(source, sourcemsgstr);
1025                         dedicated_print(msgstr); // send to server console too
1026                         FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
1027                 }
1028                 else
1029                 {
1030             if (source) {
1031                 sprint(source, sourcemsgstr);
1032                 dedicated_print(msgstr); // send to server console too
1033                 MX_Say(strcat(playername(source, true), "^7: ", msgin));
1034             }
1035             FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr));
1036         }
1037         }
1038
1039         return ret;
1040 }