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