]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/common.qc
Merge branch 'master' into Mario/entcs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / common.qc
1 #include "common.qh"
2
3 #include <common/t_items.qh>
4 #include <common/constants.qh>
5 #include <common/deathtypes/all.qh>
6 #include <common/notifications/all.qh>
7 #include <common/util.qh>
8 #include <common/weapons/_all.qh>
9 #include <common/items/_mod.qh>
10
11 void W_GiveWeapon(entity e, int wep)
12 {
13         if (!wep) return;
14
15         e.weapons |= WepSet_FromWeapon(Weapons_from(wep));
16
17         if (IS_PLAYER(e)) {
18             Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep);
19     }
20 }
21
22 void W_PlayStrengthSound(entity player) // void W_PlayStrengthSound
23 {
24         if((player.items & ITEM_Strength.m_itemid)
25                 && ((time > player.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam
26                 || (time > player.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold)))
27                 {
28                         sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM);
29                         player.prevstrengthsound = time;
30                 }
31                 player.prevstrengthsoundattempt = time;
32 }
33
34 float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
35 {
36         float is_from_contents = (deathtype == DEATH_SLIME.m_id || deathtype == DEATH_LAVA.m_id);
37         float is_from_owner = (inflictor == projowner);
38         float is_from_exception = (exception != -1);
39
40         //dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n")));
41
42         if(autocvar_g_projectiles_damage <= -2)
43         {
44                 return false; // no damage to projectiles at all, not even with the exceptions
45         }
46         else if(autocvar_g_projectiles_damage == -1)
47         {
48                 if(is_from_exception)
49                         return (exception); // if exception is detected, allow it to override
50                 else
51                         return false; // otherwise, no other damage is allowed
52         }
53         else if(autocvar_g_projectiles_damage == 0)
54         {
55                 if(is_from_exception)
56                         return (exception); // if exception is detected, allow it to override
57                 else if(!is_from_contents)
58                         return false; // otherwise, only allow damage from contents
59         }
60         else if(autocvar_g_projectiles_damage == 1)
61         {
62                 if(is_from_exception)
63                         return (exception); // if exception is detected, allow it to override
64                 else if(!(is_from_contents || is_from_owner))
65                         return false; // otherwise, only allow self damage and damage from contents
66         }
67         else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
68         {
69                 if(is_from_exception)
70                         return (exception); // if exception is detected, allow it to override
71         }
72
73         return true; // if none of these return, then allow damage anyway.
74 }
75
76 void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
77 {
78         this.takedamage = DAMAGE_NO;
79         this.event_damage = func_null;
80
81         if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
82         {
83                 this.owner = attacker;
84                 this.realowner = attacker;
85         }
86
87         MUTATOR_CALLHOOK(PrepareExplosionByDamage, this, attacker);
88
89         // do not explode NOW but in the NEXT FRAME!
90         // because recursive calls to RadiusDamage are not allowed
91         this.nextthink = time;
92         setthink(this, explode);
93 }