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