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