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